:root {
  /* Quiet study palette and spacing shared by the reading workspace. */
  --paper: #f5f3ed;
  --surface: #fffefa;
  --surface-muted: #efeee8;
  --ink: #26322e;
  --muted: #62716a;
  --line: #d9ded6;
  --accent: #315f58;
  --accent-soft: #e4ede7;
  --error: #a04e43;
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  --radius-control: 8px;
  --radius-surface: 18px;
  --ui-font: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  --reading-font: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  /* Semantic color tokens: button variants consume only this centralized palette. */
  --color-primary: #315f58;
  --color-secondary: #ffffff;
  --color-neutral: #eeeee8;
  --color-danger: #a04e43;
  --color-warning: #886641;
  --color-success: #356951;
  --color-info: #42675e;
  --color-on-strong: #ffffff;
  --color-on-secondary: #215866;
  --color-on-neutral: #34434a;
  --color-primary-hover: #3a6b63;
  --color-primary-active: #264e49;
  --color-primary-shadow: #254943;
  --color-secondary-hover: #eef7f9;
  --color-secondary-active: #e2eff2;
  --color-secondary-border: #9fb8bf;
  --color-secondary-shadow: #b8cbd0;
  --color-neutral-hover: #e7edef;
  --color-neutral-active: #dce5e8;
  --color-neutral-border: #b9c8cd;
  --color-neutral-shadow: #c7d3d7;
  --color-danger-hover: #bd3b45;
  --color-danger-active: #8e2931;
  --color-danger-shadow: #702129;
  --color-warning-hover: #9b5d00;
  --color-warning-active: #744500;
  --color-warning-shadow: #613900;
  --color-success-hover: #2d7b51;
  --color-success-active: #1d5939;
  --color-success-shadow: #174a2f;
  --color-info-hover: #2d709f;
  --color-info-active: #1d5074;
  --color-info-shadow: #173f5c;
  --color-button-disabled-bg: #e9ece7;
  --color-button-disabled-border: #d8dfd6;
  --color-button-disabled-text: #6e7a71;
  scrollbar-gutter: stable;
  color-scheme: light;
  font-size: 15px;
  font-family: var(--ui-font);
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  background: var(--paper);
}

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

/* Chinese controls and Japanese study text use one face each, never a per-glyph UI fallback. */
:lang(ja) { font-family: var(--reading-font); }

.app-shell {
  width: min(calc(100% - 48px), 1420px);
  margin: 0 auto;
  padding: var(--space-4) 0 var(--space-6);
}

.app-shell > .panel {
  min-width: 0;
}

.app-shell:not(:has(.shadowing-panel:not([hidden]))) > .panel {
  max-width: 880px;
  margin-inline: auto;
}

@media (min-width: 1000px) {
  .app-shell:has(.shadowing-panel:not([hidden])) {
    display: grid;
    grid-template-columns: clamp(280px, 23vw, 320px) minmax(0, 1fr);
    gap: var(--space-5);
    align-items: start;
  }

  .app-header {
    grid-column: 1 / -1;
  }

  .app-shell > .panel {
    padding: var(--space-4);
  }

  .app-shell > .panel + .shadowing-panel {
    margin-top: 0;
  }

  .app-shell > .panel:not(.shadowing-panel) .section-heading {
    flex-wrap: wrap;
    gap: 12px;
  }

  .app-shell > .panel:not(.shadowing-panel) .mode-options {
    grid-template-columns: 1fr;
  }
}

.app-header {
  margin-bottom: var(--space-2);
}

.eyebrow,
.step-label {
  margin: 0 0 8px;
  color: #12677a;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-family: var(--ui-font);
  font-size: clamp(1.7rem, 2.5vw, 2.25rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.035em;
}

.intro {
  max-width: 620px;
  margin-bottom: 0;
  color: #56616c;
  font-size: 1rem;
  line-height: 1.55;
}

.panel {
  padding: clamp(20px, 3vw, 32px);
  border: 0;
  border-radius: var(--radius-surface);
  background: var(--surface-muted);
  box-shadow: none;
}

.panel + .panel {
  margin-top: 18px;
}

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

h2 {
  margin-bottom: 0;
  font-size: 1.3rem;
}

.phase-badge {
  flex: 0 0 auto;
  padding: 7px 11px;
  border-radius: 999px;
  background: #e2f1f4;
  color: #12677a;
  font-size: 0.8125rem;
  font-weight: 700;
}

label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
}

textarea {
  display: block;
  width: 100%;
  min-height: 180px;
  resize: vertical;
  padding: 12px;
  border: 1px solid #bdcbd0;
  border-radius: 12px;
  outline: none;
  background: #fbfdfe;
  color: #20252c;
  font-size: 1rem;
  line-height: 1.65;
}

textarea:focus {
  border-color: #18758a;
  box-shadow: 0 0 0 3px rgb(24 117 138 / 15%);
}

.input-hint {
  margin: 9px 0 0;
  color: #66737c;
  font-size: 0.875rem;
  line-height: 1.5;
}

.mode-selector {
  min-width: 0;
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}

.mode-selector legend {
  margin-bottom: 10px;
  padding: 0;
  font-weight: 700;
}

.mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid #c8d5da;
  border-radius: 12px;
  background: #fbfdfe;
  cursor: pointer;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background-color 150ms ease,
    box-shadow 150ms ease;
}

.mode-option:hover {
  transform: translateY(-2px);
  border-color: #5793a1;
  box-shadow: 0 7px 16px rgb(31 85 98 / 10%);
}

.mode-option:active {
  transform: translateY(1px) scale(0.99);
}

.mode-option:has(input:checked) {
  border-color: #18758a;
  background: #edf8fa;
  box-shadow: inset 0 0 0 1px #18758a;
}

.mode-option input {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: #12677a;
  cursor: pointer;
}

.mode-option span,
.mode-option strong,
.mode-option small {
  display: block;
}

.mode-option small {
  margin-top: 4px;
  color: #66737c;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

button {
  --button-background: var(--color-primary);
  --button-background-hover: var(--color-primary-hover);
  --button-background-active: var(--color-primary-active);
  --button-border: var(--color-primary);
  --button-text: var(--color-on-strong);
  --button-shadow: var(--color-primary-shadow);
  --button-focus: color-mix(in srgb, var(--button-border) 38%, transparent);
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--button-border);
  border-radius: 10px;
  background: var(--button-background);
  box-shadow: 0 4px 0 var(--button-shadow);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 700;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background-color 140ms ease,
    opacity 140ms ease;
}

/* Quiet controls share the same foreground/surface roles in either colour mode. */
.quiet-action {
  --button-background: transparent;
  --button-background-hover: var(--surface-muted);
  --button-background-active: var(--accent-soft);
  --button-border: transparent;
  --button-text: var(--muted);
  --button-shadow: transparent;
  --button-focus: var(--accent);
  border: 0; box-shadow: none; color: var(--button-text); background: var(--button-background);
}
.quiet-action:where(:hover,:focus-visible) { color: var(--ink); background: var(--button-background-hover); }
.quiet-action:where(:active) { color: var(--ink); background: var(--button-background-active); }

button:where(:hover) {
  transform: translateY(-2px);
  background: var(--button-background-hover);
  box-shadow: 0 7px 0 var(--button-shadow);
}

button:where(:active) {
  transform: translateY(2px) scale(0.99);
  background: var(--button-background-active);
  box-shadow: 0 1px 0 var(--button-shadow);
}

button:focus-visible {
  outline: 3px solid var(--button-focus);
  outline-offset: 3px;
}

.btn-primary {
  --button-background: var(--color-primary);
  --button-background-hover: var(--color-primary-hover);
  --button-background-active: var(--color-primary-active);
  --button-border: var(--color-primary);
  --button-text: var(--color-on-strong);
  --button-shadow: var(--color-primary-shadow);
}

.btn-secondary {
  --button-background: var(--color-secondary);
  --button-background-hover: var(--color-secondary-hover);
  --button-background-active: var(--color-secondary-active);
  --button-border: var(--color-secondary-border);
  --button-text: var(--color-on-secondary);
  --button-shadow: var(--color-secondary-shadow);
}

.btn-neutral {
  --button-background: var(--color-neutral);
  --button-background-hover: var(--color-neutral-hover);
  --button-background-active: var(--color-neutral-active);
  --button-border: var(--color-neutral-border);
  --button-text: var(--color-on-neutral);
  --button-shadow: var(--color-neutral-shadow);
}

.btn-danger {
  --button-background: var(--color-danger);
  --button-background-hover: var(--color-danger-hover);
  --button-background-active: var(--color-danger-active);
  --button-border: var(--color-danger);
  --button-text: var(--color-on-strong);
  --button-shadow: var(--color-danger-shadow);
}

.btn-warning {
  --button-background: var(--color-warning);
  --button-background-hover: var(--color-warning-hover);
  --button-background-active: var(--color-warning-active);
  --button-border: var(--color-warning);
  --button-text: var(--color-on-strong);
  --button-shadow: var(--color-warning-shadow);
}

.btn-success {
  --button-background: var(--color-success);
  --button-background-hover: var(--color-success-hover);
  --button-background-active: var(--color-success-active);
  --button-border: var(--color-success);
  --button-text: var(--color-on-strong);
  --button-shadow: var(--color-success-shadow);
}

.btn-info {
  --button-background: var(--color-info);
  --button-background-hover: var(--color-info-hover);
  --button-background-active: var(--color-info-active);
  --button-border: var(--color-info);
  --button-text: var(--color-on-strong);
  --button-shadow: var(--color-info-shadow);
}

button[aria-disabled="true"],
button:disabled {
  border-color: var(--color-button-disabled-border);
  background: var(--color-button-disabled-bg);
  box-shadow: none;
  color: var(--color-button-disabled-text);
  cursor: not-allowed;
  opacity: 1;
}

button[aria-disabled="true"]:hover,
button:disabled:hover {
  transform: none;
  border-color: var(--color-button-disabled-border);
  background: var(--color-button-disabled-bg);
  box-shadow: none;
  color: var(--color-button-disabled-text);
}

.action-feedback {
  margin: 13px 0 0;
  color: #c62828;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.5;
}

.action-feedback.is-visible {
  animation: feedback-life 3.6s ease forwards;
}

.action-feedback[hidden] {
  display: none;
}

.shortcut-toast {
  --toast-background: var(--color-info);
  position: fixed;
  z-index: 30;
  top: 20px;
  left: 50%;
  max-width: min(88vw, 360px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--toast-background);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--toast-background) 28%, transparent);
  color: var(--color-on-strong);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -10px);
}

.shortcut-toast[data-state="success"] {
  --toast-background: var(--color-success);
}

.shortcut-toast[data-state="warning"] {
  --toast-background: var(--color-warning);
}

.shortcut-toast.is-visible {
  animation: shortcut-toast-life 2.2s ease forwards;
}

.shortcut-toast[hidden] {
  display: none;
}

@keyframes shortcut-toast-life {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  12%, 82% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

@keyframes feedback-life {
  0% {
    opacity: 0;
    transform: translateY(-4px);
  }

  10%,
  82% {
    opacity: 1;
    transform: translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateY(-2px);
  }
}

.shadowing-panel[hidden] {
  display: none;
}

.sentence-counter {
  flex: 0 0 auto;
  margin: 3px 0 0;
  color: #12677a;
  font-weight: 700;
}

.sentence-stage {
  position: relative;
  scroll-margin-top: 12px;
}

.current-sentence {
  min-height: 132px;
  margin-bottom: 0;
  padding: clamp(16px, 2.5vw, 22px);
  padding-bottom: 64px;
  border: 1px solid #c8d9de;
  border-radius: 16px;
  outline: none;
  background: #f5fafb;
  font-size: var(--subtitle-font-size, 1.18rem);
  font-weight: 600;
  line-height: 2.15;
  letter-spacing: 0.02em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-break: strict;
  word-break: normal;
}

.sentence-stage:has(.subtitle-pagination:not([hidden])) .current-sentence {
  padding-bottom: 72px;
}

.shadowing-panel.is-full-text .current-sentence {
  font-weight: 400;
  line-height: 2.3;
}

.subtitle-sentence {
  /* Sentence identity belongs to the DOM; wrapping belongs to the paragraph.
     Whole sentences still move between pages in paginateSentenceNodes. */
  display: inline;
  margin: 0;
  margin-inline-end: 0.2em;
  /* Inline backgrounds do not include ruby overflow automatically. Reserve a
     highlight band for the annotation in every fragment, even when unselected. */
  padding-block: 0.7em 0.08em;
  border: 0;
  box-shadow: none;
}

/* The same quote geometry is used in measurement clones and the visible page. */
.current-sentence .subtitle-sentence[data-hanging-quote="true"] > .reading-surface:first-child,
.current-sentence > .subtitle-sentence:first-child[data-opening-quote="true"] > .reading-surface:first-child,
.current-sentence > .sentence-translation-unit:first-child > .subtitle-sentence[data-opening-quote="true"] > .reading-surface:first-child {
  margin-inline-start: -1em;
}
.current-sentence .subtitle-sentence > ruby[data-hanging-ruby="true"]:first-child {
  ruby-align: center;
  margin-inline-start: calc(-1 * var(--ruby-start-hang, 0px));
}
.current-sentence.has-optical-highlights { position: relative; isolation: isolate; }
/* Keep a single paint surface; existing theme rules still style text and focus. */
.current-sentence.has-optical-highlights .subtitle-sentence {
  background: transparent !important;
  box-shadow: none !important;
}
.sentence-highlight-layer {
  position: absolute; top: 0; left: -1em; width: calc(100% + 2em); height: 100%;
  z-index: -1; pointer-events: none; user-select: none;
  color: var(--accent-soft); border-color: var(--accent);
  outline-color: color-mix(in srgb, var(--ink) 4%, transparent);
}
.current-sentence.has-optical-highlights .subtitle-sentence:focus-visible { outline: none; }

/* is-long-sentence is diagnostic only, never an implicit paragraph break. */

.current-sentence ruby {
  position: relative;
  left: calc(-1 * (var(--ruby-line-shift, 0px) + var(--quote-line-shift, 0px)));
  ruby-position: over;
  /* Keep ruby width independent of adjacent sentence/translation wrappers.
     Overhanging readings otherwise wrap differently in the measuring clone. */
  ruby-overhang: none;
}
.current-sentence [data-optical-shift]:not(ruby) {
  position: relative;
  left: calc(-1 * var(--quote-line-shift, 0px));
}

/* Ruby annotations overflow their base line. Give every annotation the same
   paint order (editable readings were already positioned) above the highlight. */
.current-sentence rt { position: relative; z-index: 1; }

.reading-token {
  min-width: 1.2em;
  padding: 1px 2px;
  border-radius: 4px;
  text-align: center;
}

.reading-token.is-editable-reading {
  position: relative;
  cursor: pointer;
}

.reading-token.is-editable-reading:hover,
.reading-token.is-editable-reading:focus-visible {
  color: var(--color-danger);
  background: transparent;
  outline: none;
}

.reading-token.is-editable-reading:hover::after,
.reading-token.is-editable-reading:focus-visible::after {
  content: "？";
  position: absolute;
  inset-inline-start: 100%;
  inset-block-start: -0.1em;
  color: var(--color-danger);
  font-size: 0.82em;
  font-weight: 700;
}

.reading-editor {
  width: min(92vw, 430px);
  padding: 0;
  border: 1px solid #aac7ce;
  border-radius: 16px;
  box-shadow: 0 18px 60px rgb(13 62 73 / 30%);
}

.reading-editor::backdrop {
  background: rgb(13 43 50 / 42%);
}

.reading-editor form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.reading-editor h2,
.reading-editor dl,
.reading-editor dd {
  margin: 0;
}

.reading-editor-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.reading-editor-summary div {
  padding: 10px;
  border-radius: 10px;
  background: #eef7f8;
}

.reading-editor-summary dt {
  color: #66737c;
  font-size: 0.78rem;
}

.reading-editor-summary dd {
  margin-top: 3px;
  font-size: 1.2rem;
}

.reading-candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 10px;
}

.reading-candidates label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.reading-editor input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

.reading-remember-option {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reading-context-field {
  display: grid;
  gap: 6px;
  padding: 10px;
  border-radius: 10px;
  background: #f4f8f9;
}

.reading-context-field[hidden] {
  display: none;
}

.reading-context-field small {
  color: #66737c;
  line-height: 1.45;
}

.reading-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.reading-editor-error {
  margin: 0;
  color: #a12e2e;
}

.current-sentence rt {
  color: #858b92;
  font-size: 0.52em;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.05em;
}

.furigana-status {
  margin: 6px 0 0;
  color: #66737c;
  font-size: 0.8rem;
  line-height: 1.4;
}

.furigana-status[data-state="ready"] {
  color: #277044;
}

.furigana-status[data-state="warning"],
.furigana-status[data-state="error"] {
  color: #a04b12;
}

.content-language-notice {
  margin: 4px 0 0;
  color: var(--color-warning);
  font-size: 0.84rem;
}

.content-language-notice[hidden] {
  display: none;
}

.current-sentence:focus {
  border-color: #18758a;
  box-shadow: 0 0 0 3px rgb(24 117 138 / 15%);
}

.subtitle-cover {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px 22px 72px;
  border: 1px solid #8db3bd;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgb(226 241 244 / 96%), rgb(245 250 251 / 98%)),
    #edf8fa;
  color: #12677a;
  text-align: center;
}

.subtitle-cover strong {
  font-size: clamp(1.35rem, 4vw, 2rem);
  letter-spacing: 0.04em;
}

.subtitle-cover[hidden] {
  display: none;
}

.subtitle-toggle {
  position: absolute;
  min-height: 44px;
  z-index: 2;
  right: 14px;
  bottom: 14px;
}

.tts-panel {
  width: min(100%, 540px);
  margin-top: 8px;
  padding: 0;
  border: 1px solid #d3e0e4;
  border-radius: 12px;
  background: #fbfdfe;
  scroll-margin-top: 12px;
}

.tts-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
}

.tts-heading-row::-webkit-details-marker {
  display: none;
}

.tts-heading-row:hover {
  background: #f0f7f8;
}

.tts-heading-row:focus-visible {
  outline: 3px solid rgb(24 117 138 / 25%);
  outline-offset: 2px;
}

.tts-heading-copy,
.tts-heading-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tts-heading-copy small {
  color: #66737c;
  font-size: 0.8rem;
}

.tts-title {
  font-size: 0.95rem;
}

.settings-toggle-label::before {
  content: "展开 ▾";
  color: #12677a;
  font-size: 0.8rem;
  font-weight: 700;
}

.tts-panel[open] .settings-toggle-label::before {
  content: "收起 ▴";
}

.tts-settings-body {
  padding: 14px;
  border-top: 1px solid #d3e0e4;
}

.language-badge {
  padding: 5px 9px;
  border-radius: 999px;
  background: #e2f1f4;
  color: #12677a;
  font-size: 0.8125rem;
  font-weight: 700;
}

.voice-field label {
  margin-bottom: 8px;
}

.tts-settings-body .voice-field {
  margin-top: 14px;
}

select {
  width: 100%;
  min-height: 38px;
  padding: 7px 34px 7px 10px;
  border: 1px solid #bdcbd0;
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: #20252c;
  cursor: pointer;
}

select:focus-visible {
  border-color: #18758a;
  box-shadow: 0 0 0 3px rgb(24 117 138 / 15%);
}

select:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.speed-control {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.speed-control legend {
  margin-bottom: 9px;
  padding: 0;
  font-weight: 700;
}

.speed-options {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.speed-option {
  position: relative;
  display: block;
  margin: 0;
  cursor: pointer;
}

.speed-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.speed-option span {
  display: grid;
  min-height: 36px;
  place-items: center;
  padding: 6px;
  border: 1px solid #bdcbd0;
  border-radius: 9px;
  background: #fff;
  color: #46545d;
  font-weight: 700;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background-color 140ms ease,
    box-shadow 140ms ease;
}

.speed-option:hover span {
  transform: translateY(-2px);
  border-color: #5793a1;
  box-shadow: 0 5px 10px rgb(31 85 98 / 10%);
}

.speed-option:active span {
  transform: translateY(1px) scale(0.98);
}

.speed-option input:checked + span {
  border-color: #12677a;
  background: #12677a;
  box-shadow: 0 3px 0 #0a4b5a;
  color: #fff;
}

.speed-option input:focus-visible + span {
  outline: 3px solid rgb(24 117 138 / 25%);
  outline-offset: 3px;
}

.playback-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 0;
}

.playback-actions button {
  min-height: 42px;
  padding: 8px 14px;
  white-space: nowrap;
  font-size: 0.94rem;
}

#play-speech {
  min-width: 132px;
  font-weight: 700;
}

.playback-actions .is-control-reserved {
  display: none;
}

.shortcut-guide {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "cluster"
    "wide";
  align-items: start;
  gap: 6px;
  margin-top: 5px;
  padding: 8px;
  border: 1px solid #e0e8ea;
  border-radius: 9px;
  background: rgb(255 255 255 / 58%);
}

.shortcut-keyboard-cluster {
  grid-area: cluster;
  width: 100%;
}

.shortcut-key-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
}

.shortcut-key-row + .shortcut-key-row {
  margin-top: 3px;
}

.shortcut-key-help {
  display: grid;
  justify-items: center;
  min-width: 0;
  color: #66737c;
  font-size: 0.58rem;
  line-height: 1.15;
  text-align: center;
}

.shortcut-key-help kbd {
  display: grid;
  place-items: center;
  width: 28px;
  height: 22px;
  padding: 0 3px;
  border: 1px solid #c8d5d9;
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #fff;
  color: #46545d;
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 700;
  text-align: center;
}

.shortcut-key-help small {
  margin-top: 2px;
  font-size: inherit;
  white-space: nowrap;
}

.shortcut-wide-keys {
  grid-area: wide;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  margin-top: 0;
  min-width: 0;
}

.shortcut-key-help-wide {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}

.shortcut-key-help .shortcut-shift-key {
  width: 48px;
  justify-content: start;
  padding-left: 6px;
}

.shortcut-key-help .shortcut-space-key {
  width: 66px;
}

.shortcut-key-help-wide small {
  margin: 2px 0 0;
}

.playback-panel {
  display: flow-root;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid #d3e0e4;
  border-radius: 14px;
  background: #f7fbfc;
}

.subtitle-pagination {
  position: absolute;
  z-index: 2;
  left: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin: 0;
}

.subtitle-pagination[hidden] {
  display: none;
}

.subtitle-pagination .page-direction {
  min-height: 34px;
  padding: 6px 9px;
  font-size: 0.78rem;
}

.playback-page-locator {
  display: grid;
  place-items: center;
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 7px;
}

.playback-page-locator[hidden] {
  display: none;
}

.playback-locator-icon {
  position: relative;
  width: 17px;
  height: 17px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background:
    linear-gradient(currentColor, currentColor) center / 1px 100% no-repeat,
    linear-gradient(90deg, currentColor, currentColor) center / 100% 1px no-repeat;
}

.playback-locator-icon::after {
  position: absolute;
  inset: 4px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  content: "";
}

.page-slots {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
}

.page-slot {
  position: relative;
  width: 30px;
  min-width: 30px;
  min-height: 30px;
  padding: 3px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 700;
}

.page-slot[data-tooltip]::after {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: min(240px, 70vw);
  padding: 7px 9px;
  border-radius: 7px;
  background: #24323a;
  color: #fff;
  box-shadow: 0 5px 18px rgb(19 42 49 / 22%);
  content: attr(data-tooltip);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transform: translate(-50%, 4px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: pre-line;
}

.page-slot[data-tooltip]:hover::after,
.page-slot[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.page-jump-form {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  display: flex;
  align-items: center;
  gap: 6px;
  width: max-content;
  padding: 8px;
  border: 1px solid #bfd0d5;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 24px rgb(19 42 49 / 18%);
  color: #46545d;
  font-size: 0.78rem;
  font-weight: 700;
  transform: translateX(-50%);
}

.page-jump-form[hidden] {
  display: none;
}

.page-jump-form input {
  width: 64px;
  min-height: 32px;
  padding: 4px 6px;
  border: 1px solid #aebfc5;
  border-radius: 7px;
}

.page-jump-form button {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 0.75rem;
}

.page-jump-form .page-jump-close {
  width: 30px;
  min-width: 30px;
  padding-inline: 0;
}

.playback-panel .tts-panel {
  width: min(100%, 420px);
  margin: 10px 0 0 auto;
}

button.is-speaking {
  animation: speaking-pulse 1.4s ease-in-out infinite;
}

@keyframes speaking-pulse {
  0%,
  100% {
    box-shadow: 0 4px 0 var(--button-shadow);
  }

  50% {
    box-shadow:
      0 4px 0 var(--button-shadow),
      0 0 0 6px color-mix(in srgb, var(--button-background) 18%, transparent);
  }
}

.tts-status {
  margin: 14px 0 0;
  color: #56616c;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.session-badge {
  padding: 5px 9px;
  border-radius: 999px;
  background: #edf3f5;
  color: #66737c;
  font-size: 0.75rem;
  font-weight: 700;
}

.recording-switch {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 6px 9px;
  border: 1px solid #bdcbd0;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
}

.recording-switch:has(input:checked) {
  border-color: #12677a;
  background: #e2f1f4;
  color: #12677a;
}

.compact-button {
  padding: 7px 10px;
  font-size: 0.8rem;
}

.coming-soon {
  margin: 16px 0 0;
  color: #66737c;
  font-size: 0.9375rem;
}

.sentence-navigation {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.sentence-navigation[hidden] {
  display: none;
}

.status {
  margin: 18px 0 0;
  padding-top: 18px;
  border-top: 1px solid #e3eaed;
  color: #66737c;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.is-js-ready .status::before {
  content: "●";
  margin-right: 8px;
  color: #198754;
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 880px);
    padding: 16px 0;
  }

  .panel {
    padding: 16px;
  }

  .section-heading {
    display: block;
  }

  .phase-badge {
    display: inline-block;
    margin-top: 14px;
  }

  .sentence-counter {
    margin-top: 14px;
  }

  .actions button {
    flex: 1 1 100%;
  }

  .mode-options {
    grid-template-columns: 1fr;
  }

  .sentence-navigation button {
    flex: 1 1 50%;
  }

  .playback-actions button {
    width: 100%;
    min-width: 0;
    padding-inline: 8px;
    font-size: 0.94rem;
  }

  .playback-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #play-speech {
    min-width: 0;
  }

  .current-sentence {
    min-height: 132px;
    padding: 16px;
    padding-bottom: 62px;
  }

  .sentence-stage:has(.subtitle-pagination:not([hidden])) .current-sentence {
    padding-bottom: 112px;
  }

  .subtitle-pagination {
    right: 14px;
    bottom: 58px;
    justify-content: center;
  }

  .subtitle-pagination {
    gap: 5px;
  }

  .subtitle-pagination .page-direction {
    flex: 1 1 0;
  }

  .page-slots {
    gap: 2px;
  }

  .page-slot {
    width: 27px;
    min-width: 27px;
    min-height: 29px;
    font-size: 0.72rem;
  }

  .page-jump-form {
    max-width: calc(100vw - 40px);
  }

  .tts-heading-copy small,
  .language-badge {
    display: none;
  }

  .speed-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

}

@media (prefers-reduced-motion: reduce) {
  button,
  .mode-option,
  .speed-option span,
  .subtitle-sentence {
    transition: none;
  }

  .action-feedback.is-visible {
    animation: none;
  }

  .shortcut-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
    animation: none;
  }

  button.is-speaking {
    animation: none;
  }
}
.shadowing-panel > .section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.shadowing-panel > .section-heading > div { flex: 1; }
.shadowing-panel .tts-panel {
  width: min(100%, 360px);
  margin: 0 0 0 auto;
  order: 2;
  align-self: start;
}
.shadowing-panel .sentence-counter { order: 1; font-size: 0.88rem; }
.tts-heading-row { min-height: 36px; }
.tts-status { margin-top: 8px; font-size: 0.87rem; }
.furigana-status[data-state="ready"] { display: none; }
.current-sentence,
.shadowing-panel.is-full-text .current-sentence {
  font-size: 22px;
  line-height: 2.25;
  font-weight: 400;
}
.subtitle-sentence {
  position: relative;
  z-index: 0;
  cursor: pointer;
  border-radius: 6px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-color 140ms ease;
}
.subtitle-sentence::before {
  content: none;
}
.reading-surface {
  text-decoration: underline;
  text-decoration-color: #b5cbd1;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  transition: color 140ms ease, text-decoration-color 140ms ease;
}
.subtitle-sentence:hover,
.subtitle-sentence:focus-visible {
  background: color-mix(in srgb, var(--color-primary) 9%, transparent);
}
.subtitle-sentence:active {
  background: color-mix(in srgb, var(--color-primary) 16%, transparent);
}
.subtitle-sentence.is-selected {
  background: color-mix(in srgb, var(--color-info) 13%, transparent);
  font-size: 1.055em;
}
.subtitle-sentence:hover .reading-surface,
.subtitle-sentence:focus-visible .reading-surface,
.subtitle-sentence.is-selected .reading-surface {
  text-decoration-color: var(--color-primary);
}
.subtitle-sentence.is-selected .reading-surface { color: #095b70; }
.subtitle-sentence:focus-visible { outline: none; }
.current-sentence.subtitle-measure {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  min-height: 0;
  padding: 0;
  border: 0;
  height: auto;
  box-sizing: content-box;
}
@media (max-width: 900px) {
  /* Keep mobile WebKit's hidden pagination probe at its natural text height.
     Auto grid alignment otherwise stretches it and forces one sentence per page.
     This belongs to measurement, independent of the mobile visual theme. */
  .mobile-reading-region .current-sentence.subtitle-measure {
    align-self: start;
    top: 0;
    bottom: auto;
    height: auto;
  }
}
@media (max-width: 700px) {
  .shadowing-panel .tts-panel { width: 100%; }
  .current-sentence,
  .shadowing-panel.is-full-text .current-sentence { font-size: 20px; }
}

/* Keep reading options attached to the playback controls on wide layouts. */
.playback-panel {
  position: relative;
}

.playback-settings-rail {
  position: relative;
  z-index: 3;
  float: right;
  width: min(100%, 360px);
  margin: 0 0 8px 12px;
}

.playback-settings-rail .tts-panel {
  position: static;
  width: 100%;
  margin: 0;
}

.playback-panel .playback-actions {
  padding-right: 0;
}

/* Hide the glyphs while keeping every sentence's measured width and underline. */
.current-sentence.subtitles-hidden .subtitle-sentence {
  color: transparent;
  text-shadow: none;
}

.current-sentence.subtitles-hidden .reading-surface {
  text-decoration-color: #b5cbd1;
}

.current-sentence.subtitles-hidden .subtitle-sentence:hover,
.current-sentence.subtitles-hidden .subtitle-sentence:focus-visible,
.current-sentence.subtitles-hidden .subtitle-sentence:active,
.current-sentence.subtitles-hidden .subtitle-sentence.is-selected {
  color: transparent;
}

.current-sentence.subtitles-hidden .subtitle-sentence.is-selected .reading-surface {
  color: transparent;
  text-decoration-color: #b5cbd1;
}

.current-sentence.subtitles-hidden ruby rt,
.current-sentence.subtitles-hidden ruby rp {
  visibility: hidden;
}

.current-sentence.subtitles-hidden .reading-token {
  pointer-events: none;
}

/* The optical layer draws one guide per displayed line. Preserve the real
   glyph/ruby boxes for pagination and pointer targets; hide only their paint. */
.current-sentence.has-optical-highlights.subtitles-hidden .reading-surface {
  color: transparent !important;
  text-decoration: none !important;
}
.current-sentence.subtitles-hidden .sentence-highlight-layer {
  outline-color: color-mix(in srgb, var(--muted) 70%, var(--surface));
}

@media (max-width: 700px) {
  .playback-settings-rail {
    position: static;
    float: none;
    width: 100%;
    margin: 0 0 8px;
  }

  .playback-settings-rail .tts-panel {
    width: 100%;
  }

  .playback-panel .playback-actions {
    padding-right: 0;
  }
}

/* Voice Lab beta: product-trial voice selection stays out of the main workflow. */
.voice-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: center;
}

.voice-field-label {
  color: var(--color-text-muted, #66737c);
  font-size: 0.78rem;
}

.voice-field strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}

.voice-field .voice-field-label,
.voice-field strong {
  grid-column: 1;
}

.voice-field button {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: stretch;
  padding-inline: 12px;
}

.voice-lab {
  width: min(1040px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--color-primary) 22%, white);
  border-radius: 20px;
  background: #f8fbfc;
  box-shadow: 0 24px 80px rgb(13 62 73 / 32%);
}

.voice-lab::backdrop {
  background: rgb(13 43 50 / 48%);
  backdrop-filter: blur(3px);
}

.voice-lab-shell {
  display: grid;
  gap: 18px;
  max-height: calc(100vh - 32px);
  padding: 24px;
  overflow: auto;
}

.voice-lab-header,
.voice-lab-current,
.voice-lab-provider-heading,
.voice-lab-fallback {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.voice-lab-header h2,
.voice-lab-header p,
.voice-lab-provider h3,
.voice-lab-fallback h3,
.voice-lab-fallback p {
  margin: 0;
}

.voice-lab-header > div {
  display: grid;
  gap: 4px;
}

.voice-lab-eyebrow {
  color: var(--color-primary);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.voice-lab-close {
  min-width: 42px;
  min-height: 42px;
  padding: 4px;
  border-radius: 50%;
  font-size: 1.45rem;
}

.voice-lab-current,
.voice-lab-fallback,
.voice-lab-provider,
.voice-lab-archived {
  padding: 16px;
  border: 1px solid #d3e0e4;
  border-radius: 15px;
  background: white;
}

.voice-lab-current > div {
  display: grid;
  gap: 4px;
}

.voice-lab-current span {
  color: #66737c;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.voice-lab-feedback {
  min-height: 1.35em;
  margin: -8px 2px 0;
  color: var(--color-info);
  font-size: 0.88rem;
}

.voice-lab-provider {
  display: grid;
  gap: 14px;
}

.voice-lab-archived > summary {
  cursor: pointer;
  font-weight: 700;
}

.voice-lab-archived > summary span {
  display: inline-grid;
  min-width: 1.7em;
  margin-left: 5px;
  padding: 1px 6px;
  place-items: center;
  border-radius: 999px;
  background: var(--color-neutral-hover);
  color: var(--color-on-neutral);
  font-size: 0.76rem;
}

.voice-lab-archived > p {
  margin: 8px 0 14px;
  color: #66737c;
  font-size: 0.82rem;
}

.voice-card.is-archived {
  border-style: dashed;
  background: #f7f8f8;
}

.voice-archive-identity {
  overflow-wrap: anywhere;
  color: #66737c;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.68rem;
}

.voice-lab-provider-heading > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.provider-status {
  font-size: 0.8rem;
  font-weight: 700;
}

.provider-status[data-state="available"] { color: var(--color-success); }
.provider-status[data-state="offline"] { color: var(--color-neutral); }
.provider-status[data-state="loading"] { color: var(--color-info); }

.voice-lab-filters,
.voice-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.voice-lab-filters button {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 0.78rem;
}

.voice-lab-filters button.is-active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

.voice-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.voice-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid #d7e2e5;
  border-radius: 13px;
  background: #fbfdfe;
}

.voice-card.is-current {
  border-color: var(--color-success);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-success) 55%, transparent);
}

.voice-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.voice-card-heading h4 { margin: 0; }

.voice-card-heading span {
  color: #66737c;
  font-size: 0.72rem;
}

.voice-card label,
.voice-personal-field {
  display: grid;
  gap: 5px;
  color: #66737c;
  font-size: 0.76rem;
}

.voice-card select,
.voice-personal-note,
.voice-lab-browser-control select {
  min-height: 38px;
  box-sizing: border-box;
  padding: 7px 9px;
  border: 1px solid #b8cbd0;
  border-radius: 9px;
  background: white;
  color: #243139;
}

.voice-card-actions button { flex: 1 1 112px; }
.voice-card small { color: #66737c; }

.voice-lab-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 20px;
  color: #66737c;
  text-align: center;
}

.voice-lab-browser-control {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 5px 10px;
  align-items: end;
}

.voice-lab-browser-control label { grid-column: 1; font-size: 0.78rem; }
.voice-lab-browser-control select { grid-column: 1; }
.voice-lab-browser-control button { grid-column: 2; grid-row: 1 / span 2; }

.voice-lab-developer {
  padding: 12px 14px;
  border: 1px solid #d3e0e4;
  border-radius: 12px;
  background: #f4f8f9;
}

.voice-lab-developer summary { cursor: pointer; font-weight: 700; }
.voice-lab-developer pre {
  overflow: auto;
  max-height: 240px;
  white-space: pre-wrap;
  font-size: 0.75rem;
}

@media (max-width: 700px) {
  .voice-lab-shell { padding: 16px; }
  .voice-lab-header,
  .voice-lab-current,
  .voice-lab-provider-heading,
  .voice-lab-fallback { align-items: stretch; flex-direction: column; }
  .voice-lab-close { position: absolute; top: 12px; right: 12px; }
  .voice-lab-provider-heading > div:first-child { align-items: flex-start; flex-direction: column; gap: 3px; }
  .voice-lab-browser-control { width: 100%; grid-template-columns: 1fr; }
  .voice-lab-browser-control label,
  .voice-lab-browser-control select,
  .voice-lab-browser-control button { grid-column: 1; grid-row: auto; }
}

/* OCR is an input aid only: recognized text returns to the existing article field. */
.ocr-input-tools {
  display: grid;
  gap: 8px;
  margin: 10px 0 2px;
  padding: 12px;
  border: 1px solid #d3e0e4;
  border-radius: 12px;
  background: #f7fafb;
}

.ocr-input-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ocr-input-toolbar strong { margin-right: auto; }
.ocr-input-toolbar button { min-height: 44px; min-width: 44px; padding: 6px 11px; font-weight: 500; }

.ocr-drop-zone {
  padding: 13px 14px;
  border: 2px dashed #a7bdc4;
  border-radius: 10px;
  color: #52666f;
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.ocr-drop-zone:hover,
.ocr-drop-zone:focus-visible,
.ocr-drop-zone.is-dragging {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 8%, white);
  color: var(--color-primary);
  outline: none;
}

.ocr-drop-zone.is-processing { cursor: progress; opacity: 0.7; }
.ocr-input-tools .input-hint { margin: 0; }

.ocr-status {
  min-height: 1.25em;
  margin: 0;
  color: #52666f;
  font-size: 0.82rem;
}

.ocr-status[data-state="processing"] { color: var(--color-info); }
.ocr-status[data-state="ready"] { color: var(--color-success); }
.ocr-status[data-state="error"] { color: var(--color-danger); }

.ocr-merge-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 18px 55px rgba(24, 40, 48, 0.24);
}

.ocr-merge-dialog::backdrop { background: rgba(18, 31, 38, 0.48); }

.ocr-merge-shell {
  display: grid;
  gap: 12px;
  padding: 22px;
}

.ocr-merge-shell h2,
.ocr-merge-shell p { margin: 0; }
.ocr-merge-shell label { font-weight: 700; }
.ocr-merge-shell textarea { width: 100%; box-sizing: border-box; resize: vertical; }
.ocr-merge-actions { margin-top: 2px; }

@media (max-width: 700px) {
  .ocr-input-toolbar strong { flex-basis: 100%; }
  .ocr-input-toolbar button { flex: 1 1 130px; }
  .ocr-merge-actions button { flex: 1 1 100%; }
}

/* Reading desk: typography and space take priority over container chrome. */
.skip-link {
  position: fixed;
  z-index: 40;
  top: 8px;
  left: 8px;
  padding: 9px 13px;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: white;
  transform: translateY(-160%);
}
.skip-link:focus-visible { transform: translateY(0); }

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 18px;
  padding: 0 4px var(--space-3);
  border-bottom: 1px solid var(--line);
}
.app-kicker {
  flex-basis: 100%;
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
}
.app-header-note { margin: 0; color: var(--muted); font-size: 0.88rem; }

/* In an active lesson, page chrome yields to the unchanged reading surface. */
.app-shell:has(.shadowing-panel:not([hidden])) .app-header h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0;
}
.app-shell:has(.shadowing-panel:not([hidden])) .app-kicker { color: var(--muted); }
.app-shell:has(.shadowing-panel:not([hidden])) .actions #start-learning {
  --button-background: var(--surface);
  --button-background-hover: #f4f7f2;
  --button-background-active: #edf2eb;
  --button-border: var(--line);
  --button-text: var(--ink);
}

.app-shell > .panel:not(.shadowing-panel) { background: var(--surface-muted); }
.app-shell > .shadowing-panel {
  background: var(--surface);
  box-shadow: none;
}
.section-heading { margin-bottom: var(--space-4); }
.section-heading h2 {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.shadowing-panel > .section-heading {
  max-width: 52rem;
  margin-inline: auto;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line);
}
.shadowing-panel > .section-heading h2 {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0;
}
.sentence-counter {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.sentence-stage {
  /* A flex child with auto inline margins otherwise shrink-wraps its empty
     content on entry. Pagination must measure the final reading width even
     before the first sentence or ruby has arrived. */
  width: 100%; min-width: 0; max-width: 52rem; margin: 0 auto;
}
:is(#article-input, #article-source-display),
#ocr-result-preview { font-family: var(--reading-font); font-weight: 400; }
.current-sentence,
.shadowing-panel.is-full-text .current-sentence {
  min-height: 17rem;
  padding: var(--space-4) var(--space-2) 5.25rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--reading-font);
  font-size: clamp(1.35rem, 1.5vw, 1.5rem);
  font-weight: 400;
  --reader-leading: 2.65;
  line-height: calc(var(--reader-leading) * var(--reader-leading-scale, 1));
  letter-spacing: 0.012em;
  overflow-wrap: anywhere;
}
.current-sentence[data-reading-density="compact"] { --reader-leading-scale: .955; }
.reading-passage { display: contents; }
/* Programmatic reading destination, not an interactive control. Keep focus for
   navigation/assistive technology without framing the entire reading area.
   Child sentence and button focus indicators remain independent. */
#current-sentence:focus,
#current-sentence:focus-visible { border-color: transparent; box-shadow: none; outline: none; }
/* A single short page need not occupy the full seven-line pagination measure. */
.sentence-stage:has(.subtitle-pagination[hidden]) .current-sentence { min-height: 0 !important; }
.current-sentence rt {
  color: #63746a;
  font-size: 0.56em;
  font-weight: 500;
  letter-spacing: 0.015em;
}
.reading-surface { text-decoration-color: transparent; text-underline-offset: 0.26em; }
.subtitle-sentence {
  border-radius: 3px;
  transition: background-color 180ms ease, color 180ms ease;
}
.subtitle-sentence:hover,
.subtitle-sentence:focus-visible { background: #eef2ea; }
.subtitle-sentence.is-selected {
  background: var(--accent-soft);
  box-shadow: inset 0 -2px 0 var(--accent);
  color: var(--ink);
  font-size: inherit;
}
.subtitle-sentence.is-selected .reading-surface {
  color: var(--ink);
  text-decoration-color: transparent;
}
.subtitle-sentence:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
/* Keep the authoritative reading-state rules covered by reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .subtitle-sentence,
  .reading-surface { transition: none; }
}
.reading-token.is-editable-reading {
  text-decoration: underline dotted #8da69a;
  text-underline-offset: 0.24em;
}
.reading-token.is-editable-reading:hover,
.reading-token.is-editable-reading:focus-visible {
  color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.furigana-status,
.content-language-notice,
.input-hint,
.tts-status { color: var(--muted); }
.furigana-status[data-state="error"],
.action-feedback,
.reading-editor-error { color: var(--error); }

/* Controls sit around the text rather than looking like a second dashboard. */
button {
  min-height: 40px;
  border-radius: var(--radius-control);
  box-shadow: none;
  font-weight: 700;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}
button:where(:hover) { transform: none; box-shadow: none; }
button:where(:active) { transform: none; box-shadow: none; }
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button[aria-disabled="true"],
button:disabled,
button[aria-disabled="true"]:hover,
button:disabled:hover { box-shadow: none; transform: none; }
.btn-secondary {
  --button-border: var(--line);
  --button-background: var(--surface);
  --button-background-hover: var(--surface-muted);
  --button-background-active: var(--accent-soft);
  --button-text: var(--ink);
}
.btn-neutral,
.btn-warning,
.btn-info {
  --button-border: transparent;
  --button-background: transparent;
  --button-background-hover: var(--surface-muted);
  --button-background-active: var(--accent-soft);
  --button-text: var(--ink);
}
.btn-danger {
  --button-border: transparent;
  --button-background: transparent;
  --button-background-hover: var(--surface-muted);
  --button-background-active: var(--surface-muted);
  --button-text: var(--error);
}
.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
  margin-top: var(--space-3);
}
.actions #start-learning { grid-column: 1 / -1; min-height: 46px; }
.actions #save-article {
  --button-background: var(--surface);
  --button-background-hover: #f4f7f2;
  --button-background-active: #eaf0e8;
  --button-border: var(--line);
  --button-text: var(--ink);
}
.actions button { min-width: 0; }
textarea,
select { border-color: var(--line); border-radius: var(--radius-control); background: var(--surface); color: var(--ink); }
textarea { min-height: 14rem; padding: var(--space-3); line-height: 1.75; }
textarea:focus, select:focus-visible { border-color: var(--accent); box-shadow: none; }
.status {
  margin-top: var(--space-4);
  padding: 0 0 0 var(--space-2);
  border-top: 0;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-size: 0.84rem;
}
.is-js-ready .status::before { content: none; }

.ocr-input-tools {
  display: block;
  margin-top: var(--space-3);
  padding: 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.ocr-input-tools > summary {
  padding: var(--space-2) 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.ocr-input-tools > summary span { margin-left: 0.4em; font-size: 0.78rem; font-weight: 400; }
.ocr-input-toolbar { padding-top: var(--space-1); }
.ocr-drop-zone {
  margin-top: var(--space-2);
  min-height: 44px;
  border: 1px dashed #9baea1;
  border-radius: var(--radius-control);
  color: var(--muted);
  text-align: left;
}
.ocr-input-tools:has(.ocr-pages:not([hidden])) .ocr-drop-zone {
  padding: 10px 0;
  border-color: transparent;
  background: transparent;
  font-size: 0.8rem;
}
.ocr-drop-zone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.playback-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "actions"
    "status"
    "feedback"
    "settings"
    "diagnostics";
  align-items: start;
  gap: var(--space-2) var(--space-4);
  max-width: 52rem;
  margin: var(--space-4) auto 0;
  padding: var(--space-4) 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.playback-panel .playback-actions { grid-area: actions; gap: var(--space-1); }
.playback-panel .playback-settings-rail {
  grid-area: settings;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-2) var(--space-4);
  min-width: 0;
  float: none;
  width: auto;
  margin: 0;
  z-index: 3;
}
.playback-panel .tts-panel {
  order: 0;
  flex: 0 1 22rem;
  min-width: 0;
  width: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.tts-heading-row { min-height: 44px; padding: 6px 0; }
.playback-panel .tts-heading-row:hover { background: transparent; color: var(--accent); }
.playback-panel .settings-toggle-label::before,
.tts-heading-copy { display: grid; flex: 1 1 auto; min-width: 0; gap: 1px; }
.playback-panel .tts-heading-meta { flex: 0 0 auto; white-space: nowrap; }
.tts-heading-copy small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tts-title { color: var(--muted); font-size: 0.86rem; font-weight: 500; }
.tts-settings-body { padding: var(--space-2) 0; border-color: var(--line); }
.playback-panel .speed-control legend { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.sentence-gap-control { min-width: 0; margin: var(--space-3) 0 0; padding: 0; border: 0; }
.sentence-gap-control legend { margin-bottom: 8px; padding: 0; color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.sentence-gap-inputs { display: flex; align-items: center; gap: 12px; min-width: 0; }
.sentence-gap-inputs input[type="range"] { flex: 1; width: 0; min-width: 0; min-height: 44px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.sentence-gap-scale { display: grid; grid-template-columns: repeat(5, 1fr); color: var(--muted); font-size: 0.82rem; }
.sentence-gap-scale span:first-child { grid-column: 1; }
.sentence-gap-scale span:nth-child(2) { grid-column: 3; text-align: center; }
.sentence-gap-scale span:last-child { grid-column: 5; text-align: right; }
.sentence-gap-control input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#sentence-gap-help { display: block; margin-top: 4px; color: var(--muted); font-size: 0.78rem; line-height: 1.6; }
.speed-option span { min-height: 44px; border-color: var(--line); box-shadow: none; font-variant-numeric: tabular-nums; }
.speed-option input:checked + span { background: var(--accent); border-color: var(--accent); box-shadow: none; }
.playback-actions button { min-height: 44px; padding: 9px 12px; font-size: 0.88rem; font-weight: 500; }
#play-speech { min-width: 165px; min-height: 48px; font-size: 0.98rem; font-weight: 600; }
.playback-panel #reset-speech { color: var(--muted); }
button.is-speaking { animation: none; box-shadow: none; }
.playback-panel #tts-feedback {
  grid-area: feedback;
  margin: 0;
  padding: var(--space-2);
  border-left: 2px solid var(--error);
  background: #f4e7e3;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}
.playback-panel .tts-status {
  grid-area: status;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}
.shortcuts-panel { flex: 1 1 14rem; min-width: 0; margin-top: 0; }
.shortcuts-panel > summary {
  min-height: 44px;
  padding-block: 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
}
.shortcut-guide { margin-top: 0; border-color: var(--line); background: transparent; }

.tts-diagnostics {
  grid-area: diagnostics;
  padding-top: 0;
  border-top: 0;
  color: var(--muted);
}
.tts-diagnostics > summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-1);
  min-height: 44px;
  padding-block: 12px;
  cursor: pointer;
  font-size: 0.82rem;
}
.tts-diagnostics > summary strong { color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.tts-diagnostics-body { max-width: 32rem; padding: var(--space-3) 0 var(--space-1); }
.tts-diagnostics-body label { margin: 0 0 var(--space-1); font-size: 0.82rem; }
.tts-diagnostics-body p { margin: var(--space-2) 0 0; font-size: 0.78rem; line-height: 1.6; }
.tts-diagnostics-body select { max-width: 28rem; min-height: 44px; }

/* Secondary workspaces use the same quiet surfaces as the reading desk. */
.reading-editor,
.ocr-merge-dialog,
.voice-lab {
  border: 1px solid var(--line);
  border-radius: var(--radius-surface);
  background: var(--surface);
  box-shadow: 0 24px 72px rgb(24 40 31 / 17%);
}
.reading-editor::backdrop,
.ocr-merge-dialog::backdrop,
.voice-lab::backdrop { background: rgb(25 37 30 / 43%); }
.reading-editor-summary div,
.reading-context-field,
.voice-lab-current,
.voice-lab-fallback,
.voice-lab-provider,
.voice-lab-archived,
.voice-lab-developer {
  border-color: var(--line);
  background: var(--surface-muted);
}
.voice-lab-shell { gap: var(--space-3); }
.voice-card { border-color: var(--line); background: var(--surface); }
.voice-card.is-current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.voice-card select,
.voice-personal-note,
.voice-lab-browser-control select { border-color: var(--line); color: var(--ink); }
.voice-lab-eyebrow { color: var(--accent); }
.voice-lab-filters button.is-active { border-color: var(--accent); color: var(--accent); }
.reading-editor input[type="text"] { border-color: var(--line); border-radius: var(--radius-control); }

@media (max-width: 999px) {
  .app-shell:has(.shadowing-panel:not([hidden])) { width: min(calc(100% - 32px), 880px); }
  .app-shell > .panel + .shadowing-panel { margin-top: var(--space-3); }
  .app-shell:has(.shadowing-panel:not([hidden])) > .panel:not(.shadowing-panel) textarea {
    min-height: 9rem;
  }
}

@media (max-width: 700px) {
  .app-shell { width: min(calc(100% - 24px), 880px); }
  .app-header { padding-bottom: var(--space-2); }
  .app-header-note { flex-basis: 100%; font-size: 0.82rem; }
  .panel { padding: var(--space-4); }
  .playback-panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "actions" "status" "feedback" "settings" "diagnostics";
    gap: var(--space-2);
  }
  .playback-panel .playback-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .playback-panel .playback-actions button { width: 100%; min-width: 0; white-space: normal; }
  .playback-panel #play-speech { grid-column: 1 / -1; }
  .playback-panel .playback-settings-rail { width: 100%; margin: 0; }
  .tts-heading-copy small { display: block; }
  .current-sentence,
  .shadowing-panel.is-full-text .current-sentence {
    min-height: 13rem;
    padding: var(--space-3) var(--space-1) 5.5rem;
    font-size: 1.35rem;
    --reader-leading: 2.25;
  }
  .sentence-stage:has(.subtitle-pagination:not([hidden])) .current-sentence { padding-bottom: 7rem; }
  .voice-lab-shell { gap: var(--space-2); }
}

@media (max-width: 560px) {
  .app-shell { width: min(calc(100% - 20px), 880px); padding-top: var(--space-2); }
  .panel { padding: var(--space-3); }
  .app-header { gap: 3px; }
  .app-header h1 { font-size: 1.7rem; }
  .app-header-note { line-height: 1.5; }
  .actions { gap: 6px; }
  .actions #start-learning { min-height: 44px; }
  .shadowing-panel > .section-heading { display: flex; align-items: baseline; }
  .shadowing-panel .sentence-counter { margin-top: 0; }
  .current-sentence,
  .shadowing-panel.is-full-text .current-sentence { padding-inline: 0; font-size: 1.28rem; }
  .sentence-stage:has(.subtitle-pagination:not([hidden])) .current-sentence { padding-bottom: 7.5rem; }
  /* Keep pagination above the separately positioned no-subtitle control. */
  .subtitle-pagination { right: 0; left: 0; bottom: 70px; justify-content: center; }
  .subtitle-pagination .page-direction,
  .subtitle-pagination .page-slot { min-height: 44px; }
  .tts-diagnostics > summary { align-items: baseline; }
  .reading-editor form,
  .ocr-merge-shell { padding: var(--space-3); }
  .reading-editor-summary { grid-template-columns: 1fr 1fr; }
  .voice-card-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 380px) {
  .app-header h1 { font-size: 1.55rem; }
  .playback-panel .playback-actions { grid-template-columns: 1fr; }
  .playback-panel #play-speech { grid-column: 1; }
  .sentence-counter { font-size: 0.75rem; }
}

/* A single editor heading; recovery is a contextual action, not a primary one. */
.article-editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2rem;
  margin-bottom: 0.65rem;
}
.article-editor-heading h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}
.lesson-draft-help {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
}
.article-input-label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}
.article-panel[data-lesson-stage="REVIEW_CONTENT"] .lesson-draft-help {
  font-size: 0.8rem;
}
.article-editor-heading .article-restore {
  min-height: 44px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
}
.article-restore[hidden] { display: none; }
.article-panel :is(#article-input, #article-source-display) {
  min-height: 12rem;
  padding: 1rem 0.85rem 1rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: #b6c2b9 transparent;
  scrollbar-gutter: stable;
}
#article-input::-webkit-scrollbar { width: 6px; }
#article-input::-webkit-scrollbar-track { background: transparent; }
#article-input::-webkit-scrollbar-thumb {
  background: #b6c2b9;
  border-radius: 3px;
}
#article-input::-webkit-scrollbar-thumb:hover { background: #879d90; }
#article-input::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
