:root {
  --bg: #ffffff;
  --fg: #14161a;
  --muted: #5b6472;
  --rule: #d7dce3;
  --panel: #f4f6f9;
  --anchor: #b3261e;
  --accent: #1a5fb4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e8ebf0;
    --muted: #9aa4b2;
    --rule: #2b323d;
    --panel: #171b22;
    --anchor: #ff6b5e;
    --accent: #79b8ff;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.title {
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0.25rem 0 0;
}

#source {
  width: 100%;
  min-height: 7.5rem;
  resize: vertical;
  padding: 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
}

#notes {
  margin: 0;
  min-height: 1.25rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.reader {
  min-height: 9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0.25rem;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  outline: none;
}

.reader:focus-visible {
  border-color: var(--accent);
}

.empty {
  color: var(--muted);
  font-size: 1rem;
}

.word {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: baseline;
  width: 100%;
  font-size: 4rem;
  line-height: 1.1;
  position: relative;
}

.word::before,
.word::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 1px;
  height: 0.55rem;
  background: var(--rule);
}

.word::before { top: -0.75rem; }
.word::after { bottom: -0.75rem; }

.word .left {
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
}

.word .anchor {
  color: var(--anchor);
  font-weight: 700;
  white-space: pre;
}

.word .right {
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}

.word .left.overflow,
.word .right.overflow {
  white-space: normal;
  overflow-wrap: anywhere;
}

.block {
  width: 100%;
  max-width: 100%;
  max-height: 60vh;
  overflow: auto;
  padding: 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--panel);
}

.block-badge {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.block pre {
  margin: 0;
  white-space: pre;
  overflow-x: auto;
}

.block pre code,
.block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  white-space: pre;
}

.block-heading .heading-text {
  font-size: 1.5rem;
  font-weight: 700;
}

.block-inline-code code {
  font-size: 1.05rem;
  white-space: pre-wrap;
}

.block table {
  border-collapse: collapse;
  font-size: 0.9rem;
}

.block th,
.block td {
  border: 1px solid var(--rule);
  padding: 0.3rem 0.7rem;
  text-align: left;
}

.lang {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.progress {
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  color: var(--muted);
}

.controls {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.controls button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.75rem;
  font: inherit;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
}

.controls button#play {
  min-width: 5.5rem;
}

.controls button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.speed {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--muted);
}

#wpm {
  flex: 1 1 8rem;
  min-height: 44px;
}

@media (max-width: 420px) {
  .word { font-size: 3rem; }
  .app { padding: 0.75rem; }
}
