:root {
  color: #1c211d;
  background: #f6f4ef;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(246, 244, 239, 0.92)),
    #f6f4ef;
}

button,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.app-shell {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar,
.panel-heading,
.reader-footer,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 28px;
}

.topbar-lockup {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 0 0 auto;
}

.topbar-brand {
  color: #236457;
  font-size: 1.45rem;
  font-weight: 800;
}

.topbar-line {
  max-width: 24em;
  color: #617063;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
}

.eyebrow {
  margin: 0 0 4px;
  color: #617063;
  font-size: 0.9rem;
}

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

h1 {
  font-size: 1.45rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.1rem;
}

h3 {
  font-size: 1rem;
}

.primary {
  padding: 0 18px;
  background: #236457;
  color: #fff;
  font-weight: 700;
}

.ghost {
  padding: 0 16px;
  background: #e7ece5;
  color: #213a34;
}

.danger {
  padding: 0 16px;
  background: #7f2f2f;
  color: #fff;
}

.small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.92rem;
}

.home-masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin-bottom: 14px;
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 20px 22px;
  border: 1px solid #d8dfd4;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.home-brand {
  color: #236457;
  font-size: 1.45rem;
  font-weight: 800;
}

.home-line {
  max-width: 24em;
  color: #617063;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
}

.home-actions {
  flex: 0 0 auto;
  justify-content: flex-end;
}

.home-note {
  max-width: 32em;
  color: #617063;
  font-size: 0.95rem;
  line-height: 1.5;
}

.known-helper .panel-heading p {
  margin-top: 6px;
  color: #617063;
  line-height: 1.5;
}

.helper-row {
  display: flex;
  justify-content: flex-start;
  margin-top: 12px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.home-stats {
  margin-bottom: 16px;
}

.metric,
.panel {
  border: 1px solid #d8dfd4;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.metric {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 16px;
}

.metric span {
  color: #617063;
  font-weight: 700;
}

.metric strong {
  font-size: 1.65rem;
  line-height: 1;
}

.metric em {
  color: #617063;
  font-style: normal;
  font-weight: 700;
}

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.compact {
  padding-block: 14px;
}

.known-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  min-height: 42px;
}

.known-strip span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #f0d98b;
  font-size: 1.25rem;
  font-weight: 700;
}

.known-strip em,
.empty {
  color: #69756b;
  font-style: normal;
}

textarea {
  width: 100%;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #cdd7ca;
  border-radius: 8px;
  background: #fffefa;
  color: #1c211d;
  font-size: 1.15rem;
  line-height: 1.8;
  resize: vertical;
}

.notice {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff0d6;
  color: #684b16;
}

.speech-note {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #d8dfd4;
  border-radius: 8px;
  background: #f4f8f0;
  color: #4f5d51;
  line-height: 1.5;
}

.speech-note strong {
  color: #213a34;
}

.reading-text-preview {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid #cdd7ca;
  border-radius: 8px;
  background: #fffefa;
  color: #1c211d;
  line-height: 1.7;
}

.reading-text-preview strong {
  color: #617063;
  font-size: 0.92rem;
}

.reading-text-preview span {
  font-size: 1.08rem;
}

.speech-pill {
  padding: 7px 10px;
  border-radius: 8px;
  background: #e7ece5;
  color: #213a34;
  font-size: 0.92rem;
  font-weight: 700;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.char-card {
  min-height: 146px;
  padding: 16px;
  border: 1px solid #d8dfd4;
  border-radius: 8px;
  background: #fffefa;
}

.char-card strong,
.prestudy-char {
  display: block;
  margin-bottom: 12px;
  font-size: 2.7rem;
  line-height: 1;
}

.prestudy-char {
  min-width: 64px;
  min-height: 64px;
  padding: 0 8px;
  background: #f0d98b;
  color: #1c211d;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-weight: 700;
}

.prestudy-char:focus,
.prestudy-char:hover {
  background: #efd16d;
  outline: 2px solid #86a562;
}

.char-card p {
  margin-top: 12px;
  color: #5d695e;
  line-height: 1.5;
}

.review-card {
  display: grid;
  align-content: start;
  gap: 8px;
}

.review-card p {
  margin: 0;
}

.review-card .pinyin {
  color: #2f5f55;
  font-weight: 700;
}

.review-char {
  width: 100%;
  min-height: 72px;
  background: #f0d98b;
  color: #1c211d;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
}

.reader-layout {
  height: calc(100dvh - 280px);
  min-height: 560px;
  max-height: 980px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 18px;
}

.reader-text {
  position: relative;
  min-height: 0;
  padding: 24px;
  overflow-x: hidden;
  overflow-y: auto;
  border-radius: 8px;
  background: #fffefa;
  border: 1px solid #d8dfd4;
  color: #111712;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.9;
}

.reader-line-highlight {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 0;
  display: none;
  height: 0;
  border-radius: 8px;
  background: #f3f7e9;
  box-shadow: inset 0 -3px 0 #d9e8bf;
  pointer-events: none;
  z-index: 0;
}

.reader-line {
  display: block;
  margin: 0 -8px;
  padding: 2px 8px;
  border-radius: 8px;
  position: relative;
  z-index: 1;
}

.reader-char {
  position: relative;
  z-index: 2;
  min-width: 1.55em;
  min-height: 1.55em;
  margin: 0 0.03em;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  vertical-align: baseline;
}

.reader-char:focus,
.reader-char:hover {
  background: #eef5dc;
  outline: 2px solid #86a562;
}

.reader-char.tapped {
  border: 2px solid #8d5b00;
  background: #d9a526;
  color: #111712;
  font-weight: 700;
  box-shadow: 0 0 0 2px #fff7d8;
}

.reader-char.focus-tap-feedback {
  border: 2px solid #7a4a00;
  background: #f4c430;
  color: #111712;
  font-weight: 700;
  box-shadow: 0 0 0 3px #fff2a8;
}

.reader-footer {
  position: relative;
  z-index: 4;
  padding: 14px;
  border: 1px solid #d8dfd4;
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.94);
}

.reader-progress {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.reader-footer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.reader-complete-action {
  margin-right: auto;
}

.pronunciation-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 7px 10px;
  border-radius: 8px;
  background: #fff3c4;
  color: #44320a;
  font-size: 0.92rem;
  font-weight: 700;
}

.pronunciation-choice {
  background: #e8f2ff;
  color: #183f64;
}

.pronunciation-choice-note {
  color: #54708a;
  font-size: 0.8rem;
  font-weight: 600;
}

.pronunciation-alternates {
  color: #8a6f30;
  font-size: 0.86rem;
  font-weight: 500;
}

.pronunciation-alternates .pinyin-choice {
  min-height: 24px;
  color: #6b5a36;
  font-size: 0.86rem;
  font-weight: 700;
}

.pinyin-choice {
  min-height: 28px;
  padding: 0 3px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #183f64;
  font-size: 0.92rem;
  font-weight: 800;
}

.pinyin-choice:focus,
.pinyin-choice:hover {
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
  outline: 2px solid #86a9cc;
  outline-offset: 2px;
}

.reader-help {
  padding: 7px 10px;
  border-radius: 8px;
  background: #f4f8f0;
  color: #344238;
  font-size: 0.92rem;
  font-weight: 700;
}

.clicked-char-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.clicked-char-list span {
  display: grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  background: #f0d98b;
  color: #1c211d;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 1.25rem;
  font-weight: 700;
}

.clicked-char-list em {
  color: #69756b;
  font-style: normal;
}

.baseline-grid {
  display: grid;
  gap: 24px;
  margin-top: 22px;
}

.baseline-intro {
  display: grid;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid #d8dfd4;
}

.baseline-choice-note {
  padding: 12px 14px;
  border-radius: 8px;
  background: #f4f8f0;
  color: #4f5d51;
  line-height: 1.5;
}

.baseline-block {
  display: grid;
  gap: 12px;
}

.baseline-block + .baseline-block {
  padding-top: 22px;
  border-top: 1px solid #d8dfd4;
}

.baseline-block p {
  color: #617063;
  line-height: 1.5;
}

.preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-button {
  display: grid;
  gap: 4px;
  min-height: 64px;
  padding: 10px 12px;
  background: #e7ece5;
  color: #213a34;
  text-align: left;
}

.preset-button:focus,
.preset-button:hover {
  background: #eef5dc;
  outline: 2px solid #86a562;
}

.preset-button.selected {
  background: #f0d98b;
  color: #1c211d;
}

.preset-button span {
  color: #617063;
  font-size: 0.9rem;
}

.preset-button em {
  color: #236457;
  font-size: 0.85rem;
  font-style: normal;
  font-weight: 700;
}

.baseline-actions {
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #d8dfd4;
}

.placement-panel {
  max-width: 760px;
  margin-right: auto;
  margin-left: auto;
}

.placement-panel .panel-heading p {
  margin: 4px 0 0;
  color: #617063;
  font-size: 1rem;
  font-weight: 700;
}

.placement-instruction {
  margin: 10px 0 16px;
  color: #617063;
  font-weight: 700;
}

.placement-body {
  display: grid;
  gap: 16px;
}

.placement-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  max-width: min(100%, 540px);
  margin-right: auto;
  margin-left: auto;
}

.placement-char {
  aspect-ratio: 1;
  min-width: 0;
  border: 2px solid #d2d9d0;
  border-radius: 6px;
  background: #fffefa;
  color: #121915;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: clamp(2rem, 9vw, 4.5rem);
  font-weight: 700;
  line-height: 1;
}

.placement-char.unknown {
  border-color: #b85a5a;
  background: #f6dede;
  color: #752f2f;
}

.placement-controls {
  display: grid;
  gap: 12px;
}

.placement-secondary-actions,
.placement-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  margin-top: 0;
}

.placement-finish-hint {
  margin-top: 0;
}

.result {
  display: grid;
  gap: 14px;
}

.result-counts {
  display: grid;
  gap: 8px;
}

.milestone-notice {
  padding: 12px 14px;
  border: 1px solid #cdd7ca;
  border-radius: 8px;
  background: #f4f8f0;
  color: #2f5f55;
  font-weight: 700;
  line-height: 1.5;
}

.result-details {
  padding: 12px 0;
  border-top: 1px solid #d8dfd4;
  border-bottom: 1px solid #d8dfd4;
}

.result-details summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: #236457;
  cursor: pointer;
  font-weight: 700;
}

.result-details[open] .known-strip {
  margin-top: 10px;
}

@media (min-width: 760px) and (max-height: 820px) {
  .placement-shell {
    padding-top: 14px;
    padding-bottom: 18px;
  }

  .placement-shell .topbar {
    margin-bottom: 14px;
  }

  .placement-panel {
    max-width: min(920px, 100%);
    padding: 14px;
    margin-bottom: 0;
  }

  .placement-panel .panel-heading {
    gap: 12px;
  }

  .placement-instruction {
    margin: 8px 0 10px;
  }

  .placement-body {
    grid-template-columns: minmax(300px, 390px) minmax(210px, 1fr);
    align-items: start;
    gap: 16px;
  }

  .placement-grid {
    width: min(58vh, 390px);
    max-width: 100%;
    margin: 0;
  }

  .placement-char {
    font-size: clamp(2rem, 7vmin, 3.2rem);
  }

  .placement-controls {
    align-content: start;
    gap: 10px;
  }

  .placement-secondary-actions,
  .placement-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .placement-secondary-actions button,
  .placement-actions button {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 980px);
    padding-top: 18px;
  }

  .topbar,
  .panel-heading,
  .reader-footer,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }

  .metric-row {
    grid-template-columns: 1fr;
  }

  .home-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .home-actions {
    width: 100%;
  }

  .panel-heading button,
  .reader-footer button,
  .actions button {
    width: 100%;
  }

  .reader-footer-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .reader-footer-actions .speech-pill {
    text-align: center;
  }

  .pronunciation-hint {
    text-align: center;
  }

  .home-line {
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .app-shell {
    width: min(100% - 16px, 980px);
    padding-bottom: 28px;
  }

  .panel {
    padding: 16px;
  }

  .reader-layout {
    height: calc(100dvh - 220px);
    min-height: 480px;
    gap: 12px;
  }

  .reader-text {
    padding: 18px;
    font-size: 1.85rem;
    line-height: 1.85;
  }

  .reader-help,
  .pronunciation-hint,
  .speech-pill {
    width: 100%;
  }
}

.focus-shell {
  width: 100%;
  min-height: 100dvh;
  padding: 12px;
}

.focus-reader-layout {
  height: calc(100dvh - 24px);
  min-height: 0;
  max-height: none;
  gap: 10px;
}

.focus-reader-footer {
  justify-content: flex-end;
  padding: 10px;
}

.focus-reader-footer .reader-footer-actions {
  width: 100%;
}
