/* Shared colors for both reading environments. */
:root {
  color-scheme: light;
  --paper: #f4eedb;
  --surface: #faf7ee;
  --raised: #fffbf2;
  --inset: #eeeee2;
  --ink: #1e392e;
  --muted: #526456;
  --teal: #146348;
  --line: #d3d7c8;
  --leaf-wash: #e2ebdf;
  --leaf-edge: #93ae96;
  --button-fill: #19664d;
  --button-ink: #fffaf0;
  --button-hover: #104d39;
  --mist-warm: #f3e9da;
  --warm-ink: #81472b;
  --mist-gold: #efe6ca;
  --gold-ink: #715920;
  --focus-ring: #ad562c;
  --tone-1: #0047ff;
  --tone-2: #ff8200;
  --tone-3: #00c828;
  --tone-4: #ff0000;
  --tone-5: #a000ed;
  --track-empty: #d6dacd;
  --paper-tint: rgb(254 247 223 / 80%);
  --paper-base: var(--paper);
  --paper-blend: normal;
  --sakura-ink: multiply;
  --sakura-filter: contrast(1.25) brightness(1.32);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #15201d;
  --surface: #20312a;
  --raised: #293b32;
  --inset: #1b2923;
  --ink: #eef2e6;
  --muted: #bbc8b9;
  --teal: #9ddab8;
  --line: #45584b;
  --leaf-wash: #2c4336;
  --leaf-edge: #739780;
  --button-fill: #a5dcba;
  --button-ink: #173629;
  --button-hover: #b9e9ca;
  --mist-warm: #46372e;
  --warm-ink: #f0b79a;
  --mist-gold: #433e2a;
  --gold-ink: #e4cd8d;
  --focus-ring: #f4b38f;
  --tone-1: #ff5e45;
  --tone-2: #ffb300;
  --tone-3: #2cdb61;
  --tone-4: #24b4ff;
  --tone-5: #b0b5b3;
  --track-empty: #546658;
  --paper-tint: transparent;
  --paper-base: #1b2824;
  --paper-blend: multiply;
  --sakura-ink: screen;
  --sakura-filter: contrast(1.25) brightness(1.32) invert(1) hue-rotate(180deg);
}

.pinyin-tone-1 {color: var(--tone-1)}
.pinyin-tone-2 {color: var(--tone-2)}
.pinyin-tone-3 {color: var(--tone-3)}
.pinyin-tone-4 {color: var(--tone-4)}
.pinyin-tone-5 {color: var(--tone-5)}
/* A fine edge keeps bright strokes and tone marks legible on paper. */
@media (forced-colors: none) {
  :root:not([data-theme="dark"]) :is(.pinyin-tone-2,.pinyin-tone-3,.pinyin-tone-4) {
    paint-order: stroke fill;
    -webkit-text-stroke: .04em;
  }
  :root:not([data-theme="dark"]) .pinyin-tone-2 {-webkit-text-stroke-color: #963c00}
  :root:not([data-theme="dark"]) .pinyin-tone-3 {-webkit-text-stroke-color: #006319}
  :root:not([data-theme="dark"]) .pinyin-tone-4 {-webkit-text-stroke-color: #b00000}
}
:root:not([data-theme="dark"]) .help-tones-dark,
:root[data-theme="dark"] .help-tones-light {display: none}

/* Keep the red syllables readable on the lighter panels within the dark theme. */
:root[data-theme="dark"] :is(.pr-feedback,.live-rule,.live-bank,.live-dialogue-line-alt) {
  --tone-1: #ff866e;
}

body {
  isolation: isolate;
  color: var(--ink);
  background: var(--paper);
}
.page-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  isolation: isolate;
  pointer-events: none;
  display: grid;
  grid-template: repeat(2, 1fr) / repeat(2, 1fr);
}
/* Mirror the paper at each join to keep a continuous grain at half scale. */
.page-backdrop > span {
  background-color: var(--paper-base);
  background-image: linear-gradient(var(--paper-tint), var(--paper-tint)), url("assets/backgrounds/paper.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  background-blend-mode: normal, var(--paper-blend);
}
.page-backdrop > span:nth-child(2) {transform: scaleX(-1)}
.page-backdrop > span:nth-child(3) {transform: scaleY(-1)}
.page-backdrop > span:nth-child(4) {transform: scale(-1)}
.page-backdrop::after {
  content: "";
  position: absolute;
  /* Cover a frame 120% of the viewport, preserving the painting's aspect ratio. */
  inset: -10%;
  background: url("assets/backgrounds/sakura.jpg") no-repeat 50% 60% / cover;
  opacity: .07;
  mix-blend-mode: var(--sakura-ink);
  filter: var(--sakura-filter);
}
@media print {
  .page-backdrop {display: none}
}

/* Navigation and reusable controls. */
#skip-link {background-color: var(--surface)}
.mode-card,.library-link {background-color: color-mix(in srgb, var(--surface) 63%, transparent)}
.ss-rule-panel,.ss-workbook-block,.ss-dict-inner,.ss-dialogue-main,.pr-exercise,.pr-finish,.shell-page>.card {
  background-color: color-mix(in srgb, var(--surface) 89%, transparent);
}
.mobile-menu {background-color: var(--inset)}
.locale,.live-student-locales {
  padding: 3px; gap: 3px; border: 1px solid var(--line); border-radius: 10px; background-color: var(--surface);
}
.locale button,.live-student-locales button {min-height: 36px; border-radius: 7px}
.locale button, .mode-meta, .mode-go {color: var(--muted)}
.btn {background-color: var(--inset); color: var(--ink)}
.btn-secondary {background-color: var(--surface); border-color: var(--line)}
.btn-primary {background-color: var(--button-fill); border-color: var(--button-fill); color: var(--button-ink)}
.btn-primary:hover {background-color: var(--button-hover); border-color: var(--button-hover)}
.mode-symbol, .library-icon, .profile-icon {background-color: var(--leaf-wash); color: var(--teal)}
.mode-symbol.warm, .library-icon.warm {background-color: var(--mist-warm); color: var(--warm-ink)}
.mode-symbol.gold {background-color: var(--mist-gold); color: var(--gold-ink)}
:is(button,a,input,select,textarea,summary):focus-visible {outline-color: var(--focus-ring)}
::selection {background-color: var(--button-fill); color: var(--button-ink)}
html[data-theme="dark"] #sidebar {background-color: #10281f}
html[data-theme="dark"] .lesson-hero {background-color: #244838}

/* Independent study, dictionary and audio. */
.ss-page {
  --ss-leaf: var(--teal);
  --ss-mist: var(--leaf-wash);
  --ss-played: var(--teal);
}
.ss-rule-menu,.ss-search,.ss-word-detail {background-color: var(--inset)}
.ss-listening {background-color: var(--leaf-wash)}
.ss-mark, .ss-slot {background-color: var(--raised); color: var(--teal)}
.ss-slot {border-color: var(--leaf-edge)}
.ss-plus, .ss-audio-type, .ss-person, .ss-heading .eyebrow span {color: var(--muted)}
.ss-example {border-inline-start-color: var(--leaf-edge)}
.ss-aside {background-color: var(--mist-gold)}
.ss-aside-icon {color: var(--gold-ink)}
.ss-listening audio {color-scheme: inherit}
.ss-search input::placeholder {color: var(--muted); opacity: .92}
.theme-toggle i,.ss-option .ss-switch-track,.live-toggle i {background-color: var(--muted); border-color: var(--muted)}
.theme-toggle i::after,.ss-switch-track::after,.live-toggle i::after {background-color: var(--surface)}
.theme-toggle[aria-checked=true] i,.ss-option input:checked + .ss-switch-track,.live-toggle.is-on i {
  background-color: var(--button-fill); border-color: var(--button-fill);
}
.theme-toggle[aria-checked=true] i::after,.ss-option input:checked + .ss-switch-track::after,.live-toggle.is-on i::after {
  background-color: var(--button-ink);
}
.classroom-editor input[type=radio] {accent-color: var(--button-fill)}

/* Practice and review feedback. */
.pr-answer,.pr-select {color: var(--ink); background-color: var(--raised); border-color: var(--line)}
.pr-answer[readonly],.pr-kind-options {color: var(--muted); background-color: var(--inset); border-color: var(--line)}
.pr-kind, .pr-answer::placeholder, .pr-setting-foot,.pr-total>p,.pr-key-hint,.pr-bottom-note,
.pr-setting-hint,.pr-grammar-note,.pr-resumed,.pr-sample-label,.pr-explanation,
.pr-result-grid small,.pr-result-grid span,.pr-review-label {color: var(--muted)}
.pr-settings {background-color: var(--surface)}
.pr-page .pr-start {color: var(--ink); background-color: var(--raised); border-color: var(--line)}
.pr-progress-step {background-color: var(--track-empty)}
.pr-progress-step.is-current {background-color: var(--leaf-edge)}
.pr-progress-step.is-correct,.pr-progress-step.is-accepted {background-color: var(--teal)}
.pr-progress-step.is-review {background-color: var(--warm-ink)}
.pr-pinyin,.pr-settings-icon,.pr-finish-mark {color: var(--teal)}
.pr-feedback,.pr-feedback-symbol,.pr-review-status.is-correct,.pr-review-status.is-accepted,
.pr-settings-icon,.pr-finish-mark {background-color: var(--leaf-wash); border-color: var(--leaf-edge)}
.pr-feedback.is-review,.pr-review-status.is-review,.is-review .pr-feedback-symbol {background-color: var(--mist-warm); border-color: var(--line)}
.pr-input-error,.pr-storage-note,.pr-accept,.pr-review-status.is-review,.is-review .pr-feedback-symbol {color: var(--warm-ink)}
.pr-review-status {background-color: var(--inset); color: var(--muted)}
.pr-result-grid,.pr-review-row,.pr-accept {border-color: var(--line)}

/* Teaching panels share colors so both roles can read the same lesson in their preferred theme. */
.live-view {--live-green: var(--leaf-wash); --live-coral: #a65336}
html[data-theme="dark"] .live-view {--live-coral: #efaf90}
.live-outline,.live-sheet,.live-match-word,.live-match-meaning {background-color: var(--surface); border-color: var(--line)}
.live-outline-scroll,.live-sheet {scrollbar-color: var(--leaf-edge) transparent}
.live-outline-item>span:first-child,.live-translation,.live-progress-label,
.live-cover-kicker,.live-cover-chapter small,.live-cover-annotation,.live-item-number,
.live-rule-mark,.live-rule .live-translation,.live-column-label,.live-match-number,
.live-match-reading>span,.live-budget>span,.live-text-button {color: var(--muted)}
.live-outline-item:hover,.live-icon-button:hover {background-color: var(--inset)}
.live-outline-item.is-current,.live-nav-next {background-color: var(--button-fill); color: var(--button-ink)}
.live-outline-item.is-current>span:first-child {color: var(--button-ink)}
.live-nav-next:hover {background-color: var(--button-hover); color: var(--button-ink)}
.live-progress-track, .live-cover-line {background-color: var(--track-empty)}
.live-cover-character {color: var(--teal)}
.live-cover-chapter,.live-cover-circle,.live-vocab-item,.live-example,.live-scene-label,.live-instruction,
.live-exercise-item,.live-drink,.live-match-reading,.live-verdict button {border-color: var(--line)}
.live-rule,.live-bank-toggle,.live-mobile-icon,.live-bank,.live-blank-input:focus,.live-dialogue-line-alt {background-color: var(--leaf-wash); border-color: var(--leaf-edge)}
.live-dialogue-line,.live-blank-input {background-color: var(--inset)}
.live-dialogue-speaker,.live-photo-grid figure>span {
  background-color: var(--raised); color: var(--ink); border-color: var(--line);
}
.live-verdict button,.live-match-dot {color: var(--teal)}
.live-match-center {color: var(--leaf-edge)}
.live-match-tag {background-color: var(--inset); color: var(--muted)}
.live-match-word:hover,.live-match-meaning:hover,
.live-match-word.is-correct,.live-match-meaning.is-correct {
  background-color: var(--leaf-wash); border-color: var(--leaf-edge);
}
.live-match-word.is-wrong,.live-match-meaning.is-wrong {background-color: var(--mist-warm); border-color: var(--warm-ink)}

/* Discrete choices share the HSK selector's green fill and contrasting label. */
.ss-tabs {gap: .25rem}
.ss-tabs button {padding-inline: .65rem; border-radius: 7px 7px 0 0}
.deck-source-toggle,.exr-text-link[data-exr-action=timer] {padding: .25rem .45rem; border-radius: 6px}
:is(.course-switcher :is(a,button),.course-level,.locale button,.live-student-locales button,
    .ss-tabs button,.ss-rule-menu button,.ss-segment button,.ss-tracklist button,.pr-kind,
    .register-names button,.exr-sections button,.exr-mobile-switch button,.live-verdict button,
    .live-match-word:where(:not(.is-correct,.is-wrong)),
    .slide-edit-mode,.live-icon-button,.deck-source-toggle,.exr-text-link[data-exr-action=timer],
    .ss-mark,.dr-save,.dr-listen,[data-audio-mute]):is([aria-pressed=true],[aria-current=true]) {
  background-color: var(--button-fill); color: var(--button-ink); border-color: var(--button-fill); box-shadow: none;
}
.ss-segment [aria-pressed=true] span,.course-level[aria-current=true] small,.exr-sections [aria-current=true] small,
.live-match-word[aria-pressed=true]:where(:not(.is-correct,.is-wrong)) span {
  color: inherit;
}
