:root {
  color-scheme: light;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #162744;
  background: #f1f5f9;
  --ink: #162744;
  --muted: #4f6279;
  --line: #d5e0eb;
  --blue: #1556b9;
  --navy: #13243e;
  --amber: #f7c768;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
a { color: inherit; }
:focus-visible { outline: 3px solid #236dd2; outline-offset: 3px; }

.site-header {
  background: white;
  border-top: 4px solid var(--blue);
  border-bottom: 1px solid var(--line);
}

.header-inner, main { width: min(1380px, calc(100% - 64px)); margin-inline: auto; }
.header-inner, .header-actions, .editor-heading, .editor-footer, .reader-toolbar,
.playback-row, .transport, .page-controls, .text-size-control, .progress-row {
  display: flex;
  align-items: center;
}
.header-inner { justify-content: space-between; gap: 16px; min-height: 70px; }
.site-brand { font-size: 1.35rem; font-weight: 800; letter-spacing: -.035em; text-decoration: none; }
.site-brand span { color: var(--blue); }
.header-actions { gap: clamp(12px, 3vw, 28px); }
.header-actions a { color: var(--muted); font-size: .95rem; font-weight: 650; text-underline-offset: 4px; }

main { padding-block: clamp(24px, 4vw, 54px) 44px; }
.page-heading { margin-bottom: 26px; }
.page-heading h1 { margin: 0; font-size: clamp(2rem, 4.8vw, 3.9rem); line-height: 1.04; letter-spacing: -.045em; }
.page-heading p { margin: 13px 0 0; font-size: clamp(1rem, 1.9vw, 1.2rem); line-height: 1.5; color: var(--muted); }
.workspace { display: grid; grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); gap: 22px; align-items: start; }
.card { min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 7px 25px #1b34530d; }
.editor { padding: 20px; display: grid; gap: 13px; }
.editor-heading, .editor-footer { justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.editor-heading label { font-size: 1.05rem; font-weight: 750; }
.text-button { border: 0; padding: 9px 3px; color: var(--blue); background: transparent; font-size: .9rem; font-weight: 700; }
.text-button:hover { text-decoration: underline; }
textarea {
  width: 100%;
  min-height: 278px;
  resize: vertical;
  padding: 13px 14px;
  color: var(--ink);
  background: #f8fafd;
  border: 1px solid #c6d4e4;
  border-radius: 10px;
  line-height: 1.6;
}
textarea::placeholder { color: var(--muted); }
#editor-count { font-size: .875rem; color: var(--muted); }

.reader { overflow: hidden; }
.reader-toolbar { justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 10px 16px; }
.mode-switch { display: flex; gap: 3px; max-width: 100%; padding: 4px; border-radius: 11px; background: #edf3fa; }
.mode-switch button {
  min-height: 40px;
  color: var(--muted);
  padding: 5px clamp(8px, 1.45vw, 17px);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .94rem;
  font-weight: 700;
}
.mode-switch button[aria-pressed="true"] { color: #114da9; background: #fff; border-color: #d8e4f2; box-shadow: 0 1px 3px #203b5e17; }
.mode-switch button:hover { color: #114da9; }
.button {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  justify-content: center;
  padding: 8px 13px;
  min-height: 44px;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: .94rem;
  line-height: 1.25;
  font-weight: 700;
}
.primary { background: var(--blue); color: white; }
.primary:hover:enabled { background: #104798; }
.secondary, .fullscreen { border-color: #ccd9e7; background: white; }
.secondary:hover:enabled, .fullscreen:hover { background: #edf3fa; }
.stage {
  display: grid;
  min-height: var(--stage-min, 320px);
  height: var(--stage-height, clamp(340px, 50vh, 650px));
  overflow: auto;
  background: radial-gradient(ellipse at 50% 0%, #233d60, var(--navy) 78%);
  color: #f6f8fe;
  font-family: "Verdana", "Segoe UI", system-ui, sans-serif;
}
.stage:focus-visible { outline-color: var(--amber); outline-offset: -4px; }
.passage {
  width: min(100%, 35em);
  margin: auto;
  padding: clamp(24px, 4vw, 64px);
  font-size: var(--text-size, 36px);
  line-height: 1.52;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.focus-view { display: grid; place-items: center; min-height: 100%; padding: 20px clamp(8px, 2.3vw, 20px); }
.focus-frame {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  width: 100%;
  min-height: clamp(120px, 18vw, 195px);
  padding: 18px 8px;
  border-block: 1px solid #a5bdd261;
}
.focus-frame::before, .focus-frame::after {
  content: "";
  position: absolute;
  left: calc(50% - 1px);
  width: 2px;
  height: 11px;
  background: var(--amber);
}
.focus-frame::before { top: 0; }
.focus-frame::after { bottom: 0; }
.word {
  width: 100%;
  text-align: center;
  white-space: nowrap;
  font-size: max(1rem, var(--word-size, clamp(1.75rem, 9vw, 6.5rem)));
  font-weight: 700;
  line-height: 1.25;
}
.word.is-wrapped { white-space: normal; overflow-wrap: anywhere; }

.reader-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}
.page-controls { min-width: 0; flex: 1; flex-wrap: wrap; gap: 6px 20px; }
.speech-controls, .speech-voice { display: flex; align-items: center; gap: 8px; }
.speech-controls, .speech-voice { flex-wrap: wrap; }
.speech-voice { gap: 4px; }
.speech-voice label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
}
.speech-voice input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); cursor: pointer; }
.speech-voice label:has(:checked) { color: #114da9; background: #edf3fa; border-color: #d8e4f2; }
#speech-status { flex-basis: 100%; color: var(--muted); font-size: .875rem; }
.spoken-word { color: #182743; background: #ffd578; border-radius: .15em; }
.text-size-control { min-width: 0; flex: 0 1 330px; gap: 13px; }
.text-size-control input { flex: 1; }
.playback { padding: 10px 16px 15px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.progress-row, .playback-row, .transport { gap: 9px; }
.playback-row { justify-content: space-between; flex-wrap: wrap; gap: 13px; }
.transport { min-width: 0; max-width: 100%; }
#next-paragraph { min-width: 0; }
.icon-control { flex: 0 0 44px; padding: 0; }
.control-icon { width: 20px; height: 20px; flex: none; fill: currentColor; }
.speaker-toggle { position: relative; margin-inline-start: auto; }
.speaker-toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.speaker-toggle:has(:focus-visible) { outline: 3px solid #236dd2; outline-offset: 3px; }
.speaker-toggle:has(:checked) { color: #114da9; background: #edf3fa; border-color: #a9c6eb; }
.speaker-toggle .control-icon { width: 24px; height: 24px; }
.speaker-waves, .speaker-mute { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.speaker-waves, .speaker-toggle:has(:checked) .speaker-mute { display: none; }
.speaker-toggle:has(:checked) .speaker-waves { display: inline; }
.rewind-icon { width: 30px; height: 30px; }
.rewind-icon path { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rewind-icon text { font: 750 9px "Segoe UI", system-ui, sans-serif; }
.pause-icon, .play-toggle.is-playing .play-icon { display: none; }
.play-toggle.is-playing .pause-icon { display: inline; }
.fullscreen { align-self: flex-end; margin-inline-start: auto; }
.fullscreen-icon { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.contract-icon, .fullscreen.is-expanded .expand-icon { display: none; }
.fullscreen.is-expanded .contract-icon { display: inline; }
.restart-status { margin: 0; color: var(--muted); font-size: .94rem; font-weight: 650; }
.paragraph-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
}
.paragraph-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 700;
  cursor: pointer;
}
.paragraph-toggle input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--blue); cursor: pointer; }
#paragraph-position, #page-paragraph-position { color: var(--muted); font-size: .875rem; }
.page-paragraph-buttons { display: flex; gap: 6px; max-width: 100%; }
.page-paragraph-buttons .button { min-width: 0; gap: 6px; }
.page-paragraph-buttons .button:disabled { background: #edf2f7; color: var(--muted); opacity: 1; }
.progress-row input { flex: 1; }
#word-position { min-width: 53px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .875rem; }
.speed-control { display: flex; align-items: center; gap: 9px; flex: 1 1 235px; min-width: 0; max-width: 330px; }
.speed-control input { flex: 1; }
.text-size-control label, .speed-control label, output { font-size: .9rem; font-weight: 700; }
input[type="range"] { accent-color: var(--blue); min-width: 0; margin: 0; height: 34px; cursor: pointer; }
output { white-space: nowrap; color: var(--blue); font-variant-numeric: tabular-nums; }
#speed-value { flex: none; min-width: 76px; text-align: right; }

.reader:fullscreen, .reader.is-expanded {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
}
.reader.is-expanded { position: fixed; inset: 0; z-index: 10; }
body.reader-expanded { overflow: hidden; }
.reader:fullscreen .stage, .reader.is-expanded .stage { flex: 1; min-height: 0; height: auto; }
.reader:fullscreen > :not(.stage), .reader.is-expanded > :not(.stage) { flex: none; }
.reader:fullscreen .passage, .reader.is-expanded .passage { max-width: 42em; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 920px) {
  .header-inner, main { width: calc(100% - 36px); }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  textarea { min-height: 115px; }
}
@media (max-width: 480px) {
  .header-inner, main { width: calc(100% - 24px); }
  .site-brand { font-size: 1.1rem; }
  .header-actions a { font-size: .8rem; }
  .header-actions { gap: 8px; }
  .editor, .reader-toolbar, .playback, .reader-footer { padding-inline: 11px; }
  .transport { gap: 6px; }
  #next-paragraph { gap: 6px; padding: 3px 8px; font-size: .875rem; }
  .page-paragraph-buttons .button { padding: 3px 8px; font-size: .875rem; }
  .mode-switch button { font-size: .82rem; }
  .mode-switch button { padding-inline: 6px; }
  .stage:has(.focus-view:not([hidden])) { --stage-min: 0px; --stage-height: 235px; }
  .text-size-control { gap: 8px; }
}
