/* ══════════════════════════════════════════════════════════════════
   DESIGN SYSTEM — one look for every section.
   Declared last so it overrides the older per-section styles above.
   ══════════════════════════════════════════════════════════════════ */
/* Theme tokens: neutral backgrounds with a pink accent. Dark below; [data-theme="light"] (the default) after it. */
:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1b1b1b;
  --surface-3: #262626;
  --surface-inverse: #2a2a2a;   /* deep panels with light text (tooltips, subtitle bar) */
  --border: #262626;
  --border-strong: #3a3a3a;
  --text: #fafafa;
  --text-2: #d4d4d4;
  --muted: #a3a3a3;
  --primary: #eb4799;
  --primary-strong: #e02c87;
  --primary-soft: rgba(235, 71, 153, .14);
  --primary-border: rgba(235, 71, 153, .38);
  --primary-text: #f472b6;
  --on-primary: #fff;
  --success: #2c9664;
  --success-soft: rgba(44, 150, 100, .16);
  --success-border: rgba(44, 150, 100, .4);
  --success-text: #5fd39b;
  --warn: #d48d11;
  --warn-soft: rgba(212, 141, 17, .15);
  --warn-border: rgba(212, 141, 17, .42);
  --warn-text: #fbbf24;
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, .14);
  --danger-border: rgba(229, 72, 77, .42);
  --danger-text: #fb7185;
  --overlay: rgba(0, 0, 0, .7);
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 8px 24px rgba(0, 0, 0, .45);
  --font: 'Quicksand', 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sidebar-w: 224px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --surface-3: #e2e8f0;
  --surface-inverse: #1e293b;
  --border: #e2e7ef;
  --border-strong: #cbd3df;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #e03d8d;
  --primary-strong: #c92a78;
  --primary-soft: #fde8f2;
  --primary-border: #f7bcd8;
  --primary-text: #b0246a;
  --success: #23885a;
  --success-soft: #e7f6ee;
  --success-border: #b6e3cb;
  --success-text: #17663f;
  --warn: #c27c0e;
  --warn-soft: #fff6e0;
  --warn-border: #f5d58f;
  --warn-text: #8a5208;
  --danger: #d9363e;
  --danger-soft: #fdecee;
  --danger-border: #f6b9bd;
  --danger-text: #b4232b;
  --overlay: rgba(15, 23, 42, .45);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow: 0 4px 16px rgba(15, 23, 42, .07);
}

html { scroll-behavior: smooth; }
body {
  max-width: none;
  margin: 0;
  padding: 28px 32px 64px calc(var(--sidebar-w) + 32px);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { color: var(--text); letter-spacing: -.015em; }
h1 { font-size: 1.75em; font-weight: 800; margin: 0 0 4px; }
h2 { font-weight: 700; }
.muted { color: var(--muted); font-size: .92em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
a { color: var(--primary); }

/* ── surfaces ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin: 14px 0;
  box-shadow: var(--shadow-sm);
}
.card.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(235, 71, 153, .14); }

/* ── controls ─────────────────────────────────────────────────── */
button {
  font-family: inherit;
  font-size: .9em;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .15s;
}
button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary, .cl-btn-primary, .dict-btn-create, .dict-btn-practice {
  background: var(--primary); border: 1px solid var(--primary); color: #fff;
  box-shadow: 0 1px 2px rgba(235, 71, 153, .25);
}
button.primary:hover:not(:disabled), .cl-btn-primary:hover:not(:disabled),
.dict-btn-create:hover:not(:disabled), .dict-btn-practice:hover:not(:disabled) {
  background: var(--primary-strong); border-color: var(--primary-strong); color: #fff;
  transform: none; box-shadow: 0 1px 2px rgba(235, 71, 153, .25);
}
.cl-btn-primary { padding: 9px 16px; border-radius: 10px; font-weight: 600; cursor: pointer; }
button.danger, .dict-btn-delete {
  background: var(--surface); border: 1px solid var(--danger-border); color: var(--danger);
}
button.danger:hover:not(:disabled), .dict-btn-delete:hover:not(:disabled) {
  background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger);
}
input[type="text"], input[type="number"], input[type="search"], input[type="password"], input:not([type]),
select, textarea {
  font-family: inherit;
  font-size: .95em;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 11px;
  transition: border-color .15s, box-shadow .15s;
}
/* Our own arrow: the browser's sits against the right edge (macOS), out of line with the text's padding.
   Specific enough to keep its room even where a section sets a smaller padding on its selects. */
select:not([multiple]):not([size]) {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 14px;
  cursor: pointer;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(235, 71, 153, .15);
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; vertical-align: -3px; }

/* ── sidebar navigation ───────────────────────────────────────── */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 60; width: var(--sidebar-w);
  display: flex; flex-direction: column; gap: 6px; padding: 18px 12px 14px;
  background: var(--bg); border-right: 1px solid var(--border); overflow-y: auto;
}
/* Nothing in it shrinks: when the menu is taller than the window the sidebar scrolls, instead of
   squeezing the account box until the theme box covers it */
.app-sidebar > * { flex-shrink: 0; }
.app-brand {
  display: flex; align-items: center; gap: 10px; padding: 2px 8px 12px;
  font-weight: 700; font-size: 1.05em; color: var(--text); letter-spacing: .06em; text-transform: uppercase;
}
.app-brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #f472b6, var(--primary-strong)); color: #fff;
  font-size: .9em; letter-spacing: 0; text-transform: none;
}
.top-nav { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; background: none; border: none; box-shadow: none;
           flex-shrink: 0; overflow: visible; /* a short window scrolls the sidebar instead of clipping the menu */ }
.nav-group {
  margin: 12px 10px 4px; font-size: .68em; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.top-nav-tab {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
  border: none; border-radius: 9px; box-shadow: none; background: transparent;
  font-family: inherit; font-size: .98em; font-weight: 500; text-align: left; white-space: nowrap;
  color: var(--text); letter-spacing: 0; text-decoration: none; cursor: pointer;
}
.top-nav-tab svg { flex: 0 0 auto; width: 19px; height: 19px; }
.top-nav-tab:hover:not(:disabled) { color: var(--text); background: var(--surface-3); }
.top-nav-tab.active,
.top-nav-tab.active:hover:not(:disabled) { color: var(--text); background: var(--surface-3); box-shadow: none; font-weight: 600; }
.top-nav-tab.active svg { color: var(--primary); }
.top-nav-tab.active::after { display: none; }
.nav-tag {
  margin-left: auto; padding: 1px 7px; border-radius: 999px; font-size: .62em; font-weight: 700;
  background: rgba(168, 85, 247, .22); color: #d8b4fe;
}
:root[data-theme="light"] .nav-tag { background: #f3e8ff; color: #7e22ce; }
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  font-size: .85em; color: var(--muted);
}
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--text-2);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover:not(:disabled) { background: var(--surface-3); border-color: transparent; }
.mobile-bar { display: none; }
/* Hide / show the sidebar (wide screens only; phones slide it in from the top bar) */
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding-bottom: 12px; }
.sidebar-head .app-brand { min-width: 0; gap: 8px; padding-right: 0; padding-bottom: 0; white-space: nowrap; letter-spacing: .03em; }
.sidebar-hide-btn { flex: none; width: 28px; height: 28px; color: var(--muted); }
.sidebar-hide-btn svg { width: 17px; height: 17px; }
.sidebar-show-btn { display: none; }
@media (min-width: 901px) {
  html.sidebar-hidden .app-sidebar { display: none; }
  html.sidebar-hidden body { padding-left: 64px; }
  html.sidebar-hidden .sidebar-show-btn {
    display: grid; position: fixed; top: 18px; left: 16px; z-index: 60;
    background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-sm);
  }
  /* the guests' landing has its own top bar instead */
  html.sidebar-hidden body.on-home:not(.signed-in):not(.admin) { padding-left: 32px; }
  body.on-home:not(.signed-in):not(.admin) .sidebar-show-btn { display: none; }
}
@media (max-width: 900px) { .sidebar-hide-btn { display: none; } }
:root[data-theme="light"] .theme-dark-icon, :root:not([data-theme="light"]) .theme-light-icon { display: none; }
.sidebar-scrim { display: none; }
.nav-badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: auto;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: .75em; line-height: 18px; text-align: center; vertical-align: 1px;
}
.nav-badge:empty { display: none; }

/* ── page header shared by all sections ──────────────────────── */
#homeSection, #circumlocutionSection, #dictationSection, #speakingSection, #youglishShadowSection,
#sentenceReplaySection, #progressSection, #retrySection {
  max-width: 1080px; margin: 0 auto; font-family: var(--font);
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1, .page-head h2 { margin: 0; font-size: 1.75em; font-weight: 800; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.cl-top-actions, .dict-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.cl-top-actions h1, .dict-header h2 { margin: 0; font-size: 1.75em; font-weight: 800; color: var(--text); }
.dict-header p { margin: 4px 0 0; color: var(--muted); }

/* ── circumlocution ──────────────────────────────────────────── */
.cl-subnav { gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; display: inline-flex; }
.cl-subnav-btn { border: none; border-radius: 9px; background: transparent; color: var(--muted); padding: 7px 16px; box-shadow: none; }
.cl-subnav-btn:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.cl-subnav-btn.active, .cl-subnav-btn.active:hover:not(:disabled) { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.cl-dashboard-header { text-align: left; margin-bottom: 20px; }
.cl-dashboard-header h2 {
  background: none; -webkit-text-fill-color: currentColor; color: var(--text); font-size: 1.75em;
}
.cl-stat-card { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); border-radius: var(--radius-lg); backdrop-filter: none; }
.cl-stat-card:hover { transform: none; box-shadow: var(--shadow); }
.cl-dashboard-actions { justify-content: flex-start; }
.cl-btn-review { background: var(--primary); border-radius: 12px; box-shadow: 0 2px 8px rgba(235, 71, 153, .3); padding: 12px 26px; }
.cl-btn-review:hover:not(:disabled) { background: var(--primary-strong); transform: none; box-shadow: 0 2px 8px rgba(235, 71, 153, .3); }
.cl-btn-add { border: 1px solid var(--border-strong); border-radius: 12px; padding: 12px 26px; }

/* ── list cards (speaking exercises etc.) ────────────────────── */
.cl-cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.dict-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px; box-shadow: var(--shadow-sm); transition: box-shadow .15s, border-color .15s;
}
.dict-card:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
.dict-card-title { margin: 0; font-size: 1.05em; font-weight: 700; }
.dict-card-meta { color: var(--muted); font-size: .88em; }
.dict-card-actions { display: flex; gap: 8px; margin-top: 10px; }
.dict-card-actions .dict-btn-practice { flex: 1; }
.dict-ex-item, .cl-card-item { border-radius: var(--radius-lg); border-color: var(--border); box-shadow: var(--shadow-sm); }

/* ── speaking / shadowing practice ───────────────────────────── */
.spk-btn { font-family: inherit; border-radius: 12px; }
.spk-nav-btn { border: 1px solid transparent; background: transparent; }
.spk-nav-btn.primary, .spk-nav-btn.primary:hover:not(:disabled) { color: #fff; }
.spk-nav-btn.primary:disabled { background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.spk-score-panel { background: var(--surface); border-color: var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.ygs-search input { padding: 12px 14px; font-size: 1em; border-radius: 12px; }
.ygs-search .cl-btn-primary { padding: 0 20px; border-radius: 12px; }
.ygs-widget { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; overflow: hidden; }
.ygs-clip { border-radius: var(--radius); border-color: var(--border); box-shadow: var(--shadow-sm); }
.ygs-clip a { text-decoration: none; font-weight: 600; border: 1px solid var(--border-strong); color: var(--text-2); }
.ygs-clip a:hover { background: var(--surface-2); }

.media-switch { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.media-switch button { border: none; border-radius: 9px; background: transparent; color: var(--muted); padding: 8px 18px; font-size: .92em; }
.media-switch button:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.media-switch button.active, .media-switch button.active:hover:not(:disabled) { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.media-switch .count { margin-left: 6px; padding: 0 7px; border-radius: 9px; background: var(--border); color: var(--text-2); font-size: .8em; }
.upload-tab[hidden] { display: none; }
