/* Màu sắc: mọi màu nằm ở khối :root (sáng) và :root[data-theme="dark"] (tối). */
:root {
  --bg1: #fff6fb;
  --bg2: #eef4ff;
  --card: #ffffff;
  --surface: #ffffff;
  --surface-a: rgba(255, 255, 255, 0.94);
  --ink: #3d3556;
  --muted: #726a92;
  --line: #ece7f7;
  --accent: #6d4fe4;
  --accent-soft: #efeafe;
  --pink: #ee5a8a;
  --ok: #2f9e6e;
  --danger: #c73a5f;
  --input-bg: #fdfcff;
  --tint-1: #faf8ff;
  --tint-2: #f3effc;
  --tint-3: #ebe4fb;
  --border-2: #e6dcfb;
  --border-3: #c9b6fa;
  --grad-a: #fff2f8;
  --grad-b: #f1ecff;
  --danger-bg: #fff0f4;
  --danger-bg2: #ffe9ef;
  --danger-border: #ffc9d6;
  --danger-fg: #a3294e;
  --ok-bg: #eafaf2;
  --ok-border: #bfe8d3;
  --ok-fg: #1a7a50;
  --info-bg: #e6f0ff;
  --info-fg: #2d5fc4;
  --purple-bg: #f2e8ff;
  --purple-fg: #7c3fd0;
  --chip-fg: #6b5cc4;
  --warn-bg: #fff0e0;
  --warn-fg: #a15408;
  --yellow-bg: #fff5d6;
  --yellow-fg: #846200;
  --hard-bg: #ffe4ea;
  --hard-fg: #b3234f;
  --toast-bg: #3d3556;
  --overlay: rgba(61, 53, 86, 0.38);
  --shadow: 0 10px 30px rgba(120, 100, 180, 0.14);
  --shadow-sm: 0 3px 10px rgba(120, 100, 180, 0.12);
  --shadow-lg: 0 24px 60px rgba(70, 50, 130, 0.35);
  --wheel-rim: #ffffff;
  --wheel-empty: #f4f1fb;
  --wheel-empty-line: #d9d2ee;
  --wheel-shadow: rgba(110, 90, 170, 0.28);
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Giao diện tối: theme.js đặt data-theme="dark" lên <html> */
:root[data-theme="dark"] {
  --bg1: #13111f;
  --bg2: #1a1731;
  --card: #221f38;
  --surface: #2a2648;
  --surface-a: rgba(38, 34, 66, 0.94);
  --ink: #ece8ff;
  --muted: #a59fca;
  --line: #37315a;
  --accent: #a98bff;
  --accent-soft: #322b5c;
  --pink: #ff7aa8;
  --ok: #58c996;
  --danger: #ff6d94;
  --input-bg: #1c1932;
  --tint-1: #272346;
  --tint-2: #2e2952;
  --tint-3: #3c3670;
  --border-2: #3d3766;
  --border-3: #6355b0;
  --grad-a: #3b2445;
  --grad-b: #2c2652;
  --danger-bg: #3c2033;
  --danger-bg2: #4b2539;
  --danger-border: #6e3554;
  --danger-fg: #ff9db9;
  --ok-bg: #1f3a34;
  --ok-border: #2f6b56;
  --ok-fg: #7be2b1;
  --info-bg: #22345e;
  --info-fg: #90b8ff;
  --purple-bg: #34265c;
  --purple-fg: #cbaaff;
  --chip-fg: #b9abff;
  --warn-bg: #4a3421;
  --warn-fg: #ffb56d;
  --yellow-bg: #463b17;
  --yellow-fg: #ffd95e;
  --hard-bg: #4b2133;
  --hard-fg: #ff90b1;
  --toast-bg: #3c3670;
  --overlay: rgba(6, 4, 22, 0.62);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  --wheel-rim: #2f2a55;
  --wheel-empty: #26223f;
  --wheel-empty-line: #4a4378;
  --wheel-shadow: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
:focus-visible { outline: 3px solid rgba(124, 92, 240, 0.45); outline-offset: 2px; }

/* ---------- banner ---------- */
.banner {
  display: flex; gap: 14px; align-items: center; justify-content: center;
  padding: 10px 16px; background: var(--danger-bg); color: var(--danger-fg); border-bottom: 1px solid var(--danger-border);
  font-weight: 600; text-align: center;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 12px 22px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; letter-spacing: 0.2px; }
.logo { font-size: 28px; }
.modes {
  display: flex; gap: 6px; padding: 5px; background: var(--card);
  border-radius: 999px; box-shadow: var(--shadow-sm); margin: 0 auto;
}
.mode {
  border: 0; background: transparent; color: var(--muted); font-weight: 700; font-size: 15px;
  padding: 9px 18px; border-radius: 999px; transition: background .15s, color .15s;
}
.mode:hover { color: var(--ink); }
.mode.active { background: linear-gradient(135deg, #ff9ab9, #a98bff); color: #fff; box-shadow: 0 4px 12px rgba(169, 139, 255, 0.4); }
.top-actions { display: flex; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 12px; padding: 9px 16px; font-size: 14px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent); transition: transform .08s, background .15s, box-shadow .15s;
}
.btn:hover:not(:disabled) { background: var(--tint-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, #f0699a, #8a67f5); color: #fff; box-shadow: 0 4px 12px rgba(138, 103, 245, 0.35); }
.btn.primary:hover:not(:disabled) { background: linear-gradient(135deg, #ea5a8f, #7b56ee); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn.ghost:hover:not(:disabled) { background: var(--tint-1); }
.btn.danger { background: var(--surface); border-color: var(--danger-border); color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger) !important; }

/* ---------- layout ---------- */
.layout {
  flex: 1; min-height: 0; display: grid; gap: 22px; padding: 6px 22px 22px;
  grid-template-columns: minmax(0, 1fr) clamp(350px, 32vw, 450px);
}
.stage { display: flex; flex-direction: column; align-items: center; min-width: 0; min-height: 0; gap: 12px; }

.catbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; justify-content: center;
  background: var(--card); padding: 7px; border-radius: 18px; box-shadow: var(--shadow-sm);
  max-width: 100%;
}
.cat-picker {
  display: flex; align-items: center; gap: 10px; min-width: 0; flex: 0 1 340px; text-align: left;
  padding: 0 14px 0 12px; height: 50px; border-radius: 14px; color: var(--accent);
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b)); border: 1.5px solid var(--border-2);
  transition: border-color .15s, box-shadow .15s, transform .08s;
}
.cat-picker:hover:not(:disabled) { border-color: var(--border-3); box-shadow: 0 3px 10px rgba(138, 103, 245, 0.16); }
.cat-picker:active:not(:disabled) { transform: translateY(1px); }
.cat-picker svg { flex: none; }
.cat-ico { font-size: 20px; flex: none; }
.cat-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.cat-label { font-weight: 800; font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-label.muted { color: var(--muted); }
.cat-sub { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { padding: 4px 10px; font-weight: 700; color: var(--accent); }

.wheel-wrap {
  position: relative; aspect-ratio: 1; flex: 0 1 auto;
  width: min(100%, calc(100vh - 270px), 700px); min-width: 260px;
}
#wheel { width: 100%; height: 100%; display: block; }
.hub {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 17%; aspect-ratio: 1; border-radius: 50%; border: 5px solid var(--wheel-rim);
  background: linear-gradient(145deg, #ff9ab9, #a98bff); color: #fff; font-weight: 800;
  font-size: clamp(11px, 2.2vw, 20px); letter-spacing: 0.5px;
  box-shadow: 0 6px 18px rgba(110, 90, 170, 0.4);
  transition: transform .12s;
}
.hub:hover:not(:disabled) { transform: translate(-50%, -50%) scale(1.06); }
.hub:disabled { opacity: 0.85; filter: grayscale(0.4); }

.empty-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 12%;
}
.empty-card {
  background: var(--surface-a); border-radius: var(--radius); padding: 22px 24px; text-align: center;
  box-shadow: var(--shadow); max-width: 86%;
}
.empty-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.empty-card p { color: var(--muted); margin: 6px 0 14px; line-height: 1.45; }
.empty-card p:last-child { margin-bottom: 0; }

.spin-row { display: flex; gap: 12px; align-items: center; justify-content: center; }
.btn-spin {
  border: 0; border-radius: 999px; padding: 15px 46px; font-size: 22px; font-weight: 800; letter-spacing: 1px; color: #fff;
  background: linear-gradient(135deg, #f0699a, #8a67f5);
  box-shadow: 0 10px 24px rgba(138, 103, 245, 0.42);
  transition: transform .1s, box-shadow .15s;
}
.btn-spin:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 14px 28px rgba(138, 103, 245, 0.5); }
.btn-spin:active:not(:disabled) { transform: translateY(1px); }
kbd {
  font: 600 11px var(--font); background: rgba(255, 255, 255, 0.28); padding: 2px 7px; border-radius: 6px;
  margin-left: 8px; vertical-align: middle; letter-spacing: 0;
}
body.spinning .lockable { pointer-events: none; opacity: 0.6; }

/* ---------- panel ---------- */
.panel {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.tabs { display: flex; padding: 8px; gap: 6px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; border: 0; background: transparent; padding: 10px; font-weight: 700; color: var(--muted); border-radius: 12px; font-size: 15px;
}
.tab.active { background: var(--accent-soft); color: var(--accent); }
.panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }

.add-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.add-tabs { display: flex; gap: 4px; padding: 4px; background: var(--tint-2); border-radius: 12px; }
.add-tab {
  flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px;
  font: 700 13.5px var(--font); color: var(--muted); transition: background .15s, color .15s;
}
.add-tab:hover { color: var(--ink); }
.add-tab.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 5px rgba(120, 100, 180, 0.22); }
.add-pane { display: flex; flex-direction: column; gap: 8px; }
.add-row { display: flex; gap: 8px; }
.add-row.between { align-items: center; justify-content: space-between; }
.add-row .input { flex: 1; min-width: 0; }
.add-count { font-size: 13px; font-weight: 600; color: var(--muted); }

.input { flex: 1; min-width: 0; }

.input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 12px; font: inherit; font-size: 14px;
  color: var(--ink); background: var(--input-bg); resize: vertical;
}
.input:focus { outline: none; border-color: var(--border-3); box-shadow: 0 0 0 3px rgba(124, 92, 240, 0.15); }
.input.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }

.toolbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; padding: 10px 12px; background: var(--tint-1); border-radius: 14px; }
.toolbar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat { font-weight: 700; font-size: 14px; }

.segs { display: inline-flex; gap: 2px; background: var(--tint-2); padding: 2px; border-radius: 9px; }
.seg { border: 0; background: transparent; padding: 3px 7px; border-radius: 7px; font-size: 12px; font-weight: 800; color: var(--muted); }
.seg:hover { color: var(--ink); background: var(--surface); }
.seg.on { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px rgba(120, 100, 180, 0.25); }

.rows, .hist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex; align-items: center; gap: 6px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.row.removed { background: var(--tint-2); }
.row.removed .txt { color: var(--muted); text-decoration: line-through; }
.num {
  flex: none; min-width: 26px; height: 24px; padding: 0 5px; display: grid; place-items: center; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 800;
}
.txt {
  flex: 1; min-width: 0; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tag { font-style: normal; font-size: 11px; font-weight: 700; color: var(--pink); background: var(--danger-bg); padding: 1px 7px; border-radius: 999px; margin-left: 6px; text-decoration: none; display: inline-block; }
.icon {
  flex: none; width: 27px; height: 27px; border: 0; background: transparent; border-radius: 8px; font-size: 14px; color: var(--muted);
}
.icon:hover { background: var(--tint-2); color: var(--ink); }
.row-actions { flex: none; display: flex; align-items: center; gap: 6px; }
.row-compact { display: none; flex: none; align-items: center; gap: 4px; }
.menu-btn {
  height: 34px; min-width: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--tint-1); color: var(--ink); font: 800 15px var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 3px;
}
.menu-btn.weight { color: var(--accent); font-size: 13px; }
.menu-btn .caret { font-size: 10px; color: var(--muted); }
.menu-btn[aria-expanded="true"] { border-color: var(--border-3); background: var(--tint-2); }
.menu {
  position: fixed; z-index: 60; min-width: 190px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .12s ease-out;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink); font: 600 14px var(--font); text-align: left;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--tint-2); outline: none; }
.menu-item.on { color: var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-ico { width: 18px; text-align: center; flex: none; }

.note { color: var(--muted); padding: 18px 8px; line-height: 1.5; }
.note.center { text-align: center; }
.note .big { font-size: 38px; }
.note strong { color: var(--ink); }

.h-row { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.h-row.clickable { cursor: pointer; }
.h-row.clickable:hover { background: var(--tint-1); }
.h-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.h-meta time { margin-left: auto; }
.h-cat { font-weight: 700; color: var(--ink); }
.h-result { margin-top: 5px; font-weight: 700; overflow-wrap: anywhere; }
.h-answer { margin-top: 6px; padding: 7px 10px; background: var(--ok-bg); border-radius: 9px; font-size: 14px; }
.h-answer span { font-weight: 700; color: var(--ok); }
.more-btn { margin-top: 10px; }
.h-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.badge { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.badge.normal { background: var(--info-bg); color: var(--info-fg); }
.badge.quiz { background: var(--purple-bg); color: var(--purple-fg); }
.badge.yesno { background: var(--ok-bg); color: var(--ok-fg); }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px;
  background: var(--overlay); backdrop-filter: blur(3px); animation: fade .14s ease-out;
}
.overlay.closing { opacity: 0; transition: opacity .14s; }
.modal {
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: calc(100vh - 36px); display: flex; flex-direction: column;
  animation: pop .2s cubic-bezier(.2, 1.2, .4, 1);
}
.modal.small { width: min(440px, 100%); }
.modal.wide { width: min(680px, 100%); }
.modal-title { margin: 0; padding: 20px 24px 0; font-size: 20px; }
.modal-body { padding: 16px 24px; overflow-y: auto; }
.modal-text { margin: 0; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 8px 24px 20px; flex-wrap: wrap; }
.modal h3 { margin: 0; font-size: 15px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.9) translateY(10px); } }

.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 700; font-size: 13px; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.5; }
.hint.center { text-align: center; margin-top: 12px; }
code { background: var(--accent-soft); color: var(--accent); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; }
.radio-col { display: flex; flex-direction: column; gap: 8px; }
.radio, .check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.radio input, .check input { width: 17px; height: 17px; accent-color: var(--accent); }
.file { font-size: 13px; }
.errbox { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-fg); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; line-height: 1.5; }
.errbox ul { margin: 6px 0 0; padding-left: 20px; }

/* dialog chọn category */
.cat-modal { width: min(520px, 100%); }
.cat-list { display: flex; flex-direction: column; gap: 6px; max-height: min(52vh, 420px); overflow-y: auto; padding-right: 2px; }
.cat-section { margin: 8px 4px 2px; font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.cat-row { display: flex; align-items: center; gap: 2px; border: 1.5px solid var(--line); border-radius: 13px; background: var(--surface); transition: border-color .15s, background .15s; }
.cat-row:hover { border-color: var(--border-3); background: var(--tint-1); }
.cat-row.active { border-color: #a98bff; background: linear-gradient(135deg, var(--grad-a), var(--grad-b)); }
.cat-pick {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: transparent;
  padding: 11px 8px 11px 12px; text-align: left; font-family: inherit; color: var(--ink); border-radius: 13px;
}
.cat-check { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 900; color: #fff; border: 2px solid var(--border-2); }
.cat-row.active .cat-check { background: linear-gradient(135deg, #f0699a, #8a67f5); border-color: transparent; }
.cat-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count, .cat-hint { flex: none; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.cat-row.none .cat-name { color: var(--ink); }
.cat-mini { flex: none; width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); display: grid; place-items: center; }
.cat-mini:hover { background: var(--tint-2); color: var(--accent); }
.cat-mini.del:hover { background: var(--danger-bg2); color: var(--danger); }
.cat-row:last-child { margin-right: 0; }

/* popup kết quả */
.result-modal { text-align: center; }
.result-modal .modal-title { text-align: center; }
.result { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.result-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.result-text { font-size: clamp(22px, 4vw, 30px); font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; max-height: 38vh; overflow-y: auto; padding: 2px 6px; }
.answer-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 8px; width: 100%; }
.answer { width: 100%; background: var(--ok-bg); border: 1.5px solid var(--ok-border); border-radius: 14px; padding: 10px 16px; text-align: left; animation: pop .2s ease-out; }
.answer span { font-size: 12px; font-weight: 800; color: var(--ok); text-transform: uppercase; letter-spacing: 1px; }
.answer p { margin: 4px 0 0; font-size: 19px; font-weight: 700; overflow-wrap: anywhere; max-height: 26vh; overflow-y: auto; }
.result-yn { font-size: 72px; font-weight: 900; letter-spacing: 3px; padding: 6px 0; }
.result-yn.yes { color: var(--ok-fg); }
.result-yn.no { color: var(--danger); }
.result-modal .modal-actions { justify-content: center; }

#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 80; }

/* ---------- toast ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--toast-bg); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; max-width: min(90vw, 620px);
  box-shadow: var(--shadow); animation: pop .2s ease-out; text-align: center;
}
.toast.ok { background: #2a8a62; }
.toast.err { background: #c73a62; }
.toast.out { opacity: 0; transition: opacity .25s; }

/* ---------- responsive ---------- */
.mode-short { display: none; }

@media (max-width: 960px) {
  /* nền cuộn theo trang: `fixed` + height 100% làm phần dưới trang mất nền trên mobile */
  html, body { height: auto; min-height: 100%; }
  body { display: block; background-attachment: scroll; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 6px 14px 22px; }
  .wheel-wrap { width: min(100%, 560px); }
  .panel { min-height: 420px; max-height: none; }
  .panel-body { overflow: visible; }
  .topbar { padding: 12px 14px; justify-content: center; }
  .modes { order: 3; width: 100%; justify-content: center; }
  .mode { padding: 8px 12px; font-size: 14px; }
}
@media (max-width: 620px) {
  /* điện thoại: thanh trên gọn 1 hàng (logo + nút chỉ icon), tab loại vòng chia đều */
  body { -webkit-tap-highlight-color: transparent; }
  .topbar { gap: 10px; padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); justify-content: space-between; }
  .brand { font-size: 18px; gap: 8px; }
  .logo { font-size: 24px; }
  .top-actions { gap: 6px; }
  .top-actions .btn { min-width: 40px; height: 40px; padding: 0 10px; font-size: 16px; line-height: 1; }
  .top-actions .lbl { display: none; }
  .modes { padding: 4px; gap: 4px; }
  .mode { flex: 1 1 0; min-width: 0; padding: 9px 6px; white-space: nowrap; }
  .mode-full { display: none; }
  .mode-short { display: inline; }

  .layout { padding: 4px 12px max(18px, env(safe-area-inset-bottom)); gap: 16px; }
  .stage { gap: 10px; }
  .catbar { flex-wrap: wrap; width: 100%; }
  .cat-picker { flex: 1 1 100%; }
  .wheel-wrap { min-width: 0; }
  .empty-overlay { padding: 14%; }
  .empty-card { padding: 12px 14px; max-width: 100%; }
  .empty-title { font-size: 16px; }
  .empty-card p { font-size: 13px; margin: 4px 0 10px; line-height: 1.4; }
  .empty-card .btn { padding: 8px 14px; font-size: 13px; }

  /* nút Quay chiếm cả hàng, các nút phụ chia đều hàng dưới */
  .spin-row { flex-wrap: wrap; gap: 8px; width: 100%; }
  .btn-spin { flex: 1 1 100%; padding: 14px 20px; font-size: 20px; }
  .spin-row .btn { flex: 1 1 0; min-width: 0; padding: 10px 6px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  kbd { display: none; }

  .panel { min-height: 360px; }
  .panel-body { padding: 10px; }
  /* iOS tự zoom khi focus ô nhập chữ < 16px */
  .input, select.input, textarea.input { font-size: 16px; }
  .icon { width: 34px; height: 34px; }
  /* item 1 dòng: tên + 2 nút mở menu (hệ số, thao tác) */
  .row { padding: 6px 6px 6px 8px; }
  .row-actions { display: none; }
  .row-compact { display: flex; }

  /* modal gần như full màn hình, nút hành động dễ bấm */
  .overlay { padding: 10px; }
  .modal { max-height: calc(100dvh - 20px); border-radius: 18px; }
  .modal-title { padding: 16px 16px 0; font-size: 18px; }
  .modal-body { padding: 12px 16px; }
  .modal-actions { padding: 8px 16px 16px; }
  .modal-actions .btn { flex: 1 1 auto; padding: 11px 14px; }
  .cat-list { max-height: 50dvh; }
  .result-yn { font-size: 56px; }
  #toasts { bottom: max(16px, env(safe-area-inset-bottom)); width: calc(100vw - 24px); }
}
@media (max-width: 440px) {
  .brand span:last-child { display: none; }
}
@media (max-width: 380px) {
  .mode { font-size: 13px; }
}
/* màn cảm ứng: không có hover, nút nhỏ cần vùng bấm lớn hơn */
@media (hover: none) {
  .btn:hover:not(:disabled), .btn-spin:hover:not(:disabled), .choice:hover:not(:disabled), .emoji-pick:hover { transform: none; }
  .hub:hover:not(:disabled) { transform: translate(-50%, -50%); }
  .cat-mini { width: 40px; height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}


/* ================= emoji, hàng danh sách, badge ================= */
.row-emoji { flex: none; font-size: 20px; line-height: 1; width: 26px; text-align: center; }
.cell { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px; }
.badge.tag-chip { background: var(--tint-2); color: var(--chip-fg); font-weight: 700; }
.badge.mcq { background: var(--info-bg); color: var(--info-fg); }
.badge.link { background: var(--warn-bg); color: var(--warn-fg); }
.badge.diff-easy { background: var(--ok-bg); color: var(--ok-fg); }
.badge.diff-medium { background: var(--yellow-bg); color: var(--yellow-fg); }
.badge.diff-hard { background: var(--hard-bg); color: var(--hard-fg); }

.emoji-input { width: 84px !important; flex: none !important; font-size: 22px; text-align: center; padding: 6px; }
.emoji-grid { max-height: 168px; overflow-y: auto; border: 1.5px solid var(--line); border-radius: 12px; padding: 6px 8px 8px; background: var(--input-bg); }
.emoji-group { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 6px 2px 2px; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 2px; }
.emoji-pick { width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent; font-size: 21px; line-height: 1; }
.emoji-pick:hover { background: var(--tint-2); transform: scale(1.12); }
.two-col { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.advanced { border: 1.5px solid var(--line); border-radius: 12px; padding: 4px 12px 12px; }
.advanced summary { cursor: pointer; font-weight: 700; font-size: 13.5px; color: var(--accent); padding: 8px 0; }
.advanced[open] summary { margin-bottom: 4px; }

/* bộ lọc câu hỏi */
.filter { display: flex; flex-direction: column; gap: 7px; padding-top: 8px; border-top: 1px dashed var(--border-2); }
.filter .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 1.5px solid var(--border-2); background: var(--surface); color: var(--ink); font: 700 12.5px var(--font); padding: 4px 10px; border-radius: 999px; }
.chip:hover { border-color: var(--border-3); }
.chip.on { background: linear-gradient(135deg, #f0699a, #8a67f5); border-color: transparent; color: #fff; }

/* ================= popup kết quả nâng cao ================= */
.result-emoji { font-size: clamp(56px, 11vw, 92px); line-height: 1.05; animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.chain { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin-bottom: 4px; }
.chain-step { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--tint-2); color: var(--chip-fg); }
.chain-step.now { background: linear-gradient(135deg, var(--grad-a), var(--grad-b)); color: var(--ink); }
.chain-arrow { color: var(--muted); font-weight: 800; }
.q-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.result-modal.quiz { width: min(680px, 100%); }
.result-modal.quiz .result-text { font-size: clamp(20px, 3.4vw, 28px); }

.timer { display: flex; align-items: center; gap: 10px; width: min(420px, 100%); margin-top: 6px; padding: 7px 12px; border-radius: 14px; background: var(--tint-2); }
.timer-bar { flex: 1; height: 10px; border-radius: 99px; background: var(--border-2); overflow: hidden; }
.timer-bar span { display: block; height: 100%; width: 100%; border-radius: 99px; background: linear-gradient(90deg, #6bcf9d, #8a67f5); transition: width .12s linear; }
.timer-label { min-width: 62px; text-align: right; font: 800 16px var(--font); font-variant-numeric: tabular-nums; }
.timer-btn { border: 0; background: var(--surface); width: 30px; height: 30px; border-radius: 9px; box-shadow: var(--shadow-sm); }
.timer-btn:disabled { opacity: .4; }
.timer.low .timer-bar span { background: linear-gradient(90deg, #ffb347, #ee5a8a); }
.timer.low .timer-label { color: var(--danger); animation: blink 1s steps(2) infinite; }
.timer.over { background: var(--danger-bg2); }
.timer.over .timer-label { color: var(--danger); }
@keyframes blink { 50% { opacity: .35; } }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; margin-top: 8px; }
.choice {
  display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border-radius: 14px;
  border: 2px solid var(--border-2); background: var(--surface); font: 600 15.5px var(--font); color: var(--ink);
  transition: border-color .15s, background .15s, transform .08s;
}
.choice b { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 9px; background: var(--accent-soft); color: var(--accent); }
.choice span { min-width: 0; overflow-wrap: anywhere; }
.choice:hover:not(:disabled) { border-color: #a98bff; background: var(--tint-1); transform: translateY(-1px); }
.choice:disabled { cursor: default; opacity: 1; }
.choice.correct { border-color: var(--ok-border); background: var(--ok-bg); }
.choice.correct b { background: var(--ok-border); color: #fff; }
.choice.wrong { border-color: #ee7a9b; background: var(--danger-bg); }
.choice.wrong b { background: #ee7a9b; color: #fff; }
.verdict { font-weight: 800; font-size: 18px; margin-top: 4px; }
.verdict.ok { color: var(--ok-fg); }
.verdict.bad { color: var(--danger); }
.explain-label { display: block; margin-top: 8px; font-size: 12px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; }
.answer .explain { font-size: 15px; font-weight: 500; }
.result-modal .modal-actions .btn { max-width: 100%; }

/* ================= trình chiếu ================= */
.present-title { display: none; font-weight: 800; letter-spacing: .3px; }
.exit-present { display: none; position: fixed; top: 14px; right: 14px; z-index: 45; opacity: .55; transition: opacity .15s; }
.exit-present:hover { opacity: 1; }
body.presenting { overflow: hidden; }
body.presenting .topbar, body.presenting .panel, body.presenting .catbar { display: none !important; }
body.presenting .exit-present { display: inline-flex; }
body.presenting .layout { grid-template-columns: minmax(0, 1fr); padding: 6px 10px 12px; height: 100vh; }
body.presenting .stage { justify-content: center; gap: 8px; }
body.presenting .present-title { display: block; font-size: clamp(22px, 3.2vw, 40px); color: var(--ink); text-align: center; }
body.presenting .wheel-wrap { width: min(94vw, calc(100vh - 175px)); }
body.presenting .btn-spin { font-size: 28px; padding: 17px 64px; }
body.presenting .result-modal { width: min(860px, 94vw); }
body.presenting .result-text { font-size: clamp(30px, 5.6vw, 64px); }
body.presenting .result-modal.quiz .result-text { font-size: clamp(24px, 4vw, 44px); }
body.presenting .choice { font-size: clamp(16px, 2vw, 24px); padding: 14px 16px; }
body.presenting .answer p { font-size: clamp(20px, 3vw, 34px); }

@media (max-width: 620px) {
  .choices { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}

.detected { font-weight: 600; color: var(--ok); }
.detected.bad { color: var(--danger); }


/* ================= cài đặt desktop ================= */
.desktop-box h3 { margin: 0; font-size: 15px; }
.hk-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; }
.hk-plus { font-weight: 800; color: var(--muted); }
.hk-key { width: 96px !important; }

/* ================= widget mini (?mini=1) ================= */
.mini-tools { display: none; position: fixed; top: 6px; right: 6px; z-index: 40; gap: 4px; }
.mini-btn { width: 28px; height: 28px; border: 0; border-radius: 9px; background: var(--surface-a); color: var(--muted); font-size: 14px; box-shadow: var(--shadow-sm); }
.mini-btn:hover { color: var(--ink); background: var(--surface); }
body.mini { overflow: hidden; user-select: none; }
body.mini .mini-tools { display: flex; }
body.mini .topbar, body.mini .panel, body.mini .catbar, body.mini #dbBanner,
body.mini #shuffleBtn, body.mini #orderReset, body.mini #undoBtn, body.mini #keepBtn, body.mini kbd { display: none !important; }
body.mini .layout { grid-template-columns: minmax(0, 1fr); padding: 4px 8px 10px; height: 100vh; }
body.mini .stage { justify-content: center; gap: 4px; }
body.mini .present-title { display: block; font-size: 16px; text-align: center; color: var(--ink); padding: 0 36px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
body.mini .wheel-wrap { width: min(calc(100vw - 16px), calc(100vh - 118px)); min-width: 200px; }
body.mini .btn-spin { font-size: 19px; padding: 11px 38px; }
body.mini .result-modal { width: min(94vw, 420px); }
body.mini .result-text { font-size: clamp(22px, 7vw, 34px); }
body.mini .empty-card { padding: 14px 16px; }
body.mini .empty-title { font-size: 16px; }
body.mini .hub { font-size: 12px; }

/* ================= đổi giao diện sáng / tối ================= */
.theme-toggle { min-width: 42px; padding-left: 12px; padding-right: 12px; font-size: 16px; line-height: 1; }
body, .panel, .modal, .btn, .row, .cat-row, .choice, .input { transition: background-color .25s, color .25s, border-color .25s; }

/* ================= đăng nhập / đăng ký ================= */
.auth-screen { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: linear-gradient(160deg, var(--bg1), var(--bg2)); }
body:not(.auth) .auth-screen { display: none; }
body.auth { overflow: hidden; }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 24px 22px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 24px; font-weight: 800; }
.auth-card .hint.center { margin: 6px 0 16px; }
.auth-card .btn.primary { padding: 12px 16px; font-size: 15px; }

/* ================= footer ================= */
.site-footer { text-align: center; font-size: 12.5px; color: var(--muted); padding: 4px 16px max(14px, env(safe-area-inset-bottom)); }
.site-footer strong { color: var(--accent); font-weight: 700; }
body.presenting .site-footer, body.mini .site-footer { display: none; }
.auth-footer { margin: 18px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
