@font-face {
  font-family: 'Course Han';
  src: url('./assets/vendor/course-han.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+3000-303F, U+3400-9FFF, U+FF00-FFEF;
}

:root {
  color-scheme: dark;
  --wine-black: #210c15;
  --wine: #3c1524;
  --wine-light: #562033;
  --line: #86563e;
  --gold: #edc47d;
  --gold-light: #f8dea7;
  --ink: #f9ead1;
  --muted: #dbba97;
  --dark-ink: #30121c;
  font: 17px/1.55 system-ui, 'Course Han', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--wine-black); color: var(--ink); }
body:has(.application:not(.is-cover)) {
  background: radial-gradient(ellipse at top, #431827 0, var(--wine-black) min(38rem, 90vh));
}
h1, h2, h3, p { margin: 0; overflow-wrap: anywhere; }
h1, h2, h3 { color: var(--gold); line-height: 1.15; }
h1, h2 { font-family: Georgia, serif; }
h1 { font-size: clamp(1.9rem, 7vw, 2.8rem); font-weight: 500; }
h2 { font-size: clamp(1.35rem, 5vw, 1.75rem); }
h3 { font-size: 1.1rem; }
a { color: var(--gold-light); }
button, select {
  min-width: 0;
  min-height: 46px;
  padding: .55rem .7rem;
  border: 1px solid #ad7d54;
  border-radius: .7rem;
  background: var(--wine-light);
  color: var(--ink);
  font: inherit;
  line-height: 1.25;
}
button { cursor: pointer; }
button:disabled { cursor: default; }
button:active:not(:disabled) { filter: brightness(.93); }
:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }

.application { width: 100%; max-width: 42rem; margin: auto; padding: clamp(14px, 4vw, 26px); }
.is-cover { max-width: 480px; padding: 22px; }
.start-cover {
  display: grid;
  align-content: center;
  gap: clamp(14px, 4vw, 20px);
  min-height: calc(100vh - 44px);
  min-height: calc(100svh - 44px);
  max-width: min(100%, max(240px, calc(100svh - 128px)));
  margin-inline: auto;
}
.start-cover__art { margin: 0; box-shadow: 0 0 0 1px #a77b49, 0 12px 28px #14060d; }
.start-cover__art img { display: block; width: 100%; height: auto; object-fit: contain; }
.gold, .start-cover__button {
  min-height: 52px;
  border-color: #f3d494;
  background: linear-gradient(180deg, var(--gold-light), #e7bd76 58%, #d19b51);
  color: var(--dark-ink);
  font-weight: 700;
  letter-spacing: .015em;
  box-shadow: 0 4px 12px #14060d90, inset 0 1px 0 #fff1ce;
}
.start-cover__button { width: 100%; padding: 12px 20px; }

nav { display: flex; gap: .35rem; margin-top: 1.35rem; }
nav button { flex: 1; padding-inline: .25rem; font-size: .83rem; }
nav [aria-current="page"] { background: #e7bd76; color: var(--dark-ink); font-weight: 700; }
#sync { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; min-height: 1.4rem; margin-top: .6rem; color: var(--muted); font-size: .81rem; }
#sync button { font-size: .81rem; }

.stack { display: grid; gap: .9rem; }
.stack-tight { display: grid; gap: .45rem; }
.page-head { display: grid; gap: .5rem; }
.eyebrow { color: var(--gold); font-size: .73rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.minor { color: var(--muted); font-size: .89rem; }
.panel {
  min-width: 0;
  padding: clamp(.8rem, 3.5vw, 1.25rem);
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: linear-gradient(145deg, #471b2c, var(--wine) 65%);
}
.hero-panel { border-top: 2px solid var(--gold); }
.back { justify-self: start; background: transparent; color: var(--gold-light); }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.row > * { flex: 1 1 8rem; }
.full { width: 100%; }
.lesson-list { display: grid; gap: .45rem; margin: 0; padding: 0; list-style: none; }
.lesson-link {
  display: grid;
  grid-template-columns: 2.1rem minmax(0, 1fr) auto;
  align-items: center;
  gap: .6rem;
  width: 100%;
  min-height: 50px;
  padding: .7rem;
  text-align: left;
  background: var(--wine);
  border-color: var(--line);
}
.lesson-link .step { color: var(--gold); font-family: Georgia, serif; font-size: 1.15rem; }
.lesson-link .name { overflow-wrap: anywhere; }
.lesson-link .status { color: var(--muted); font-size: .75rem; text-align: right; }
.plan-list { display: grid; gap: .2rem; margin: .65rem 0 0; padding: 0; list-style: none; }
.plan-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .35rem; padding: .35rem 0; border-top: 1px solid #86563e70; }
summary { cursor: pointer; color: var(--gold-light); padding: .25rem 0; }
progress { width: 100%; height: .65rem; accent-color: var(--gold); }

.study-card { display: grid; justify-items: center; gap: .53rem; text-align: center; border-top: 2px solid var(--gold); }
.han {
  max-width: 100%;
  color: var(--gold);
  font-family: 'Course Han', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif;
  font-size: clamp(4.2rem, 24vw, 6.6rem);
  font-weight: 600;
  line-height: 1.12;
  text-wrap: balance;
}
.han.long { font-size: clamp(2.55rem, 11.6vw, 4.5rem); }
.reading { color: var(--ink); font-size: clamp(1.35rem, 5.5vw, 2rem); font-weight: 850; line-height: 1.15; letter-spacing: .025em; }
.pinyin { color: var(--gold); font-size: 1.05rem; font-weight: 650; }
.translation { font-size: 1rem; }
.audio { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; }
.audio svg { width: 1.1rem; height: 1.1rem; flex: none; }
#audio-status:empty { display: none; }

.tone-list { display: grid; gap: .6rem; }
.tone { display: grid; grid-template-columns: minmax(0, 1fr) 4rem; gap: .35rem .55rem; align-items: start; }
.tone > :not(svg) { grid-column: 1 / -1; }
.tone .tone-example { grid-column: 1; }
.tone .tone-line { grid-column: 2; grid-row: 2; align-self: center; width: 100%; color: var(--gold); }
.tone .audio { justify-self: start; }
.tone-han { color: var(--gold); font-size: 1.65rem; font-weight: 700; }

.answers { display: grid; gap: .5rem; }
.answers button { text-align: left; }
.answers .correct { border-color: #9ac88f; background: #284b36; }
.answers .incorrect { border-color: #ed9b92; background: #722736; }
.feedback { border-inline-start: 3px solid var(--gold); padding: .3rem .65rem; }
.result-score { color: var(--gold-light); font: 500 clamp(2.5rem, 12vw, 4rem)/1.1 Georgia, serif; }

.writing-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: .55rem; }
.writing-controls select { width: 100%; }
.writing-grid {
  position: relative;
  width: min(100%, 320px);
  aspect-ratio: 1;
  margin-inline: auto;
  border: 1px solid #aa7b55;
  border-radius: .6rem;
  background: #32131f;
  background-image: linear-gradient(#aa7b5560, #aa7b5560), linear-gradient(#aa7b5560, #aa7b5560);
  background-size: 1px 100%, 100% 1px;
  background-position: center;
  background-repeat: no-repeat;
}
.writing-grid > div { position: absolute; inset: 0; touch-action: none; user-select: none; }
.writing-grid svg { display: block; }
.writing-status { min-height: 1.6rem; }

@media (min-width: 520px) {
  .tone-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .writing-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
