:root {
  color-scheme: light;
  --yellow: #f6bd16;
  --yellow-strong: #d99700;
  --yellow-soft: #fff2b8;
  --ink: #23210f;
  --muted: #6d6757;
  --line: #e9dfc2;
  --paper: #fffdf7;
  --surface: #ffffff;
  --teal: #0f766e;
  --coral: #c7502f;
  --gray: #f4f4f0;
  --shadow: 0 16px 40px rgba(76, 57, 13, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100svh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(158px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  border-bottom: 1px solid rgba(35, 33, 15, 0.08);
  background: rgba(255, 253, 247, 0.92);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  color: var(--ink);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 20px;
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.topnav {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.topnav a {
  min-width: 52px;
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.topnav a:hover,
.topnav a:focus-visible {
  background: var(--yellow-soft);
  color: var(--ink);
  outline: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px 20px 28px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.practice-panel,
.topics-panel,
.library-panel,
.review-panel,
.structure-panel,
.coach-panel {
  padding: 18px;
}

.practice-panel {
  border-top: 8px solid var(--yellow);
}

.coach-panel {
  position: sticky;
  top: 86px;
  align-self: start;
}

.topics-panel,
.library-panel,
.review-panel {
  grid-column: 1 / -1;
}

.structure-panel {
  align-self: start;
}

.section-heading {
  display: flex;
  gap: 16px;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.compact-heading {
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--yellow-strong);
  font-size: 12px;
  font-weight: 800;
}

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

h1,
h2 {
  margin-bottom: 0;
  line-height: 1.18;
}

h1 {
  max-width: 720px;
  font-size: clamp(28px, 4vw, 48px);
}

h2 {
  font-size: 22px;
}

h3 {
  margin-bottom: 8px;
  font-size: 17px;
}

.timer {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--gray);
}

#timerLabel {
  min-width: 54px;
  color: var(--ink);
  font-weight: 800;
  text-align: center;
}

.question-card {
  display: flex;
  gap: 16px;
  align-items: start;
  justify-content: space-between;
  min-height: 138px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid rgba(35, 33, 15, 0.14);
  border-radius: var(--radius);
  background: var(--yellow-soft);
}

.question-card h2 {
  margin: 8px 0 8px;
  font-size: 30px;
}

.question-card p {
  margin-bottom: 0;
  max-width: 760px;
  color: #3f3b2d;
  font-size: 18px;
}

.topic-pill,
.tag,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
}

.answer-input {
  display: block;
  width: 100%;
  min-height: 220px;
  resize: vertical;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
  color: var(--ink);
  outline: none;
}

.answer-input:focus,
.search-input:focus,
.select-input:focus {
  border-color: var(--yellow-strong);
  box-shadow: 0 0 0 3px rgba(246, 189, 22, 0.24);
}

.input-tools,
.coach-actions,
.library-actions,
.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.input-tools {
  margin-top: 12px;
}

#wordStats {
  margin-right: auto;
  color: var(--muted);
  font-size: 14px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 8px 13px;
  font-weight: 800;
}

.primary-button {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: #000;
  outline: none;
}

.secondary-button {
  border-color: var(--ink);
  background: var(--yellow);
  color: var(--ink);
}

.secondary-button:hover,
.secondary-button:focus-visible {
  background: #ffd84a;
  outline: none;
}

.ghost-button,
.icon-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.ghost-button:hover,
.ghost-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--yellow-strong);
  background: var(--yellow-soft);
  outline: none;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--gray);
}

.tab-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab-button.active {
  background: var(--yellow);
  color: var(--ink);
}

.sample-answer {
  min-height: 420px;
  max-height: 58svh;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
}

.sample-answer p,
.sample-answer li {
  color: #3e3929;
}

.sample-answer ul {
  padding-left: 20px;
}

.sample-answer blockquote {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-left: 5px solid var(--yellow);
  background: var(--gray);
  color: var(--ink);
}

.coach-actions {
  margin-top: 12px;
}

.search-input,
.select-input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.search-input {
  width: min(320px, 100%);
  padding: 9px 12px;
}

.select-input {
  padding: 9px 34px 9px 12px;
}

.category-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
}

.category-button {
  flex: 0 0 auto;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 8px 12px;
  font-weight: 800;
}

.category-button.active {
  border-color: var(--ink);
  background: var(--yellow);
  color: var(--ink);
}

.topic-grid,
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.topic-card,
.library-card {
  display: flex;
  flex-direction: column;
  min-height: 230px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.topic-card:hover,
.library-card:hover {
  border-color: var(--yellow-strong);
  box-shadow: 0 10px 26px rgba(76, 57, 13, 0.1);
}

.topic-card .meta-row,
.library-card .meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
}

.topic-card h3,
.library-card h3 {
  margin: 0 0 8px;
}

.topic-card p,
.library-card p {
  margin-bottom: 10px;
  color: var(--muted);
}

.card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: auto;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
}

.tag {
  border: 1px solid var(--line);
  background: var(--gray);
}

.status-pill {
  color: var(--teal);
}

.formula-list {
  display: grid;
  gap: 8px;
}

.formula {
  display: block;
  width: 100%;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
}

.formula strong,
.formula span {
  display: block;
}

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

.formula.active {
  border-color: var(--ink);
  background: var(--yellow-soft);
}

.formula-detail {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
}

.formula-detail code {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}

.library-filters {
  margin-bottom: 12px;
}

.library-filters .search-input {
  flex: 1 1 280px;
  width: auto;
}

.empty-state {
  min-height: 160px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fffefa;
  color: var(--muted);
  text-align: center;
}

.review-box {
  min-height: 150px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
}

.review-box p:last-child {
  margin-bottom: 0;
}

.record-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(760px, calc(100svh - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
}

.record-dialog::backdrop {
  background: rgba(35, 33, 15, 0.44);
}

.dialog-header {
  display: flex;
  gap: 16px;
  align-items: start;
  justify-content: space-between;
  position: sticky;
  top: 0;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.dialog-body {
  padding: 16px;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section h3 {
  color: var(--yellow-strong);
}

.detail-section pre {
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--gray);
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: min(360px, calc(100vw - 36px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 14px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .coach-panel {
    position: static;
  }

  .sample-answer {
    max-height: none;
    min-height: 300px;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .topnav {
    grid-column: 1 / -1;
    justify-content: space-between;
    overflow-x: auto;
  }

  .topnav a {
    flex: 1 0 auto;
  }

  .workspace {
    gap: 12px;
    padding: 12px;
  }

  .practice-panel,
  .topics-panel,
  .library-panel,
  .review-panel,
  .structure-panel,
  .coach-panel {
    padding: 14px;
  }

  .section-heading {
    display: block;
  }

  .section-heading > :not(:first-child) {
    margin-top: 12px;
  }

  h1 {
    font-size: 30px;
  }

  h2 {
    font-size: 20px;
  }

  .question-card {
    display: block;
    min-height: 0;
  }

  .question-card .secondary-button {
    margin-top: 14px;
    width: 100%;
  }

  .question-card h2 {
    font-size: 26px;
  }

  .input-tools .primary-button,
  .input-tools .secondary-button,
  .library-actions .ghost-button,
  .file-button {
    flex: 1 1 140px;
  }

  #wordStats {
    flex: 1 0 100%;
  }

  .topic-grid,
  .library-grid {
    grid-template-columns: 1fr;
  }
}

@media (display-mode: standalone) {
  .topbar {
    padding-top: calc(14px + env(safe-area-inset-top));
  }
}
