/* EchoCard AI: a dark shell with a sidebar (the views, the library of decks, the open deck's cards) and one main
   pane. Two main screens: the deck's page (step 1) and the card (step 2), which has a player bar under it. */

:root {
  color-scheme: dark;
  --bg: #121212;
  --chrome: #000000;
  --surface: #181818;
  --raised: #242424;
  --hover: #2c2c2c;
  --border: #333333;
  --text: #ffffff;
  --muted: #b3b3b3;
  --accent: #1ed760;
  --accent-hover: #3be477;
  --on-accent: #000000;
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #f87171;
  --radius-s: 4px;
  --radius-m: 8px;
  --radius-pill: 999px;
  --gap-s: 8px;
  --gap-m: 16px;
  --gap-l: 24px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --deck-hue: 150; /* the open deck's colour: set from its id (ui/library.js) */
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--chrome);
  color: var(--text);
  font: 14px/1.5 var(--font);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
h1, h2, p { margin: 0; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.grow { flex: 1 1 200px; }
.wide { grid-column: 1 / -1; }

/* ---- Shell ---- */
.shell { display: grid; grid-template: minmax(0, 1fr) auto / 280px minmax(0, 1fr); gap: var(--gap-s); height: 100dvh; padding: var(--gap-s); }
.sidebar, .main { background: var(--bg); border-radius: var(--radius-m); min-height: 0; min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: var(--gap-m); padding: var(--gap-m); overflow-y: auto; }
.main {
  overflow-y: auto; padding: var(--gap-l);
  background: linear-gradient(hsl(var(--deck-hue) 42% 26%), var(--bg) 380px);
  transition: background 0.3s;
}
.now-bar { grid-column: 1 / -1; }

/* ---- Sidebar: the views, the library of decks, the open deck's cards ---- */
.brand { font-size: 22px; font-weight: 900; letter-spacing: -0.03em; padding: 4px var(--gap-s); }
.nav-links { display: flex; flex-direction: column; gap: 2px; }
.nav-link, .deck-chip {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 8px; border: 0; border-radius: var(--radius-s);
  background: none; color: var(--muted); font-weight: 700; text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover, .deck-chip:hover { color: var(--text); background: var(--raised); }
.nav-link[aria-current], .deck-chip[aria-pressed="true"] { color: var(--text); background: var(--raised); }
.sidebar-library { flex: 1 0 auto; } /* it does not shrink: a long list scrolls the sidebar, and never runs under the foot */
.sidebar-decks { display: flex; flex-direction: column; gap: 2px; margin-top: var(--gap-s); }
.deck-chip { font-weight: 400; }
.deck-chip-text { display: flex; flex-direction: column; min-width: 0; }
.deck-chip-text strong { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-chip[aria-pressed="true"] strong { color: var(--accent); }
.sidebar-cards { display: flex; flex-direction: column; gap: 2px; margin-top: var(--gap-s); }
.card-stage { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--gap-s); }
.stage-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--gap-s); padding: 6px 8px 2px; font-size: 11px; color: var(--muted); }
.stage-head-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-head-count { flex: none; }
.card-link {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 6px 8px; border: 0; border-radius: var(--radius-s);
  background: none; color: var(--muted); font-size: 13px; text-align: left;
  transition: background 0.15s, color 0.15s;
}
.card-link:hover:not(:disabled) { color: var(--text); background: var(--raised); }
.card-link[aria-current] { color: var(--accent); background: var(--raised); font-weight: 700; }
.card-link-mark { flex: none; width: 20px; text-align: right; font-size: 12px; }
.card-link-mark.done { color: var(--accent); }
.card-link-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot { display: flex; flex-direction: column; gap: var(--gap-s); font-size: 12px; color: var(--muted); }
.account-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-s); }

.overline { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.overline.text-success { color: var(--success); }
.overline.text-error { color: var(--error); }
.spaced { margin-top: var(--gap-m); }

.view-title { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: var(--gap-m); }

/* ---- Covers ---- */
.cover {
  display: grid; place-items: center; flex: none;
  aspect-ratio: 1; width: 100%; border-radius: var(--radius-s);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}
.cover-letters { font-size: 64px; font-weight: 900; letter-spacing: -0.04em; color: rgba(255, 255, 255, 0.94); text-shadow: 0 2px 12px rgba(0, 0, 0, 0.25); }
.cover-small { width: 48px; box-shadow: none; }
.cover-small .cover-letters { font-size: 17px; letter-spacing: -0.02em; }
.cover-large { width: clamp(140px, 20vw, 232px); border-radius: var(--radius-m); }
.cover-large .cover-letters { font-size: clamp(52px, 8vw, 96px); }

/* ---- Step 1: the deck's page ---- */
.deck-head { display: flex; align-items: flex-end; gap: var(--gap-l); margin-bottom: var(--gap-l); }
.deck-head-text { display: flex; flex-direction: column; gap: var(--gap-s); min-width: 0; }
.deck-title { font-size: clamp(32px, 6vw, 72px); font-weight: 900; letter-spacing: -0.04em; line-height: 1.02; margin: 0; }
.deck-description { color: rgba(255, 255, 255, 0.78); max-width: 68ch; }
.deck-meta { font-size: 13px; font-weight: 600; }
.deck-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-m); margin-bottom: var(--gap-s); }
.deck-rule { margin-bottom: var(--gap-l); }
.btn-play {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 28px 14px 22px; border: 0; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--on-accent); font-size: 16px; font-weight: 800;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); transition: transform 0.12s, background 0.12s;
}
.btn-play::before { content: ""; border-style: solid; border-width: 8px 0 8px 13px; border-color: transparent transparent transparent currentColor; }
.btn-play:hover { background: var(--accent-hover); transform: scale(1.04); }
.btn-play:active { transform: scale(0.98); }
.stage { margin-bottom: var(--gap-l); }
.stage-title {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--gap-s);
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  padding: var(--gap-s); border-bottom: 1px solid rgba(255, 255, 255, 0.1); margin: 0 0 4px;
}
.stage-count { letter-spacing: 0; text-transform: none; font-weight: 400; }
.track-row {
  display: grid; grid-template-columns: 32px 1fr 64px 88px; align-items: center; gap: 12px;
  width: 100%; padding: 8px; border: 0; border-radius: var(--radius-s); background: none; text-align: left;
  transition: background 0.15s;
}
.track-row:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
/* On a row that can be opened, the number gives way to a play mark. */
.track-row:hover:not(:disabled) .track-number, .track-row:focus-visible .track-number { font-size: 0; }
.track-row:hover:not(:disabled) .track-number::after, .track-row:focus-visible .track-number::after {
  content: ""; display: inline-block; border-style: solid; border-width: 6px 0 6px 10px; border-color: transparent transparent transparent var(--text);
}
.track-row.current strong { color: var(--accent); }
.track-number, .track-mastery, .track-mark { color: var(--muted); font-size: 13px; }
.track-number, .track-mastery { text-align: right; }
.track-name { display: flex; flex-direction: column; min-width: 0; }
.track-mark.done { justify-self: start; padding: 2px 10px; border-radius: var(--radius-pill); background: rgba(30, 215, 96, 0.14); color: var(--accent); font-weight: 700; font-size: 12px; }

/* ---- Buttons and fields ---- */
.btn-primary, .btn-secondary, .btn-ghost, .btn-record, .speed-btn {
  border-radius: var(--radius-pill); padding: 8px 20px; font-weight: 700; border: 1px solid transparent; white-space: nowrap;
}
.btn-primary, .btn-record { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled), .btn-record:hover { background: var(--accent-hover); }
.btn-secondary { background: none; border-color: #727272; }
.btn-secondary:hover:not(:disabled) { border-color: var(--text); }
.btn-ghost { background: none; color: var(--muted); padding: 8px 12px; }
.btn-ghost:hover { color: var(--text); }
.btn-small { padding: 4px 12px; font-size: 12px; }
.file-pick { cursor: pointer; }
.file-pick:focus-within { outline: 2px solid var(--text); outline-offset: 2px; }

.input, .select, .engine-badge-btn {
  background: var(--raised); border: 1px solid transparent; border-radius: var(--radius-s); padding: 8px 12px; min-width: 0; max-width: 100%;
}
.input:hover, .select:hover, .engine-badge-btn:hover { border-color: #727272; }
.input::placeholder { color: #8a8a8a; }
.csv-textarea { width: 100%; font-family: var(--font-mono); font-size: 12px; resize: vertical; margin: var(--gap-m) 0; }

.panel { background: var(--surface); border-radius: var(--radius-m); padding: var(--gap-m); margin-bottom: var(--gap-m); }
.note { font-size: 12px; color: var(--muted); }
.note-warning { color: var(--warning); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--gap-s); margin-bottom: var(--gap-m); }
.toolbar-controls { display: flex; flex-wrap: wrap; gap: var(--gap-s); }

/* ---- Step 2: the card ---- */
.practice { max-width: 760px; margin: 0 auto; }
/* The card turns over: both sides lie in one grid cell, so the card is as tall as its taller side. */
.flashcard { perspective: 1600px; margin: 0 0 var(--gap-m); }
.flashcard-inner { display: grid; transform-style: preserve-3d; transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1); }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  grid-area: 1 / 1; min-width: 0;
  padding: 32px var(--gap-l);
  background: linear-gradient(160deg, hsl(var(--deck-hue) 38% 22%), var(--surface) 70%);
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.flashcard-front { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--gap-s); text-align: center; }
.flashcard-back { transform: rotateY(180deg); background: linear-gradient(200deg, hsl(var(--deck-hue) 38% 22%), var(--surface) 70%); }
.flip-hint { margin-top: var(--gap-s); }
.back-meaning { margin: var(--gap-s) 0 var(--gap-m); font-size: clamp(17px, 2.2vw, 21px); line-height: 1.5; white-space: pre-line; }
.stimulus-image { width: min(100%, 320px); }
.stimulus-image img { display: block; width: 100%; border-radius: var(--radius-m); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); }
.stimulus-phrase { font-size: clamp(30px, 6vw, 56px); font-weight: 900; letter-spacing: -0.03em; line-height: 1.1; margin-top: var(--gap-s); }
.stimulus-ipa { color: rgba(255, 255, 255, 0.72); font-size: 17px; }
.audio-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--gap-m); margin-top: var(--gap-s); }
.speed-group { display: flex; gap: 4px; }
.speed-btn { background: none; color: var(--muted); padding: 4px 10px; font-size: 12px; }
.speed-btn.active { background: var(--raised); color: var(--text); }

/* ---- Player bar: the card's controls, on the card screen ---- */
.now-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--gap-m); padding: var(--gap-s) var(--gap-m); }
.now-card { display: flex; align-items: center; gap: 12px; min-width: 0; }
.now-text { min-width: 0; }
.now-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-center { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: min(46vw, 460px); }
.now-controls { display: flex; align-items: center; gap: var(--gap-s); }
.btn-record { min-width: 150px; padding: 12px 28px; font-size: 15px; transition: transform 0.12s; }
.btn-record:hover { transform: scale(1.04); }
.btn-record.recording { background: var(--error); animation: pulse 1.2s ease-in-out infinite; }
.progress { width: 100%; height: 4px; border-radius: 2px; background: #4d4d4d; overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 2px; background: var(--text); transition: width 0.25s; }
.now-bar:hover .progress-fill { background: var(--accent); }
.now-side { display: flex; align-items: center; justify-content: flex-end; gap: 12px; min-width: 0; }
.now-side .select { flex: none; width: auto; } /* the mode and the engine are never cut short: the status line wraps */
.save-status { font-size: 12px; color: var(--muted); text-align: right; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0.25); } }
@media (prefers-reduced-motion: reduce) {
  .btn-record.recording { animation: none; }
  .wave-bar, .progress-fill, .main, .btn-play, .btn-record, .track-row, .nav-link, .deck-chip, .card-link, .flashcard-inner { transition: none; } /* the card shows its other side at once */
  .btn-play:hover, .btn-record:hover { transform: none; }
}

.answer { margin-bottom: var(--gap-m); }
.answer .input { width: 100%; padding: 12px 16px; border-radius: var(--radius-m); background: rgba(255, 255, 255, 0.07); }
.waveform-bars { display: flex; align-items: center; justify-content: center; gap: 4px; height: 36px; margin-bottom: var(--gap-s); }
.wave-bar { width: 4px; border-radius: 2px; background: var(--accent); transition: height 0.08s; }

.eval-grid { display: grid; grid-template-columns: 150px 1fr; gap: 12px var(--gap-m); margin-top: var(--gap-m); }
.eval-row { display: contents; } /* a label and its value, as two cells of the grid */
.eval-label { color: var(--muted); font-size: 12px; font-weight: 700; padding-top: 2px; }
.score { font-size: 28px; color: var(--accent); }
.locked-answer { color: var(--muted); font-style: italic; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.fb-pill { display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.fb-pill.perfect { color: var(--success); }
.fb-pill.check_syllable { color: var(--warning); }
.fb-pill.missed { color: var(--error); }

/* ---- Track record, studio, import ---- */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap-m); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap-m); align-items: start; }
.kpi-val { font-size: 30px; font-weight: 700; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.diag-item { display: block; width: 100%; margin-top: var(--gap-s); padding: 10px 12px; border: 0; border-radius: var(--radius-s); background: var(--raised); text-align: left; }
.diag-item.clickable:hover:not(:disabled) { background: var(--hover); }
.diag-row { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-s); }
.diag-meta, .diag-meta-error { font-size: 12px; margin-top: 4px; }
.diag-meta { color: var(--muted); }
.diag-meta-error { color: var(--error); }
.empty-note { color: var(--muted); font-size: 13px; margin-top: var(--gap-s); }
#btn-practice-weak { margin-top: var(--gap-m); }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: var(--raised); }
.studio-actions .btn-small { margin: 0 4px 4px 0; }
.drag-handle { padding: 0 8px 0 0; border: 0; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: grab; }
.drag-handle:hover, .drag-handle:focus-visible { color: var(--text); }
.table tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
.table tr.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }

.tabs { display: flex; gap: 4px; margin-bottom: var(--gap-m); border-bottom: 1px solid var(--border); }
.tab { padding: 8px 16px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-weight: 700; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.json-textarea { min-height: 320px; margin-top: var(--gap-s); line-height: 1.5; white-space: pre; }
.problems { margin: var(--gap-s) 0 0; padding-left: 20px; font-size: 12px; color: var(--error); }
.schema-details { margin-top: var(--gap-m); font-size: 13px; color: var(--muted); }
.schema-details summary { cursor: pointer; font-weight: 700; }
.schema-text { max-height: 360px; overflow: auto; margin: var(--gap-s) 0 0; padding: 12px; border-radius: var(--radius-s); background: var(--raised); color: var(--text); font-size: 12px; }

.studio-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap-s); padding: var(--gap-m); margin-bottom: var(--gap-m); background: var(--raised); border-radius: var(--radius-m); }
.studio-form .input { background: var(--bg); }
.form-buttons { display: flex; flex-wrap: wrap; gap: var(--gap-s); }

/* ---- Narrow screens: the sidebar becomes a strip (the views, the decks side by side, the cards side by side), the player bar stacks ---- */
@media (max-width: 780px) {
  .shell { grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr); }
  .sidebar { gap: var(--gap-s); padding: var(--gap-s); overflow: visible; }
  .brand, .sidebar-library .overline { display: none; }
  .nav-links { flex-direction: row; overflow-x: auto; }
  .nav-link { width: auto; white-space: nowrap; padding: 6px 12px; }
  .sidebar-library { flex: none; }
  .sidebar-decks { flex-direction: row; overflow-x: auto; margin-top: 0; }
  .deck-chip { width: auto; flex: none; max-width: 240px; padding: 4px 8px; }
  .deck-chip .cover-small { width: 32px; }
  .sidebar-cards { flex-direction: row; align-items: center; overflow-x: auto; margin-top: 4px; }
  .card-stage { display: contents; }
  .stage-head { flex: none; padding: 0 4px 0 8px; }
  .stage-head-count { display: none; }
  .card-link { width: auto; flex: none; max-width: 200px; padding: 4px 10px 4px 4px; }
  .main { padding: var(--gap-m); }
  .grid-4, .grid-2, .studio-form { grid-template-columns: 1fr; }
  .eval-grid { grid-template-columns: 1fr; gap: 4px; }
  .eval-label { margin-top: var(--gap-s); }
  .deck-head { flex-direction: column; align-items: flex-start; gap: var(--gap-m); }
  .track-row { grid-template-columns: 24px 1fr 48px; }
  .track-mark { display: none; }
  .flashcard-face { padding: var(--gap-l) var(--gap-m); }
  .now-bar { grid-template-columns: 1fr; justify-items: center; gap: var(--gap-s); padding: var(--gap-s); }
  .now-card { display: none; } /* the card is right above the bar */
  .now-center { width: 100%; min-width: 0; }
  .now-side { justify-content: center; flex-wrap: wrap; }
  .save-status { flex-basis: 100%; text-align: center; }
}
