:root {
  color-scheme: light;
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --ink: #17221c;
  --muted: #66736c;
  --line: #dbe3de;
  --brand: #176b4d;
  --brand-dark: #0e5339;
  --brand-soft: #e7f3ed;
  --danger: #b83a3a;
  --danger-soft: #fff0f0;
  --success: #21734f;
  --warning: #9a6414;
  --warning-soft: #fff8e8;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 0; overflow-x: hidden; }
body { min-width: 0; margin: 0; background: var(--bg); color: var(--ink); }
button, select, input { font: inherit; }
button, select, .file-button { min-height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); padding: .6rem 1rem; cursor: pointer; }
button:hover, select:hover, .file-button:hover { border-color: var(--brand); }
button:focus-visible, select:focus-visible, input:focus-visible, .file-button:focus-visible { outline: 3px solid rgba(23, 107, 77, .25); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .55; }
button.primary { color: white; border-color: var(--brand); background: var(--brand); }
button.primary:hover { border-color: var(--brand-dark); background: var(--brand-dark); }
button.success { color: white; border-color: var(--success); background: var(--success); }
button.danger { color: white; border-color: var(--danger); background: var(--danger); }
button.subtle-button { color: var(--muted); background: transparent; }
[hidden] { display: none !important; }

.app-header { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; min-width: 0; padding: 1.25rem max(1rem, 5vw); border-bottom: 1px solid var(--line); background: var(--surface); }
.brand-block, .section-heading > div, .dashboard-columns, .settings-card, .subsection, .question-card { min-width: 0; }
.eyebrow { margin: 0 0 .35rem; color: var(--brand); font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(1.35rem, 2.4vw, 2rem); }
h2 { margin: 0; font-size: clamp(1.2rem, 2vw, 1.55rem); }
h3 { margin: 0; font-size: 1rem; }
.header-caption { max-width: 48rem; margin: .4rem 0 0; color: var(--muted); font-size: .92rem; }
.main-nav { display: flex; flex-wrap: wrap; gap: .5rem; }
.nav-button { border-color: transparent; background: transparent; }
.nav-button.is-active { color: var(--brand); border-color: var(--brand-soft); background: var(--brand-soft); font-weight: 700; }

.app-main { width: min(1180px, calc(100% - 2rem)); min-width: 0; margin: 1.5rem auto 4rem; }
.view { min-width: 0; border: 1px solid var(--line); border-radius: 18px; padding: clamp(1rem, 3vw, 2rem); background: var(--surface); box-shadow: 0 8px 30px rgba(23, 34, 28, .035); }
.section-heading, .practice-toolbar, .subsection-heading, .answer-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; min-width: 0; }
.section-heading { margin-bottom: 1.5rem; }
.result-count { flex: 0 0 auto; color: var(--muted); font-size: .9rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
.stat-card { display: grid; gap: .4rem; min-width: 0; border: 1px solid var(--line); border-radius: 14px; padding: 1rem; background: var(--surface-muted); }
.stat-label { color: var(--muted); font-size: .88rem; }
.stat-card strong { font-size: clamp(1.4rem, 3vw, 2rem); }
.dashboard-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1rem; }
.subsection, .settings-card { border: 1px solid var(--line); border-radius: 14px; padding: 1rem; background: var(--surface-muted); }
.subsection-heading { margin-bottom: .75rem; }
.stats-list { display: grid; gap: .65rem; }
.stats-list > * { min-width: 0; }

.filter-bar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.filter-bar label { display: grid; gap: .35rem; min-width: 0; color: var(--muted); font-size: .86rem; font-weight: 600; }
.filter-bar select { width: 100%; min-width: 0; }
.question-list { display: grid; min-width: 0; }
.question-row { display: grid; gap: .5rem; min-width: 0; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.question-row:first-child { padding-top: 0; }
.question-row:last-child { border-bottom: 0; }
.question-row-title, .question-row-meta, .question-row-progress { min-width: 0; overflow-wrap: anywhere; }
.question-row-title { font-weight: 700; line-height: 1.55; }
.question-row-meta, .question-row-progress { color: var(--muted); font-size: .88rem; }

.practice-toolbar { align-items: center; margin-bottom: 1rem; }
.practice-meta { color: var(--muted); font-size: .9rem; text-align: right; overflow-wrap: anywhere; }
.question-card { margin-bottom: 1.25rem; }
.question-card, .question-card p, .question-card li, .answer-content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.8; }
.question-card-placeholder, .empty-state { color: var(--muted); }
.question-card-placeholder { border: 1px dashed var(--line); border-radius: 12px; padding: 2rem 1rem; text-align: center; }
.question-number { margin: 0 0 .65rem; color: var(--brand); font-size: .9rem; font-weight: 700; }
.question-stem { margin: 0 0 1rem; font-size: 1.12rem; font-weight: 700; }
.question-options { margin: 0; padding-left: 1.5rem; }
.answer-panel { min-width: 0; border: 1px solid var(--brand-soft); border-radius: 14px; padding: 1rem; background: var(--brand-soft); }
.answer-heading { align-items: center; margin-bottom: .65rem; }
.answer-content { min-width: 0; }
.practice-actions, .button-row { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; }
.practice-actions { margin-top: 1.25rem; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.settings-card { display: grid; align-content: start; gap: .85rem; }
.settings-card p { margin: 0; color: var(--muted); line-height: 1.65; }
.warning-card { border-color: #ead7a9; background: var(--warning-soft); }
.file-button { display: inline-flex; align-items: center; justify-content: center; }
#import-input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; clip-path: inset(50%); }
.toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 10; max-width: min(28rem, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; background: var(--surface); box-shadow: 0 12px 30px rgba(23, 34, 28, .15); overflow-wrap: anywhere; }
.toast.error { color: var(--danger); border-color: #efbdbd; background: var(--danger-soft); }

@media (max-width: 720px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .main-nav { width: 100%; }
  .main-nav button { flex: 1 1 auto; }
  .app-main { width: min(100% - 1rem, 1180px); margin-top: .75rem; }
  .view { border-radius: 14px; padding: 1rem; }
  .dashboard-columns, .settings-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .practice-toolbar { align-items: flex-start; flex-direction: column; }
  .practice-meta { text-align: left; }
}

@media (max-width: 440px) {
  .filter-bar { grid-template-columns: minmax(0, 1fr); }
  .practice-actions > button, .button-row > button, .button-row > .file-button { width: 100%; }
}
