:root {
  color-scheme: light;
  --bg: #efe7d6;
  --bg-deep: #e4d9c4;
  --card: #fffaf1;
  --ink: #221c14;
  --muted: #6d6254;
  --line: #e0d3bd;
  --accent: #0f6e56;
  --accent-ink: #f3fff8;
  --accent-press: #0c5946;
  --highlight: #d7f3e4;
  --highlight-ink: #114838;
  --shadow: 0 16px 40px rgba(60, 40, 10, 0.08);
  --radius: 18px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", Palatino, Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141210;
    --bg-deep: #1c1916;
    --card: #242019;
    --ink: #f6f0e6;
    --muted: #b7ab9b;
    --line: #3c342b;
    --accent: #3dbe8c;
    --accent-ink: #06281c;
    --accent-press: #67d4a6;
    --highlight: #1c4033;
    --highlight-ink: #d8ffee;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.45;
}

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

button { touch-action: manipulation; }

.app {
  width: min(44rem, 100%);
  margin: 0 auto;
  height: 100dvh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  padding:
    calc(12px + env(safe-area-inset-top))
    14px
    calc(8px + env(safe-area-inset-bottom));
  gap: 10px;
}

.sheet {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mast {
  display: flex;
  gap: 14px;
  align-items: center;
}

.mast h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.mast p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.mark {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 16px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 10px;
}

.mark span {
  display: block;
  width: 4px;
  border-radius: 99px;
  background: var(--accent-ink);
}

.mark span:nth-child(1) { height: 12px; }
.mark span:nth-child(2) { height: 22px; }
.mark span:nth-child(3) { height: 32px; }
.mark span:nth-child(4) { height: 18px; }
.mark span:nth-child(5) { height: 26px; }

.composer, .player, .transcript-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer { padding: 12px; }

textarea {
  width: 100%;
  min-height: 6.5rem;
  max-height: 22vh;
  resize: vertical;
  border: 0;
  border-radius: 12px;
  padding: 12px;
  background: var(--bg);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.45;
}

textarea:focus { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }

body.is-active textarea {
  min-height: 3.4rem;
  max-height: 5.5rem;
}

.actions {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 10px;
  margin-top: 10px;
}

.primary, .secondary, .toggle, .skip, .speed button {
  border-radius: 14px;
  min-height: 52px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.05rem;
}

.primary:active { background: var(--accent-press); }

.secondary {
  background: transparent;
  border-color: var(--line);
  font-weight: 650;
}

.status, .hint, .transcript-head p, .voice-label {
  color: var(--muted);
  font-size: 0.92rem;
}

.status {
  min-height: 1.3em;
  margin: 10px 4px 2px;
}

.transcript-wrap {
  min-height: 9rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 8px;
}

.transcript-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding: 0 6px 8px;
}

.transcript-head h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.transcript-head p { margin: 0; }

.transcript {
  overflow: auto;
  min-height: 0;
  padding-bottom: 8px;
  scroll-padding-bottom: 12px;
}

.chunk, textarea {
  overflow-wrap: anywhere;
}

.chunk {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 12px 12px;
  margin: 0 0 4px;
  min-height: 48px;
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.4;
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: auto 52px;
  scroll-margin: 12px;
}

.chunk.is-current {
  background: var(--highlight);
  color: var(--highlight-ink);
}

.player { padding: 8px 12px 10px; }

.times {
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.92rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  background: transparent;
  margin: 2px 0 6px;
}

input[type="range"]:disabled { opacity: 0.45; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 99px;
  background: var(--bg-deep);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1px var(--accent);
}

input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 99px;
  background: var(--bg-deep);
}

input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--card);
}

.transport {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin: 4px 0 12px;
}

.skip, .toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--bg);
  border-color: var(--line);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.skip { min-height: 56px; font-size: 1.05rem; }
.skip:first-child { justify-self: end; width: min(100%, 9rem); }
.skip:last-child { justify-self: start; width: min(100%, 9rem); }

.skip svg, .toggle svg { width: 22px; height: 22px; fill: currentColor; }

.toggle {
  width: 68px;
  height: 68px;
  min-height: 68px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
}

.toggle svg { width: 32px; height: 32px; }

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

.speed button {
  min-height: 48px;
  white-space: nowrap;
  background: var(--bg);
  border-color: var(--line);
  border-radius: 12px;
  padding: 0 2px;
  font-size: 0.86rem;
  font-weight: 650;
}

.speed button[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.voice-label { display: block; margin: 12px 2px 6px; }

select {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0 12px;
}

.hint { margin: 12px 2px 0; }

button:disabled, select:disabled { opacity: 0.45; cursor: not-allowed; }

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

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

#keepalive {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 380px) {
  .speed button { font-size: 0.75rem; }
  .primary { font-size: 0.95rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

@media (min-width: 800px) {
  .app { padding-top: 28px; }
  textarea { min-height: 10rem; }
}
