/* Classes Ayazpoor — app.css
   Design: squared, high-contrast, no gradients. Surfaces have a hard 2px
   border and a solid offset shadow that "pops" on hover. Light + dark. */

/* Up-to-date colour emoji, served (COLRv1, subset-delivered by unicode-range),
   so the newest emoji render the same on every OS — Windows' Segoe UI Emoji is
   often a version or two behind. Listed FIRST among the emoji fonts in --font. */
@import url('https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&display=swap');

:root {
  color-scheme: light dark;

  --bg: #f2f3f7;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #14161f;
  --muted: #5c6273;
  --line: #14161f;            /* hard borders use the ink colour */
  --line-soft: #dcdfe8;
  --primary: #3730d8;
  --primary-ink: #ffffff;
  --primary-soft: #e8e7fb;
  --success: #0f8a52;
  --success-soft: #dcf5e8;
  --danger: #d62828;
  --danger-soft: #fde4e4;
    --warning: #fbbf24;
  --warning-soft: #fdefd7;
  --gold-soft: #fdefd7;
    --gold: #fbbf24;
  --radius: 0px;              /* square angles */
  --radius-sm: 0px;
  --border: 2px;
  --shadow-col: #14161f;
  --shadow: 3px 3px 0 var(--shadow-col);
  --shadow-lg: 5px 5px 0 var(--shadow-col);
  --shadow-pop: 6px 6px 0 var(--shadow-col);
  --font: 'Inter', -apple-system, 'Segoe UI', Roboto, 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif;
}

/* Dark palette. Applied when the OS asks for dark AND the user hasn't forced
   light, or when the user explicitly picks dark (html[data-theme="dark"]). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f16;
    --surface: #161922;
    --surface-2: #1d212c;
    --ink: #eef0f6;
    --muted: #9aa1b4;
    --line: #4a5168;
    --line-soft: #2a2f3d;
    --primary: #8b85ff;
    --primary-ink: #10121a;
    --primary-soft: #23213f;
    --success: #34d399;
    --success-soft: #10291f;
    --danger: #f87171;
    --danger-soft: #2c1416;
  --warning: #b45309;
    --warning-soft: #2b1f0c;
  --gold: #a16207;
    --gold-soft: #2b1f0c;
    --shadow-col: #000000;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f16;
  --surface: #161922;
  --surface-2: #1d212c;
  --ink: #eef0f6;
  --muted: #9aa1b4;
  --line: #4a5168;
  --line-soft: #2a2f3d;
  --primary: #8b85ff;
  --primary-ink: #10121a;
  --primary-soft: #23213f;
  --success: #34d399;
  --success-soft: #10291f;
  --danger: #f87171;
  --danger-soft: #2c1416;
    --warning: #b45309;
  --warning-soft: #2b1f0c;
    --gold: #a16207;
  --gold-soft: #2b1f0c;
  --shadow-col: #000000;
}
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

/* Theme toggle button (topbar) */
.theme-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; cursor: pointer;
  background: var(--surface); color: var(--ink);
  border: 2px solid var(--line-soft); border-radius: var(--radius);
}
.theme-btn:hover { border-color: var(--line); box-shadow: 2px 2px 0 var(--shadow-col); transform: translate(-1px, -1px); }
.theme-btn .ic-sun { display: none; }
.theme-btn .ic-moon { display: flex; }
:root[data-theme="dark"] .theme-btn .ic-sun { display: flex; }
:root[data-theme="dark"] .theme-btn .ic-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .ic-sun { display: flex; }
  :root:not([data-theme="light"]) .theme-btn .ic-moon { display: none; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.55;
}
img, video { max-width: 100%; }
a { color: var(--primary); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1 { font-size: 1.7rem; font-weight: 900; letter-spacing: -.03em; margin: 0 0 4px; }
h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: -.02em; margin: 0 0 8px; }
h3 { font-size: 1.05rem; font-weight: 800; margin: 0 0 10px; }
h4 { margin: 0 0 8px; font-size: .95rem; font-weight: 800; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small, small { font-size: .84rem; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
code {
  background: var(--surface-2); border: 1px solid var(--line-soft);
  padding: 1px 6px; border-radius: var(--radius-sm); font-size: .88em;
}
::selection { background: var(--primary); color: var(--primary-ink); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 20px;
  background: var(--surface);
  border-bottom: var(--border) solid var(--line);
  padding: 0 clamp(14px, 4vw, 32px);
  height: 62px;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 1.05rem; font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand-name { letter-spacing: -.02em; }
.brand-name b { color: var(--primary); }
.brand-logo { width: 34px; height: 34px; object-fit: contain; flex: none; }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav a {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-weight: 700; font-size: .9rem;
  padding: 7px 12px; border-radius: var(--radius); border: 2px solid transparent;
}
.topnav a:hover { color: var(--ink); background: var(--surface-2); border-color: var(--line-soft); text-decoration: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.role-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--primary-soft); color: var(--primary);
  border: 1.5px solid var(--primary);
  font-size: .72rem; font-weight: 800; padding: 2px 8px; border-radius: var(--radius-sm);
  text-transform: uppercase; letter-spacing: .03em;
}
.avatar {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--primary-soft); border: 2px solid var(--line);
  color: var(--primary); font-size: .8rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center; flex: none;
  object-fit: cover;
}
img.avatar { display: inline-block; }

/* ---------- Icons (Lucide) ---------- */
.ic {
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: -0.22em; flex: none;
  width: 18px; height: 18px;
}
.ic svg { width: 100%; height: 100%; stroke-width: 2.25; }
.hub-h2 .ic, h1 .ic, h2 .ic, h3 .ic { color: var(--primary); }
.empty-ic { color: var(--muted); opacity: .5; margin-bottom: 10px; display: flex; justify-content: center; }
.empty-ic .ic { width: 44px; height: 44px; }

/* ---------- Profile dropdown ---------- */
.profile-menu { position: relative; }
.profile-btn {
  display: flex; align-items: center; gap: 3px; background: none;
  border: 2px solid transparent; border-radius: var(--radius);
  padding: 2px; cursor: pointer; color: var(--muted);
}
.profile-btn:hover, .profile-btn[aria-expanded="true"] { border-color: var(--line); }
.profile-caret { display: flex; transition: transform .15s; }
.profile-btn[aria-expanded="true"] .profile-caret { transform: rotate(180deg); }
.profile-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 70;
  background: var(--surface); border: var(--border) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg); min-width: 252px; overflow: hidden;
}
.profile-dropdown.open { display: block; }
.profile-head { display: flex; gap: 10px; padding: 14px; border-bottom: var(--border) solid var(--line); background: var(--surface-2); }
.profile-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.profile-id b { line-height: 1.2; }
.profile-id small { overflow: hidden; text-overflow: ellipsis; }
.profile-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.profile-dropdown > a {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  color: var(--ink); font-weight: 700; font-size: .9rem;
}
.profile-dropdown > a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.profile-logout { border-top: var(--border) solid var(--line); color: var(--danger) !important; }
.profile-logout:hover { background: var(--danger-soft) !important; color: var(--danger) !important; }

/* Language switcher */
.lang-switch { position: relative; }
.lang-btn {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  font: 700 .8rem var(--font); padding: 6px 10px; cursor: pointer; color: var(--ink);
}
.lang-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); min-width: 150px;
  /* Nine languages overrun a short viewport. `overflow: hidden` would clip the
     last few with no way to reach them, so the menu scrolls instead. */
  max-height: min(60vh, 420px); overflow-y: auto; overscroll-behavior: contain;
}
.lang-menu.open { display: block; }
.lang-menu a { display: block; padding: 9px 14px; color: var(--ink); font-size: .9rem; font-weight: 500; }
.lang-menu a:hover { background: var(--bg); }
.lang-menu a.active { color: var(--primary); font-weight: 700; }

/* Content translation fields */
.lang-fieldset {
  border: 1.5px dashed var(--line); border-radius: 12px;
  padding: 12px 14px 2px; margin: 0 0 14px;
}
.lang-fieldset legend { font-weight: 700; font-size: .82rem; color: var(--primary); padding: 0 8px; }
.lang-tabs { margin-bottom: 18px; }
.lang-tabs .tab { background: none; border: 0; border-bottom: 2.5px solid transparent; cursor: pointer; font-family: var(--font); }
.lang-tabs .tab.active { border-bottom-color: var(--primary); }
.check-row.compact { margin: 6px 0 0; }
.check-row.compact .check { padding: 3px 6px; font-size: .88rem; }
.nowrap { white-space: nowrap; }
.avatar-pending { background: var(--bg); }
.burger { display: none; margin-left: auto; background: none; border: 0; font-size: 1.5rem; cursor: pointer; color: var(--ink); }
.mobile-menu { display: none; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--line); }
.mobile-menu a { padding: 14px 20px; border-top: 1px solid var(--line); font-weight: 600; color: var(--ink); }
.mobile-menu.open { display: flex; }
/* Wraps because nine language codes are wider than a phone. */
.mobile-langs { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 20px; border-top: 1px solid var(--line); }
.mobile-langs a { padding: 5px 10px; border-radius: 8px; font-weight: 700; font-size: .82rem; color: var(--muted); border: 1px solid var(--line); }
.mobile-langs a.active { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

/* ---------- Layout ---------- */
.page { max-width: 1020px; margin: 0 auto; padding: clamp(16px, 3.5vw, 32px); min-height: calc(100vh - 130px); }
.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.crumbs { font-size: .85rem; margin-bottom: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.crumb-sep { color: #c3c7d4; }
.crumb-current { color: var(--ink); font-weight: 600; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn-row.right { justify-content: flex-end; margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.narrow { max-width: 560px; }

/* ---------- Buttons: square, hard border, shadow pops on hover ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 800 .9rem var(--font); letter-spacing: -.01em;
  border: var(--border) solid var(--line); border-radius: var(--radius);
  padding: 9px 16px; cursor: pointer; white-space: nowrap;
  background: var(--surface); color: var(--ink);
  box-shadow: 2px 2px 0 var(--shadow-col);
  transition: transform .1s ease, box-shadow .1s ease, background .12s;
  text-decoration: none;
  margin-bottom: 7px;
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-pop); text-decoration: none; }
.btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--shadow-col); }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: 2px 2px 0 var(--shadow-col); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-ghost { color: var(--danger); }
.btn-lg { padding: 13px 26px; font-size: 1rem; }
.btn-sm { padding: 6px 11px; font-size: .8rem; box-shadow: 2px 2px 0 var(--shadow-col); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 2px solid transparent; border-radius: var(--radius);
  padding: 6px; cursor: pointer; color: var(--muted); transition: .1s;
}
.icon-btn:hover:not(:disabled) {
  background: var(--surface); border-color: var(--line); color: var(--ink);
  box-shadow: 2px 2px 0 var(--shadow-col); transform: translate(-1px, -1px);
}
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }

/* ---------- Panels, lists, cards ---------- */
.panel {
  background: var(--surface); border: var(--border) solid var(--line);
  border-radius: var(--radius); padding: clamp(16px, 3vw, 24px);
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.panel-sub {
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 12px 14px; margin: 10px 0;
}
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.course-card {
  background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius);
  overflow: hidden; color: var(--ink); box-shadow: var(--shadow);
  transition: transform .1s ease, box-shadow .1s ease;
  display: flex; flex-direction: column;
}
.course-card:hover { transform: translate(-3px, -3px); box-shadow: var(--shadow-pop); text-decoration: none; }
.course-band { height: 8px; background: var(--course-color, var(--primary)); }
.course-body { padding: 18px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.course-body h3 { margin: 0; }
.course-meta { display: flex; gap: 14px; font-size: .84rem; color: var(--muted); margin-top: auto; padding-top: 8px; }
.course-head .dot { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--course-color, var(--primary)); margin-right: 9px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 14px 6px 6px; box-shadow: var(--shadow);
}
.list-item.draft { opacity: .72; border-style: dashed; }
.list-link { display: flex; align-items: center; gap: 14px; flex: 1; color: var(--ink); padding: 8px; min-width: 0; }
.list-num {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.list-main { display: flex; flex-direction: column; min-width: 0; }
.list-main b { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.list-actions { display: flex; align-items: center; gap: 2px; }
.list-actions form { display: flex; }

.row-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row-item:last-of-type, .row-item.no-border { border-bottom: 0; }
.row-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.file-kind { font-size: 1.3rem; }

/* ---------- Chips & flash ---------- */
.chip {
  font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 99px;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.chip-draft { background: #fef3c7; color: #92400e; }
.chip-time { background: #ede9fe; color: #6d28d9; }
.chip-done { background: #d1fae5; color: #065f46; }
.chip-progress { background: #dbeafe; color: #1e40af; }
.chip-late { background: #fee2e2; color: #991b1b; }
.flash { border-radius: 12px; padding: 12px 18px; margin-bottom: 18px; font-weight: 600; font-size: .93rem; }
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 14px; }
input[type=text], input[type=number], input[type=email], input[type=tel], textarea, select {
  width: 100%; margin-top: 6px;
  font: 400 .95rem var(--font); color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 11px;
  padding: 10px 13px; transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; }
input[type=file] { margin-top: 6px; font-size: .88rem; }
.check-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 0; padding: 7px 10px; border-radius: 9px; cursor: pointer; }
.check:hover { background: var(--bg); }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.inline-add { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.inline-add input[type=text] { flex: 1; min-width: 220px; margin: 0; }
.inline-add select { width: auto; margin: 0; }
.color-row { display: flex; gap: 9px; margin-top: 8px; flex-wrap: wrap; }
.swatch {
  appearance: none; width: 32px; height: 32px; border-radius: 50%;
  background: var(--swatch); cursor: pointer; border: 3px solid transparent; transition: .12s;
}
.swatch:checked { border-color: var(--ink); transform: scale(1.12); }
.grow { flex: 1; }

/* Toggle switches (settings) */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0; border-bottom: 1px solid var(--line); font-weight: 500; cursor: pointer;
}
.switch-row span { display: flex; flex-direction: column; gap: 2px; }
.switch-row input {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  width: 46px; height: 26px; min-width: 46px; flex: none; border: 0;
  background: #d5d8e2; position: relative; cursor: pointer; transition: .18s; margin: 0;
}
.switch-row span { min-width: 0; }
.switch-row input::after {
  content: ''; position: absolute; top: 1px; left: 2px; width: 20px; height: 20px;
  background: #fff; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch-row input:checked { background: var(--success); }
.switch-row input:checked::after { left: 20px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; border-bottom: 1.5px solid var(--line); margin-bottom: 20px; }
.tab {
  padding: 9px 16px; font-weight: 600; font-size: .93rem; color: var(--muted);
  border-radius: 10px 10px 0 0; border-bottom: 2.5px solid transparent; margin-bottom: -2px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Modals ---------- */
.modal {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 23, 40, .45); backdrop-filter: blur(3px);
  align-items: center; justify-content: center; padding: 18px;
}
.modal.open { display: flex; }
.modal-box {
  background: var(--surface); border-radius: 18px; padding: 24px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow: auto;
  box-shadow: 0 24px 64px -12px rgba(0, 0, 0, .35);
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-close { background: none; border: 0; font-size: 1.1rem; cursor: pointer; color: var(--muted); padding: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.modal-actions.space-between { justify-content: space-between; }

/* ---------- Map: curve + per-lesson colours ---------- */
.map-path { position: relative; }
/* The curve sits behind the nodes and must never eat their clicks. */
.map-curve { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.map-step { z-index: 1; }
/* The per-lesson node colours and .map-label live further down, in the square
   override layer: it is the last word in the cascade, and copies up here would
   simply be overridden by the map rules below (same specificity, later wins). */

/* Chapter success rate */
.rate-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.rate-chip {
  display: inline-flex; align-items: center; gap: 4px; margin-left: 6px;
  border: 1.5px solid var(--line); background: var(--surface-2);
  font: 800 .68rem var(--font); text-transform: uppercase; letter-spacing: .03em;
  padding: 1px 6px; white-space: nowrap;
}
.rate-hi { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.rate-mid { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.rate-lo { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ---------- XP / leagues ---------- */
.xp-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.xp-pill, .league {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1.5px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: 800 .72rem var(--font); text-transform: uppercase; letter-spacing: .03em;
  padding: 3px 8px;
}
.xp-pill { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.league-bronze { background: #f5e6d8; color: #8a5a2b; border-color: #8a5a2b; }
.league-silver { background: #ecedf0; color: #5c6273; border-color: #5c6273; }
.league-gold { background: var(--gold-soft); color: var(--gold); border-color: var(--gold); }
.league-platinum { background: #e0f2fe; color: #0369a1; border-color: #0369a1; }
.league-diamond { background: #ede9fe; color: #6d28d9; border-color: #6d28d9; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .league-bronze { background: #2b1f0c; color: #d9a066; }
  :root:not([data-theme="light"]) .league-silver { background: #1d212c; color: #c7ccd8; }
  :root:not([data-theme="light"]) .league-platinum { background: #0c2233; color: #7dd3fc; }
  :root:not([data-theme="light"]) .league-diamond { background: #1e1b3a; color: #c4b5fd; }
}
.xp-bar { height: 10px; background: var(--surface-2); border: 1.5px solid var(--line); }
.xp-bar-fill { height: 100%; background: var(--primary); }
.league-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.league-row:first-child { border-top: 0; }
.league-rank { font-weight: 900; width: 26px; color: var(--muted); }
.league-me { background: var(--primary-soft); }

/* ---------- Pronunciation module ---------- */
.sp-prompt {
  background: var(--surface-2); border: var(--border) solid var(--line);
  box-shadow: var(--shadow); padding: 28px 20px; margin: 16px 0 6px;
  text-align: center; font-size: 1.6rem; font-weight: 900; overflow-wrap: anywhere;
}
.sp-status { text-align: center; min-height: 1.2em; }
.sp-result { margin: 10px 0; text-align: center; }
.sp-verdict { font-size: 1.1rem; }
.sp-verdict.sp-ok { color: var(--success); }
.sp-verdict.sp-part { color: var(--warning); }
.sp-verdict.sp-ko { color: var(--danger); }
.sp-words { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
/* Per-word marking: this is the correction, not the percentage. */
.sp-w { border: 1.5px solid var(--line); padding: 2px 8px; font-weight: 800; font-size: .9rem; }
.sp-w.sp-ok { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.sp-w.sp-close { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.sp-w.sp-missed { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); text-decoration: line-through; }

/* ---------- Map jump buttons (fixed, bottom-right) ---------- */
.map-jumps {
  position: fixed; right: 16px; bottom: 16px; z-index: 40;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.map-jump[hidden] { display: none; }
.map-jump-level { background: var(--warning); color: var(--ink); }
/* Clear of the mobile bottom bar. */
@media (max-width: 860px) { .map-jumps { bottom: 78px; } }

/* ---------- Admin console ---------- */
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.chk input { margin: 0; }
.stat-card {
  background: var(--surface); border: var(--border) solid var(--line); box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column; gap: 4px;
}
.stat-ico { color: var(--primary); }
.stat-n { font-size: 1.7rem; font-weight: 900; line-height: 1; }

/* ---------- Class badges, ratings, favourites ---------- */
.cbadges { display: inline-flex; gap: 5px; flex-wrap: wrap; vertical-align: middle; }
.cbadge {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1.5px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: 800 .68rem var(--font); text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 6px;
}
/* Official outranks Certified, so it gets the blue; certified stays neutral grey. */
.badge-official { background: #dbeafe; color: #1d4ed8; border-color: #1d4ed8; }
.badge-certified { background: var(--surface-2); color: var(--muted); border-color: var(--muted); }
.badge-team-fav { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.badge-recommended { background: var(--gold-soft); color: var(--gold); border-color: var(--gold); }
.badge-popular { background: var(--success-soft); color: var(--success); border-color: var(--success); }
/* On dense cards only the icon shows; the label returns when there is room. */
.cbadge-t { display: none; }
.cbadges-full .cbadge-t { display: inline; }

.books { display: inline-flex; gap: 2px; vertical-align: middle; color: var(--line-soft); }
.books .book.on { color: var(--gold); }
.rating-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rating-n { color: var(--muted); font-size: .82rem; }
/* Radio-driven 0–5 picker: the native inputs stay for keyboard and screen readers. */
.books-pick { display: inline-flex; gap: 4px; }
.books-pick input { position: absolute; opacity: 0; width: 0; height: 0; }
.books-pick label {
  cursor: pointer; color: var(--line-soft); display: inline-flex; padding: 2px;
  transition: color .1s, transform .1s;
}
.books-pick label.on { color: var(--gold); }
.books-pick label.hover { color: var(--gold); transform: translateY(-2px); }
.books-pick label:hover { transform: translateY(-2px); }
.books-pick input:focus-visible + label { outline: 2px solid var(--primary); }
.fav-btn.on { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.comment-item { border-top: 1px solid var(--line-soft); padding: 12px 0; }
.comment-item:first-child { border-top: 0; }
.comment-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }

/* ---------- Empty states, hero, onboarding ---------- */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-emoji { font-size: 3rem; margin-bottom: 10px; }
/* Icon standing in for the old empty-state emoji. */
.empty-ico { display: flex; justify-content: center; margin-bottom: 12px; color: var(--muted); }
.empty-ico .ic { stroke-width: 1.5; }
.empty-state.is-good .empty-ico { color: var(--success); }
.empty-state .btn { margin-top: 14px; }
/* Icon sitting next to a heading / inside a chip or button label. */
.h-ico { display: inline-flex; vertical-align: -3px; margin-right: 8px; color: var(--primary); }
.chip .ic, .btn .ic, .list-main .ic, .row-main .ic { vertical-align: -2px; }
.hero { text-align: center; padding: clamp(30px, 8vw, 80px) 10px; max-width: 760px; margin: 0 auto; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.12; margin-bottom: 18px; }
.hero .grad { background: linear-gradient(90deg, var(--primary), #a855f7); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-badge { display: inline-block; background: var(--primary-soft); color: var(--primary); font-weight: 700; padding: 6px 16px; border-radius: 99px; margin-bottom: 22px; }
.hero-sub { color: var(--muted); font-size: 1.08rem; margin-bottom: 28px; }
.hero-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-top: 54px; text-align: left; }
.feat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.feat span { font-size: 1.5rem; }
.feat small { color: var(--muted); }
.onboarding { max-width: 640px; margin: 40px auto; text-align: center; }
.role-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 28px; }
.role-card {
  background: var(--surface); border: 2px solid var(--line); border-radius: 18px;
  padding: 28px 20px; cursor: pointer; font: inherit; text-align: center;
  display: flex; flex-direction: column; gap: 8px; align-items: center; transition: .15s;
}
.role-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: var(--shadow); }
.role-emoji { font-size: 2.6rem; }
.role-card small { color: var(--muted); font-weight: 400; }

/* ---------- Timer ---------- */
.timer-banner {
  position: sticky; top: 66px; z-index: 40;
  background: #ede9fe; border: 1px solid #ddd6fe; color: #5b21b6;
  border-radius: 12px; padding: 11px 18px; margin-bottom: 18px;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: .95rem;
}
.timer-banner .timer-value { font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.timer-banner.urgent { background: #fee2e2; border-color: #fecaca; color: #991b1b; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .75; } }

/* ---------- Statement / exercise content ---------- */
.statement { overflow-wrap: break-word; }
.statement img { border-radius: 10px; margin: 6px 0; }
.statement-file { margin: 12px 0; }
.statement-file audio { width: 100%; }
.statement-file video, .answer-video { max-height: 380px; border-radius: 12px; background: #000; }
.pdf-link {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 11px;
  padding: 10px 16px; font-weight: 600; color: var(--ink);
}
.pdf-link:hover { border-color: var(--primary); color: var(--primary); }
.answer-recap { background: var(--bg); border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; }
.statement-preview { min-height: 34px; }
.statement-details { margin-bottom: 12px; }
.statement-details summary { cursor: pointer; }
.grade-box { background: #d1fae5; color: #065f46; border-radius: 12px; padding: 14px 18px; margin: 12px 0; }
.feedback-box { background: var(--primary-soft); border-radius: 12px; padding: 10px 16px; margin: -4px 0 6px 52px; font-size: .9rem; }
.grade-form { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.grade-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.grade-row label { margin-bottom: 0; }
.grade-input { display: flex; align-items: center; gap: 8px; }
.grade-input input { width: 90px; }
.start-panel, .finish-panel { text-align: center; padding: 40px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 8px; }
.finish-panel { margin-top: 20px; }

/* ---------- WYSIWYG ---------- */
.wysiwyg { border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; margin-top: 6px; background: var(--surface); }
.wysiwyg:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.wysiwyg-toolbar {
  display: flex; flex-wrap: wrap; gap: 3px; align-items: center;
  background: var(--bg); border-bottom: 1px solid var(--line); padding: 7px;
}
.wysiwyg-toolbar button {
  background: none; border: 1px solid transparent; border-radius: 8px;
  font: 600 .85rem var(--font); padding: 6px 10px; cursor: pointer; color: var(--ink);
}
.wysiwyg-toolbar button:hover { background: var(--surface); border-color: var(--line); }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 5px; }
.wysiwyg-area { min-height: 180px; padding: 14px 16px; outline: none; font-weight: 400; }
.wysiwyg-area:empty::before { content: attr(data-ph); color: var(--muted); }

/* ---------- Fill-in-the-blank ---------- */
.fill-block { margin-top: 6px; }
.fill-input { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: .9rem; }
.fill-preview {
  min-height: 30px; line-height: 2.4; font-size: 1.02rem;
}
.fill-gap-preview {
  display: inline-block; min-width: 54px; text-align: center;
  border-bottom: 2px solid var(--primary); margin: 0 3px; padding: 0 8px;
  color: var(--primary); font-style: italic;
}
.fill-answer { margin-bottom: 18px; }
.fill-sentence { line-height: 2.8; font-size: 1.08rem; }
.fill-text { white-space: pre-wrap; }
.fill-gap-wrap { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 3px; }
.fill-gap-input {
  width: auto; min-width: 90px; margin: 0 !important; text-align: center;
  padding: 5px 10px !important; border-radius: 8px !important;
  border: 1.5px solid var(--primary) !important; background: var(--primary-soft);
  font-size: 1rem;
}
.fill-gap-hint { color: var(--muted); font-style: italic; font-size: .72rem; margin-top: 2px; }
.fill-recap { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.fill-result {
  display: inline-flex; flex-direction: column; gap: 1px;
  border-radius: 10px; padding: 6px 12px; font-size: .95rem;
}
.fill-result b { font-weight: 700; }
.fill-result small { font-size: .74rem; opacity: .85; }
.fill-result.ok { background: #d1fae5; color: #065f46; }
/* Partial credit: right idea, letters missing or misspelt. */
.fill-result.part { background: var(--warning-soft); color: var(--warning); }
.fill-result.ko { background: #fee2e2; color: #991b1b; }
.fill-pts { font-weight: 800; opacity: 1; }

/* ---------- Fill toolbar ---------- */
.fill-toolbar { margin: 4px 0 6px; }

/* ---------- Multiple choice ---------- */
.mcq-block { margin-top: 8px; }
.mcq-mode { display: flex; gap: 18px; margin: 4px 0 12px; }
.radio-inline { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; margin: 0; cursor: pointer; }
.radio-inline input { width: 17px; height: 17px; accent-color: var(--primary); margin: 0; }
.mcq-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.mcq-option-row { display: flex; align-items: center; gap: 10px; }
.mcq-option-row .mcq-correct { width: 20px; height: 20px; accent-color: var(--success); flex: none; margin: 0; }
.mcq-option-row .mcq-text { margin: 0; }
.mcq-trans { display: flex; flex-direction: column; gap: 8px; }
.mcq-trans-row { display: flex; align-items: center; gap: 10px; }
.mcq-trans-src { flex: none; min-width: 120px; font-size: .85rem; }
.mcq-trans-row input { margin: 0; }

.mcq-answer { margin-bottom: 18px; }
.mcq-choice {
  display: flex; align-items: center; gap: 12px; font-weight: 500; margin: 0 0 9px;
  padding: 12px 16px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; transition: .12s;
}
.mcq-choice:hover { border-color: var(--primary); background: var(--primary-soft); }
.mcq-choice input { width: 20px; height: 20px; accent-color: var(--primary); flex: none; margin: 0; }
.mcq-recap { margin-bottom: 12px; }
.mcq-verdict-ok { font-weight: 700; color: #065f46; }
.mcq-verdict-ko { font-weight: 700; color: #991b1b; }
.mcq-opt-result {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  border-radius: 10px; margin-bottom: 6px; border: 1px solid var(--line);
}
.mcq-opt-result .mcq-mark { width: 18px; font-weight: 800; }
.mcq-opt-result.is-correct { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.mcq-opt-result.is-wrong { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ---------- Flashcards (management) ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 0 14px; }
.section-head h2 { margin: 0; }
.small-empty { padding: 30px 20px; }
.card-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; }
.card-row summary { padding: 14px 16px; cursor: pointer; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; list-style: none; }
.card-row summary::-webkit-details-marker { display: none; }
.card-ab { flex: 1; }
.card-arrow { color: var(--muted); margin: 0 6px; }
.card-edit-form { padding: 0 16px 16px; border-top: 1px solid var(--line); }
.card-edit-form .grid-2 { margin-top: 14px; }

/* ---------- Flashcards (study) ---------- */
.study-dir { text-align: right; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 4px; }
.seg-btn { background: var(--surface); border: 0; padding: 7px 14px; cursor: pointer; font: 600 .85rem var(--font); color: var(--muted); border-right: 1px solid var(--line); }
.seg-btn:last-child { border-right: 0; }
.seg-btn.active { background: var(--primary); color: #fff; }
.study { max-width: 620px; margin: 0 auto; }
.study-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.study-progress-track { flex: 1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.study-progress-fill { height: 100%; background: var(--primary); border-radius: 99px; transition: width .25s; width: 0; }
.study-count { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.flashcard { perspective: 1400px; margin-bottom: 20px; cursor: pointer; }
.flashcard-inner { position: relative; width: 100%; min-height: 260px; transition: transform .5s; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: var(--shadow); padding: 30px; text-align: center;
}
.flashcard-front { background: linear-gradient(135deg, #eef2ff, #ffffff); }
.flashcard-back { transform: rotateY(180deg); background: linear-gradient(135deg, #ecfdf5, #ffffff); }
.fc-content { font-size: 1.7rem; font-weight: 700; overflow-wrap: anywhere; }
.fc-hint { color: var(--muted); font-style: italic; }
.study-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 16px; }
.study-actions .btn { min-width: 220px; }
.study-verdict { display: flex; gap: 12px; }
.study-verdict .btn { min-width: 150px; }
.study-tools { display: flex; justify-content: center; gap: 10px; }
.study-done { text-align: center; padding: 40px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Recorder ---------- */
.recorder { background: var(--bg); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.rec-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--danger); }
.rec-preview { width: 100%; max-height: 300px; border-radius: 10px; background: #000; margin-bottom: 10px; }
.rec-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.rec-item { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rec-item audio { flex: 1; min-width: 200px; }
.rec-item video { max-height: 220px; border-radius: 10px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; padding: 8px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; }
.table td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }

/* ---------- Retention strip (course page, student) ---------- */
.learn-strip {
  display: flex; align-items: stretch; gap: 12px; flex-wrap: wrap; margin-bottom: 22px;
}
.strip-cta {
  position: relative; display: flex; align-items: center; gap: 12px; flex: 1; min-width: 230px;
  background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff;
  border-radius: 16px; padding: 14px 18px; box-shadow: var(--shadow); transition: .15s;
}
.strip-cta:hover { transform: translateY(-2px); }
.strip-emoji { font-size: 1.9rem; }
.strip-main { display: flex; flex-direction: column; line-height: 1.25; }
.strip-main small { opacity: .85; }
.strip-badge {
  position: absolute; top: -8px; right: -8px; min-width: 26px; height: 26px;
  background: var(--danger); color: #fff; border-radius: 99px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; font-size: .8rem;
  padding: 0 7px; box-shadow: 0 2px 8px rgba(239,68,68,.5); animation: pulse 1.6s infinite;
}
@keyframes pulse { 50% { transform: scale(1.12); } }
/* Stacked, not side by side: Games and Pronunciation are two separate
   activities and read better one above the other than squeezed in a row. */
.strip-games { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.strip-game {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 13px;
  padding: 12px 14px; font-weight: 700; font-size: .9rem; color: var(--ink); transition: .12s;
}
/* Pronunciation reads as its own activity, not a second Games button. */
.strip-game-speech { background: var(--primary); color: var(--primary-ink); }
.mix-cta-speech { background: var(--primary); color: var(--primary-ink); }
.strip-game:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); }
/* MUST stay after .strip-game:hover — identical specificity (0,2,0), so source
   order is what decides. Placed before it, the generic rule wins and paints
   --primary text on this button's --primary background: blue on blue. Keep the
   ink fixed; the lift and shadow are what signal the hover. */
.strip-game-speech:hover { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.strip-game.disabled { opacity: .45; pointer-events: none; }
.strip-side { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; justify-content: center; margin-left: auto; }
.chip-streak { background: #ffedd5; color: #9a3412; font-size: .85rem; padding: 5px 12px; }
.mode-toggle-form { margin: 0; }

/* ---------- Flashcards hub ---------- */
.hub-h2 { margin: 26px 0 12px; font-size: 1.1rem; }
.mix-cta {
  display: flex; flex-direction: column; gap: 4px; text-align: center; align-items: center;
  background: linear-gradient(135deg, #4f46e5, #a855f7); color: #fff;
  border-radius: 18px; padding: 22px; margin-bottom: 14px; box-shadow: var(--shadow); transition: .15s;
}
.mix-cta:hover { transform: translateY(-2px); }
.mix-cta-title { font-size: 1.15rem; font-weight: 800; }
.mix-cta-sub { opacity: .85; font-size: .88rem; }
.game-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 10px; }
.game-tile {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 14px; display: flex; flex-direction: column; gap: 3px; color: var(--ink);
  box-shadow: var(--shadow); transition: .12s;
}
.game-tile:hover { border-color: var(--primary); transform: translateY(-2px); }
.game-tile small { color: var(--muted); }
.game-row-big .game-tile { padding: 22px 18px; font-size: 1.05rem; text-align: center; align-items: center; }
.game-tile-main { background: linear-gradient(135deg, #f59e0b, #f97316); border: 0; color: #fff; }
.game-tile-main small { color: rgba(255,255,255,.85); }
.game-tile-main:hover { border: 0; color: #fff; }
.strip-game-main { background: linear-gradient(135deg, #f59e0b, #f97316); border: 0; color: #fff; }
.strip-game-main:hover { color: #fff; }
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.deck-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
}
.deck-card-new { border-style: dashed; }
.deck-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.deck-bar { height: 7px; background: var(--line); border-radius: 99px; overflow: hidden; }
.deck-bar-fill { height: 100%; background: linear-gradient(90deg, var(--success), #34d399); border-radius: 99px; transition: width .4s; }
.fc-new-chip {
  position: absolute; top: 12px; left: 12px; background: var(--primary-soft);
  color: var(--primary); font-size: .72rem; font-weight: 800; padding: 3px 10px; border-radius: 99px;
}

/* ---------- Mini-games ---------- */
.game { max-width: 640px; margin: 0 auto; }
.game-area { min-height: 260px; }
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match-col { display: flex; flex-direction: column; gap: 10px; }
.match-item {
  background: var(--surface); border: 2px solid var(--line); border-radius: 13px;
  padding: 13px 10px; font: 600 .98rem var(--font); cursor: pointer; transition: .12s;
  color: var(--ink); overflow-wrap: anywhere;
}
.match-item:hover:not(:disabled) { border-color: var(--primary); }
.match-item.sel { border-color: var(--primary); background: var(--primary-soft); }
.match-item.ok { border-color: var(--success); background: #d1fae5; color: #065f46; opacity: .75; }
.match-item.ko { border-color: var(--danger); background: #fee2e2; animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.quiz-q {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 26px; text-align: center; font-size: 1.4rem; font-weight: 800; margin-bottom: 16px;
  box-shadow: var(--shadow); overflow-wrap: anywhere;
}
.quiz-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quiz-opt {
  background: var(--surface); border: 2px solid var(--line); border-radius: 13px;
  padding: 15px 12px; font: 600 1rem var(--font); cursor: pointer; transition: .12s; color: var(--ink);
  overflow-wrap: anywhere;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--primary); }
.quiz-opt.ok { border-color: var(--success); background: #d1fae5; color: #065f46; }
.quiz-opt.ko { border-color: var(--danger); background: #fee2e2; color: #991b1b; animation: shake .3s; }
.write-row { display: flex; gap: 10px; }
.write-row input { font-size: 1.1rem; text-align: center; margin: 0; }
.write-row input.ok { border-color: var(--success) !important; background: #d1fae5; }
.write-row input.ko { border-color: var(--danger) !important; background: #fee2e2; animation: shake .3s; }
.write-fb { text-align: center; font-weight: 700; min-height: 24px; margin-top: 12px; }
.write-fb.good { color: #065f46; }
.write-fb.bad { color: #991b1b; }

/* ---------- Game-mode map (Duolingo style) ---------- */
.map-wrap { max-width: 560px; margin: 0 auto; }
.map-chapter { margin-bottom: 30px; }
.map-chapter.locked { opacity: .55; }
.map-chapter-head {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 18px; box-shadow: var(--shadow); margin-bottom: 22px;
  position: sticky; top: 66px; z-index: 5;
}
.map-chapter-num {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff;
  font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
}
.map-chapter-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.map-lock { font-size: 1.4rem; }
/* Roomy gap: the curve needs space to read as a curve rather than a kink, and
   the coloured labels need air between them. */
.map-path { display: flex; flex-direction: column; gap: 58px; padding: 6px 0; margin-top: 70px; }
.map-step { display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; }
.map-step.side-1 { transform: translateX(-70px); }
.map-step.side-3 { transform: translateX(70px); }
.map-node {
  width: 74px; height: 74px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 1.7rem; font-weight: 800; position: relative;
  border: 0; text-decoration: none; transition: .15s;
  box-shadow: 0 6px 0 rgba(0,0,0,.15), var(--shadow);
}
.map-node:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.map-node.done { background: linear-gradient(135deg, var(--success), #34d399); color: #fff; }
.map-node.current {
  background: linear-gradient(135deg, #f59e0b, #f97316); color: #fff;
  animation: bounce 1.6s infinite;
}
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.map-node.future { background: #e5e7eb; color: #9ca3af; cursor: default; box-shadow: 0 4px 0 rgba(0,0,0,.08); }
.map-callout {
  position: absolute; top: -42px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: .74rem; font-weight: 700;
  padding: 6px 12px; border-radius: 10px; white-space: nowrap;
}
.map-callout::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--ink);
}
/* Label in a box in its lesson's colour (--lc is set per step in course.php),
   so a stretch of the path reads as one lesson. Every palette hue is dark
   enough for white text. */
/* --lc-ink is computed per colour by color_ink() (WCAG contrast), because white
   is unreadable on the lighter hues. The fallback is --ink, which is readable
   on the --surface-2 fallback background. */
.map-label {
  background: var(--lc, var(--surface-2)); color: var(--lc-ink, var(--ink));
  border: 2px solid var(--line); box-shadow: 2px 2px 0 var(--shadow-col);
  font-weight: 800; font-size: .78rem; padding: 4px 9px;
  max-width: 170px; text-align: center; overflow-wrap: anywhere;
}
/* Not reached yet: keep the colour but drain it, so the eye goes to the current node. */
.map-step[data-state="future"] .map-label { opacity: .5; }

/* ---------- Teacher chapter board ---------- */
#chapterBoard { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.chapter-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.chapter-box-pool { border-style: dashed; background: var(--bg); }
.chapter-box-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.chapter-drop { min-height: 54px; padding: 12px; display: flex; flex-wrap: wrap; gap: 8px; transition: background .15s; }
.chapter-drop.over { background: var(--primary-soft); }
.lesson-chip {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 11px;
  padding: 8px 14px; font-weight: 600; font-size: .9rem; cursor: grab; user-select: none;
}
.lesson-chip.dragging { opacity: .4; }
.lesson-chip:active { cursor: grabbing; }
.lesson-chip.chip-unpub { border-style: dashed; opacity: .65; }
.chapter-rename { display: flex; align-items: center; gap: 8px; flex: 1; margin: 0; min-width: 0; }
.chapter-rename input[type=text] {
  margin: 0; padding: 6px 10px; font-weight: 700; border-color: transparent; background: transparent;
}
.chapter-rename input[type=text]:hover, .chapter-rename input[type=text]:focus { border-color: var(--line); background: var(--surface); }
.chapter-rename .lang-mini {
  flex: 0 1 110px; min-width: 70px; font-weight: 500; font-size: .82rem; color: var(--muted);
}
.inline-add .lang-mini { flex: 0 1 130px; min-width: 90px; margin: 0; }
.chapter-drop.over { outline: 2px dashed var(--primary); outline-offset: -4px; }

/* ---------- Auto-submit countdown (student recording) ---------- */
.autosubmit-bar {
  display: flex; align-items: center; gap: 12px; margin-top: 10px;
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
  border-radius: 10px; padding: 8px 14px; font-weight: 700; font-size: .9rem;
}
.autosubmit-msg { flex: 1; }

/* ---------- AJAX grade feedback ---------- */
.grade-row { position: relative; }
.grade-flash {
  color: var(--success); font-weight: 800; margin-left: 10px; white-space: nowrap;
  animation: fadeInOut 1.8s ease;
}
@keyframes fadeInOut { 0% { opacity: 0; transform: translateY(4px); } 15%,70% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.grade-saved .grade-btn { background: var(--success); }

/* ---------- Marketplace: catalog, class page, plans, bottom bar ---------- */
.search-bar { display: flex; gap: 10px; margin: 0 0 18px; }
.search-bar input[type=search] { flex: 1; margin: 0; }
.search-bar select { width: auto; margin: 0; }
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.cat-chip {
  border: 0; border-radius: 99px;
  padding: 8px 16px; font-weight: 700; font-size: .86rem; transition: .12s;
  background: var(--primary-soft); color: var(--primary);
}
.cat-chip:nth-child(6n+2) { background: #ffe4e6; color: #be123c; }
.cat-chip:nth-child(6n+3) { background: #d1fae5; color: #047857; }
.cat-chip:nth-child(6n+4) { background: #fef3c7; color: #b45309; }
.cat-chip:nth-child(6n+5) { background: #e0f2fe; color: #0369a1; }
.cat-chip:nth-child(6n+6) { background: #f3e8ff; color: #7e22ce; }
.cat-chip:hover { transform: translateY(-2px) scale(1.04); }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.catalog-card {
  --cc: var(--primary);
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  overflow: hidden; color: var(--ink); box-shadow: var(--shadow);
  transition: transform .18s, box-shadow .18s;
  display: flex; flex-direction: column; position: relative;
}
.catalog-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 5px; z-index: 2;
  background: linear-gradient(90deg, var(--cc), color-mix(in srgb, var(--cc) 40%, #ffffff));
}
.catalog-card:hover { transform: translateY(-5px) rotate(-.4deg); box-shadow: 0 18px 40px -14px color-mix(in srgb, var(--cc) 55%, transparent); }
.catalog-thumb-wrap { position: relative; }
.catalog-thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--bg); }
.catalog-thumb-ph {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--cc), color-mix(in srgb, var(--cc) 45%, #1c2033));
}
.catalog-thumb-ph { color: #fff; }
.catalog-thumb-ph .ic { opacity: .9; filter: drop-shadow(0 4px 10px rgba(0,0,0,.3)); }
.lists-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 8px; }
.list-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; color: var(--ink); box-shadow: var(--shadow); transition: .15s;
}
.list-card:hover { transform: translateY(-3px); border-color: var(--primary); }
.list-card-icon {
  width: 40px; height: 40px; flex: none; border-radius: 11px; display: flex;
  align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary);
}
.list-card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.price-badge {
  position: absolute; right: 10px; bottom: 10px;
  background: rgba(28,32,51,.85); color: #fff; backdrop-filter: blur(4px);
  font-weight: 800; font-size: .85rem; padding: 5px 12px; border-radius: 99px;
}
.price-badge.free { background: var(--success); }
.catalog-body { padding: 13px 15px 15px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.catalog-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 8px; }
.cta-banner {
  text-align: center; margin: 34px 0; padding: 34px 22px; border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; box-shadow: var(--shadow);
}
.cta-banner h2 { color: #fff; }
.cta-banner p { opacity: .9; max-width: 520px; margin: 0 auto 18px; }
.hero-catalog { padding-bottom: 26px; }

/* class presentation page */
.class-cover {
  height: clamp(140px, 26vw, 260px); border-radius: var(--radius); margin-bottom: 20px;
  background-size: cover; background-position: center; box-shadow: var(--shadow);
}
.class-layout { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
.class-main h1 { margin-bottom: 6px; }
.class-desc { margin-top: 12px; }
.class-side {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
  position: sticky; top: 78px;
}
.class-thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 10px; }
.price-tag { font-size: 1.7rem; font-weight: 800; color: var(--primary); text-align: center; }
.w100 { width: 100%; }
.video-wrap { position: relative; aspect-ratio: 16/9; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* plans */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; max-width: 720px; margin: 0 auto 18px; }
.plan-card {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 18px;
  padding: 26px; text-align: center; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.plan-gold { border-color: #f59e0b; box-shadow: 0 10px 30px -12px rgba(245,158,11,.45); }
.plan-price { font-size: 2rem; font-weight: 800; color: var(--primary); }
.plan-price small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.sub-chip-gold { background: #fef3c7; color: #92400e; }
.sub-chip-silver { background: #e5e7eb; color: #374151; }

/* mobile bottom bar */
.bottombar { display: none; }
@media (max-width: 760px) {
  .bottombar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: rgba(255,255,255,.94); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottombar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--muted); font-size: .68rem; font-weight: 700; padding: 4px 0; border-radius: 10px;
  }
  .bottombar a.active { color: var(--primary); }
  /* the topbar profile menu is replaced by the bottom bar on phones */
  .profile-menu, .topnav { display: none; }
  .topbar-right { display: flex; }
  body { padding-bottom: 68px; }
  .class-layout { grid-template-columns: 1fr; }
  .class-side { position: static; }
  .search-bar { flex-wrap: wrap; }
  .search-bar input[type=search] { min-width: 100%; }
}

/* ---------- "Course" (lecture) exercises + lists ---------- */
.chip-lecture { background: #e0f2fe; color: #0369a1; }
.lecture-toggle {
  border: 1.5px dashed var(--primary); border-radius: 12px; padding: 12px 14px;
  background: var(--primary-soft); margin-bottom: 16px; align-items: flex-start;
}
.lecture-done { text-align: center; }
.list-thumb { width: 64px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; flex: none; }

/* ---------- Legal pages (privacy / terms) ---------- */
.legal { max-width: 760px; margin: 0 auto; line-height: 1.65; }
.legal h1 { margin-bottom: 6px; }
.legal h2 { font-size: 1.1rem; margin: 26px 0 8px; }
.legal ul { padding-left: 22px; }
.legal li { margin-bottom: 6px; }
.legal p { color: #2b3040; }

/* ---------- Stats dashboard ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; text-align: center; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.stat-card b { font-size: 1.6rem; color: var(--primary); }
.stat-card small { color: var(--muted); font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .topnav, .topbar-right { display: none; }
  .burger { display: block; }
  .grid-2, .role-cards { grid-template-columns: 1fr; }
  .list-item { flex-wrap: wrap; padding: 8px; }
  .list-actions { width: 100%; justify-content: flex-end; border-top: 1px dashed var(--line); padding-top: 4px; margin-top: 4px; }
  .page-head { flex-direction: column; }
  .page-head .btn-row { width: 100%; }
  .page-head .btn-row .btn { flex: 1; }
  .timer-banner { top: 60px; }
  .feedback-box { margin-left: 0; }
  .grade-row { flex-direction: column; align-items: stretch; }
  .grade-row .grade-input input { width: 100%; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-box { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; }
  /* retention strip stacks */
  .learn-strip { flex-direction: column; }
  .strip-games { width: 100%; }
  .strip-game { flex: 1; text-align: center; padding: 11px 6px; }
  .strip-side { flex-direction: row; width: 100%; justify-content: space-between; align-items: center; margin-left: 0; }
  .game-row { grid-template-columns: 1fr; }
  .quiz-opts { grid-template-columns: 1fr; }
  .map-step.side-1 { transform: translateX(-44px); }
  .map-step.side-3 { transform: translateX(44px); }
  .map-node { width: 64px; height: 64px; font-size: 1.4rem; }
  .map-chapter-head { position: static; }
  .write-row { flex-direction: column; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

/* =====================================================================
   SQUARE THEME — final override layer.
   Kills legacy rounding/gradients from earlier iterations and enforces the
   squared, high-contrast, hard-shadow language in light AND dark mode.
   ===================================================================== */

/* 1. No gradients anywhere: flat, bold fills only. */
.hero .grad { background: none; -webkit-background-clip: border-box; background-clip: border-box; color: var(--primary); }
.flashcard-front { background: var(--surface); }
.flashcard-back { background: var(--success-soft); }
.strip-cta, .mix-cta, .cta-banner, .game-tile-main, .strip-game-main,
.catalog-thumb-ph, .map-chapter-num, .map-node.done, .map-node.current {
  background-image: none !important;
}
.strip-cta, .mix-cta, .cta-banner { background: var(--primary); color: var(--primary-ink); }
.cta-banner h2 { color: var(--primary-ink); }
.game-tile-main, .strip-game-main { background: var(--warning); color: var(--ink); }
.game-tile-main small { color: var(--ink); opacity: .8; }
.catalog-thumb-ph { background: var(--cc, var(--primary)); }
.map-chapter-num { background: var(--primary); color: var(--primary-ink); }
/* --lc is the node's lesson colour, set per step in course.php. These live in
   the override layer on purpose: it is the last word in the cascade, so the
   earlier map rules above cannot win over them. */
/* The lesson colour (--lc) goes ON the set, EXCEPT when the set is submitted or
   is the current level — those keep their own fill (green / gold) and carry the
   lesson colour on the border instead (see the border rules further down).
   --lc-ink is the WCAG-contrast text colour for --lc. */
.map-node.done { background: var(--success); color: #fff; }
.map-node.current { background: var(--warning); color: var(--ink); }
.map-node.future { background: var(--lc, var(--surface-2)); color: var(--lc-ink, var(--muted)); }

/* 2. Square everything. Only the switch knob stays round. */
.panel, .card, .modal-box, .course-card, .catalog-card, .list-card, .chip, .role-chip,
.flash, .btn, .icon-btn, .deck-card, .game-tile, .plan-card, .stat-card, .cta-banner,
.mix-cta, .strip-cta, .strip-game, .cat-chip, .price-badge, .lesson-chip, .chapter-box,
.list-item, .recorder, .wysiwyg, .quiz-q, .quiz-opt, .match-item, .mcq-choice,
.mcq-opt-result, .fill-result, .grade-box, .feedback-box, .answer-recap, .pdf-link,
.timer-banner, .autosubmit-bar, .lang-menu, .lang-btn, .seg, .statement img,
.statement-file video, .answer-video, .rec-preview, .rec-item video, .list-thumb,
.catalog-thumb, .class-thumb, .class-cover, .video-wrap, .study-done, .start-panel,
.finish-panel, .flashcard-face, .empty-state, .lang-fieldset, .card-row, .avatar,
.map-node, .list-num, .list-card-icon, .map-callout, .strip-badge,
input[type=text], input[type=number], input[type=email], input[type=tel],
input[type=search], textarea, select, .fill-gap-input, .study-progress-track,
.study-progress-fill, .deck-bar, .deck-bar-fill {
  border-radius: var(--radius) !important;
}
.tabs .tab { border-radius: var(--radius) var(--radius) 0 0; }

/* 3. Hard borders + solid offset shadows (surfaces that "pop"). */
.panel, .modal-box, .course-card, .catalog-card, .list-card, .deck-card, .game-tile,
.plan-card, .stat-card, .chapter-box, .list-item, .card-row, .quiz-q, .study-done,
.start-panel, .finish-panel, .flashcard-face, .timer-banner, .strip-cta, .mix-cta,
.cta-banner, .wysiwyg, .recorder {
  border: var(--border) solid var(--line);
  box-shadow: var(--shadow);
}
.catalog-card, .list-card, .deck-card, .game-tile, .plan-card, .strip-cta, .mix-cta,
.strip-game, .cat-chip, .course-card {
  transition: transform .1s ease, box-shadow .1s ease;
}
.catalog-card:hover, .list-card:hover, .deck-card:hover, .game-tile:hover,
.plan-card:hover, .strip-cta:hover, .mix-cta:hover, .strip-game:hover,
.cat-chip:hover, .course-card:hover {
  transform: translate(-3px, -3px);
  box-shadow: var(--shadow-pop);
  text-decoration: none;
}
.stat-card:hover { transform: none; }

/* 4. Chips / badges: flat, bordered, uppercase. */
.chip {
  border: 1.5px solid var(--line); background: var(--surface-2); color: var(--ink);
  font-weight: 800; font-size: .7rem; text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 7px; box-shadow: none;
}
.chip-draft { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.chip-time, .chip-lecture { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.chip-done { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.chip-progress { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.chip-late { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.chip-streak { background: var(--warning-soft); color: var(--danger); border-color: var(--danger); }
.sub-chip-gold { background: var(--gold-soft); color: var(--gold); border-color: var(--gold); }
.sub-chip-silver { background: var(--surface-2); color: var(--muted); border-color: var(--muted); }
.price-badge {
  border: 2px solid var(--line); background: var(--ink); color: var(--surface);
  box-shadow: 2px 2px 0 var(--shadow-col); backdrop-filter: none;
}
.price-badge.free { background: var(--success); color: #fff; }
.strip-badge { border: 2px solid var(--line); box-shadow: 2px 2px 0 var(--shadow-col); animation: none; }

/* 5. Flash / callouts. */
.flash {
  border: var(--border) solid var(--line); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; font-weight: 700;
}
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.grade-box { background: var(--success-soft); color: var(--success); border: var(--border) solid var(--success); }
.feedback-box { background: var(--primary-soft); border: 2px solid var(--primary); color: var(--ink); }
.answer-recap { background: var(--surface-2); border: 1px solid var(--line-soft); }
.timer-banner { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.timer-banner.urgent { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); animation: none; }
.autosubmit-bar { background: var(--warning-soft); color: var(--warning); border: 2px solid var(--warning); }

/* 6. Forms: square, thick, high contrast. */
input[type=text], input[type=number], input[type=email], input[type=tel],
input[type=search], textarea, select {
  border: var(--border) solid var(--line-soft);
  background: var(--surface); color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary); box-shadow: 2px 2px 0 var(--primary);
}
.swatch { border-radius: var(--radius-sm) !important; border-width: 2px; }
.swatch:checked { transform: none; box-shadow: 2px 2px 0 var(--shadow-col); }
.switch-row input { border: 2px solid var(--line); background: var(--line-soft); }
.switch-row input::after { background: var(--surface); box-shadow: none; }
.switch-row input:checked { background: var(--success); border-color: var(--line); }

/* 7. Modals / menus. */
.modal { background: rgba(10, 12, 18, .6); backdrop-filter: none; }
.modal-box { box-shadow: var(--shadow-lg); animation: none; }
.lang-menu { border: var(--border) solid var(--line); box-shadow: var(--shadow-lg); }
.lang-menu a { font-weight: 700; }
.lang-menu a:hover { background: var(--primary-soft); text-decoration: none; }

/* 8. Category chips: flat, square, no rainbow. */
.cat-chip {
  background: var(--surface); color: var(--ink);
  border: var(--border) solid var(--line);
  box-shadow: 2px 2px 0 var(--shadow-col);
  text-transform: uppercase; font-size: .74rem; letter-spacing: .03em;
}
.cat-chip:nth-child(n) { background: var(--surface); color: var(--ink); }
.cat-chip:hover { background: var(--primary); color: var(--primary-ink); }

/* 9. Map nodes: flat + hard shadow. */
.map-node { border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col); }
/* A finished node keeps the success fill but carries its lesson's colour as the
   border, so a cleared stretch still reads as belonging to that lesson. */
/* Submitted / current: the lesson colour lives on the border, since the fill is
   already saying "done" (green) or "you are here" (gold). */
.map-node.done { border: 3px solid var(--lc, var(--success)); }
.map-node.current { border: 3px solid var(--lc, var(--line)); }
/* Not reached yet: the fill IS the lesson colour, so a plain hard border. */
.map-node.future { border: var(--border) solid var(--line); opacity: .85; }
.map-node:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow-col); }
.map-node.current { animation: none; }
.map-chapter-head { border: var(--border) solid var(--line); box-shadow: var(--shadow); }
.map-callout { border: 2px solid var(--line); background: var(--ink); color: var(--surface); }
.map-callout::after { border-top-color: var(--ink); }
.list-num { background: var(--primary-soft); color: var(--primary); border: 2px solid var(--primary); }

/* 10. Progress bars: square, bordered. */
.study-progress-track, .deck-bar { border: 2px solid var(--line); background: var(--surface-2); height: 10px; }
.study-progress-fill { background: var(--primary); }
.deck-bar-fill { background: var(--success); }

/* 11. Bottom bar + footer. */
.bottombar { background: var(--surface); border-top: var(--border) solid var(--line); backdrop-filter: none; }
.footer { border-top: 2px solid var(--line-soft); }
.hero-badge {
  border: var(--border) solid var(--primary); background: var(--primary-soft);
  color: var(--primary); border-radius: var(--radius) !important;
  text-transform: uppercase; letter-spacing: .04em; font-weight: 800;
  display: inline-flex; align-items: center; gap: 6px;
}
.feat { border: var(--border) solid var(--line); box-shadow: var(--shadow); border-radius: var(--radius); }
.feat span { color: var(--primary); display: flex; }
.role-card { border: var(--border) solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.role-card:hover { transform: translate(-3px, -3px); box-shadow: var(--shadow-pop); border-color: var(--primary); }
.plan-gold { border-color: var(--gold); box-shadow: var(--shadow); }

/* 12. Dark mode: keep answer states readable. */
@media (prefers-color-scheme: dark) {
  .statement-file video, .answer-video, .rec-preview, .rec-item video { background: #000; }
  .quiz-opt.ok, .match-item.ok { background: var(--success-soft); color: var(--success); }
  .quiz-opt.ko, .match-item.ko { background: var(--danger-soft); color: var(--danger); }
  .match-item.sel { background: var(--primary-soft); color: var(--primary); }
  .mcq-opt-result.is-correct { background: var(--success-soft); color: var(--success); border-color: var(--success); }
  .mcq-opt-result.is-wrong { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
  .fill-result.ok { background: var(--success-soft); color: var(--success); }
  .fill-result.part { background: var(--warning-soft); color: var(--warning); }
  .fill-result.ko { background: var(--danger-soft); color: var(--danger); }
  .write-row input.ok { background: var(--success-soft); }
  .write-row input.ko { background: var(--danger-soft); }
  .write-fb.good, .mcq-verdict-ok { color: var(--success); }
  .write-fb.bad, .mcq-verdict-ko { color: var(--danger); }
  .legal p { color: var(--ink); }
  .fill-gap-input { background: var(--primary-soft); }
  .catalog-thumb, .list-thumb, .class-thumb { background: var(--surface-2); }
}

/* ===========================================================================
   Ranking, achievements, records, friends, notifications
   ---------------------------------------------------------------------------
   These are new class names, so nothing earlier in the file targets them and
   source order is not a factor. The square look is set explicitly here rather
   than relied upon: the !important radius reset near the end of this file
   lists specific selectors, and these are not in it.
   =========================================================================== */

/* --- summary strip --- */
.rank-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.rank-card {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink); padding: 12px 14px;
}
.rank-card b { font-size: 1.25rem; line-height: 1.2; }
.rank-card small { font-size: .74rem; }
.rank-card-ico { color: var(--primary); margin-bottom: 2px; }

/* --- toolbar --- */
.rank-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.rank-toolbar .seg-btn { text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.rank-course-pick { max-width: 320px; }

/* --- leaderboard --- */
.rank-table td, .rank-table th { vertical-align: middle; }
.rank-pos { width: 46px; text-align: center; font-weight: 800; color: var(--muted); }
.rank-num { text-align: right; white-space: nowrap; }
.rank-user { text-decoration: none; color: inherit; }
.rank-user:hover b { color: var(--primary); }
.rank-me { background: var(--primary-soft); }
.rank-me td { font-weight: 700; }
.rank-medal { display: inline-flex; }
.rank-medal-1 { color: #d4a017; }
.rank-medal-2 { color: #9ca3af; }
.rank-medal-3 { color: #b45309; }

/* --- XP graph --- */
.graph-panel { margin-bottom: 18px; }
.graph-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.xp-graph { width: 100%; height: 160px; display: block; }
.xp-bar { fill: var(--primary); }
.xp-bar.zero { fill: var(--line); }
.xp-bar.today { fill: var(--warning); }
.graph-foot { display: flex; justify-content: space-between; margin-top: 6px; }

/* --- achievements --- */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.ach-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink); padding: 16px 12px;
}
.ach-card.locked { opacity: .55; }
/* Greyed rather than hidden: an achievement you cannot see is one you cannot
   aim for. Saturation returns the moment the first level lands. */
.ach-card.locked .ach-img { filter: grayscale(1); }
.ach-img, .rec-img { image-rendering: auto; }
.ach-lvl { font-weight: 700; font-size: .82rem; color: var(--primary); }
.ach-bar { width: 100%; height: 8px; background: var(--bg); border: 1px solid var(--ink); }
.ach-bar-fill { height: 100%; background: var(--primary); }

/* --- personal records --- */
.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.rec-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink); padding: 16px 12px;
}
.rec-value { font-size: 1.3rem; font-weight: 800; }
.rec-value small { font-size: .72rem; font-weight: 600; margin-left: 3px; }

/* --- profile --- */
.profile-hero {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink); padding: 18px; margin-bottom: 18px;
}
.profile-hero-av { width: 88px; height: 88px; }
.profile-hero-id { flex: 1; min-width: 200px; }
.profile-hero-id h1 { margin: 0 0 6px; }
.profile-hero-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.profile-hero-action { margin-left: auto; display: flex; gap: 8px; }

/* --- friends --- */
.friend-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.friend-row:last-child { border-bottom: 0; }
.friend-row .row-item { text-decoration: none; color: inherit; gap: 10px; }
.friend-row .row-item:hover b { color: var(--primary); }
.friend-row-end { text-align: right; display: flex; flex-direction: column; line-height: 1.15; }
.friend-ids { display: inline-flex; flex-direction: column; line-height: 1.15; }
.friend-ids small { font-size: .78rem; }
.friend-act { display: inline-flex; align-items: center; }

/* --- notifications --- */
.notif-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.notif-row:last-child { border-bottom: 0; }
.notif-row.unread { font-weight: 600; }
.notif-ico { color: var(--primary); flex: 0 0 auto; }
.notif-body { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.notif-dot { width: 9px; height: 9px; background: var(--primary); flex: 0 0 auto; }

/* --- topbar bell / people badges --- */
.topbar-ico { position: relative; text-decoration: none; }
.ico-badge {
  position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px;
  padding: 0 3px; background: var(--danger); color: #fff; border: 1px solid var(--ink);
  font: 800 .64rem/15px var(--font); text-align: center;
}

@media (max-width: 720px) {
  .rank-summary { grid-template-columns: repeat(2, 1fr); }
  .profile-hero-action { margin-left: 0; width: 100%; }
  .rank-toolbar { flex-direction: column; align-items: stretch; }
  .rank-course-pick { max-width: none; }
}

/* ===========================================================================
   Timed sprint challenges
   ===========================================================================
   Note on <select>: the global form rule gives every select width:100% and a
   top margin, which is right inside a <label> stack and wrong on a toolbar —
   it is what pushes an adjacent button onto its own line. The same override
   already exists for .inline-add and .search-bar; .duel-send needs it too.
   =========================================================================== */

/* --- explainer + week counters --- */
.duel-banner {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink); padding: 14px 16px; margin-bottom: 20px;
}
.duel-banner-txt { flex: 1 1 260px; min-width: 0; }
.duel-banner-txt b { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.duel-banner-txt p { margin: 0; }

/* Each stat is its own column, and the row needs a real gap — without it the
   number and its label run into the next pair. */
.duel-banner-stats { display: flex; gap: 22px; flex: 0 0 auto; }
.duel-banner-stats span { display: flex; flex-direction: column; line-height: 1.15; }
.duel-banner-stats b { font-size: 1.35rem; font-weight: 800; }
.duel-banner-stats small { font-size: .72rem; color: var(--muted); white-space: nowrap; }

/* --- cards --- */
.duel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-bottom: 26px; }
.duel-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink); padding: 16px 14px;
  min-width: 0;
}
/* A running sprint is the one thing on screen that is time-critical. */
.duel-card.is-running { border-color: var(--primary); box-shadow: 3px 3px 0 var(--primary); }

.duel-top { display: flex; align-items: center; gap: 9px; width: 100%; min-width: 0; }
.duel-name {
  flex: 1; min-width: 0; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.duel-invite .duel-name { text-align: center; }

.duel-terms { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.duel-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .74rem; font-weight: 700; padding: 3px 8px;
  background: var(--bg); border: 2px solid var(--ink); white-space: nowrap;
}
.duel-pill-prize { background: var(--warning); color: var(--ink); }

/* --- score --- */
.duel-score { display: flex; align-items: center; gap: 12px; width: 100%; justify-content: center; }
.duel-side { display: flex; flex-direction: column; align-items: center; min-width: 0; flex: 1; }
.duel-side b { font-size: 2rem; font-weight: 900; line-height: 1; color: var(--muted); }
.duel-side small {
  font-size: .7rem; color: var(--muted); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Only the leader is coloured, so a draw reads as a draw. */
.duel-side.lead b { color: var(--primary); }
.duel-vs { font-size: .78rem; font-weight: 800; color: var(--muted); flex: 0 0 auto; }

.duel-hint { margin: 0; }

/* --- clocks --- */
.duel-timer {
  display: flex; flex-direction: column; align-items: center; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  background: var(--bg); border: 2px solid var(--ink); padding: 5px 12px; min-width: 104px;
}
.duel-timer small { font-size: .64rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.duel-timer b { font-size: 1.15rem; font-weight: 800; }
.duel-timer.sprint b { font-size: 1.45rem; }
.duel-timer.urgent { background: var(--warning); }
.duel-timer.urgent small, .duel-timer.urgent b { color: var(--ink); }
.duel-timer.over { opacity: .5; }

.duel-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 0; }
.duel-card .btn { margin: 0; }

/* --- send form (select + button on one line) --- */
.duel-send { display: flex; align-items: center; gap: 8px; margin: 0; flex-wrap: wrap; }
.duel-send select { width: auto; margin: 0; padding: 6px 9px; font-size: .85rem; }
.duel-send .btn { margin: 0; white-space: nowrap; }

@media (max-width: 720px) {
  .duel-grid { grid-template-columns: 1fr; }
  .duel-banner { flex-direction: column; align-items: stretch; }
  .duel-banner-stats { justify-content: space-between; gap: 12px; }
  /* The friend row stacks on narrow screens, so the send form must fill the
     width rather than sit in a squeezed column. */
  .duel-send { width: 100%; }
  .duel-send select { flex: 1; min-width: 0; }
}

/* ===========================================================================
   Responsive safety net
   ---------------------------------------------------------------------------
   Appended last so it settles the cases that leak past the component rules.
   Deliberately NOT using `overflow-x: hidden` on html/body: that makes the body
   the scroll container and breaks `position: sticky`, which the topbar and the
   chapter headers on the course map both rely on. The real causes are fixed
   instead — unconstrained media, unbreakable strings, and flex children that
   refuse to shrink.
   =========================================================================== */

/* 1. Media can never be wider than its column. */
img, svg, video, iframe, canvas, embed, object {
  max-width: 100%;
}
img, video { height: auto; }

/* 2. A flex or grid child defaults to min-width:auto, which means "never
      shrink below my content". One long word then widens the whole row and
      the page scrolls sideways. These all carry text, so they may shrink. */
.page-head > *, .list-main, .rank-card, .rec-card, .ach-card,
.friend-row > *, .notif-body, .duel-banner-txt, .duel-card,
.profile-hero-id, .strip-game, .catalog-card, .list-card, .course-card {
  min-width: 0;
}

/* 3. Email addresses, URLs and long compounds must wrap rather than push. */
.notif-body, .friend-row, .profile-id, .profile-head, .list-main,
.rec-card, .ach-card, .duel-card, .empty-state, .page-head h1,
.hub-h2, .chip, .rank-user {
  overflow-wrap: anywhere;
}
/* A bare token with no break opportunity (a token, a hash) still needs a hard
   break, but only where such values actually appear. */
code, .share-link, .profile-id small { word-break: break-all; }

/* 4. Code and pre scroll inside themselves instead of widening the page. */
pre { overflow-x: auto; max-width: 100%; }
pre code { word-break: normal; white-space: pre; }

/* 5. Any table wide enough to matter scrolls in its own box. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 520px; }

@media (max-width: 720px) {
  /* The top bar now carries theme, language, bell, people and avatar. Tighten
     the gaps so they fit a 360px screen instead of pushing the avatar off. */
  .topbar { gap: 10px; }
  .topbar-right { gap: 6px; }

  /* Section headings and page titles get tight on small screens. */
  .page-head { margin-bottom: 16px; }
  .hub-h2 { margin-top: 22px; }

  /* Grids that were two-up become one-up where a squeezed column would clip. */
  .rec-grid, .ach-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  /* Rows of label + control stack, and the control takes the width instead of
     sitting in a 40px sliver. */
  .friend-row { flex-wrap: wrap; row-gap: 8px; }
  .friend-row > form, .friend-row .btn-row { width: 100%; justify-content: flex-start; }
  .friend-row-end { text-align: left; }
}

@media (max-width: 460px) {
  /* Very small phones: drop to a single column everywhere a two-up grid would
     leave less than ~150px per card. */
  .rank-summary, .rec-grid, .ach-grid { grid-template-columns: 1fr; }
  .duel-banner-stats { flex-direction: column; gap: 8px; }
  .tabs { gap: 4px; }
  .tab { padding: 8px 10px; font-size: .82rem; }
}

/* --- /correct.php : one student, every ungraded answer, collapsed per set --- */
.correct-set {
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink); margin-bottom: 16px; overflow: hidden;
}
.correct-set > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; cursor: pointer; font-weight: 700; list-style: none;
  background: var(--bg); border-bottom: 2px solid var(--ink);
}
/* The default triangle sits badly against a hard-bordered bar; the chip on the
   right already says whether the set has work left. */
.correct-set > summary::-webkit-details-marker { display: none; }
.correct-set:not([open]) > summary { border-bottom: 0; }
.correct-set > summary:hover { background: var(--primary-soft); }
.correct-set-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.correct-set-title small { font-weight: 500; }

.correct-item { border: 0; box-shadow: none; margin: 0; border-bottom: 1px solid var(--line); }
.correct-item:last-child { border-bottom: 0; }
.correct-item h3 { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 0; }
/* A thick left edge marks what still needs a mark, so scrolling a long backlog
   shows at a glance where the work is. */
.correct-item.is-pending { border-left: 4px solid var(--warning); }

@media (max-width: 720px) {
  .correct-set > summary { padding: 11px 12px; }
  .correct-item h3 { font-size: 1rem; }
}

/* ---------------------------------------------------------------------------
   Chat
   One hard frame around the whole thing; the message area sits on the page
   background so the bubbles (surface + primary) actually pop. Square design
   system throughout: 0 radius, 2px ink borders, solid offset shadows.
   --------------------------------------------------------------------------- */

/* The chat fits the viewport so nothing about it needs page scrolling. The page
   keeps its topbar, breadcrumb and footer; the chat is sized to sit between
   them, and the message list + recipient list each scroll INTERNALLY. Only the
   page's own min-height/padding are neutralised (they'd otherwise force extra
   height). :has() targets only pages that contain the chat. */
main.page:has(.chat-layout) { min-height: 0; padding-top: 0; padding-bottom: 8px; }

.chat-layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  /* dvh (not vh) so the mobile URL bar doesn't cause overflow. 160px is the
     real chrome this page carries: sticky topbar (62) + breadcrumb (~34) +
     footer (~64). Get this wrong and the box either overflows or leaves a gap. */
  height: calc(100dvh - 168px);
  /* min-height:0 on the grid ITEMS (below) is what actually lets the inner
     lists scroll — a grid item defaults to min-height:auto and grows to fit
     its content, which is exactly what pushed the box past the fold before. */
  min-height: 320px;
  overflow: hidden;
  background: var(--surface);
  border: var(--border) solid var(--line);
  box-shadow: var(--shadow-lg);
}
.chat-sidebar, .chat-main { min-height: 0; }

/* ---- sidebar ---- */
.chat-sidebar { overflow-y: auto; border-right: var(--border) solid var(--line); background: var(--surface); }
.chat-sidebar-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; border-bottom: var(--border) solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.chat-sidebar-head h2 { font-size: 1.05rem; margin: 0; }

.chat-convs { list-style: none; margin: 0; padding: 0; }
.chat-conv {
  display: flex; align-items: center; gap: 11px; padding: 12px 14px;
  color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line-soft);
}
.chat-conv:hover { background: var(--primary-soft); text-decoration: none; }
.chat-conv.is-active { background: var(--primary); color: var(--primary-ink); }
.chat-conv.is-active .chat-conv-preview,
.chat-conv.is-active .chat-conv-time { color: var(--primary-ink); opacity: .75; }
.chat-conv-ico { flex: 0 0 auto; display: flex; }
.chat-conv-ico .avatar { width: 34px; height: 34px; }
.chat-conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.chat-conv-top { display: flex; align-items: center; gap: 6px; }
.chat-conv-title { font-weight: 700; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conv-time { margin-left: auto; flex: 0 0 auto; font-size: .68rem; color: var(--muted); }
.chat-conv-preview { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-badge {
  flex: 0 0 auto; min-width: 20px; padding: 2px 6px; text-align: center;
  background: var(--primary); color: var(--primary-ink);
  border: var(--border) solid var(--line); font-size: .7rem; font-weight: 800;
}
.chat-conv.is-active .chat-badge { background: var(--primary-ink); color: var(--primary); }

/* ---- open conversation ---- */
.chat-main { display: flex; flex-direction: column; min-width: 0; position: relative; }
/* Loader shown until the history + polls/challenges finish hydrating, then JS
   scrolls to the bottom and removes it (see chat.js boot). */
.chat-loader {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.chat-spin {
  width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--primary);
  border-radius: 50%; animation: chat-spin .7s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }
/* Emoji-name tooltip (reaction chips + full-picker hover). */
.chat-emoji-tip {
  position: fixed; z-index: 130; display: none; pointer-events: none;
  background: var(--ink); color: var(--surface); padding: 3px 8px; font-size: .72rem;
  font-weight: 700; white-space: nowrap; text-transform: capitalize;
  border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col);
}
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: var(--border) solid var(--line); background: var(--surface);
}
.chat-head h2 { font-size: 1rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .avatar { width: 32px; height: 32px; }
.chat-back { display: none; }          /* mobile single-pane only */

.chat-messages {
  flex: 1 1 0; min-height: 0;           /* min-height:0 lets overflow scroll instead of growing */
  overflow-y: auto; overflow-x: hidden; /* never scroll sideways (side action bars live in the gutter) */
  overscroll-behavior: contain;
  padding: 18px 18px 10px; display: flex; flex-direction: column; gap: 10px;
  background: var(--bg);               /* bubbles pop against the page bg */
}
.chat-msg { max-width: min(74%, 480px); align-self: flex-start; }
.chat-msg-mine { align-self: flex-end; }
.chat-msg-who { font-size: .72rem; font-weight: 700; color: var(--muted); margin: 0 0 3px 2px; }
.chat-msg-body {
  padding: 9px 12px; background: var(--surface);
  border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col);
  white-space: pre-wrap; word-break: break-word; font-size: .95rem; line-height: 1.45;
}
.chat-msg-mine .chat-msg-body { background: var(--primary); color: var(--primary-ink); }
.chat-msg-deleted { font-style: italic; color: var(--muted); background: var(--surface-2); }
.chat-msg-mine .chat-msg-deleted { color: var(--primary-ink); }

.chat-msg-media { position: relative; display: inline-block; line-height: 0; }
.chat-msg-media img { max-width: 100%; height: auto; border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col); }
/* An image/GIF/sticker message must not take more than 55% of the pane width. */
.chat-msg:has(.chat-msg-media) { max-width: 55%; }
/* Klipy watermark on every card (sticker, GIF, meme). A condition of the free
   tier, but it must NOT dominate: at most 1/5 of the width AND at most 1/8 of
   the height, whichever is tighter. width/height stay auto so the SVG keeps its
   aspect ratio; min() clamps against both a relative and an absolute ceiling. */
.chat-media-mark {
  position: absolute; right: 5px; bottom: 5px;
  width: auto; height: auto;
  max-width: min(20%, 56px);
  max-height: min(12.5%, 20px);
  opacity: .85; border: 0 !important; box-shadow: none !important; pointer-events: none;
}

/* [hidden] must beat the display rules below (an attribute selector alone loses
   to a class). Without this the reply bar / action bar / menus show by default. */
.chat-msg-actions[hidden], .chat-ctx-menu[hidden],
.chat-emoji-pop[hidden], .chat-reply-bar[hidden] { display: none !important; }

/* Reply quote inside a bubble (click to jump to the quoted message). */
.chat-reply-quote {
  display: flex; flex-direction: column; gap: 1px; padding: 4px 8px; margin-bottom: 4px;
  border-left: 3px solid var(--primary); background: var(--primary-soft);
  font-size: .82rem; cursor: pointer;
}
.chat-reply-quote b { font-size: .74rem; }
.chat-reply-quote span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; color: var(--muted); }
.chat-msg-mine .chat-reply-quote { background: color-mix(in srgb, var(--primary) 20%, transparent); }

/* Brief flash when a reply-quote scrolls you to its target. */
@keyframes chat-flash { 0%, 100% { outline-color: transparent; } 30% { outline-color: var(--primary); } }
.chat-msg.is-flash { outline: 2px solid transparent; outline-offset: 3px; animation: chat-flash 1.3s ease; }

/* Footer row: reactions and the time/ticks share one line. */
.chat-msg-foot { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; min-width: 0; }
.chat-msg-mine .chat-reactions { justify-content: flex-end; }
.chat-react-chip {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
  font-size: .8rem; line-height: 1.5;
}
.chat-react-chip.is-mine { border-color: var(--primary); background: var(--primary-soft); }
.chat-react-chip span { font-variant-numeric: tabular-nums; font-size: .74rem; }

/* Per-message action bar: BESIDE the bubble, vertically centred, never over it.
   To the RIGHT of a received message, to the LEFT of one I sent. Lives in the
   26% gutter so it never triggers a horizontal scrollbar. */
.chat-msg { position: relative; }
.chat-msg-actions {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 5;
  display: flex; gap: 2px; padding: 2px;
  background: var(--surface); border: var(--border) solid var(--line); box-shadow: 2px 2px 0 var(--shadow-col);
  opacity: 0; pointer-events: none; transition: opacity .08s;
}
/* left:100% / right:100% keep the bar TOUCHING the message (no empty gap that
   would drop :hover); the spacing is padding — inside the box, so hovering it
   still counts as hovering the message and the bar stays reachable + clickable. */
.chat-msg:not(.chat-msg-mine) .chat-msg-actions { left: 100%; padding-left: 8px; }
.chat-msg-mine .chat-msg-actions { right: 100%; padding-right: 8px; }
.chat-msg:hover > .chat-msg-actions,
.chat-msg-actions:hover { opacity: 1; pointer-events: auto; }
.chat-act { min-width: 28px; height: 26px; padding: 0 5px; background: none; border: 0; cursor: pointer; color: var(--ink); display: inline-flex; align-items: center; justify-content: center; }
.chat-act:hover { background: var(--primary-soft); color: var(--primary); }
.chat-act svg, .chat-act .ic { width: 16px; height: 16px; }
.chat-ctx-menu svg { width: 16px; height: 16px; vertical-align: -3px; }

.chat-ctx-menu {
  position: fixed; z-index: 70; display: flex; flex-direction: column; min-width: 150px;
  background: var(--surface); border: var(--border) solid var(--line); box-shadow: 4px 4px 0 var(--shadow-col);
}
.chat-ctx-menu button { text-align: left; padding: 9px 14px; background: none; border: 0; cursor: pointer; color: var(--ink); font: inherit; }
.chat-ctx-menu button:hover { background: var(--primary-soft); }
.chat-emoji-pop {
  position: fixed; z-index: 80; padding: 6px; max-width: 260px;
  background: var(--surface); border: var(--border) solid var(--line); box-shadow: 4px 4px 0 var(--shadow-col);
}
.chat-emoji-row { display: flex; flex-wrap: wrap; gap: 2px; max-height: 180px; overflow-y: auto; }
.chat-emoji-pop button { width: 32px; height: 32px; background: none; border: 0; cursor: pointer; font-size: 1.1rem; display: inline-flex; align-items: center; justify-content: center; }
.chat-emoji-pop button:hover { background: var(--primary-soft); }
.chat-emoji-more { color: var(--primary); }
.chat-emoji-more svg, .chat-emoji-more .ic { width: 18px; height: 18px; }

/* Full emoji picker: a centred panel with a search box + scrollable grid. */
.chat-emoji-full {
  position: fixed; inset: 0; z-index: 120; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 23, 40, .45); padding: 18px;
}
.chat-emoji-full-box {
  width: 100%; max-width: 400px; height: 70vh; max-height: 520px;
  display: flex; flex-direction: column; gap: 10px; overflow: hidden;
  background: var(--surface); border: var(--border) solid var(--line); box-shadow: var(--shadow-lg); padding: 12px;
}
.chat-emoji-full-head { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.chat-emoji-full-head .input { flex: 1; width: auto; min-width: 0; margin: 0; }
.chat-emoji-full-name { flex: 0 0 auto; text-align: center; font-weight: 700; font-size: .82rem; min-height: 1.1em; color: var(--ink); text-transform: capitalize; }
.chat-emoji-full-close { flex: 0 0 auto; background: none; border: 0; cursor: pointer; color: var(--muted); display: inline-flex; padding: 6px; }
.chat-emoji-full-close svg { width: 20px; height: 20px; }
.chat-emoji-full-grid {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; align-content: start;
}
.chat-emoji-full-grid button {
  aspect-ratio: 1; width: 100%; background: none; border: 0; cursor: pointer;
  font-size: 1.4rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.chat-emoji-full-grid button:hover { background: var(--primary-soft); }
.chat-emoji-full-empty { grid-column: 1 / -1; padding: 20px; text-align: center; color: var(--muted); }

/* Emoji-bearing controls must use --font (buttons don't inherit font-family),
   so the served Noto Color Emoji applies to reactions and both pickers. */
.chat-emoji-row button, .chat-emoji-full-grid button,
.chat-react-chip, .chat-poll-opt-txt { font-family: var(--font); }

/* Reply-compose bar above the composer. */
.chat-reply-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 14px; border-top: var(--border) solid var(--line); background: var(--primary-soft);
  font-size: .85rem;
}
.chat-reply-bar-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-msg-meta { display: flex; align-items: center; gap: 5px; justify-content: flex-end; font-size: .68rem; color: var(--muted); flex: 0 0 auto; }
.chat-ticks { font-weight: 800; letter-spacing: -1px; }
.chat-ticks.is-read { color: var(--primary); }
.chat-typing { padding: 2px 18px 6px; font-size: .78rem; font-style: italic; min-height: 1.2em; background: var(--bg); }

/* Sidebar head action buttons (new group + friends). */
.chat-head-actions { display: flex; gap: 4px; flex: 0 0 auto; }

/* Sidebar search: input + a results panel that replaces the conversation list. */
.chat-search {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  border-bottom: var(--border) solid var(--line); color: var(--muted);
}
.chat-search .input { flex: 1; width: auto; min-width: 0; height: 34px; margin: 0; }
.chat-search-results { flex: 1 1 0; min-height: 0; overflow-y: auto; }
.chat-search-group { padding: 6px 0; }
.chat-search-group h4 {
  margin: 0; padding: 8px 14px 4px; font-size: .7rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted);
}
.chat-search-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  text-decoration: none; color: inherit;
}
.chat-search-item:hover { background: var(--primary-soft); }
.chat-search-item .avatar, .chat-search-ico { width: 32px; height: 32px; flex: 0 0 auto; }
.chat-search-ico { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.chat-search-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-search-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-search-main .muted { font-size: .78rem; }
.chat-search-snip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-search-empty { padding: 20px 14px; text-align: center; }

/* New-group form (scrolls internally; the composer/layout height rules apply). */
.chat-newgroup { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-newgroup .input { width: 100%; }
.chat-newgroup-label { font-weight: 700; font-size: .9rem; }
.chat-friend-picklist { display: flex; flex-direction: column; gap: 2px; border: var(--border) solid var(--line); padding: 6px; }
.chat-friend-picklist .check .avatar { width: 28px; height: 28px; }
.chat-newgroup .btn-primary { align-self: flex-start; }
.chat-newchat { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.chat-newchat .chat-search { margin: 0; }
.chat-newchat-group { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; }
.chat-newchat-friends { flex: 1 1 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-newchat #newChatResults { flex: 1 1 0; }

/* Message-request bar (accept/decline a stranger's first message). */
.chat-request-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 12px 16px;
  border-bottom: var(--border) solid var(--line); background: var(--primary-soft);
}
.chat-request-bar p { margin: 2px 0 0; }
.chat-request-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.chat-composer {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-top: var(--border) solid var(--line); background: var(--surface);
}
/* Beats the global `input { width: 100% }` that pushes buttons onto their own line.
   margin-top:-6px pulls the input into vertical alignment with the icon buttons. */
.chat-composer .input { flex: 1; width: auto; min-width: 0; height: 42px; margin-top: -6px; }
.chat-composer .btn { flex: 0 0 auto; height: 42px; min-width: 42px; display: inline-flex; align-items: center; justify-content: center; }
.chat-gif-btn { font-weight: 800; font-size: .7rem; letter-spacing: .03em; }
.chat-disabled { padding: 14px; text-align: center; border-top: var(--border) solid var(--line); }

/* Smaller sticker/GIF/meme buttons so the composer isn't icon-heavy. */
.chat-composer .btn.chat-tool-sm { min-width: 34px; height: 34px; padding: 0 6px; }
.chat-tool-sm .ic { width: 16px; height: 16px; }
/* Troll face = the MEME picker only. currentColor via a mask, so it is black in
   light mode and white in dark mode (button text colour is --ink). */
.troll-ico {
  display: inline-block; width: 18px; height: 18px; background-color: currentColor;
  -webkit-mask: url(/assets/troll.svg) center / contain no-repeat;
          mask: url(/assets/troll.svg) center / contain no-repeat;
}

/* "+" attach modal: a small grid of labelled actions. */
.chat-plus-box { max-width: 360px; }
.chat-plus-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chat-plus-item {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 10px; background: var(--surface); cursor: pointer;
  border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col);
  color: inherit; font: inherit;
}
.chat-plus-item:hover { background: var(--primary-soft); }
.chat-plus-ico { color: var(--primary); }

/* File-message bubble. */
.chat-msg-file {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface); border: var(--border) solid var(--line);
  box-shadow: 3px 3px 0 var(--shadow-col); text-decoration: none; color: inherit;
}
.chat-msg-mine .chat-msg-file { background: var(--primary); color: var(--primary-ink); }
.chat-file-ico { flex: 0 0 auto; display: inline-flex; }
.chat-file-ico svg { width: 22px; height: 22px; }
.chat-file-meta { display: flex; flex-direction: column; min-width: 0; }
.chat-file-meta b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.chat-file-meta small { opacity: .8; font-size: .74rem; }
.chat-msg-uploading { opacity: .6; }
/* Squared voice / audio player (Instagram-ish, but square). */
.chat-audio { display: flex; align-items: center; gap: 8px; padding: 6px 10px; min-width: 190px; }
.chat-audio-play {
  flex: 0 0 auto; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: var(--primary-ink); border: var(--border) solid var(--line); cursor: pointer;
}
.chat-msg-mine .chat-audio-play { background: var(--surface); color: var(--ink); }
.chat-audio-play svg { width: 16px; height: 16px; }
.chat-audio-track { flex: 1; height: 6px; background: var(--line); cursor: pointer; position: relative; min-width: 90px; }
.chat-audio-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--primary); }
.chat-msg-mine .chat-audio-fill { background: var(--primary-ink); }
.chat-msg-mine .chat-audio-track { background: color-mix(in srgb, var(--primary-ink) 40%, transparent); }
.chat-audio-time { flex: 0 0 auto; font-size: .72rem; font-variant-numeric: tabular-nums; opacity: .85; }
.chat-msg-video { max-width: 55%; max-height: 320px; border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col); }
.chat-msg:has(.chat-msg-video) { max-width: 55%; }
/* Recording state on the mic button. */
#chatMic.is-recording { color: var(--danger, #e5484d); animation: chat-rec 1s steps(2) infinite; }
@keyframes chat-rec { 50% { opacity: .35; } }

/* Poll bubble. */
.chat-poll {
  min-width: 240px; padding: 10px 12px; background: var(--surface);
  border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col);
  display: flex; flex-direction: column; gap: 6px;
}
.chat-poll-q { font-weight: 800; margin-bottom: 2px; }
.chat-poll-opt {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--bg); border: 1px solid var(--line);
  cursor: pointer; overflow: hidden; text-align: left; font: inherit; color: inherit;
}
.chat-poll-opt:hover { border-color: var(--primary); }
.chat-poll-opt.is-mine { border-color: var(--primary); font-weight: 700; }
.chat-poll-bar {
  position: absolute; inset: 0 auto 0 0; background: var(--primary-soft);
  z-index: 0; transition: width .3s ease;
}
.chat-poll-opt-txt { position: relative; z-index: 1; flex: 1; min-width: 0; }
.chat-poll-opt-n { position: relative; z-index: 1; font-variant-numeric: tabular-nums; opacity: .8; }
.chat-poll-total { font-size: .74rem; }
.chat-poll-form { display: flex; flex-direction: column; gap: 10px; }
.chat-poll-options-edit { display: flex; flex-direction: column; gap: 6px; }
.chat-poll-form .input { width: 100%; }

/* Challenge bubble + picker. */
.chat-challenge-card {
  min-width: 220px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col);
}
.chat-ch-head { font-size: .95rem; }
.chat-ch-head svg, .chat-ch-result svg { width: 15px; height: 15px; vertical-align: -2px; }
.chat-ch-meta { font-size: .8rem; }
.chat-ch-result { font-weight: 800; }
.chat-ch-pending { font-size: .82rem; font-style: italic; }
.chat-challenge-card .btn { align-self: flex-start; }
.chat-challenge-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.chat-challenge-class { justify-content: flex-start; text-align: left; }
.chat-challenge-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chat-challenge-modes .btn { justify-content: flex-start; }

/* Transient toast (upload errors, "coming soon"). */
.chat-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--surface); padding: 10px 16px;
  border: var(--border) solid var(--line); box-shadow: 4px 4px 0 var(--shadow-col);
  font-size: .85rem; font-weight: 700; z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.chat-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Clickable conversation title + the header "i" button open the info modal. */
.chat-head-title { cursor: pointer; }
.chat-head-title:hover { text-decoration: underline; }
.chat-head-info { flex: 0 0 auto; }

/* Composer tool tooltips (sticker / GIF / meme / +): shown on hover & focus. */
.chat-tool { position: relative; }
.chat-tool::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--surface); color: var(--ink);
  border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col);
  padding: 3px 8px; font-size: .72rem; font-weight: 700; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 30;
}
.chat-tool:hover::after, .chat-tool:focus-visible::after { opacity: 1; }

/* Active picker button: hover-style background + an accent border. --primary is
   the brand accent and already flips lighter in dark mode, so the border reads
   correctly in both themes. */
.chat-composer .btn.btn-selected {
  background: var(--primary-soft);
  border: 2px solid var(--primary); color: var(--primary);
}

/* Conversation-info modal contents. */
.conv-info-stats { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.conv-info-stats li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.conv-info-stats li:last-child { border-bottom: 0; }
.conv-info-report { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.conv-info-report .input { width: 100%; }
.conv-info-report .btn { align-self: flex-start; }
.conv-info-block { border-top: var(--border) solid var(--line); padding-top: 14px; }
.conv-info-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.conv-search-panel { margin-bottom: 14px; }
.conv-search-panel .input { width: 100%; margin-bottom: 8px; }
.conv-search-results { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-search-item { text-align: left; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); cursor: pointer; font: inherit; color: inherit; }
.conv-search-item:hover { background: var(--primary-soft); }
/* Group members list + per-member 3-dot menu. */
.conv-members { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.conv-member { display: flex; align-items: center; gap: 10px; padding: 6px 4px; position: relative; }
.conv-member .avatar { width: 30px; height: 30px; }
.conv-member-name { flex: 1; min-width: 0; }
.conv-member-menu { position: absolute; right: 0; top: 100%; z-index: 10; background: var(--surface); border: var(--border) solid var(--line); box-shadow: 3px 3px 0 var(--shadow-col); display: flex; flex-direction: column; min-width: 160px; }
.conv-member-menu form { margin: 0; }
.conv-member-menu button, .conv-member-menu a { display: block; width: 100%; text-align: left; padding: 8px 12px; background: none; border: 0; cursor: pointer; color: var(--ink); text-decoration: none; font: inherit; }
.conv-member-menu button:hover, .conv-member-menu a:hover { background: var(--primary-soft); }
.conv-member-chip { font-size: .68rem; }
.chat-main .alert { margin: 12px 14px 0; padding: 10px 12px; border: var(--border) solid var(--line); background: var(--danger-soft, #fdecec); font-size: .9rem; }

/* ---- sticker / GIF picker ---- */
.media-picker {
  border-top: var(--border) solid var(--line); background: var(--surface-2);
  padding: 10px 12px; max-height: 44vh; display: flex; flex-direction: column; gap: 8px;
}
.media-picker[hidden] { display: none; }
.media-picker-head { display: flex; gap: 8px; align-items: center; }
.media-picker-head .input { flex: 1; width: auto; min-width: 0; height: 38px; }
/* "Powered by KLIPY" logo, in the search row, a quarter of its width.
   Explicit flex-basis (not max-width alone) or the auto-sized item collapses
   and the % width on the img resolves against zero. */
.picker-powered { display: flex; align-items: center; flex: 0 0 25%; max-width: 110px; opacity: .85; }
.picker-powered img { width: 100%; max-height: 20px; height: auto; object-fit: contain; }
/* Black logo in light mode, white logo in dark. Media query first (system
   preference), then the explicit data-theme toggle overrides it. */
.picker-powered .k-dark { display: none; }
.picker-powered .k-light { display: block; }
@media (prefers-color-scheme: dark) {
  .picker-powered .k-light { display: none; }
  .picker-powered .k-dark { display: block; }
}
:root[data-theme="light"] .picker-powered .k-light { display: block; }
:root[data-theme="light"] .picker-powered .k-dark { display: none; }
:root[data-theme="dark"] .picker-powered .k-light { display: none; }
:root[data-theme="dark"] .picker-powered .k-dark { display: block; }
.picker-grid {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px;
}
.picker-item {
  padding: 0; border: var(--border) solid var(--line); background: var(--surface);
  cursor: pointer; line-height: 0; aspect-ratio: 1; transition: transform .06s;
}
.picker-item img { width: 100%; height: 100%; object-fit: cover; }
.picker-item:hover { transform: translate(-2px, -2px); box-shadow: 2px 2px 0 var(--shadow-col); }
.picker-attribution { display: flex; justify-content: flex-end; opacity: .8; }

/* ---- moderation queue (never had styles: new markup needs new CSS) ---- */
.report-card { margin-bottom: 14px; }
.report-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.report-snapshot {
  margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--line);
  background: var(--surface-2); font-size: .92rem; white-space: pre-wrap; word-break: break-word;
}
.report-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.report-actions .input { flex: 1; min-width: 180px; width: auto; }
.chip-danger { background: var(--danger, #c62828); color: #fff; border-color: var(--line); }

/* ---- blocked-sender messages: collapsed behind a tap, not removed ---- */
.chat-blocked-reveal {
  display: block; width: 100%; text-align: left; cursor: pointer;
  font: inherit; font-size: .84rem; font-style: italic; color: var(--muted);
  padding: 9px 12px;
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, var(--bg) 6px, var(--bg) 12px);
  border: var(--border) dashed var(--line-soft); box-shadow: none;
}
.chat-blocked-reveal:hover { border-color: var(--line); color: var(--ink); }
.chat-blocked-body[hidden] { display: none; }
.chat-blocked-body img { max-width: 100%; height: auto; }

/* ---- mobile: one pane at a time ---- */
@media (max-width: 820px) {
  /* Topbar (62) + breadcrumb (~34) + footer (~64) + fixed bottombar (~56). */
  .chat-layout { grid-template-columns: 1fr; height: calc(100dvh - 216px); min-height: 280px; }
  .chat-layout.has-open .chat-sidebar { display: none; }
  .chat-layout.has-open .chat-back { display: inline-flex; }
  .chat-msg { max-width: 88%; }
  .picker-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}
