:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  --paper: #f5f5f7;
  --sheet: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --control-line: #86868b;
  --accent: #0071e3;
  --accent-hover: #0062c3;
  --focus: #0071e3;
  --danger: #a12831;
  --danger-hover: #7e1822;
  --control-radius: 10px;
  --panel-radius: 18px;
  --reader: #101012;
  --reader-panel: #1c1c1e;
  --reader-text: #f5f5f7;
  --reader-muted: #c7c7cc;
  --reader-line: #3a3a3c;
  --reader-control: #2c2c2e;
  --reader-control-line: #828288;
  --reader-hover: #39393d;
  --reader-focus: #64b5ff;
  --reader-warning: #ffe0a8;
  --cue: #8ac7ff;
  --reading-line: 34%;
  --numerals: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p, dl, dd { margin: 0; }
button, textarea, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }
.shell { width: min(100% - 64px, 1240px); margin-inline: auto; }

.topbar { background: var(--sheet); border-bottom: 1px solid var(--line); }
.topbar-content {
  min-height: 76px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.identity { display: flex; align-items: baseline; gap: 16px; }
.identity h1 { font-size: clamp(1.5rem, 3vw, 2.05rem); line-height: 1.12; letter-spacing: -.045em; }
.brand {
  border-inline-start: 1px solid var(--line);
  padding-inline-start: 16px;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 600;
}
.topbar nav { display: flex; align-items: center; gap: clamp(10px, 2.1vw, 24px); font-size: .9rem; font-weight: 600; }
.topbar a { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); text-underline-offset: 4px; }
.topbar a:hover { color: var(--accent-hover); }
.language {
  min-width: 44px;
  min-height: 44px;
  padding-inline: 12px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--paper);
  color: var(--ink);
  font-weight: 650;
}
.language:hover { border-color: var(--accent); background: var(--sheet); color: var(--accent-hover); }

.workbench { padding-block: clamp(20px, 3vw, 24px) 30px; }
.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: clamp(16px, 2vw, 24px);
}
.side-column { display: grid; align-content: start; gap: 18px; min-width: 0; }
.editor, .preview-panel, .settings {
  min-width: 0;
  padding: clamp(16px, 2vw, 20px);
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--sheet);
}
.editor { display: flex; flex-direction: column; min-width: 0; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-height: 44px;
  margin-bottom: 12px;
}
.section-heading h2, .settings h2 {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.editor-actions, .result-actions, .dialog-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.button {
  min-height: 44px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: var(--control-radius);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
}
.secondary { border-color: var(--line); background: var(--paper); }
.secondary:hover { border-color: var(--control-line); background: #ededf0; }
.secondary:disabled { border-color: var(--line); background: var(--paper); color: var(--muted); }
.editor-actions #load-example { border-color: transparent; background: transparent; color: var(--accent); }
.editor-actions #load-example:hover { background: var(--paper); color: var(--accent-hover); }
.primary { border-color: var(--accent); background: var(--accent); color: var(--sheet); }
.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.primary:disabled { border-color: var(--line); background: #e8e8ed; color: #515154; }
.upload-icon {
  position: relative;
  display: inline-block;
  width: 13px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-top: 0;
}
.upload-icon::before {
  content: "";
  position: absolute;
  inset-block-start: -4px;
  inset-inline-start: 2.5px;
  width: 5px;
  height: 5px;
  border: solid currentColor;
  border-width: 1.5px 0 0 1.5px;
  transform: rotate(45deg);
}
.upload-icon::after {
  content: "";
  position: absolute;
  inset-block-start: -3px;
  inset-inline-start: 4.5px;
  width: 1.5px;
  height: 7px;
  background: currentColor;
}
.play-icon { border: solid transparent; border-width: 6px 0 6px 9px; border-left-color: currentColor; }

#script-input {
  flex: 1;
  width: 100%;
  min-height: 320px;
  padding: clamp(16px, 2.5vw, 30px);
  resize: vertical;
  border: 1px solid var(--control-line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.03rem;
  line-height: 1.75;
}
#script-input::placeholder { color: var(--muted); opacity: 1; }
.editor-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding-top: 10px;
  color: var(--muted);
  font-size: .875rem;
}
#char-count { font-variant-numeric: tabular-nums; }
.editor-status { margin-top: 5px; color: var(--muted); font-size: .875rem; line-height: 1.45; }
.editor-status[data-tone="error"] { color: var(--danger); }
.editor-status:empty { margin-top: 0; }

.workspace-footer {
  position: sticky;
  inset-block-end: max(10px, env(safe-area-inset-bottom));
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  margin-top: 18px;
  padding: 10px 16px;
  background: var(--sheet);
  box-shadow: 0 4px 16px #0000000a;
}
html:has(#workspace:not([hidden])) { scroll-padding-block-end: calc(122px + env(safe-area-inset-bottom)); }
.storage-setting { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; min-width: 0; }
.storage-setting p { color: var(--muted); font-size: .875rem; line-height: 1.45; }
.storage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; }
.current-script {
  max-width: min(24ch, 100%);
  overflow: hidden;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.start-slot { display: flex; align-items: stretch; gap: 8px; flex: none; }
#start-over { min-height: 48px; }
#start { min-height: 48px; padding-inline: 22px; }
.switch-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
}
.switch-label input {
  position: absolute;
  inset-inline-start: 0;
  width: 34px;
  height: 20px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch-track {
  flex: none;
  display: grid;
  align-items: center;
  width: 34px;
  height: 20px;
  padding-inline: 3px;
  border-radius: 12px;
  border: 1px solid var(--control-line);
  background: #e8e8ed;
}
.switch-track::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.switch-label input:checked + .switch-track { border-color: var(--accent); background: var(--accent); }
.switch-label input:checked + .switch-track::before { justify-self: end; background: var(--sheet); }
.switch-label input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 3px; }
.switch-label:has(input:disabled) { color: var(--muted); cursor: default; }

.preview-frame { position: relative; background: var(--reader); border-radius: 12px; }
.preview-stage {
  position: relative;
  height: clamp(164px, 13vw, 224px);
  overflow: auto;
  border-radius: inherit;
  background: var(--reader);
  color: var(--reader-text);
  scrollbar-color: var(--reader-control-line) var(--reader);
  --script-width: min(100%, var(--line-width, 72%));
}
.preview-stage:focus-visible { outline-color: var(--focus); }
.preview-inner { display: flex; justify-content: center; min-height: 100%; padding: 40px var(--script-margin, 8%); }
#preview-script {
  width: var(--script-width);
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: clamp(.9rem, var(--preview-font, 27px), 3rem);
  line-height: 1.33;
}
#preview-script[data-empty="true"] { color: var(--reader-muted); font-size: .95rem; align-self: center; text-align: center; }
#preview-script[data-mirror="true"], #reader-script[data-mirror="true"] { transform: scaleX(-1); }
:lang(ko) #script-input, :lang(ko) #preview-script, :lang(ko) .reader-script { word-break: keep-all; }

.settings h2 { margin-bottom: 12px; }
.ranges { border-top: 1px solid var(--line); }
.range-control {
  display: grid;
  grid-template-columns: minmax(6.35rem, max-content) minmax(0, 1fr) 5.1rem;
  align-items: center;
  gap: clamp(9px, 1.1vw, 16px);
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}
.range-control label, .countdown-control label { color: var(--ink); font-size: .875rem; font-weight: 600; }
.range-control output {
  color: var(--ink);
  font: .875rem var(--numerals);
  font-variant-numeric: tabular-nums;
  text-align: end;
}
.range-control input { width: 100%; height: 44px; margin: 0; cursor: pointer; accent-color: var(--accent); }
.countdown-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-block: 6px;
  border-bottom: 1px solid var(--line);
}
.countdown-control select {
  max-width: 100%;
  min-height: 44px;
  padding-inline: 10px;
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  background: var(--sheet);
  color: var(--ink);
  font-size: 1rem;
}
.pace-readout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 4px 12px;
  margin-block: 14px 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--paper);
}
#pace-label { font-size: .875rem; font-weight: 650; }
#pace-estimate { font: 700 1.1rem var(--numerals); font-variant-numeric: tabular-nums; }
#pace-help { grid-column: 1 / -1; color: var(--muted); font-size: .875rem; line-height: 1.45; }
.setting-details { border-bottom: 1px solid var(--line); }
.setting-details summary {
  position: relative;
  min-height: 44px;
  padding-block: 12px;
  padding-inline-end: 24px;
  list-style: none;
  color: var(--ink);
  font-size: .9rem;
  font-weight: 650;
  cursor: pointer;
}
.setting-details summary::-webkit-details-marker { display: none; }
.setting-details summary::after {
  content: "";
  position: absolute;
  inset-block-start: 18px;
  inset-inline-end: 3px;
  width: 7px;
  height: 7px;
  border: solid var(--muted);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.setting-details[open] summary::after { transform: translateY(3px) rotate(225deg); }
.setting-details summary:hover { color: var(--accent-hover); }
.setting-details .ranges { margin-block-end: 10px; }
.target-controls { display: flex; align-items: end; flex-wrap: wrap; gap: 8px; padding-block: 3px 8px; }
.target-field { display: grid; gap: 4px; }
.target-field label { color: var(--muted); font-size: .875rem; font-weight: 650; }
.target-controls input {
  width: 4.2rem;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  background: var(--sheet);
  color: var(--ink);
  font-family: var(--numerals);
}
.target-controls input[aria-invalid="true"] { border-color: var(--danger); }
#pace-note:not(:empty) { padding-block-end: 10px; }
.cue-help, #cue-status { color: var(--muted); font-size: .875rem; line-height: 1.45; }
.cue-help { margin-block: 0 8px; }
#cue-status:not(:empty) { padding-block-end: 10px; }
.reader-remaining { color: var(--reader-muted); font-size: .875rem; line-height: 1.3; display: inline-flex; flex-wrap: wrap; gap: 2px 5px; }
#remaining-time { color: var(--reader-text); font-family: var(--numerals); font-variant-numeric: tabular-nums; white-space: nowrap; }

.reader {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--reader);
  color: var(--reader-text);
  color-scheme: dark;
}
.reader[data-measuring="true"][hidden] { display: grid !important; inline-size: 100vw; visibility: hidden; pointer-events: none; }
.reader:fullscreen { width: 100%; height: 100%; }
.reader :focus-visible { outline-color: var(--reader-focus); }
.reader-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--reader-line);
  background: var(--reader-panel);
  font-size: .9rem;
  font-weight: 650;
}
.reader-header-status { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.reader-display-controls { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.voice-status { font-size: .875rem; color: var(--reader-warning); }
.voice-help { color: var(--muted); margin-block: 8px; font-size: .875rem; line-height: 1.45; }
.voice-setup-control { flex-wrap: wrap; }
.voice-setup-control select { min-width: 0; max-width: 100%; }
.voice-consent { padding: 12px; margin-block: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); font-size: .875rem; line-height: 1.45; }
.voice-consent p { font-size: 1rem; }
.voice-consent label { display: flex; align-items: center; gap: 9px; min-height: 44px; margin-top: 6px; padding-block: 4px; cursor: pointer; }
.voice-consent input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.reader[data-voice="true"] .reader-display-controls { flex-wrap: wrap; }
.reader-status { color: var(--reader-muted); font-size: .88rem; font-weight: 500; line-height: 1.3; }
.reader[data-quiet="true"] .reader-footer,
.reader[data-quiet="true"] .reader-title { display: none; }
.reader:is([data-phase="playing"], [data-phase="listening"]) .reader-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-inline-end: 7px;
  border-radius: 50%;
  background: var(--cue);
}
.reader-stage { position: relative; overflow: hidden; }
.cue { position: absolute; inset-inline: 0; z-index: 2; pointer-events: none; }
.preview-frame .cue { top: 53px; }
#reading-marker { top: var(--reading-line); }
.cue::before, .cue::after { content: ""; position: absolute; top: -6px; border-block: 6px solid transparent; }
.cue::before { inset-inline-start: 8px; border-left: 8px solid var(--cue); }
.cue::after { inset-inline-end: 8px; border-right: 8px solid var(--cue); }
.reader-stage::before, .reader-stage::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  z-index: 1;
  height: 8%;
  pointer-events: none;
}
.reader-stage::before { top: 0; background: linear-gradient(var(--reader), transparent); }
.reader-stage::after { bottom: 0; background: linear-gradient(transparent, var(--reader)); }
.reader-track { position: absolute; top: var(--reading-line); inset-inline: 0; padding-inline: var(--script-margin, 8%); }
.reader[data-phase="playing"] .reader-track { will-change: transform; }
.reader-script {
  width: min(var(--line-width, 72%), 100%);
  margin-inline: auto;
  font-size: var(--script-font, 52px);
  font-weight: 580;
  line-height: 1.25;
}
.reader-script p { min-height: calc(1.25em * var(--blank-lines, 1)); white-space: pre-wrap; overflow-wrap: anywhere; }
.reader-script [data-outside-cue] { visibility: hidden; }
.countdown {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  background: #101012db;
  color: var(--cue);
  font: 650 clamp(3.7rem, 15vh, 8rem) var(--numerals);
  font-variant-numeric: tabular-nums;
}
.reader-footer {
  padding: 12px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--reader-line);
  background: var(--reader-panel);
}
.reader-controls { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
.reader-recovery { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
:is(.reader-secondary, .reader #marks-dialog .secondary) { border-color: var(--reader-control-line); background: var(--reader-control); color: var(--reader-text); }
:is(.reader-secondary, .reader #marks-dialog .secondary):hover { border-color: var(--reader-control-line); background: var(--reader-hover); }
:is(.reader-secondary, .reader #marks-dialog .secondary):is(:disabled, [aria-disabled="true"]) {
  border-color: var(--reader-line);
  background: var(--reader-panel);
  color: var(--reader-muted);
  cursor: default;
}
.reader-play { min-width: 101px; border-color: var(--cue); background: var(--cue); color: var(--reader); }
.reader-play:hover { border-color: #b8dcff; background: #b8dcff; }
.speed-controls, .paragraph-controls { display: flex; align-items: center; justify-content: center; gap: 5px; }
.speed-controls button, .paragraph-controls button { width: 44px; min-width: 44px; padding-inline: 0; font-size: 1.2rem; }
.paragraph-caption { padding-inline: 3px; color: var(--reader-text); font-size: .875rem; }
#reader-speed {
  min-width: 68px;
  color: var(--reader-text);
  font: .875rem var(--numerals);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.keyboard-hints { margin-top: 9px; color: var(--reader-muted); text-align: center; font-size: .875rem; }

.result { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.result-sheet {
  width: min(100%, 560px);
  padding: clamp(22px, 5vw, 42px);
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--sheet);
}
.result h1 { margin-bottom: 24px; font-size: clamp(1.7rem, 5vw, 2.2rem); line-height: 1.12; letter-spacing: -.04em; }
.result-times { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-block: 1px solid var(--line); }
.result-times > div { display: grid; align-content: space-between; gap: 6px; padding: 16px 10px 16px 0; }
.result-times > div + div { padding-inline-start: 16px; border-inline-start: 1px solid var(--line); }
.result-times dt { color: var(--muted); font-size: .9rem; font-weight: 600; }
.result-times dd { font: 650 clamp(1.65rem, 6vw, 2.35rem) var(--numerals); font-variant-numeric: tabular-nums; }
#result-note, #replace-note { margin-block: 16px; color: var(--muted); line-height: 1.55; }
.result-actions, .dialog-actions { justify-content: flex-end; }
dialog { width: min(100% - 36px, 480px); padding: 24px; border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--sheet); color: var(--ink); }
dialog::backdrop { background: #10101280; }
#paragraph-dialog {
  position: fixed;
  width: min(100% - 24px, 550px);
  max-block-size: calc(100vh - 24px);
  max-block-size: calc(100dvh - 24px);
  padding: clamp(12px, 3vw, 22px);
  border-color: var(--reader-control-line);
  background: var(--reader-panel);
  color: var(--reader-text);
}
#paragraph-dialog::backdrop { background: #101012b8; }
.paragraph-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-block-end: 10px; }
.paragraph-dialog-heading h2 { font-size: 1.15rem; }
.field-label { display: block; margin-block-end: 5px; color: var(--reader-text); font-size: .875rem; font-weight: 650; }
#paragraph-query {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--reader-control-line);
  border-radius: var(--control-radius);
  background: var(--reader);
  color: var(--reader-text);
}
#paragraph-query::placeholder { color: var(--reader-muted); opacity: 1; }
.paragraph-summary { margin-block: 8px; color: var(--reader-muted); font-size: .875rem; line-height: 1.4; }
.paragraph-summary:empty { margin: 0; }
.paragraph-results {
  display: grid;
  gap: 4px;
  max-block-size: min(43vh, 344px);
  max-block-size: min(43dvh, 344px);
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
}
.paragraph-results button {
  display: grid;
  justify-items: start;
  gap: 2px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--reader-control-line);
  border-radius: var(--control-radius);
  background: var(--reader-control);
  color: var(--reader-text);
  text-align: start;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.paragraph-results button:hover { background: var(--reader-hover); }
.paragraph-results button > :first-child { color: var(--cue); font-size: .875rem; font-weight: 650; }
.paragraph-results button > :last-child { font-size: .875rem; }

.remote-setup-link {
  display: inline-flex;
  align-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: .875rem;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: .18em;
}
.remote-setup-link:hover { color: var(--accent-hover); }
.remote-owner { width: min(100% - 24px, 540px); max-height: calc(100dvh - 24px); }
.remote-owner .button { min-height: 44px; }
#reader .remote-owner { color-scheme: light; }
#reader .remote-owner :focus-visible { outline-color: var(--focus); }
.remote-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.remote-heading h1, .remote-heading h2 { font-size: clamp(1.2rem, 5vw, 1.65rem); }
.remote-owner > p, .remote-card p { line-height: 1.45; }
.remote-notice {
  margin-block: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
}
.remote-invite-box { display: grid; gap: 6px; }
.remote-invite-box label { font-weight: 650; }
.remote-link-row { display: flex; gap: 8px; }
.remote-link-row input {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  background: var(--sheet);
  color: var(--ink);
  font-family: var(--numerals);
}
.remote-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 12px; }
.remote-muted { color: var(--muted); font-size: .875rem; }
.remote-screen { width: min(100% - 28px, 520px); padding-block: max(22px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-bottom)); }
.remote-card { padding: clamp(16px, 4vw, 24px); border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--sheet); }
.remote-command-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.remote-command-grid button { min-height: 64px; font-size: 1rem; }
#remote-reader-open { white-space: nowrap; }

.saved-dialog {
  position: fixed;
  width: min(100% - 24px, 560px);
  max-block-size: calc(100vh - 24px);
  max-block-size: calc(100dvh - 24px);
  padding: clamp(14px, 4vw, 24px);
}
.saved-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.saved-dialog-heading h2 { font-size: clamp(1.15rem, 5vw, 1.48rem); }
.saved-help, .saved-summary { color: var(--muted); font-size: .875rem; line-height: 1.42; }
.saved-help { margin-bottom: 12px; }
.saved-status { margin-block: 6px; }
.saved-status:empty, .saved-summary:empty { margin: 0; }
.saved-enable { margin-block: 5px; }
.saved-field { display: grid; gap: 5px; font-size: .875rem; font-weight: 650; }
.saved-field input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  background: var(--sheet);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 500;
}
.saved-field input::placeholder { color: var(--muted); opacity: 1; }
.saved-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.saved-summary { margin-block: 6px; }
.saved-list {
  display: grid;
  gap: 6px;
  max-block-size: min(33vh, 245px);
  max-block-size: min(33dvh, 245px);
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
}
.saved-list:empty { padding: 0; }
.saved-row { display: flex; align-items: stretch; gap: 6px; min-width: 0; }
.saved-item {
  display: grid;
  flex: 1;
  align-content: center;
  gap: 3px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--sheet);
  color: var(--ink);
  text-align: start;
  overflow-wrap: anywhere;
}
.saved-item:hover { background: var(--paper); }
.saved-item[aria-current="true"] { border-color: var(--accent); background: #eef6ff; }
.saved-item-detail, .saved-badge { color: var(--muted); font-size: .875rem; }
.saved-badge { font-weight: 700; }
.saved-remove { min-height: 44px; padding-inline: 9px; }
.library-actions { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.library-action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.saved-dialog .button { min-height: 44px; }
.saved-destructive { color: var(--danger); }
.saved-warning { margin-top: 10px; border: 1px solid #e5bcc0; border-radius: 12px; padding: 10px 12px; background: #fff3f4; }
.saved-warning p { font-size: .875rem; line-height: 1.42; overflow-wrap: anywhere; }
#library-delete-confirm { border-color: var(--danger); background: var(--danger); }
#library-delete-confirm:hover { border-color: var(--danger-hover); background: var(--danger-hover); }
#library-delete-confirm:disabled { border-color: var(--line); background: #e8e8ed; color: #515154; }
.reader #marks-dialog { border-color: var(--reader-control-line); background: var(--reader-panel); color: var(--reader-text); }
.reader #marks-dialog::backdrop { background: #101012b8; }
.reader #marks-dialog :is(.saved-help, .saved-status, .saved-item-detail) { color: var(--reader-muted); }
.reader #marks-dialog .saved-status[data-tone="error"] { color: var(--reader-warning); }
.reader #marks-dialog .saved-field input { border-color: var(--reader-control-line); background: var(--reader); color: var(--reader-text); }
.reader #marks-dialog .saved-field input::placeholder { color: var(--reader-muted); }
.reader #marks-dialog .saved-item { border-color: var(--reader-control-line); background: var(--reader-control); color: var(--reader-text); }
.reader #marks-dialog .saved-item:hover { background: var(--reader-hover); }

@media (max-width: 840px) {
  .shell { width: calc(100% - 40px); }
}
@media (min-width: 721px) and (max-height: 850px) {
  .workbench { padding-block: clamp(20px, 3vw, 28px) 24px; }
  .preview-stage { height: clamp(170px, min(16vw, 29vh), 224px); }
}
@media (max-width: 720px) {
  html:has(#workspace:not([hidden])) { scroll-padding-block-end: calc(76px + env(safe-area-inset-bottom)); }
  .workbench { padding-block-end: 0; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  #script-input { flex: none; min-height: 176px; height: clamp(176px, 31svh, 247px); }
  .preview-stage { height: 200px; }
  .workspace-footer { display: contents; }
  .storage-setting {
    display: block;
    margin-block: 16px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--panel-radius);
    background: var(--sheet);
  }
  .start-slot {
    position: sticky;
    inset-block-end: 0;
    z-index: 3;
    border: 1px solid var(--line);
    border-block-end: 0;
    border-radius: 16px 16px 0 0;
    padding: 8px 9px max(9px, env(safe-area-inset-bottom));
    background: var(--sheet);
    box-shadow: 0 -3px 14px #0000000a;
  }
  #start { min-width: 0; flex: 1; }
}
@media (max-width: 480px) {
  .shell { width: calc(100% - 28px); }
  .topbar-content { min-height: 60px; gap: 12px; }
  .brand { display: none; }
  .editor, .preview-panel, .settings { padding: 14px; }
  .section-heading { gap: 5px 8px; }
  .editor-actions { gap: 6px; }
  .editor-actions .button { padding-inline: 8px; }
  .editor-actions .upload-icon { display: none; }
  .range-control { grid-template-columns: 6.15rem minmax(0, 1fr) 4.35rem; }
  .reader-header { gap: 7px; }
  .reader-title { display: none; }
  .reader-display-controls .button { padding-inline: 9px; }
  .reader-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 410px; margin-inline: auto; }
  .reader-recovery { grid-column: 1 / -1; }
  .reader-recovery .button { padding-inline: 7px; font-size: .875rem; }
  .reader-play { min-width: 0; }
  .speed-controls, .paragraph-controls { gap: 3px; }
  #reader-speed { min-width: 48px; }
  .result-actions .button { flex: 1 0 auto; }
}
@media (min-width: 380px) and (max-width: 480px) {
  .editor-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; width: 100%; }
  .editor-actions .button { padding-inline: 4px; }
}
@media (max-width: 368px) {
  .paragraph-caption { display: none; }
}
@media (max-width: 420px) {
  .reader-header:has(:is(#remote-reader-open, #voice-stop):not([hidden])) { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .reader-header:has(:is(#remote-reader-open, #voice-stop):not([hidden])) .reader-display-controls { justify-content: flex-start; flex-wrap: wrap; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .reader-header, .reader-footer { padding-block: 5px; }
  .keyboard-hints { display: none; }
  .result { padding: 12px; }
  .result-sheet { padding: 16px 20px; }
  .result h1 { margin-bottom: 12px; }
  .result-times > div { padding-block: 8px; }
  #result-note { margin-block: 10px; }
}
@media (forced-colors: active) {
  :root { --focus: Highlight; --reader-focus: Highlight; --cue: CanvasText; }
  .switch-track { forced-color-adjust: none; border-color: ButtonText; background: ButtonFace; }
  .switch-track::before { background: ButtonText; }
  .switch-label input:checked + .switch-track { border-color: Highlight; background: Highlight; }
  .switch-label input:checked + .switch-track::before { background: HighlightText; }
  .reader-stage::before, .reader-stage::after { display: none; }
}
