* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0 0 var(--space-2); }
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 700; }
p { margin: 0 0 var(--space-3); color: var(--muted); }

a { color: var(--ink); text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }

button, input, select {
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-control);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-control);
  z-index: 100;
}
.skip-link:focus {
  left: var(--space-3);
  top: var(--space-3);
}

/* ---------------------------------------------------------------- shell */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}
/* the o of Morse is a dot and the name ends on a dash: dot-dash-dot */
.wordmark .dot {
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin: 0 0.06em;
  border-radius: 50%;
  background: var(--accent);
}
.wordmark .dash {
  display: inline-block;
  width: 0.62em;
  height: 0.2em;
  margin-left: 0.14em;
  border-radius: 999px;
  background: var(--accent);
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-btn {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0 var(--space-2);
  cursor: pointer;
  border-bottom: 3px solid var(--raised-edge);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { border-bottom-width: 1px; transform: translateY(2px); }

#volume {
  width: 90px;
  accent-color: var(--accent);
  min-height: var(--tap-min);
}

.tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4) 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab-btn {
  min-height: var(--tap-min);
  padding: 0 var(--space-3);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

main {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
}

.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}
.field label { font-weight: 600; font-size: 0.9rem; }
.field .hint { color: var(--muted); font-size: 0.8rem; }

input[type="text"], input[type="number"], textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  color: var(--ink);
  min-height: var(--tap-min);
}
textarea { min-height: 88px; resize: vertical; font-family: var(--font-body); }

input[type="range"] {
  accent-color: var(--accent);
  min-height: var(--tap-min);
  padding: calc((var(--tap-min) - 4px) / 2) 0;
  box-sizing: content-box;
}
/* the native track is thin; the padded box above and a sized thumb keep the
   actual pointer/touch target at 44px even though the track itself is not */
input[type="range"]::-webkit-slider-thumb {
  width: var(--tap-min);
  height: var(--tap-min);
  margin-top: 0;
}
input[type="range"]::-moz-range-thumb {
  width: var(--tap-min);
  height: var(--tap-min);
  border: none;
}

.btn {
  min-height: var(--tap-min);
  padding: 0 var(--space-4);
  border-radius: var(--radius-control);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
  border-bottom: 3px solid color-mix(in srgb, var(--accent) 60%, var(--raised-edge));
}
.btn:active:not(:disabled) { border-bottom-width: 1px; transform: translateY(2px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary {
  background: var(--raised);
  color: var(--ink);
  border-color: var(--border);
  border-bottom-color: var(--raised-edge);
}

.row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* -------------------------------------------------------- dot/dash timeline */

.timeline {
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 56px;
  padding: var(--space-3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-tile);
  overflow-x: auto;
}
.timeline .mark {
  height: 14px;
  background: var(--mark);
  border-radius: 999px;
  flex: 0 0 auto;
  transition: background-color 0.06s linear;
}
.timeline .mark.tone { background: var(--mark); }
.timeline .mark.playing { background: var(--accent); }
.timeline .gap { flex: 0 0 auto; }

/* ------------------------------------------------------------------ drill */
/* Family Drill: progress pinned top, prompt centered, answer at bottom,
   feedback slides up. */

.drill {
  display: flex;
  flex-direction: column;
  min-height: 60vh;
}

.drill-progress {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.drill-progress .bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.drill-progress .bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}
@media (prefers-reduced-motion: reduce) {
  .drill-progress .bar > i { transition: none; }
}

.drill-prompt {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-3);
}
.drill-prompt .hero-timeline { min-height: 80px; width: 100%; justify-content: center; }

.drill-answer {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.drill-answer input {
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  width: 220px;
}

.drill-feedback {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  text-align: center;
  font-weight: 700;
  transform: translateY(8px);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.drill-feedback.show { transform: translateY(0); opacity: 1; box-shadow: var(--ambient); }
.drill-feedback.correct { background: color-mix(in srgb, var(--success) 15%, var(--surface)); color: var(--success); }
.drill-feedback.incorrect { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
@media (prefers-reduced-motion: reduce) {
  .drill-feedback { transition: none; }
}

/* -------------------------------------------------------------- heatmap */

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: var(--space-1);
}
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-tile);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--heat-ink);
  min-height: var(--tap-min);
}

/* ---------------------------------------------------------------- key */

.key-pad {
  min-height: 160px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  padding: var(--space-4);
}
.key-pad.active {
  border-color: var(--accent);
  border-style: solid;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--ink);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat .value { font-family: var(--font-display); font-size: 1.4rem; font-weight: 800; }
.stat .label { font-size: 0.8rem; color: var(--muted); }

/* ----------------------------------------------------------- reference */

.ref-table { width: 100%; border-collapse: collapse; }
.ref-table th, .ref-table td {
  text-align: left;
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.code-cell { font-family: var(--font-display); letter-spacing: 0.15em; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: var(--space-5) var(--space-3);
}

.flash-box {
  min-height: 220px;
  border-radius: var(--radius);
  background: var(--ink);
  transition: background-color 0.02s linear;
}
.flash-box.lit { background: var(--accent); }

.footer {
  padding: var(--space-4);
  text-align: center;
}
.footer-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

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