:root {
  --bg: #0e1117;
  --fg: #e6e6e6;
  --muted: #8a93a3;
  --accent: #5dd2ff;
  --accent-dim: #1f4e63;
  --ok: #79e08a;
  --bad: #ff7878;
  --panel: #161b22;
  --panel-2: #1c222b;
  --border: #232a35;
  --kbd: #232a35;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 12px 32px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --fg: #1d232b;
    --muted: #5b6573;
    --accent: #0085b3;
    --accent-dim: #cfeaf6;
    --ok: #2c8c43;
    --bad: #c63131;
    --panel: #ffffff;
    --panel-2: #f1f4f8;
    --border: #e3e7ee;
    --kbd: #eef0f4;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 12px 32px rgba(0, 0, 0, 0.06);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.aid-status {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas:
    "prompt   settings"
    "progress settings";
  gap: 1.25rem;
  padding: 1.25rem;
  max-width: 1180px;
  margin: 0 auto;
}

@media (max-width: 820px) {
  main {
    grid-template-columns: 1fr;
    grid-template-areas:
      "prompt"
      "settings"
      "progress";
  }
}

.prompt-area {
  grid-area: prompt;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.settings {
  grid-area: settings;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  box-shadow: var(--shadow);
  align-self: start;
}

.settings h2,
.progress h2 {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.progress {
  grid-area: progress;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

/* Prompt area */
.prompt {
  font-size: clamp(5rem, 18vw, 10.5rem);
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.morse-visual {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", monospace;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  letter-spacing: 0.12em;
  min-height: 2.2rem;
  color: var(--accent);
  transition: opacity 0.25s ease, color 0.15s ease;
}

.morse-visual.hidden-aid { opacity: 0; }
.morse-visual.wrong-answer { color: var(--bad); }
/* Non-color cue: a ✗ badge prefixes the morse so the wrong-answer state is
   visible to anyone who can't perceive the red. */
.morse-visual.wrong-answer::before {
  content: "✗\00a0\00a0";   /* ✗ + two non-breaking spaces */
  margin-right: 0.1em;
}

.buffer {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", monospace;
  font-size: 1.8rem;
  letter-spacing: 0.18em;
  min-height: 3rem;
  margin-top: 1rem;
  padding: 0.6rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--fg);
  white-space: pre;
}

.buffer.wrong-prefix {
  color: var(--bad);
  border-color: var(--bad);
  animation: shake 0.18s linear 1;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

.feedback {
  margin-top: 0.9rem;
  min-height: 1.6rem;
  font-family: ui-monospace, monospace;
  font-size: 0.95rem;
}

.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

.controls {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.paddles {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.paddle {
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: 2rem;
  font-weight: 700;
  width: 5.5rem;
  height: 3.5rem;
  border-radius: 12px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  touch-action: manipulation;     /* avoid 300ms tap delay on mobile */
  user-select: none;
  -webkit-user-select: none;
}

.paddle:active { filter: brightness(1.2); transform: translateY(1px); }
.paddle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, background 0.15s;
}

button:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.danger:hover { background: rgba(255, 100, 100, 0.08); }

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0.9rem 0 0;
}

kbd {
  background: var(--kbd);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.05rem 0.4rem;
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: 0.82rem;
  color: var(--fg);
}

/* Settings */
.settings label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.settings label .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.settings label .row strong { color: var(--fg); font-weight: 600; }

.settings label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--fg);
}

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

.settings select,
.settings input[type="text"] {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.45rem;
  font: inherit;
}

.settings input[type="text"] { width: 3em; text-align: center; }

details {
  border-top: 1px dashed var(--border);
  padding-top: 0.5rem;
}

details summary {
  cursor: pointer;
  color: var(--fg);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  list-style: none;
}

details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸ "; color: var(--muted); }
details[open] summary::before { content: "▾ "; }

.keybinds {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.keybinds label {
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  color: var(--fg);
  font-size: 0.9rem;
}

.muted { color: var(--muted); font-size: 0.78rem; line-height: 1.4; }
.muted.bad { color: var(--bad); }

/* Progress table */
.progress table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.progress th,
.progress td {
  text-align: left;
  padding: 0.32rem 0.45rem;
  border-bottom: 1px solid var(--border);
}

.progress th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.progress td code { font-family: ui-monospace, monospace; color: var(--accent); }
.progress .meta { color: var(--muted); font-size: 0.78rem; margin-top: 0.5rem; }

/* Start overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  max-width: 26rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-card h2 { margin: 0 0 0.6rem; font-size: 1.2rem; }
.overlay-card p { margin: 0.4rem 0; color: var(--muted); font-size: 0.92rem; }
.overlay-card button {
  margin: 0.75rem 0 0.4rem;
  padding: 0.6rem 1.4rem;
  background: var(--accent);
  color: #001923;
  border: none;
  font-weight: 700;
  font-size: 1rem;
}
.overlay-card button:hover { filter: brightness(1.05); }
