:root {
  color-scheme: light;
  --bg: #f4f2ec;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #202225;
  --muted: #686d73;
  --line: #ded9ce;
  --accent: #176b63;
  --accent-dark: #0f4d47;
  --good: #197640;
  --bad: #b33a2f;
  --warn: #996400;
  --shadow: 0 18px 45px rgba(31, 35, 40, 0.09);
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    linear-gradient(120deg, rgba(23, 107, 99, 0.08), transparent 34%),
    linear-gradient(0deg, rgba(166, 133, 76, 0.08), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  padding: 20px;
  background: rgba(255, 253, 248, 0.72);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.panel {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.panel-title {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mode-button,
.system-button,
.primary-button,
.secondary-button,
.icon-button,
.option-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.mode-button {
  min-height: 38px;
  font-size: 14px;
}

.mode-button.active,
.system-button.active {
  background: rgba(23, 107, 99, 0.12);
  border-color: rgba(23, 107, 99, 0.55);
  color: var(--accent-dark);
}

.systems-panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.systems-panel .panel-title {
  flex: 0 0 auto;
}

.system-list {
  display: grid;
  flex: 1 1 auto;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.system-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 9px 10px;
  text-align: left;
}

.system-button strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.system-button span {
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: 28px;
  min-width: 0;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.scope-label {
  color: var(--accent-dark);
  font-size: 15px;
  font-weight: 700;
}

.progress-label {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}

.top-actions,
.question-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 40px;
  padding: 0 14px;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button:hover,
.icon-button:hover,
.option-button:hover,
.system-button:hover,
.mode-button:hover {
  border-color: rgba(23, 107, 99, 0.55);
  transform: translateY(-1px);
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

.stats-strip {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stats-strip div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.75);
  padding: 13px 14px;
}

.stats-strip strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
}

.stats-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.question-card {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
  max-width: 1040px;
  overflow: hidden;
}

.question-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 8px;
}

.question-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.question-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 13px;
}

#answerStateLabel.correct {
  color: var(--good);
  border-color: rgba(25, 118, 64, 0.35);
}

#answerStateLabel.wrong {
  color: var(--bad);
  border-color: rgba(179, 58, 47, 0.35);
}

#reviewLabel {
  color: var(--warn);
  border-color: rgba(153, 100, 0, 0.35);
}

#mediaLabel {
  color: #8a4b00;
  border-color: rgba(138, 75, 0, 0.35);
}

#questionStem {
  margin: 0 0 20px;
  font-size: 25px;
  line-height: 1.55;
  letter-spacing: 0;
}

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

.option-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  padding: 14px;
  text-align: left;
  line-height: 1.55;
  background: #fffdf8;
}

.option-key {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #e9e4d9;
  color: var(--ink);
  font-weight: 700;
}

.option-button.correct {
  border-color: rgba(25, 118, 64, 0.55);
  background: rgba(25, 118, 64, 0.08);
}

.option-button.wrong {
  border-color: rgba(179, 58, 47, 0.55);
  background: rgba(179, 58, 47, 0.08);
}

.feedback {
  margin-top: 18px;
  border: 1px solid rgba(23, 107, 99, 0.24);
  border-radius: 8px;
  background: rgba(23, 107, 99, 0.07);
  padding: 16px;
}

.feedback.hidden {
  display: none;
}

.feedback-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--accent-dark);
}

.feedback p {
  margin: 10px 0 0;
  line-height: 1.75;
}

.detailed-explanation {
  margin-top: 14px;
}

.eye-focus {
  border-top: 1px solid rgba(23, 107, 99, 0.18);
  padding-top: 12px;
}

.eye-focus h3 {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 15px;
}

.eye-focus p,
.eye-focus ul {
  margin: 0;
  line-height: 1.75;
}

.eye-focus .eye-trigger {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-weight: 700;
}

.eye-focus .logic-extra {
  margin-top: 8px;
  color: #4f565e;
}

.eye-focus ul {
  margin-bottom: 8px;
  padding-left: 1.2em;
}

.quality-notes {
  margin-top: 14px;
  border-top: 1px solid rgba(153, 100, 0, 0.22);
  padding-top: 12px;
  color: #5b4a2f;
}

.quality-notes strong {
  color: var(--warn);
}

.quality-notes ul {
  margin: 8px 0 0;
  padding-left: 1.2em;
  line-height: 1.65;
}

.question-actions {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 18px;
}

@media (max-width: 860px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    min-height: 0;
    max-height: none;
    padding: calc(8px + env(safe-area-inset-top)) 12px 7px;
  }

  .brand {
    gap: 10px;
    margin-bottom: 8px;
  }

  .brand h1 {
    font-size: 22px;
    line-height: 1;
  }

  .brand p {
    margin-top: 4px;
    font-size: 12px;
  }

  .panel {
    margin-top: 7px;
    padding-top: 0;
    border-top: 0;
  }

  .panel-title {
    display: none;
  }

  .mode-grid {
    gap: 6px;
  }

  .mode-button {
    min-height: 32px;
    border-radius: 999px;
    font-size: 14px;
  }

  .systems-panel {
    flex: 0 0 auto;
    min-height: 0;
  }

  .system-list {
    display: flex;
    gap: 6px;
    min-height: 0;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 2px 4px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .system-button {
    flex: 0 0 auto;
    grid-template-columns: minmax(0, auto) auto;
    min-height: 34px;
    max-width: 220px;
    border-radius: 999px;
    padding: 6px 10px;
    scroll-snap-align: start;
  }

  .system-button strong {
    max-width: 150px;
    font-size: 14px;
  }

  .system-button span {
    font-size: 12px;
  }

  .workspace {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
  }

  .top-actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .scope-label {
    font-size: 15px;
    line-height: 1.25;
  }

  .progress-label {
    margin-top: 2px;
    font-size: 12px;
    line-height: 1.35;
  }

  .stats-strip {
    display: none;
  }

  .question-card {
    flex: 1 1 auto;
    min-height: 0;
    max-width: none;
    border-radius: 10px;
    box-shadow: none;
    padding: 12px;
  }

  .question-scroll {
    padding-right: 2px;
  }

  .question-meta {
    gap: 6px;
    margin-bottom: 8px;
  }

  .question-meta span {
    padding: 3px 8px;
    font-size: 12px;
  }

  #questionStem {
    margin-bottom: 10px;
    font-size: 18px;
    line-height: 1.45;
  }

  .options-list {
    gap: 8px;
  }

  .option-button {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
    border-radius: 10px;
    padding: 10px;
    line-height: 1.45;
  }

  .option-key {
    width: 28px;
    height: 28px;
  }

  .feedback {
    margin-top: 12px;
    padding: 12px;
  }

  .feedback-head {
    flex-direction: column;
    gap: 4px;
  }

  .feedback p,
  .eye-focus p,
  .eye-focus ul,
  .quality-notes ul {
    line-height: 1.65;
  }

  .primary-button,
  .secondary-button,
  .icon-button {
    min-height: 36px;
    padding: 0 10px;
    white-space: nowrap;
  }

  .icon-button {
    width: 40px;
  }

  .question-actions {
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
  }

  .question-actions .secondary-button {
    flex: 1 1 0;
    min-width: 0;
  }
}
