/* ------------------------------------------------------------ tokens */
:root,
:root[data-theme="dark"] {
  --bg: #0e121b;
  --bg-glow: radial-gradient(120% 55% at 50% -12%, #1b2744 0%, rgba(14, 18, 27, 0) 62%);
  --surface: #161b26;
  --surface-2: #1e2431;
  --surface-3: #282f3f;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f4f6fb;
  --muted: #8a93a8;
  --primary: #2f57d6;
  --primary-2: #3a6ae6;
  --primary-soft: rgba(70, 112, 255, 0.16);
  --ring: #4f7dff;
  --hero: linear-gradient(135deg, #1c46a4 0%, #2a5fc4 55%, #3976d6 100%);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.14);
  --bad: #f05252;
  --bad-soft: rgba(240, 82, 82, 0.14);
  --warn: #f5a524;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
  --backdrop: rgba(5, 8, 14, 0.62);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f2f4f9;
  --bg-glow: radial-gradient(120% 55% at 50% -12%, #dbe5fb 0%, rgba(242, 244, 249, 0) 62%);
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --surface-3: #e1e6f0;
  --border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --muted: #64748b;
  --primary-soft: rgba(47, 87, 214, 0.1);
  --ok-soft: rgba(34, 197, 94, 0.12);
  --bad-soft: rgba(240, 82, 82, 0.12);
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.1);
  --backdrop: rgba(15, 23, 42, 0.4);
  color-scheme: light;
}

:root {
  --font-display: "Unbounded", "Onest", system-ui, sans-serif;
  --font-body: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --r-xl: 28px;
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ------------------------------------------------------------- base */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: clamp(13px, 3.85vw, 16px); }
html, body { margin: 0; padding: 0; }
body {
  overflow-x: hidden;
  min-height: 100vh;
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 500 0.9375rem/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { max-width: 560px; margin: 0 auto; padding: 14px 16px 24px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.ic {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
#i-play path { fill: currentColor; }

/* ------------------------------------------------------------ appbar */
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 18px; }
.brand { display: flex; align-items: center; gap: 12px; font: 800 1.5rem/1 var(--font-display); letter-spacing: -0.02em; }
.logo {
  width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center;
  background: var(--hero); color: #fff; font: 800 1.5rem/1 var(--font-display);
  box-shadow: 0 8px 22px rgba(47, 87, 214, 0.45);
}
.appbar-actions { display: flex; gap: 10px; align-items: center; }
.appbar-title { font: 700 1.0625rem/1 var(--font-display); }
.icon-btn, .icon-btn-space {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.icon-btn-space { visibility: hidden; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.ghost { background: transparent; border-color: transparent; }
.icon-btn.danger { color: var(--bad); }
.icon-btn.active { color: var(--warn); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); font: 700 0.875rem/1 var(--font-body);
}

/* --------------------------------------------------------- segmented */
.segmented {
  display: flex; gap: 4px; padding: 5px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
}
.segmented button {
  flex: 1; height: 42px; border: 0; border-radius: 14px; background: transparent; color: var(--muted);
  font-weight: 800; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background 0.2s, color 0.2s;
}
.segmented button.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(47, 87, 214, 0.35); }
.segmented .ic { width: 18px; height: 18px; }
.segmented.small { margin-bottom: 14px; }
.segmented.small button { height: 38px; font-size: 0.875rem; }
.segmented.inline { margin: 0; padding: 4px; border-radius: 14px; }
.segmented.inline button { height: 32px; padding: 0 12px; border-radius: 10px; font-size: 0.8125rem; }

/* -------------------------------------------------------------- hero */
.hero {
  position: relative; overflow: hidden; color: #fff;
  background: var(--hero); border-radius: var(--r-xl); padding: 24px 22px 26px; margin-bottom: 16px;
  box-shadow: 0 18px 40px rgba(28, 70, 164, 0.35);
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 99px;
  background: rgba(255, 255, 255, 0.18); font-weight: 800; font-size: 0.875rem;
}
.hero-title {
  position: relative; z-index: 1; margin: 16px 0 8px;
  font: 800 1.875rem/1.12 var(--font-display); letter-spacing: -0.02em; word-break: break-word;
}
.hero-title.sm { font-size: 1.625rem; }
.hero-sub { position: relative; z-index: 1; margin: 0; max-width: 85%; color: rgba(255, 255, 255, 0.85); font-weight: 700; }
.hero-sub.center { max-width: none; }
.hero-art {
  position: absolute; right: -26px; bottom: -30px; width: 170px; height: 170px;
  fill: none; stroke: rgba(255, 255, 255, 0.16); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
  transform: rotate(-12deg);
}

/* ------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 20px 18px; margin-bottom: 14px;
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 26px 2px 12px; }
.section-head.first { margin-top: 6px; }
.count-badge {
  min-width: 32px; height: 28px; padding: 0 10px; border-radius: 99px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font: 700 0.8125rem/1 var(--font-body);
}
.section-head h2 { margin: 0; font: 700 1.1875rem/1.2 var(--font-display); letter-spacing: -0.01em; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.empty .tile { margin: 0 auto 14px; }
.empty b { display: block; color: var(--text); font: 700 1.0625rem/1.3 var(--font-body); margin-bottom: 6px; }

/* -------------------------------------------------------- empty home */
.home-empty {
  min-height: calc(100vh - 120px); display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 8px 40px;
}
.empty-art { position: relative; width: 180px; height: 150px; margin-bottom: 26px; }
.empty-art .tile.xl { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.empty-art .float { position: absolute; width: 46px; height: 46px; border-radius: 15px; animation: bob 3.2s ease-in-out infinite; }
.empty-art .float .ic { width: 22px; height: 22px; }
.empty-art .f1 { left: 4px; top: 8px; transform: rotate(-12deg); }
.empty-art .f2 { right: 2px; bottom: 6px; transform: rotate(10deg); animation-delay: -1.6s; }
@keyframes bob { 50% { translate: 0 -8px; } }
.empty-title { margin: 0 0 10px; font: 700 1.5rem/1.2 var(--font-display); letter-spacing: -0.02em; }
.empty-sub { margin: 0 0 28px; max-width: 320px; color: var(--muted); font-weight: 500; }
.btn-wide { max-width: 320px; }

/* colored icon tiles */
.tile {
  width: 56px; height: 56px; border-radius: 18px; flex: none; display: grid; place-items: center; color: #fff;
}
.tile .ic { width: 26px; height: 26px; }
.tile.xl { width: 96px; height: 96px; border-radius: 30px; }
.tile.xl .ic { width: 44px; height: 44px; }
.tile.sm { width: 42px; height: 42px; border-radius: 14px; }
.tile.sm .ic { width: 21px; height: 21px; }
.tile.green { background: linear-gradient(145deg, #34d399, #10b981); box-shadow: 0 8px 22px rgba(16, 185, 129, 0.35); }
.tile.gold { background: linear-gradient(145deg, #fbbf24, #e39b06); box-shadow: 0 8px 22px rgba(227, 155, 6, 0.35); }
.tile.orange { background: linear-gradient(145deg, #fb923c, #f26b1d); box-shadow: 0 8px 22px rgba(242, 107, 29, 0.35); }
.tile.sky { background: linear-gradient(145deg, #38bdf8, #0b93e0); box-shadow: 0 8px 22px rgba(11, 147, 224, 0.35); }
.tile.pink { background: linear-gradient(145deg, #fb7185, #e9475d); box-shadow: 0 8px 22px rgba(233, 71, 93, 0.35); }
.tile.violet { background: linear-gradient(145deg, #a78bfa, #7656ee); box-shadow: 0 8px 22px rgba(118, 86, 238, 0.35); }
.tile.blue { background: linear-gradient(145deg, #5b8cff, #2f57d6); box-shadow: 0 8px 22px rgba(47, 87, 214, 0.38); }
.tile.white { background: #fff; color: var(--primary); }

/* ------------------------------------------------------------ banner */
.banner {
  display: flex; align-items: center; gap: 12px; padding: 14px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid rgba(245, 165, 36, 0.4); border-radius: var(--r-lg);
}
.banner-text { flex: 1; min-width: 0; }
.banner-text b { display: block; }
.banner-text span { display: block; color: var(--muted); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  height: 58px; padding: 0 18px; border: 0; border-radius: 18px;
  font-weight: 800; font-size: 1.0625rem; transition: transform 0.12s, opacity 0.2s, background 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary {
  background: linear-gradient(180deg, var(--primary-2), var(--primary)); color: #fff;
  box-shadow: 0 10px 24px rgba(47, 87, 214, 0.38);
}
.btn-soft { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-chip { width: auto; height: 40px; padding: 0 14px; border-radius: 12px; font-size: 0.875rem; background: var(--primary); color: #fff; }
.btn-row { display: flex; gap: 10px; margin: 14px 0; }
.btn-row .btn { font-size: 0.9688rem; padding: 0 12px; white-space: nowrap; }
.btn .ic { width: 20px; height: 20px; }

.bottom-spacer { height: calc(96px + var(--safe-b)); }
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.bottom-bar .btn { max-width: 528px; margin: 0 auto; display: flex; }

/* ------------------------------------------------------------- forms */
.form-card { padding: 22px 18px; }
.field + .field, .field + .more, .more .field { margin-top: 22px; }
.label { display: block; margin-bottom: 10px; color: var(--muted); font-weight: 800; font-size: 0.875rem; }
.label .opt {
  margin-left: 6px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2);
  font-size: 0.6875rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
}
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.label-row .label { margin: 0; }
.label-row > b { font: 700 0.9375rem/1 var(--font-body); }
.hint { margin: -2px 0 0; color: var(--muted); font-size: 0.8125rem; font-weight: 600; }

input[type="text"], input[type="number"], textarea {
  width: 100%; background: var(--surface-2); border: 1.5px solid transparent; border-radius: var(--r-md);
  padding: 15px 16px; outline: none; font-weight: 700; transition: border-color 0.2s;
}
input::placeholder, textarea::placeholder { color: var(--muted); font-weight: 600; opacity: 0.8; }
input:focus, textarea:focus { border-color: var(--ring); }
textarea { resize: vertical; font: 600 0.8438rem/1.5 var(--font-mono); }
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
input[type="number"] { -moz-appearance: textfield; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  min-width: 48px; height: 44px; padding: 0 15px; border: 1.5px solid transparent; border-radius: 14px;
  background: var(--surface-2); font-weight: 800; transition: background 0.2s, color 0.2s;
}
.chips button.active { background: var(--primary); color: #fff; }
.chips button:disabled { opacity: 0.35; }
.chips.sm { gap: 6px; }
.chips.sm button { min-width: 0; height: 34px; padding: 0 12px; border-radius: 10px; font-size: 0.8438rem; }
.chip-input { width: 84px !important; height: 44px; padding: 0 10px !important; text-align: center; border-radius: 14px !important; }
.chip-input.active { border-color: var(--ring) !important; }

/* range */
.range-box { display: flex; align-items: center; gap: 14px; }
.range-box b { min-width: 52px; text-align: right; font: 700 1rem/1 var(--font-body); }
input[type="range"] {
  -webkit-appearance: none; appearance: none; flex: 1; height: 8px; border-radius: 99px; outline: none;
  background: linear-gradient(to right, var(--primary) var(--fill, 60%), var(--surface-3) var(--fill, 60%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: 5px solid var(--primary); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 5px solid var(--primary);
}

/* switch */
.switch { position: relative; width: 54px; height: 32px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); transition: background 0.2s; }
.switch span::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); transition: transform 0.2s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(22px); }

/* order choice */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 14px; border-radius: var(--r-lg); background: var(--surface-2); border: 1.5px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}
.choice .tile { margin-bottom: 8px; }
.choice b { font: 700 0.9375rem/1.2 var(--font-body); }
.choice small { color: var(--muted); font-weight: 700; font-size: 0.8125rem; }
.choice.active { border-color: var(--ring); background: var(--primary-soft); }

/* more settings */
.more { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 16px; }
.more summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between;
  color: var(--muted); font-weight: 800; cursor: pointer;
}
.more summary::-webkit-details-marker { display: none; }
.more summary .ic { width: 18px; height: 18px; transition: transform 0.2s; }
.more[open] summary .ic { transform: rotate(90deg); }

/* template example */
.edit-qinfo { margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.edit-qinfo .hint { margin: 0 0 12px; }
.edit-qinfo .segmented { margin-bottom: 0; }
.tpl-example {
  margin: 10px 0 14px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-2);
  font: 600 0.7188rem/1.5 var(--font-mono); color: var(--muted); white-space: pre-wrap; max-height: 140px; overflow: auto;
}

/* dropzone */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 26px 16px; border-radius: var(--r-lg); border: 2px dashed var(--surface-3); background: var(--surface-2);
  cursor: pointer; transition: border-color 0.2s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--ring); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone .tile { margin-bottom: 8px; }
.dropzone b { font-weight: 800; word-break: break-all; }
.dropzone small { color: var(--muted); font-weight: 700; }
.dropzone.has-file { border-style: solid; border-color: var(--ok); }

/* parse preview */
.preview { margin-top: 14px; padding: 14px; border-radius: var(--r-lg); background: var(--surface-2); }
.preview.ok { box-shadow: inset 0 0 0 1.5px rgba(34, 197, 94, 0.5); }
.preview.bad { box-shadow: inset 0 0 0 1.5px rgba(240, 82, 82, 0.5); }
.preview-head { display: flex; align-items: center; gap: 12px; }
.preview-head b { display: block; font: 700 1rem/1.25 var(--font-body); }
.preview-head span { color: var(--muted); font-size: 0.8125rem; font-weight: 700; }
.preview-q { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.875rem; }
.preview-q p { margin: 0 0 6px; font-weight: 800; }
.preview-q li { color: var(--muted); }
.preview-q li.ok { color: var(--ok); font-weight: 800; }
.preview-q ol { margin: 0; padding-left: 20px; }
.preview-errors { margin: 12px 0 0; padding: 10px 12px; border-radius: var(--r-sm); background: var(--bad-soft); color: var(--bad); font-size: 0.8125rem; }
.preview-errors div + div { margin-top: 2px; }

/* ------------------------------------------------------------- lists */
.list { display: flex; flex-direction: column; gap: 12px; }
.q-card {
  display: flex; align-items: center; gap: 14px; padding: 16px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  transition: transform 0.12s;
}
.q-card:active { transform: scale(0.985); }
.q-card .info { flex: 1; min-width: 0; }
.q-card .info b {
  display: block; font: 700 0.9688rem/1.3 var(--font-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.q-card .info span { display: block; margin-top: 4px; color: var(--muted); font-size: 0.8125rem; font-weight: 700; }
.q-card > .ic { color: var(--muted); }
.score-tile {
  width: 56px; height: 56px; border-radius: 18px; flex: none; display: grid; place-items: center;
  color: #fff; font: 700 0.9375rem/1 var(--font-body);
}
.score-tile.ok { background: linear-gradient(145deg, #34d399, #10b981); }
.score-tile.bad { background: linear-gradient(145deg, #fb7185, #e9475d); }
.score-tile.neutral { background: linear-gradient(145deg, #5b8cff, #2f57d6); }
.create-card { border-style: dashed; border-width: 2px; background: transparent; justify-content: center; color: var(--muted); font-weight: 800; }

/* ------------------------------------------------------------- bento */
.bento { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.b-cell {
  display: flex; flex-direction: column; gap: 14px; padding: 18px; min-height: 140px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl);
}
.b-cell b { display: block; font: 700 1.375rem/1.1 var(--font-body); letter-spacing: -0.01em; }
.b-cell > div > span { color: var(--muted); font-weight: 700; font-size: 0.875rem; }
.b-cell.wide { grid-column: span 2; min-height: 0; flex-direction: row; align-items: center; }

/* ------------------------------------------------------------ detail */
.detail-hero { padding: 18px 20px 20px; margin-bottom: 12px; }
.pill.sm { padding: 5px 12px; font-size: 0.7812rem; }
.hero-title.xs {
  font-size: 1.25rem; margin: 12px 0 6px; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.hero-title.xs.long { font-size: 1.06rem; line-height: 1.2; }
.detail-hero .hero-sub { font-size: 0.875rem; }
.detail-hero .hero-art { width: 130px; height: 130px; right: -18px; bottom: -26px; }
.info-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 12px 6px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.info-item { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; min-width: 0; }
.info-item .ic { width: 18px; height: 18px; }
.info-item b { font: 700 0.875rem/1.1 var(--font-body); white-space: nowrap; }
.info-item span { color: var(--muted); font-size: 0.7188rem; font-weight: 600; }
.info-item + .info-item { border-left: 1px solid var(--border); }
.c-blue { color: #5b8cff; } .c-sky { color: #38bdf8; } .c-green { color: #34d399; } .c-violet { color: #a78bfa; }
.info-note { margin: -2px 4px 10px; color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.invite {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; margin-bottom: 18px; text-align: left;
  background: var(--surface); border: 1px dashed rgba(52, 211, 153, 0.45); border-radius: var(--r-lg);
}
.invite:active { transform: scale(0.99); }
.invite-text { flex: 1; min-width: 0; }
.invite-text b { display: block; font: 700 0.9062rem/1.25 var(--font-body); }
.invite-text span { display: block; color: var(--muted); font-size: 0.7812rem; font-weight: 600; }
.invite > .ic { color: var(--muted); }

.lb-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.lb-row.me { border-color: var(--ring); background: var(--primary-soft); }
.lb-rank {
  width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 50%;
  color: var(--muted); font: 700 0.8125rem/1 var(--font-body);
}
.lb-rank.r1 { background: linear-gradient(145deg, #fde68a, #f5b40b); color: #5a3d00; }
.lb-rank.r2 { background: linear-gradient(145deg, #e5e7eb, #a8b0bd); color: #2b303a; }
.lb-rank.r3 { background: linear-gradient(145deg, #f3c39b, #c98247); color: #4a2a10; }
.lb-avatar {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 14px;
  color: #fff; font: 700 0.875rem/1 var(--font-body);
}
.lb-avatar.blue { background: linear-gradient(145deg, #5b8cff, #2f57d6); }
.lb-avatar.green { background: linear-gradient(145deg, #34d399, #10b981); }
.lb-avatar.orange { background: linear-gradient(145deg, #fb923c, #f26b1d); }
.lb-avatar.sky { background: linear-gradient(145deg, #38bdf8, #0b93e0); }
.lb-avatar.pink { background: linear-gradient(145deg, #fb7185, #e9475d); }
.lb-avatar.violet { background: linear-gradient(145deg, #a78bfa, #7656ee); }
.lb-avatar.gold { background: linear-gradient(145deg, #fbbf24, #e39b06); }
.lb-info { flex: 1; min-width: 0; }
.lb-info b { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-info span { color: var(--muted); font-size: 0.7812rem; font-weight: 600; }
.lb-score { font: 700 1rem/1 var(--font-body); }
.lb-score.ok { color: var(--ok); } .lb-score.bad { color: var(--bad); }
.list-empty { padding: 26px 16px; text-align: center; color: var(--muted); font-weight: 600; }
.list-empty b { display: block; margin-bottom: 4px; color: var(--text); font: 700 0.9375rem/1.3 var(--font-body); }
.q-card .owner { color: var(--ring); }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
#d-tabs { margin-bottom: 0; }
.action-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px; text-align: left;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--r-lg);
  transition: transform 0.12s, border-color 0.2s, background 0.2s;
}
.action-card:active { transform: scale(0.98); }
.action-card .tile { margin-bottom: 6px; }
.action-card b { font: 700 0.9375rem/1.25 var(--font-body); }
.action-card small { color: var(--muted); font-size: 0.78rem; font-weight: 600; line-height: 1.3; }
.appbar-center { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.appbar-center small {
  max-width: 100%; color: var(--muted); font-size: 0.8125rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* -------------------------------------------------------------- quiz */
/* Compact header: progress, meta and question strip take little height. */
.quiz-bar { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; margin: -4px -6px 8px; }
.quiz-bar .icon-btn { width: 36px; height: 36px; }
.quiz-bar .icon-btn .ic { width: 20px; height: 20px; }
.track { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.track-fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--ring)); transition: width 0.3s; }
.timer {
  display: inline-flex; align-items: center; gap: 5px; color: var(--muted);
  font: 700 0.875rem/1 var(--font-mono); font-variant-numeric: tabular-nums;
}
.timer .ic { width: 17px; height: 17px; }
.timer.low { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.quiz-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-weight: 700; font-size: 0.8125rem; margin-bottom: 8px; }
.mistakes { display: inline-flex; align-items: center; gap: 6px; }
.mistakes b { color: var(--text); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-3); transition: background 0.2s; }
.dots i.on { background: var(--bad); box-shadow: 0 0 8px rgba(240, 82, 82, 0.6); }

.q-strip {
  display: flex; gap: 6px; overflow-x: auto; padding: 3px 16px 6px; margin: 0 -16px;
  scroll-snap-type: x proximity; scrollbar-width: none;
}
.q-strip::-webkit-scrollbar { display: none; }
.q-chip {
  position: relative; flex: none; width: 38px; height: 38px; border-radius: 11px; scroll-snap-align: center;
  background: var(--surface); border: 1.5px solid var(--border); color: var(--muted); font-weight: 700; font-size: 0.875rem;
}
.q-chip.answered { background: var(--primary-soft); color: var(--text); border-color: transparent; }
.q-chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.q-chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.q-chip.current { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(47, 87, 214, 0.45); }
.q-chip.flagged::after {
  content: ""; position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn);
}
.divider { height: 1px; background: var(--border); margin: 6px 0 16px; }

.q-text { margin: 0 0 22px; font: 700 1.3125rem/1.38 var(--font-body); word-break: break-word; white-space: pre-wrap; }
.options { display: flex; flex-direction: column; gap: 12px; }
.option {
  display: flex; align-items: center; gap: 16px; width: 100%; min-height: 72px; padding: 14px 16px; text-align: left;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 20px;
  font-weight: 800; font-size: 1.0625rem; word-break: break-word; transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.option:active:not(:disabled) { transform: scale(0.99); }
.option:disabled { cursor: default; }
.option .letter {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 14px;
  background: var(--surface-2); color: var(--muted); font: 700 0.9375rem/1 var(--font-body); transition: background 0.15s, color 0.15s;
}
.option.selected { border-color: var(--ring); background: var(--primary-soft); }
.option.selected .letter { background: var(--primary); color: #fff; }
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.correct .letter { background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .letter { background: var(--bad); color: #fff; }
.option.dim { opacity: 0.55; }
.slide-in { animation: slide 0.25s ease; }
@keyframes slide { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ result */
.result-hero { text-align: center; padding-top: 28px; }
.result-hero.pass { background: linear-gradient(135deg, #0d7d45 0%, #1aa65c 60%, #2cc06e 100%); box-shadow: 0 18px 40px rgba(13, 125, 69, 0.35); }
.result-hero.fail { background: linear-gradient(135deg, #a3213a 0%, #d23d52 60%, #e85a62 100%); box-shadow: 0 18px 40px rgba(163, 33, 58, 0.35); }
.ring { --p: 0; position: relative; width: 156px; height: 156px; margin: 0 auto 16px; display: grid; place-items: center; }
.ring::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(#fff calc(var(--p) * 1%), rgba(255, 255, 255, 0.22) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 13px), #000 calc(100% - 12px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 13px), #000 calc(100% - 12px));
  transition: background 0.6s;
}
.ring-in { display: flex; flex-direction: column; align-items: center; }
.ring-in b { font: 800 2.125rem/1 var(--font-display); letter-spacing: -0.02em; }
.ring-in span { margin-top: 6px; font-size: 0.7812rem; font-weight: 800; opacity: 0.85; }
.verdict { font: 700 1.25rem/1.25 var(--font-display); margin-bottom: 6px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.stat b { display: block; font: 700 1.25rem/1.1 var(--font-body); }
.stat > div > span { color: var(--muted); font-size: 0.8125rem; font-weight: 700; }
.review-item { padding: 18px 16px; }
.review-item .q-text { font-size: 1.0625rem; margin-bottom: 14px; }
.review-item .option { min-height: 56px; font-size: 0.9375rem; padding: 10px 12px; }
.review-item .option .letter { width: 36px; height: 36px; border-radius: 12px; font-size: 0.8125rem; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 99px; font-size: 0.7812rem; font-weight: 900; margin-bottom: 12px; }
.tag .ic { width: 15px; height: 15px; stroke-width: 2.6; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.skip { background: rgba(245, 165, 36, 0.15); color: var(--warn); }

/* -------------------------------------------------------------- sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: var(--backdrop);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto;
  max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: 0;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.4);
  transform: translateY(105%); visibility: hidden;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.32s;
}
.sheet.open { transform: none; visibility: visible; transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet-head { flex: none; padding: 10px 18px 0; }
.sheet-grip { width: 40px; height: 5px; border-radius: 99px; background: var(--surface-3); margin: 0 auto 14px; }
.sheet-title { margin: 0 0 2px; font: 700 1.125rem/1.2 var(--font-display); }
.sheet-sub {
  margin: 0 0 14px; color: var(--muted); font-size: 0.875rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Only the conditions scroll; the buttons stay pinned at the bottom. */
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 18px 12px; }
.sheet-actions {
  flex: none; display: flex; gap: 10px; padding: 12px 18px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border); background: var(--surface);
}
.sheet-actions .btn { height: 50px; font-size: 0.95rem; }
.rules { display: flex; flex-direction: column; padding: 2px 14px; border-radius: var(--r-md); background: var(--surface-2); }
.rule { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.rule + .rule { border-top: 1px solid var(--border); }
.rule .ic { width: 18px; height: 18px; }
.rule .r-label { flex: 1; min-width: 0; color: var(--muted); font-size: 0.875rem; font-weight: 600; }
.rule .r-value { font: 700 0.9rem/1.2 var(--font-body); text-align: right; }
.c-pink { color: #fb7185; } .c-gold { color: #fbbf24; }
.rules-notes { margin: 12px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.rules-notes li { display: flex; gap: 8px; color: var(--muted); font-weight: 600; font-size: 0.8125rem; line-height: 1.35; }
.rules-notes li .ic { width: 16px; height: 16px; color: var(--ring); margin-top: 1px; }

/* ------------------------------------------------------------- misc */
.loader { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: var(--backdrop); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--surface-3); border-top-color: var(--ring); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); z-index: 70; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 16px;
  background: var(--surface-3); color: var(--text); font-weight: 800; font-size: 0.875rem; box-shadow: var(--shadow);
  animation: fade 0.2s ease;
}

@media (max-width: 400px) {
  #app { padding: 10px 12px 20px; }
  .card, .form-card { padding: 16px 14px; border-radius: 22px; }
  .hero { padding: 18px 16px 20px; border-radius: 22px; }
  .detail-hero { padding: 14px 16px 16px; }
  .appbar { margin-bottom: 14px; }
  .icon-btn, .icon-btn-space, .avatar { width: 42px; height: 42px; }
  .logo { width: 42px; height: 42px; border-radius: 14px; }
  .btn { height: 52px; border-radius: 16px; }
  .tile { width: 48px; height: 48px; border-radius: 15px; }
  .tile .ic { width: 22px; height: 22px; }
  .tile.sm { width: 38px; height: 38px; border-radius: 12px; }
  .tile.sm .ic { width: 19px; height: 19px; }
  .q-card, .lb-row { padding: 12px; gap: 10px; }
  .lb-avatar, .score-tile { width: 36px; height: 36px; border-radius: 12px; }
  .score-tile { width: 48px; height: 48px; }
  .info-strip { padding: 10px 2px; }
  .info-item .ic { width: 16px; height: 16px; }
  .option { min-height: 58px; padding: 10px 12px; gap: 12px; border-radius: 16px; }
  .option .letter { width: 36px; height: 36px; border-radius: 12px; }
  .chips button { height: 40px; padding: 0 12px; }
  .chip-input { height: 40px; width: 72px !important; }
  .ring { width: 132px; height: 132px; }
  .bottom-bar { padding: 10px 12px calc(10px + var(--safe-b)); }
  .bottom-spacer { height: calc(84px + var(--safe-b)); }
  .q-strip { margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
  .quiz-bar { margin: -4px -4px 8px; }
}
@media (max-width: 340px) {
  .rules, .stat-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------------------- duels */
.duel-card {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 26px 12px 22px; margin-bottom: 16px; border-radius: var(--r-xl); color: #fff;
  background: var(--hero); box-shadow: 0 18px 40px rgba(28, 70, 164, 0.35);
}
.duel-player { position: relative; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.duel-player b { max-width: 100%; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.duel-player small { font-size: 0.78rem; font-weight: 600; opacity: 0.85; }
.duel-pts { font: 700 1.5rem/1 var(--font-display); }
.lb-avatar.lg { width: 64px; height: 64px; border-radius: 22px; font-size: 1.2rem; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3); }
.lb-avatar.ghost { background: rgba(255, 255, 255, 0.14); border: 2px dashed rgba(255, 255, 255, 0.55); box-shadow: none; animation: pulse 1.4s infinite; }
.duel-player.win .lb-avatar { box-shadow: 0 0 0 3px #fbbf24, 0 0 24px rgba(251, 191, 36, 0.65); }
.duel-crown { position: absolute; top: -20px; font-size: 1.3rem; }
.duel-vs { min-width: 46px; text-align: center; font: 800 1.2rem/1 var(--font-display); opacity: 0.9; }
.duel-vs.count { font-size: 2.8rem; opacity: 1; }
.duel-status { text-align: center; margin: 0 8px 8px; }
.duel-status b { display: block; margin-bottom: 4px; font: 700 1.2rem/1.25 var(--font-display); }
.duel-status b.win { color: var(--ok); } .duel-status b.lose { color: var(--bad); }
.duel-status span { color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.duel-info { margin: 10px 8px 0; text-align: center; color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.bar-row { display: flex; gap: 10px; max-width: 528px; margin: 0 auto; }
.bar-row .btn { margin: 0; }

.duel-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 7px 10px; margin-bottom: 8px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border);
}
.db-side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.db-side.opp { flex-direction: row-reverse; text-align: right; }
.db-side div { flex: 1; min-width: 0; }
.db-side b { display: block; font-size: 0.8125rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-side small { color: var(--muted); font-size: 0.72rem; font-weight: 600; }
.db-side strong { font: 700 0.95rem/1 var(--font-display); }
.db-side.me strong { color: var(--ring); } .db-side.opp strong { color: var(--warn); }
.db-vs { color: var(--muted); font: 800 0.72rem/1 var(--font-display); }
.lb-avatar.xs { width: 28px; height: 28px; border-radius: 9px; font-size: 0.68rem; }

/* ----------------------------------------------------- safe area / swipe */
/* Telegram sets --tg-*safe-area-inset-* (fullscreen, notches); keep the
   content below the status bar and Telegram's own buttons. */
:root {
  --safe-t: max(env(safe-area-inset-top, 0px),
    calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
}
#app { padding-top: calc(18px + var(--safe-t)); }
.screen { transition: transform 0.2s ease; }
.screen.swiping { transition: none; }

/* Long brand name on very narrow phones. */
@media (max-width: 360px) {
  .brand { gap: 8px; font-size: 1.2rem; }
  .appbar-actions { gap: 6px; }
  .appbar-actions .icon-btn, .appbar-actions .avatar { width: 38px; height: 38px; }
  .logo { width: 38px; height: 38px; font-size: 1.25rem; }
}

/* ------------------------------------------------------------- promo */
/* Same look as the hero cards: pill, big headline, line, link, faded art. */
.promo {
  position: relative; overflow: hidden; display: block; margin-bottom: 14px; padding: 20px 20px 22px;
  border-radius: var(--r-xl); color: #fff; text-decoration: none;
  background: var(--hero); box-shadow: 0 18px 40px rgba(28, 70, 164, 0.35);
}
.promo:active { transform: scale(0.99); }
.promo > :not(.promo-art) { position: relative; z-index: 1; }
.promo-big { display: block; margin: 14px 0 6px; font: 800 2rem/1.05 var(--font-display); letter-spacing: -0.02em; }
.promo-sub { display: block; max-width: 80%; color: rgba(255, 255, 255, 0.88); font-size: 0.92rem; font-weight: 600; line-height: 1.4; }
.promo-link { display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 1rem; font-weight: 800; }
.promo-link .ic { width: 20px; height: 20px; }
.promo-art {
  position: absolute; right: -12px; bottom: -14px; width: 140px; height: 140px;
  fill: rgba(255, 255, 255, 0.14); transform: rotate(-8deg);
}
/* The empty home is centred below the promo. */
.home-empty { min-height: calc(100vh - 280px - var(--safe-t)); }
