:root {
  --bg: #f4f0e8;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --ink: #1b2530;
  --muted: #697580;
  --line: #d8d3ca;
  --teal: #0f766e;
  --teal-soft: #d7f0ec;
  --blue: #2854a3;
  --coral: #cf4f3f;
  --coral-soft: #fde8e4;
  --amber: #b7791f;
  --green: #198754;
  --shadow: 0 20px 55px rgba(35, 37, 41, 0.12);
  --radius: 8px;
  --practice-font-size: clamp(1.18rem, 2vw, 1.45rem);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.12), transparent 36%),
    linear-gradient(240deg, rgba(207, 79, 63, 0.12), transparent 34%),
    var(--bg);
}

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

button {
  border: 0;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto;
  display: grid;
  gap: 16px;
}

.topbar,
.status-strip,
.workspace,
.results-panel,
.retry-panel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid rgba(216, 211, 202, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
}

.brand {
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: var(--radius);
}

.brand h1,
.results-heading h2 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

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

.field span,
.metric-label,
.panel-title span,
.result-tile span,
.retry-input-label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

select {
  min-width: 180px;
  height: 42px;
  padding: 0 38px 0 12px;
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

select:focus,
textarea:focus,
input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

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

.icon-button,
.primary-button,
.secondary-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.icon-button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.icon-button.ghost,
.secondary-button {
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.file-button {
  background: var(--teal);
}

.primary-button {
  background: var(--teal);
}

.icon-button.active {
  background: var(--coral);
}

.icon-button.paused {
  color: #fff;
  background: var(--amber);
}

.icon-button.sound-on {
  color: #fff;
  background: var(--green);
}

.icon-button.reading {
  color: #fff;
  background: var(--teal);
}

.icon-button.dictation-on {
  color: #fff;
  background: var(--blue);
}

.icon-button.dictating {
  color: #fff;
  background: var(--teal);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
}

.metric {
  min-height: 86px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.45);
}

.metric strong {
  font-size: clamp(1.35rem, 2.7vw, 1.85rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  width: 100%;
  height: 6px;
  overflow: hidden;
  background: #e8e3da;
  border-radius: 999px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--blue), var(--coral));
  transition: width 220ms ease;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.03fr) minmax(320px, 0.97fr);
  min-height: 520px;
  overflow: hidden;
}

.target-panel,
.typing-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  padding: 22px;
}

.target-panel {
  border-right: 1px solid var(--line);
  background:
    linear-gradient(rgba(255, 255, 255, 0.64), rgba(255, 255, 255, 0.64)),
    repeating-linear-gradient(0deg, transparent 0 33px, rgba(40, 84, 163, 0.08) 34px 35px);
}

.panel-title {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title strong {
  color: var(--blue);
  font-size: 0.88rem;
  font-weight: 800;
}

.target-text {
  align-self: start;
  min-height: 245px;
  max-height: 390px;
  overflow: auto;
  color: #263443;
  font-size: var(--practice-font-size);
  line-height: 1.95;
  user-select: none;
  overflow-wrap: anywhere;
}

.target-text.is-hidden .char.hidden-part:not(.typed-correct):not(.typed-error) {
  filter: blur(5px);
  opacity: 0.22;
}

.word {
  display: inline-block;
  white-space: nowrap;
}

.char {
  position: relative;
  display: inline-block;
  min-width: 0.08em;
  transition: color 150ms ease, background 150ms ease, opacity 150ms ease, filter 150ms ease;
}

.char.space {
  width: 0.42em;
}

.char.typed-correct {
  color: var(--green);
  filter: none !important;
  opacity: 1 !important;
}

.char.typed-error {
  color: var(--coral);
  background: var(--coral-soft);
  filter: none !important;
  opacity: 1 !important;
}

.char.active::after {
  position: absolute;
  right: -2px;
  bottom: 0.22em;
  width: 2px;
  height: 1.2em;
  content: "";
  background: var(--teal);
  animation: blink 1s steps(2, start) infinite;
}

textarea {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  padding: 17px;
  color: var(--ink);
  background: #fffefa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  font-size: var(--practice-font-size);
  line-height: 1.7;
}

textarea.overrun {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(207, 79, 63, 0.16);
}

.feedback {
  min-height: 28px;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 650;
}

.feedback.success {
  color: var(--green);
}

.feedback.error {
  color: var(--coral);
}

.results-panel,
.retry-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
}

[hidden] {
  display: none !important;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
}

.result-tile {
  display: grid;
  gap: 8px;
  min-height: 96px;
  align-content: center;
  padding: 16px;
  background: #fffefa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.result-tile strong {
  font-size: 1.55rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.missed-box {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: #fff7f4;
  border: 1px solid rgba(207, 79, 63, 0.22);
  border-radius: var(--radius);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  color: #8d2f22;
  background: var(--coral-soft);
  border: 1px solid rgba(207, 79, 63, 0.2);
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 750;
}

.chip.current {
  color: var(--teal);
  background: var(--teal-soft);
  border-color: rgba(15, 118, 110, 0.22);
}

.compact {
  max-height: 100px;
  overflow: auto;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.retry-panel {
  max-width: 720px;
  justify-self: center;
  width: 100%;
}

.retry-panel h2 {
  color: var(--teal);
  font-size: clamp(2rem, 7vw, 4rem);
  overflow-wrap: anywhere;
}

.retry-input-label {
  display: grid;
  gap: 8px;
}

#retry-input {
  width: 100%;
  height: 62px;
  padding: 0 16px;
  color: var(--ink);
  background: #fffefa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  font-size: 1.45rem;
  font-weight: 750;
  text-align: center;
}

#retry-input.retry-error {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(207, 79, 63, 0.16);
}

#retry-input.retry-correct {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.16);
}

.drop-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  color: var(--teal);
  background: rgba(244, 240, 232, 0.86);
  backdrop-filter: blur(6px);
}

.drop-layer div {
  display: grid;
  gap: 10px;
  place-items: center;
  width: min(360px, calc(100% - 32px));
  padding: 34px;
  background: var(--panel);
  border: 2px dashed var(--teal);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.drop-layer svg {
  width: 42px;
  height: 42px;
}

.drop-layer p {
  margin: 0;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 800;
}

@keyframes blink {
  0%,
  45% {
    opacity: 1;
  }

  46%,
  100% {
    opacity: 0;
  }
}

@media (max-width: 900px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .target-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .target-text {
    max-height: none;
  }

  textarea {
    min-height: 240px;
  }

  .results-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    margin: 9px auto;
  }

  .topbar,
  .target-panel,
  .typing-panel,
  .results-panel,
  .retry-panel {
    padding: 14px;
  }

  .toolbar,
  .icon-button,
  .primary-button,
  .secondary-button,
  .field,
  select {
    width: 100%;
  }

  .icon-button,
  .primary-button,
  .secondary-button {
    justify-content: center;
  }

  .status-strip,
  .results-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 72px;
  }
}
