:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #607089;
  --line: #d9e0ea;
  --accent: #0b57d0;
  --accent-dark: #0846aa;
  --danger: #b42318;
  --soft: #eef3fb;
  --focus: #8ab4f8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.control-panel,
.reader {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.control-panel {
  align-self: start;
  position: sticky;
  top: 20px;
  display: grid;
  gap: 16px;
  padding: 18px;
}

.brand-row,
.reader-head,
.progress-meta,
.speed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.1rem;
}

.status,
#chunkCounter {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.speed-head span {
  color: var(--muted);
  font-size: 0.88rem;
}

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

input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.source-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px 40px 40px;
  align-items: end;
  gap: 8px;
}

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

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-height: 40px;
  padding: 0;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.transport {
  display: grid;
  grid-template-columns: auto 40px 40px 40px auto;
  align-items: center;
  gap: 8px;
}

.jump-group {
  display: grid;
  grid-template-columns: minmax(78px, 1fr) 40px;
  gap: 4px;
}

.jump-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 78px;
  padding: 0 8px;
}

.jump-button svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-wrap {
  position: relative;
}

.jump-menu,
.action-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 10;
  display: none;
  min-width: 104px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(23, 32, 51, 0.14);
}

.jump-menu.align-right,
.action-menu.align-right {
  right: 0;
  left: auto;
}

.menu-wrap.open .jump-menu,
.menu-wrap.open .action-menu {
  display: grid;
}

.jump-menu button,
.action-menu button {
  min-height: 34px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
  text-align: left;
  cursor: pointer;
}

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

.check-box {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border: 1px solid var(--muted);
  border-radius: 3px;
}

.check-option.active .check-box {
  border-color: var(--accent);
  background: var(--accent);
}

.check-option.active .check-box::after {
  width: 7px;
  height: 4px;
  border-bottom: 2px solid #ffffff;
  border-left: 2px solid #ffffff;
  content: "";
  transform: rotate(-45deg) translate(1px, -1px);
}

.action-menu {
  min-width: 210px;
}

.action-menu button {
  white-space: nowrap;
}

.jump-menu button:last-child,
.action-menu button:last-child {
  border-bottom: 0;
}

.jump-menu button:hover,
.jump-menu button.active,
.action-menu button:hover {
  background: var(--soft);
  color: var(--accent-dark);
}

.button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
  cursor: pointer;
}

.button:hover,
.speed-option:hover {
  background: var(--soft);
}

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

.button.primary:hover {
  background: var(--accent-dark);
}

.button.danger {
  border-color: #f3c0bc;
  color: var(--danger);
}

.settings {
  display: grid;
  gap: 14px;
}

.speed-box {
  display: grid;
  gap: 10px;
}

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

.speed-option {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
}

.speed-option.active {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.progress-wrap {
  display: grid;
  gap: 8px;
}

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

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--range-fill, var(--line));
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 1px 4px rgba(23, 32, 51, 0.22);
  appearance: none;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--line);
}

input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 1px 4px rgba(23, 32, 51, 0.22);
}

#rate {
  accent-color: var(--muted);
}

#progress {
  accent-color: var(--muted);
}

body.is-speaking #progress {
  accent-color: var(--accent);
}

body.is-speaking #progress::-webkit-slider-thumb {
  background: var(--accent);
}

body.is-speaking #progress::-moz-range-progress,
body.is-speaking #progress::-moz-range-thumb {
  background: var(--accent);
}

.reader {
  min-width: 0;
  padding: 22px;
}

.reader-head {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.content {
  max-width: 920px;
  padding-top: 20px;
  line-height: 1.65;
  font-size: 1.02rem;
}

.content h1,
.content h2,
.content h3,
.content h4 {
  margin: 22px 0 10px;
  line-height: 1.25;
}

.content h1:first-child,
.content h2:first-child,
.content h3:first-child {
  margin-top: 0;
}

.content h1 {
  font-size: 1.7rem;
}

.content h2 {
  font-size: 1.35rem;
}

.content h3 {
  font-size: 1.15rem;
}

.content p,
.content li,
.content blockquote,
.content pre {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 6px;
}

.content ul,
.content ol {
  margin: 0 0 14px;
  padding-left: 28px;
}

.content li {
  margin-bottom: 4px;
}

.content blockquote {
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.content pre {
  overflow-x: auto;
  background: #f7f9fc;
  border: 1px solid var(--line);
}

.content code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.94em;
}

.content a {
  color: var(--accent);
}

.content .read-block {
  cursor: pointer;
}

.content .current {
  background: #fff7d6;
  box-shadow: inset 3px 0 0 #e5a700;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .source-row,
  .transport,
  .speed-buttons {
    grid-template-columns: 1fr;
  }

  .icon-button {
    width: 100%;
  }

  .jump-group {
    grid-template-columns: 1fr 1fr;
  }

  .jump-menu,
  .jump-menu.align-right,
  .action-menu,
  .action-menu.align-right {
    right: 0;
    left: 0;
  }
}
