:root {
  --page: #f3f0e8;
  --paper: #fbf8f1;
  --paper-soft: #f7f2e9;
  --ink: #171611;
  --ink-soft: #5c574d;
  --muted: #928a7d;
  --line: rgba(55, 50, 41, 0.16);
  --line-strong: rgba(55, 50, 41, 0.3);
  --accent: #676e4b;
  --accent-soft: rgba(103, 110, 75, 0.14);
  --danger: #8a514a;
  --shadow: 0 20px 60px rgba(52, 46, 38, 0.18);
  --radius: 22px;
  --font-scale: 1;
  --caret-duration: 140ms;
  --font-jp: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Times New Roman", serif;
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Token guidance palette - soft backgrounds with a stronger lower edge. */
  --guide-boundary-edge: var(--line-strong);
  --guide-word-bg: #eaf2f6;
  --guide-word-edge: #0072b2;
  --guide-place-bg: #e4f0e8;
  --guide-place-edge: #007a5a;
  --guide-name-bg: #f2e3d8;
  --guide-name-edge: #a44c00;
  --guide-verb-bg: #eaf1df;
  --guide-verb-edge: #4d7c00;
  --guide-adjective-bg: #efe6f3;
  --guide-adjective-edge: #8a4f73;
  --guide-particle-bg: #f4ead1;
  --guide-particle-edge: #a95a00;
  --guide-phrase-bg: #ece7dc;
  --guide-phrase-edge: #676e4b;
  --guide-date-bg: #f8f2e6;
  --guide-date-edge: #7b6500;
  --guide-number-bg: #eef0f5;
  --guide-number-edge: #4f63a3;
  --review-missed-bg: #f8e4df;
  --review-missed-edge: #b64b35;
  --review-skipped-bg: #ede7dc;
  --review-skipped-edge: #8a7861;
  --review-slow-bg: #f4ead1;
  --review-slow-edge: #a95a00;
}

[data-theme="dark"] {
  --page: #161612;
  --paper: #202019;
  --paper-soft: #25251d;
  --ink: #eee8dc;
  --ink-soft: #bbb2a2;
  --muted: #8e8677;
  --line: rgba(238, 232, 220, 0.14);
  --line-strong: rgba(238, 232, 220, 0.28);
  --accent: #a8ad82;
  --accent-soft: rgba(168, 173, 130, 0.13);
  --danger: #c5867e;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.36);
  --guide-word-bg: #24323a;
  --guide-word-edge: #56b4e9;
  --guide-place-bg: #25352e;
  --guide-place-edge: #33b58b;
  --guide-name-bg: #3a2d27;
  --guide-name-edge: #d55e00;
  --guide-verb-bg: #2a3427;
  --guide-verb-edge: #8dbd45;
  --guide-adjective-bg: #352b3a;
  --guide-adjective-edge: #cc79a7;
  --guide-particle-bg: #3b3522;
  --guide-particle-edge: #e69f00;
  --guide-phrase-bg: #302e29;
  --guide-phrase-edge: #a8ad82;
  --guide-date-bg: #27271f;
  --guide-date-edge: #f0e442;
  --guide-number-bg: #292d3a;
  --guide-number-edge: #8ea0e8;
  --review-missed-bg: #3b2824;
  --review-missed-edge: #e07a62;
  --review-skipped-bg: #302e29;
  --review-skipped-edge: #b7a891;
  --review-slow-bg: #3b3522;
  --review-slow-edge: #e69f00;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 16% 0%, rgba(255, 255, 255, 0.72), transparent 36%),
    radial-gradient(circle at 90% 12%, rgba(255, 255, 255, 0.45), transparent 30%),
    var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  padding: 24px;
}

[data-theme="dark"] body,
body[data-theme="dark"] {
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 255, 255, 0.04), transparent 34%),
    var(--page);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.app-stage {
  width: min(1440px, 100%);
  margin: 0 auto;
}

.app-window {
  min-height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  border: 1px solid rgba(42, 38, 31, 0.14);
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.12)),
    radial-gradient(circle at 14% 12%, rgba(255, 255, 255, 0.58), transparent 26%),
    var(--paper);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

[data-theme="dark"] .app-window {
  background:
    linear-gradient(rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.01)),
    var(--paper);
  border-color: var(--line);
}

.top-bar {
  min-height: 78px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 28px;
  align-items: center;
  padding: 18px 30px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.18)),
    rgba(251, 248, 241, 0.84);
}

[data-theme="dark"] .top-bar,
[data-theme="dark"] .bottom-controls {
  background: rgba(32, 32, 25, 0.9);
}

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

.seal {
  width: 46px;
  height: 46px;
  border: 2px solid currentColor;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-jp);
  font-size: 24px;
  line-height: 1;
  color: var(--ink);
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.35), transparent 62%),
    repeating-conic-gradient(from -8deg, color-mix(in srgb, var(--ink) 68%, transparent) 0 6deg, transparent 6deg 12deg);
  box-shadow: inset 0 0 0 5px var(--paper);
  flex: 0 0 auto;
}

.brand-text {
  min-width: 0;
}

.brand-subline {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-top: 4px;
}

.lesson-title {
  margin: 0;
  font-family: var(--font-jp);
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.lesson-subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
}

.rss-link {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--paper-soft) 76%, transparent);
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.04em;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  animation: rss-border-once 1600ms ease-out 1800ms 1;
}

.rss-link:hover,
.rss-link:focus-visible {
  color: var(--ink);
  border-color: var(--line-strong);
  outline: none;
}

@keyframes rss-border-once {
  0% {
    border-color: var(--line);
    box-shadow: none;
  }

  38% {
    border-color: color-mix(in srgb, var(--accent) 52%, var(--line));
    box-shadow: 0 0 0 3px var(--accent-soft);
  }

  100% {
    border-color: var(--line);
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rss-link {
    animation: none;
  }
}

.session-meta {
  display: flex;
  align-items: center;
  gap: 22px;
  color: var(--ink-soft);
  font-size: 15px;
  white-space: nowrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: max-content;
}

.meta-divider {
  width: 1px;
  height: 30px;
  background: var(--line);
}

.progress-group {
  display: grid;
  gap: 6px;
  min-width: 120px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.progress-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(29, 28, 25, 0.1);
  overflow: hidden;
}

[data-theme="dark"] .progress-track {
  background: rgba(238, 232, 220, 0.12);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.menu-button,
.icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  display: grid;
  place-items: center;
}

.menu-button::before {
  content: "";
  width: 19px;
  height: 13px;
  background:
    linear-gradient(var(--ink-soft), var(--ink-soft)) 0 0 / 100% 1.5px no-repeat,
    linear-gradient(var(--ink-soft), var(--ink-soft)) 0 50% / 100% 1.5px no-repeat,
    linear-gradient(var(--ink-soft), var(--ink-soft)) 0 100% / 100% 1.5px no-repeat;
  opacity: 0.9;
}

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 48px 24px 96px;
  min-height: 520px;
}

.empty-copy {
  width: min(650px, 100%);
  text-align: center;
}

.empty-copy .eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  letter-spacing: 0.08em;
}

.empty-copy h2 {
  margin: 0 0 18px;
  font-family: var(--font-jp);
  font-size: clamp(34px, 5vw, 64px);
  line-height: 1.15;
  font-weight: 500;
}

.empty-copy p {
  margin: 0 auto 14px;
  max-width: 560px;
  color: var(--ink-soft);
  line-height: 1.8;
}

.primary-button,
.secondary-button,
.danger-button,
.quiet-button,
.control-button {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.34);
  color: var(--ink);
  padding: 0 18px;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.38);
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}

.empty-state .primary-button {
  margin-top: 16px;
}

.sample-loader {
  width: min(430px, 100%);
  margin: 22px auto 0;
  display: grid;
  gap: 9px;
  justify-items: stretch;
  color: var(--ink-soft);
}

.sample-loader label {
  font-size: 13px;
  letter-spacing: 0.04em;
}

.sample-loader select {
  width: 100%;
  min-height: 42px;
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--paper-soft) 88%, transparent);
}

.sample-text-status {
  min-height: 20px;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.danger-button {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
}

.quiet-button {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--ink-soft);
}

.practice-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
}

.practice-scroll::-webkit-scrollbar {
  width: 10px;
}

.practice-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.practice-scroll::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 55%, transparent);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.practice-area {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(250px, 31%) minmax(0, 1fr);
  gap: 36px;
  padding: 34px 34px calc(34px + var(--bottom-controls-height, 80px));
}

.practice-area.no-article-image {
  grid-template-columns: minmax(0, 1fr);
}

.practice-area.no-article-image .article-art {
  display: none;
}

.article-art {
  position: relative;
  align-self: start;
  min-height: 0;
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(to bottom, rgba(251, 248, 241, 0), rgba(251, 248, 241, 0.72) 84%),
    radial-gradient(circle at 52% 18%, rgba(90, 82, 67, 0.13), transparent 30%),
    radial-gradient(circle at 36% 54%, rgba(90, 82, 67, 0.1), transparent 36%);
  opacity: 0.95;
}

.article-art.empty {
  background: transparent;
}

.article-art img {
  display: block;
  width: 100%;
  height: auto;
  filter: saturate(0.58) contrast(0.92);
  opacity: 0.86;
}

.article-art .art-caption {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 22px;
  color: rgba(65, 59, 48, 0.58);
  font-family: var(--font-jp);
  font-size: 13px;
  line-height: 1.8;
  letter-spacing: 0.04em;
}

[data-theme="dark"] .article-art img {
  opacity: 0.72;
}

.reading-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 10px 0 0;
}

.previous-sentence {
  position: relative;
  min-height: 70px;
  padding: 6px 0 24px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-jp);
  font-size: calc(clamp(16px, 1.32vw, 20px) * var(--font-scale));
  line-height: 1.9;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-align: center;
}

.previous-sentence.empty {
  color: transparent;
}

.sentence-zone-row,
.remaining-sentence-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.sentence-speak-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper-soft) 86%, transparent);
  color: var(--ink-soft);
  display: inline-grid;
  place-items: center;
  line-height: 1;
  box-shadow: none;
}

.sentence-speak-button:hover,
.sentence-speak-button:focus-visible {
  color: var(--ink);
  border-color: var(--line-strong);
}

.sentence-speak-button.active {
  position: absolute;
  left: 0;
  top: 36px;
  width: 38px;
  height: 38px;
  z-index: 1;
}

.sentence-speak-button.small {
  width: 30px;
  height: 30px;
  font-size: 13px;
}

.zone-label,
.current-label {
  position: absolute;
  right: 0;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.05em;
}

.zone-label {
  bottom: 7px;
}

.active-sentence {
  position: relative;
  padding: 34px 0 42px 52px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.sentence-line {
  font-family: var(--font-jp);
  font-size: calc(clamp(34px, 3.05vw, 52px) * var(--font-scale));
  line-height: 1.72;
  letter-spacing: 0.08em;
  color: var(--ink);
  white-space: normal;
}

.active-meaning-line {
  max-width: 760px;
  margin: 12px auto 0;
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: calc(15px * var(--font-scale));
  line-height: 1.7;
  letter-spacing: 0.01em;
}

.token {
  position: relative;
  display: inline-block;
  vertical-align: baseline;
}

.token.focus-token {
  margin: 0 0.06em;
  position: relative;
  z-index: 1;
}

/* Guidance: Word Boundaries - subtle segmentation, no semantic color. */
body[data-guidance-mode="boundaries"] .token {
  border-radius: 0.22em;
  padding-inline: 0.06em;
  box-shadow: inset 0 -0.06em 0 var(--guide-boundary-edge);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Guidance: Grammar Colors - soft role backgrounds behind unchanged text. */
body[data-guidance-mode="grammar"] .token {
  border-radius: 0.22em;
  padding-inline: 0.08em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

body[data-guidance-mode="grammar"] .token[data-token-type="word"] {
  background: var(--guide-word-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-word-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="place"] {
  background: var(--guide-place-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-place-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="name"] {
  background: var(--guide-name-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-name-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="verb"] {
  background: var(--guide-verb-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-verb-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="adjective"] {
  background: var(--guide-adjective-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-adjective-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="particle"] {
  background: var(--guide-particle-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-particle-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="phrase"] {
  background: var(--guide-phrase-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-phrase-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="date"] {
  background: var(--guide-date-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-date-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="number"] {
  background: var(--guide-number-bg);
  box-shadow: inset 0 -0.09em 0 var(--guide-number-edge);
}

body[data-guidance-mode="grammar"] .token[data-token-type="punctuation"] {
  background: transparent;
  box-shadow: inset 0 -0.09em 0 var(--line-strong);
}

/* Guidance: Review Highlights - mark missed, skipped, and slow tokens only. */
body[data-guidance-mode="review"] .token.review-missed,
body[data-guidance-mode="review"] .token.review-skipped,
body[data-guidance-mode="review"] .token.review-slow {
  border-radius: 0.22em;
  padding-inline: 0.08em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

body[data-guidance-mode="review"] .token.review-missed {
  background: var(--review-missed-bg);
  box-shadow: inset 0 -0.1em 0 var(--review-missed-edge);
}

body[data-guidance-mode="review"] .token.review-skipped {
  background: var(--review-skipped-bg);
  box-shadow: inset 0 -0.1em 0 var(--review-skipped-edge);
}

body[data-guidance-mode="review"] .token.review-slow {
  background: var(--review-slow-bg);
  box-shadow: inset 0 -0.1em 0 var(--review-slow-edge);
}

/* The active token stays the strongest visual element in every guidance mode:
   its role highlight is dropped so only the caret treatment remains. */
body[data-guidance-mode="boundaries"] .token.focus-token,
body[data-guidance-mode="grammar"] .token.focus-token,
body[data-guidance-mode="review"] .token.focus-token {
  background: transparent;
  box-shadow: none;
  padding-inline: 0;
}

.legend-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
}

.legend-swatch {
  width: 28px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 5px;
  background: var(--paper-soft);
  box-shadow: inset 0 -0.3em 0 var(--line-strong);
}

.legend-swatch[data-token-type="word"] { background: var(--guide-word-bg); box-shadow: inset 0 -0.3em 0 var(--guide-word-edge); }
.legend-swatch[data-token-type="place"] { background: var(--guide-place-bg); box-shadow: inset 0 -0.3em 0 var(--guide-place-edge); }
.legend-swatch[data-token-type="name"] { background: var(--guide-name-bg); box-shadow: inset 0 -0.3em 0 var(--guide-name-edge); }
.legend-swatch[data-token-type="verb"] { background: var(--guide-verb-bg); box-shadow: inset 0 -0.3em 0 var(--guide-verb-edge); }
.legend-swatch[data-token-type="adjective"] { background: var(--guide-adjective-bg); box-shadow: inset 0 -0.3em 0 var(--guide-adjective-edge); }
.legend-swatch[data-token-type="particle"] { background: var(--guide-particle-bg); box-shadow: inset 0 -0.3em 0 var(--guide-particle-edge); }
.legend-swatch[data-token-type="phrase"] { background: var(--guide-phrase-bg); box-shadow: inset 0 -0.3em 0 var(--guide-phrase-edge); }
.legend-swatch[data-token-type="date"] { background: var(--guide-date-bg); box-shadow: inset 0 -0.3em 0 var(--guide-date-edge); }
.legend-swatch[data-token-type="number"] { background: var(--guide-number-bg); box-shadow: inset 0 -0.3em 0 var(--guide-number-edge); }
.legend-swatch[data-token-type="punctuation"] { background: transparent; border: 1px solid var(--line); box-shadow: inset 0 -0.3em 0 var(--line-strong); }

.focus-token-text {
  display: inline-block;
  padding: 0 0.14em 0.03em;
  border: 1.5px solid color-mix(in srgb, var(--accent) 80%, var(--ink));
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.22);
  box-shadow:
    0 0 0 3px var(--accent-soft),
    inset 0 -0.16em 0 rgba(111, 115, 82, 0.06);
  transition: border-color var(--caret-duration) ease, box-shadow var(--caret-duration) ease, background var(--caret-duration) ease;
}

.caret-off .focus-token-text {
  transition: none;
}

.focus-hint-top,
.focus-hint-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-ui);
  line-height: 1.1;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
}

.focus-hint-top {
  bottom: calc(100% + 0.52em);
  color: var(--ink-soft);
  font-size: calc(13px * var(--font-scale));
}

.focus-hint-bottom {
  top: calc(100% + 0.48em);
  display: grid;
  gap: 4px;
  justify-items: center;
  color: var(--ink-soft);
  font-size: calc(15px * var(--font-scale));
}

.focus-hint-bottom .romaji-echo {
  color: var(--accent);
}

.focus-token::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid color-mix(in srgb, var(--accent) 80%, var(--ink));
  border-bottom: 1.5px solid color-mix(in srgb, var(--accent) 80%, var(--ink));
  background: var(--paper);
  transform: translateX(-50%) rotate(45deg);
}

.current-label {
  bottom: 10px;
}

.typing-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.typing-input {
  display: block;
  width: min(360px, 100%);
  height: 42px;
  margin: 32px auto 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
  outline: 0;
}

.typing-input.invalid {
  border-bottom-color: var(--danger);
  color: var(--danger);
}

.typing-input-hidden #typing-input {
  display: none;
}

.remaining-text {
  padding: 24px 0 0;
  font-family: var(--font-jp);
  font-size: calc(clamp(16px, 1.25vw, 19px) * var(--font-scale));
  line-height: 2.05;
  letter-spacing: 0.035em;
  color: var(--ink);
}

.remaining-text p {
  margin: 0 0 18px;
}

.remaining-sentence-row span {
  min-width: 0;
}

.bottom-controls {
  min-height: 80px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 16px 30px;
  background: rgba(251, 248, 241, 0.78);
}

.guidance-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.guidance-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.guidance-control-label {
  white-space: nowrap;
}

.guidance-control select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: color-mix(in srgb, var(--paper-soft) 86%, transparent);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
}

.legend-button {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 13px;
  white-space: nowrap;
}

.legend-button:hover,
.legend-button:focus-visible {
  color: var(--ink);
  border-color: var(--line-strong);
}

.legend-button[hidden] {
  display: none;
}

.picture-hints-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
}

.picture-hints-control input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.picture-hints-control[hidden] {
  display: none;
}

/* Custom picture-hint tooltip. A fixed paper card holds a cropped sprite cut from
   the lesson atlas image, with the same romaji / reading / meaning the focus token
   shows. It is positioned in viewport coordinates by JS. */
.visual-hint-tooltip {
  position: fixed;
  z-index: 60;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: max-content;
  max-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 14px 36px rgba(23, 22, 17, 0.18);
  pointer-events: none;
  text-align: center;
}

.visual-hint-tooltip[hidden] {
  display: none;
}

.visual-hint-sprite {
  width: 132px;
  height: 132px;
  border-radius: 8px;
  background-repeat: no-repeat;
  background-color: var(--paper-soft);
  image-rendering: auto;
}

/* Romaji sits above the picture; reading and meaning sit below it, mirroring the
   focus token's romaji-above, reading/meaning-below arrangement. */
.visual-hint-romaji {
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.visual-hint-reading {
  font-family: var(--font-jp);
  font-size: 15px;
  color: var(--ink);
}

.visual-hint-meaning {
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.3;
  color: var(--accent);
}

.visual-hint-romaji[hidden],
.visual-hint-reading[hidden],
.visual-hint-meaning[hidden] {
  display: none;
}

[data-theme="dark"] .visual-hint-tooltip {
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
}

/* A token with a usable picture hint invites interaction without shouting. */
.token.has-visual-hint {
  cursor: help;
}

body[data-picture-hints="off"] .token.has-visual-hint {
  cursor: inherit;
}

/* On touch the hint is pinned to the bottom-center of the screen so a finger does
   not cover it, and it sits above the bottom controls and the safe-area inset. */
.visual-hint-tooltip-mobile {
  top: auto !important;
  left: 50% !important;
  bottom: calc(var(--bottom-controls-height, 96px) + 18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
}

.nav-controls {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
}

.control-button {
  min-width: 116px;
  height: 42px;
  padding: 0 20px;
}

.control-button.prev {
  justify-self: start;
}

.control-button.pause {
  justify-self: center;
  min-width: 142px;
}

.control-button.next {
  justify-self: end;
}

.drop-overlay,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(35, 32, 27, 0.28);
  backdrop-filter: blur(4px);
  padding: 20px;
}

.drop-overlay[hidden] {
  display: none;
}

.drop-overlay > div {
  width: min(520px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  padding: 34px;
  text-align: center;
  box-shadow: var(--shadow);
}

.drop-overlay strong {
  display: block;
  font-family: var(--font-jp);
  font-size: 28px;
  font-weight: 500;
}

.drop-overlay p {
  margin: 12px 0 0;
  color: var(--ink-soft);
  line-height: 1.7;
}

.modal {
  width: min(680px, 100%);
  max-height: min(86vh, 760px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal.small {
  width: min(520px, 100%);
}

.modal-header {
  padding: 24px 26px 14px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-family: var(--font-jp);
  font-weight: 500;
  font-size: 26px;
}

.modal-header p {
  margin: 10px 0 0;
  color: var(--ink-soft);
  line-height: 1.6;
}

.modal-body {
  padding: 18px 26px;
  overflow: auto;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
  padding: 16px 26px 22px;
  border-top: 1px solid var(--line);
}

.modal-actions .primary-button,
.modal-actions .secondary-button,
.modal-actions .danger-button,
.modal-actions .quiet-button {
  min-height: 48px;
  height: 48px;
  padding: 0 22px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  white-space: nowrap;
  border-radius: 8px;
}

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

.menu-list button {
  min-height: 42px;
  padding-left: 0;
  padding-right: 0;
  text-align: left;
  display: grid;
  gap: 3px;
  align-content: center;
  justify-content: start;
}

.menu-button-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.menu-row,
.setting-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.row-title {
  font-weight: 600;
}

.row-desc {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
}

select,
input[type="number"] {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--paper-soft);
  color: var(--ink);
  padding: 0 10px;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.settings-section {
  padding: 4px 0 18px;
}

.settings-section h3 {
  margin: 10px 0 4px;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.report-card {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.report-card span {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
}

.report-card strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  font-weight: 600;
}

.token-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 14px;
}

.token-table th,
.token-table td {
  border-top: 1px solid var(--line);
  padding: 9px 6px;
  text-align: left;
}

.token-table th {
  color: var(--ink-soft);
  font-weight: 500;
}

.report-modal .modal-body {
  display: grid;
  gap: 14px;
}

.url-fallback {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper-soft);
  color: var(--ink);
  padding: 10px;
}

.toast-region {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 8px 30px rgba(52, 46, 38, 0.14);
  padding: 10px 16px;
  font-size: 14px;
}

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

@media (max-width: 900px) {
  body {
    padding: 0;
    background: var(--paper);
  }

  .app-stage {
    width: 100%;
  }

  .app-window {
    min-height: 100vh;
    max-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .top-bar {
    min-height: 0;
    grid-template-columns: 1fr auto;
    padding: 18px 18px 12px;
    gap: 12px;
  }

  .seal {
    width: 42px;
    height: 42px;
    font-size: 22px;
  }

  .lesson-title {
    font-size: 17px;
  }

  .lesson-subtitle {
    font-size: 12px;
  }

  .brand-subline {
    gap: 8px;
  }

  .rss-link {
    min-height: 22px;
    padding-inline: 8px;
    font-size: 10px;
  }

  .session-meta {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: space-between;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: 13px;
  }

  .meta-divider {
    height: 24px;
  }

  .progress-group {
    min-width: 92px;
  }

  .practice-area {
    display: block;
    padding: 14px 18px calc(22px + var(--bottom-controls-height, 132px));
  }

  .article-art {
    min-height: 0;
    height: auto;
    margin: 0 0 18px;
    border-radius: 10px;
  }

  .article-art img {
    min-height: 0;
  }

  .article-art .art-caption {
    display: none;
  }

  .reading-column {
    padding: 0;
  }

  .previous-sentence {
    padding: 0 0 16px;
    min-height: 48px;
    font-size: calc(14px * var(--font-scale));
    line-height: 1.85;
    text-align: left;
  }

  .zone-label {
    bottom: 4px;
    font-size: 11px;
  }

  .active-sentence {
    padding: 30px 0 44px 42px;
    text-align: left;
  }

  .sentence-speak-button.active {
    top: 32px;
    left: 0;
    width: 32px;
    height: 32px;
  }

  .sentence-line {
    font-size: calc(clamp(29px, 8vw, 42px) * var(--font-scale));
    line-height: 1.86;
    letter-spacing: 0.05em;
  }

  .active-meaning-line {
    margin-top: 10px;
    font-size: calc(13px * var(--font-scale));
    line-height: 1.65;
  }

  .focus-hint-top {
    bottom: calc(100% + 0.42em);
    font-size: calc(11px * var(--font-scale));
  }

  .focus-hint-bottom {
    top: calc(100% + 0.5em);
    font-size: calc(12px * var(--font-scale));
  }

  .current-label {
    right: 0;
    bottom: 8px;
    font-size: 11px;
  }

  .typing-input {
    margin-top: 28px;
  }

  body:not(.typing-input-visible) #typing-input {
    display: none;
  }

  .remaining-text {
    padding-top: 18px;
    font-size: calc(15px * var(--font-scale));
    line-height: 1.95;
  }

  .remaining-text p {
    margin-bottom: 14px;
  }

  .bottom-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: 78px;
    flex-direction: column;
    align-items: stretch;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    gap: 10px;
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: blur(12px);
    z-index: 10;
  }

  .guidance-bar {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .picture-hints-control {
    flex: 0 0 auto;
    height: 40px;
  }

  .guidance-control {
    flex: 1 1 auto;
    min-width: 0;
  }

  .guidance-control select {
    flex: 1 1 auto;
    min-width: 0;
    height: 40px;
  }

  .legend-button {
    height: 40px;
  }

  .nav-controls {
    width: 100%;
    gap: 10px;
  }

  .control-button {
    width: 100%;
    min-width: 0;
    height: 44px;
    padding: 0 10px;
    font-size: 14px;
  }

  .control-button.pause {
    min-width: 0;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
}

@media (max-width: 520px) {
  .meta-item.characters,
  .meta-divider.characters-divider {
    display: none;
  }

  .session-meta {
    gap: 8px;
  }

  .sentence-line {
    font-size: calc(clamp(27px, 9vw, 38px) * var(--font-scale));
  }

  .remaining-text {
    font-size: calc(14px * var(--font-scale));
  }

  .menu-row,
  .setting-row {
    grid-template-columns: 1fr;
  }

  .inline-controls {
    justify-content: flex-start;
  }

  .report-grid {
    grid-template-columns: 1fr;
  }
}
