:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1a1a1a;
  background: #f4f1ec;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

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

button {
  border: 1px solid var(--divider);
  background: var(--panel);
  color: var(--ink);
  min-height: 42px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: var(--muted);
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  --surface: #f4f1ec;
  --panel: #ede9e2;
  --ink: #1a1a1a;
  --muted: #6e6a62;
  --accent: #b23b2a;
  --divider: #d8d2c6;
  --field: #fbfaf7;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(380px, 1fr) minmax(240px, 300px);
  gap: 1px;
  min-height: 100vh;
  background: var(--divider);
  color: var(--ink);
}

.app-shell[data-theme="dark"] {
  --surface: #131313;
  --panel: #1a1a1a;
  --ink: #ede9e2;
  --muted: #8c877c;
  --accent: #d85945;
  --divider: #2a2826;
  --field: #101010;
}

.app-shell[data-theme="amoled"] {
  --surface: #000000;
  --panel: #050505;
  --ink: #f1eee8;
  --muted: #918b80;
  --accent: #df5a47;
  --divider: #202020;
  --field: #000000;
}

.input-pane,
.reader-pane,
.controls-pane {
  background: var(--surface);
}

.input-pane,
.controls-pane {
  padding: 22px;
}

.input-pane {
  display: grid;
  grid-template-rows: auto auto minmax(260px, 1fr) auto;
  gap: 12px;
}

.brand-row,
.input-actions,
.reader-top,
.reader-bottom,
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: 0;
}

.brand-row p,
.quiet-metric,
.stage-status,
.control-group output,
.stats-list span,
.progress-block,
.sentence-context {
  color: var(--muted);
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 24px;
}

.field-label,
.control-group label,
.control-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

textarea {
  width: 100%;
  min-height: 240px;
  resize: none;
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 14px;
  background: var(--field);
  color: var(--ink);
  line-height: 1.45;
}

textarea:focus,
select:focus,
input:focus,
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  outline-offset: 2px;
}

.primary-button {
  min-width: 104px;
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
  font-weight: 650;
}

.input-tabs {
  display: inline-flex;
  align-items: center;
  width: max-content;
  padding: 3px;
  border: 1px solid var(--divider);
  border-radius: 999px;
  background: var(--panel);
}

.tab-button {
  min-height: 32px;
  min-width: 86px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.tab-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--divider);
}

.tab-panel {
  min-height: 0;
  display: grid;
  gap: 8px;
}

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

.source-panel {
  overflow: auto;
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 14px;
  background: var(--field);
  font-family: Georgia, "Times New Roman", serif;
  color: var(--muted);
  line-height: 1.55;
}

.source-paragraph {
  margin: 0 0 12px;
  padding-left: 10px;
  border-left: 2px solid transparent;
}

.source-paragraph.active {
  border-left-color: var(--accent);
  color: var(--ink);
}

.source-paragraph.heading {
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}

.source-paragraph.quote {
  font-style: italic;
}

.source-paragraph.list::before {
  content: "• ";
}

.reader-pane {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
}

.reader-top {
  padding: 18px 22px 8px;
  z-index: 2;
}

.progress-block {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 140px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 300;
}

.progress-track {
  width: 140px;
  height: 4px;
  border-radius: 999px;
  background: var(--divider);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--ink);
  transition: width 120ms linear;
}

.sentence-context {
  min-height: 42px;
  max-width: 720px;
  padding: 0 32px;
  margin: 0 auto;
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
}

.sentence-context .active-word {
  color: var(--ink);
  font-weight: 700;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 420px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  overflow: hidden;
}

.stage:active {
  transform: none;
}

.axis {
  position: absolute;
  left: 50%;
  top: calc(50% + 36px);
  width: min(56%, 430px);
  height: 1px;
  transform: translateX(-50%);
  background: var(--divider);
}

.word-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  width: min(86vw, 780px);
  padding: 0 24px;
  font-size: var(--reader-size, 72px);
  line-height: 1;
  font-weight: 560;
  letter-spacing: 0;
  white-space: pre;
}

.word-left {
  justify-self: end;
  color: var(--ink);
}

.word-pivot {
  justify-self: center;
  color: var(--accent);
}

.word-right {
  justify-self: start;
  color: var(--ink);
}

.stage-status {
  position: absolute;
  top: calc(50% + 88px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
}

.reader-bottom {
  padding: 12px 22px 22px;
  justify-content: center;
}

.reader-bottom button {
  min-width: 92px;
}

#wpmReadout {
  min-width: 90px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
}

.completion {
  position: absolute;
  inset: auto 24px 92px;
  max-width: 520px;
  margin: 0 auto;
  padding: 18px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  z-index: 4;
  left: 50%;
  transform: translateX(-50%);
}

.completion h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.completion strong {
  display: block;
  margin-top: 12px;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
}

.controls-pane {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group output {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

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

select {
  min-height: 40px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--field);
  color: var(--ink);
}

.stats-list {
  display: grid;
  gap: 10px;
  margin-top: auto;
  border-top: 1px solid var(--divider);
  padding-top: 18px;
}

.stats-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.stats-list strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 500;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(520px, 68vh) auto;
  }

  .reader-pane {
    order: 1;
  }

  .input-pane {
    order: 2;
    grid-template-rows: auto auto minmax(220px, 38vh) auto;
  }

  .controls-pane {
    order: 3;
  }

  .stage {
    min-height: 360px;
  }

  .word-grid {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .input-pane,
  .controls-pane {
    padding: 16px;
  }

  .reader-top {
    padding-inline: 14px;
  }

  .progress-track {
    width: 104px;
  }

  .sentence-context {
    padding-inline: 18px;
  }

  .word-grid {
    padding-inline: 12px;
    font-size: min(var(--reader-size, 64px), 19vw);
  }

  .completion {
    inset-inline: 14px;
    bottom: 88px;
    transform: none;
    left: auto;
  }
}
