:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef4fb;
  --text: #17202a;
  --muted: #607083;
  --line: #d9e3ee;
  --accent: #2d6cdf;
  --accent-strong: #174fb2;
  --green: #20a464;
  --green-soft: #e8f7ef;
  --red: #d34c4c;
  --red-soft: #fdecec;
  --shadow: 0 18px 50px rgba(42, 65, 94, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background:
    radial-gradient(circle at 0 0, rgba(45, 108, 223, 0.12), transparent 30rem),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 48%, #eef4fb 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 136px;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 12px 0 32px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.study-main {
  min-width: 0;
}

.stats-rail {
  align-self: start;
  position: sticky;
  top: 12px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-width: 0;
}

.stats div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.stats span {
  display: block;
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1;
}

.stats small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 0 10px;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented button,
.plain-button,
.primary-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  color: var(--text);
  background: transparent;
  transition:
    transform 160ms ease,
    background 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.segmented button:disabled,
.plain-button:disabled,
.primary-button:disabled,
.danger-button:disabled,
.option-button:disabled {
  cursor: default;
}

.segmented button.is-active,
.primary-button {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(45, 108, 223, 0.24);
}

.plain-button {
  border: 1px solid var(--line);
  background: var(--surface);
}

.danger-button {
  color: var(--red);
  border: 1px solid rgba(211, 76, 76, 0.35);
  background: var(--red-soft);
}

.segmented button:hover,
.plain-button:hover,
.primary-button:hover,
.danger-button:hover,
.option-button:hover {
  transform: translateY(-1px);
}

.filters {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.sync-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding-left: 4px;
}

#syncStatus {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

#syncStatus.is-on {
  color: #0c6337;
}

#syncStatus.is-pending,
#syncStatus.is-syncing {
  color: var(--accent-strong);
}

#syncStatus.is-error {
  color: var(--red);
}

.compact-button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select,
.fill-input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}

.workspace {
  animation: rise-in 240ms ease both;
}

.question-panel,
.review-item,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.question-panel {
  min-height: 0;
  overflow: hidden;
}

.question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: linear-gradient(90deg, #eaf2ff 0%, #f8fbff 100%);
  border-bottom: 1px solid var(--line);
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.pill.is-wrong {
  color: var(--red);
  background: var(--red-soft);
}

.pill.is-starred {
  color: #8a5a00;
  background: #fff4d6;
}

.question-body {
  padding: 22px 24px 20px;
}

.stem {
  margin-bottom: 18px;
  font-size: clamp(1.08rem, 1.7vw, 1.35rem);
  line-height: 1.72;
  white-space: pre-wrap;
}

.options {
  display: grid;
  gap: 10px;
}

.option-button {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  transition:
    transform 160ms ease,
    border 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.option-button strong {
  margin-right: 8px;
}

.option-button.is-selected {
  color: var(--accent-strong);
  border-color: rgba(45, 108, 223, 0.55);
  background: #eaf2ff;
}

.option-button.is-correct {
  color: #0c6337;
  border-color: rgba(32, 164, 100, 0.35);
  background: var(--green-soft);
}

.option-button.is-wrong {
  color: #8d2222;
  border-color: rgba(211, 76, 76, 0.35);
  background: var(--red-soft);
}

.star-button {
  color: #8a5a00;
  border-color: rgba(188, 132, 32, 0.38);
  background: #fff9eb;
}

.star-button.is-starred {
  color: #684000;
  background: #fff0bd;
}

.fill-grid {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.fill-grid label {
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
}

.fill-input {
  width: 100%;
  min-height: 52px;
  font-size: 1rem;
}

.fill-input.is-correct {
  border-color: rgba(32, 164, 100, 0.5);
  background: var(--green-soft);
}

.fill-input.is-wrong {
  border-color: rgba(211, 76, 76, 0.48);
  background: var(--red-soft);
}

.feedback {
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.feedback.is-correct {
  color: #0c6337;
  background: var(--green-soft);
}

.feedback.is-wrong {
  color: #8d2222;
  background: var(--red-soft);
}

.feedback p {
  margin-bottom: 8px;
}

.answer-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 1.2rem;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.actions-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.review-list {
  display: grid;
  gap: 14px;
}

.review-item {
  padding: 20px;
  box-shadow: none;
}

.review-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.review-stem {
  margin-bottom: 14px;
  font-size: 1.05rem;
  line-height: 1.8;
}

.review-options {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.review-option,
.answer-chip {
  border-radius: 8px;
  padding: 10px 12px;
  background: #f4f7fb;
}

.review-option.is-answer,
.answer-chip {
  color: #0c6337;
  background: var(--green-soft);
}

.answer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.empty-state {
  min-height: 260px;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 32px;
  text-align: center;
  box-shadow: none;
}

.empty-state p {
  color: var(--muted);
}

.is-hidden {
  display: none !important;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    width: min(100% - 18px, 1120px);
    padding-top: 10px;
    padding-bottom: 28px;
  }

  .stats-rail {
    order: -1;
    position: static;
    margin-bottom: 10px;
  }

  .stats {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-width: 0;
    gap: 6px;
  }

  .stats div {
    min-height: 56px;
    padding: 8px 6px;
  }

  .stats span {
    font-size: 1.18rem;
  }

  .stats small {
    margin-top: 5px;
    font-size: 0.72rem;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 0 0 10px;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    width: 100%;
    min-height: 48px;
  }

  .filters {
    justify-content: stretch;
  }

  .filters label {
    flex: 1 1 150px;
  }

  .sync-control {
    width: 100%;
    justify-content: space-between;
    padding-left: 0;
  }

  .compact-button {
    min-height: 48px;
  }

  select {
    width: 100%;
    min-height: 48px;
  }

  .question-head,
  .review-head,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .question-body {
    padding: 20px 14px 18px;
  }

  .question-panel {
    min-height: auto;
  }

  .stem {
    font-size: 1.08rem;
    line-height: 1.82;
  }

  .option-button {
    min-height: 56px;
    padding: 13px 14px;
    font-size: 1rem;
  }

  .fill-input {
    min-height: 52px;
  }

  .actions-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .actions-group .plain-button,
  .actions-group .danger-button,
  .primary-button {
    width: 100%;
    min-height: 48px;
    padding: 0 10px;
  }

  .review-item,
  .empty-state {
    padding: 16px 14px;
  }
}

@media (max-width: 430px) {
  .stats {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .stats div {
    min-height: 54px;
    padding: 8px 4px;
  }

  .stats span {
    font-size: 1.05rem;
  }

  .stats small {
    font-size: 0.68rem;
  }

  .question-head {
    padding: 14px;
  }

  .pill {
    font-size: 0.78rem;
  }

  .actions-group {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) {
  .segmented button:hover,
  .plain-button:hover,
  .primary-button:hover,
  .danger-button:hover,
  .option-button:hover {
    transform: none;
  }
}
