:root {
  --bg: #0d0f14;
  --bg2: #151821;
  --card: #1b1f2a;
  --card2: #232836;
  --line: #2e3445;
  --text: #f2f4f8;
  --muted: #9aa3b5;
  --accent: #ff3b30;
  --accent2: #ffd60a;
  --good: #30d158;
  --radius: 14px;
  --head: 'Saira Condensed', 'Arial Narrow', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -200px, #2a1216 0%, transparent 60%),
    repeating-linear-gradient(135deg, transparent 0 22px, rgba(255,255,255,.012) 22px 44px),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
h1, h2, h3 { font-family: var(--head); letter-spacing: .02em; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--card2); border-radius: 12px;
  padding: 10px 14px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; justify-content: center;
  transition: transform .08s, background .15s; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.gold { background: var(--accent2); border-color: var(--accent2); color: #111; }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 22px; font-size: 18px; font-family: var(--head); font-weight: 800; letter-spacing: .06em; text-transform: uppercase; border-radius: 14px; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--card2); }

input[type=text], select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%;
  outline: none;
}
input[type=text]:focus, select:focus { border-color: var(--accent); }

/* home */
.home { max-width: 460px; margin: 0 auto; padding: 48px 16px 32px; display: grid; gap: 22px; }
.logo { text-align: center; }
.logo h1 { font-size: 56px; line-height: .9; font-weight: 800; text-transform: uppercase; font-style: italic; }
.logo h1 span { color: var(--accent); }
.logo p { margin: 8px 0 0; color: var(--muted); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.panel h2 { font-size: 20px; text-transform: uppercase; }
.code-input { text-transform: uppercase; letter-spacing: .5em; font-family: var(--head); font-weight: 800; font-size: 26px !important; text-align: center; }
.strip { display: flex; gap: 6px; overflow: hidden; border-radius: 12px; height: 70px; }
.strip img { height: 100%; flex: 1; object-fit: cover; min-width: 0; filter: saturate(1.1); }

/* room */
.room { max-width: 1100px; margin: 0 auto; padding: 10px 16px 120px; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 6px 0 10px; }
.code-chip {
  font-family: var(--head); font-weight: 800; font-size: 26px; letter-spacing: .18em; padding: 2px 12px;
  background: var(--accent2); color: #111; border-radius: 10px; border: 0;
}
.players { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; min-width: 0; }
.pl { display: inline-flex; align-items: center; gap: 5px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px 3px 4px; font-size: 13px; }
.pl .dot { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #111; }
.pl.off { opacity: .45; }
.pl .crown { color: var(--accent2); font-size: 12px; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 14px; }
.step { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; text-align: left; display: grid; gap: 0; min-width: 0; }
.step b { font-family: var(--head); font-size: 17px; text-transform: uppercase; letter-spacing: .04em; }
.step span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step.on { border-color: var(--accent); background: linear-gradient(180deg, #2a1517, var(--card)); }
.step.done span { color: var(--good); }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 380px); gap: 18px; align-items: start; }
@media (max-width: 860px) { .stage { grid-template-columns: 1fr; } }
.wheel-box { position: relative; display: grid; place-items: center; }
.wheel-box canvas { width: min(100%, 560px); aspect-ratio: 1; touch-action: manipulation; }
.pointer {
  position: absolute; top: -4px; left: 50%; transform: translateX(-50%); width: 0; height: 0;
  border-left: 16px solid transparent; border-right: 16px solid transparent; border-top: 30px solid var(--accent2);
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.6)); z-index: 2;
}
.wheel-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 30%; color: var(--muted); pointer-events: none; }
.controls { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.votes-left { text-align: center; font-size: 13px; color: var(--muted); margin-top: 6px; }

.side h3 { font-size: 18px; text-transform: uppercase; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.entries { display: grid; gap: 6px; }
.entry { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.entry .thumb { width: 64px; height: 44px; border-radius: 8px; overflow: hidden; flex: none; background: var(--card2); }
.entry .thumb img { width: 100%; height: 100%; object-fit: cover; }
.entry .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voters { display: flex; gap: 2px; margin-top: 2px; }
.voters i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.entry.mine { border-color: #4a3a12; }
.entry.win { border-color: var(--accent2); box-shadow: 0 0 0 1px var(--accent2) inset; }
.empty-list { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }

/* result */
.result { margin-top: 18px; background: var(--card); border: 1px solid var(--accent2); border-radius: 18px; overflow: hidden; animation: pop .5s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.result .hero { position: relative; aspect-ratio: 16/7; background: var(--card2); }
.result .hero img { width: 100%; height: 100%; object-fit: cover; }
.result .hero .label { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 16px 12px; background: linear-gradient(transparent, rgba(0,0,0,.85)); }
.result .hero .label small { color: var(--accent2); font-family: var(--head); text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }
.result .hero .label h2 { font-size: 34px; line-height: 1; text-transform: uppercase; }
.result .body { padding: 14px 16px 16px; display: grid; gap: 12px; }

/* summary */
.summary { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.sum-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.sum-card .hero { aspect-ratio: 16/8; background: var(--card2); position: relative; }
.sum-card .hero img { width: 100%; height: 100%; object-fit: cover; }
.sum-card .pad { padding: 12px 14px 14px; display: grid; gap: 8px; }
.sum-card h2 { font-size: 26px; text-transform: uppercase; line-height: 1.05; }
.kicker { font-family: var(--head); text-transform: uppercase; letter-spacing: .14em; font-size: 13px; color: var(--accent2); font-weight: 700; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.stat { background: var(--bg2); border-radius: 10px; padding: 7px 9px; min-width: 0; }
.stat small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.bars { display: inline-flex; gap: 2px; vertical-align: middle; }
.bars i { width: 9px; height: 9px; border-radius: 2px; background: var(--line); }
.bars i.on { background: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 500; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--card2); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tag.dlc { background: #2a2140; color: #c9b6ff; }
.tag.fit { background: #13301c; color: #7dffa0; }

.advice { display: grid; gap: 6px; }
.adv { display: flex; gap: 10px; align-items: center; background: var(--bg2); border-radius: 12px; padding: 6px; border: 1px solid transparent; text-align: left; width: 100%; }
.adv:hover { border-color: var(--line); }
.adv .thumb { width: 72px; height: 46px; border-radius: 8px; overflow: hidden; flex: none; background: var(--card2); }
.adv .thumb img { width: 100%; height: 100%; object-fit: cover; }
.adv b { display: block; }
.adv span { font-size: 12px; color: var(--muted); }
.cond { background: var(--bg2); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.cond .big { font-family: var(--head); font-size: 22px; font-weight: 700; }
.slots { display: flex; gap: 4px; flex-wrap: wrap; }
.slots span { background: var(--card2); padding: 3px 8px; border-radius: 6px; font-size: 12px; }
.rolled { font-family: var(--head); font-size: 26px; font-weight: 800; color: var(--accent2); text-transform: uppercase; }

/* modals */
.modal-bg { position: fixed; inset: 0; background: rgba(4,5,8,.72); backdrop-filter: blur(3px); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
@media (min-width: 760px) { .modal-bg { align-items: center; padding: 24px; } }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 20px 20px 0 0; width: 100%; max-width: 1040px; max-height: 94dvh; display: flex; flex-direction: column; overflow: hidden; animation: up .2s ease-out; }
.modal.narrow { max-width: 680px; }
@media (min-width: 760px) { .modal { border-radius: 20px; max-height: 90dvh; } }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 22px; text-transform: uppercase; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-body { overflow-y: auto; padding: 12px 14px 20px; overscroll-behavior: contain; }
.modal-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.filters { display: grid; gap: 10px; margin-bottom: 12px; }
.filter-row { display: grid; gap: 4px; }
.filter-row > small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.range { display: flex; gap: 8px; align-items: center; }
.range input[type=range] { flex: 1; accent-color: var(--accent); }
.range output { font-size: 12px; color: var(--muted); min-width: 60px; text-align: right; }
.more-filters summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 4px 0; list-style: none; }
.more-filters summary::before { content: '▸ '; }
.more-filters[open] summary::before { content: '▾ '; }
.more-filters[open] > div { margin-top: 10px; display: grid; gap: 10px; }
.result-count { font-size: 13px; color: var(--muted); margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
@media (max-width: 480px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; text-align: left; padding: 0; display: flex; flex-direction: column; position: relative; transition: border-color .15s, transform .1s; }
.card:hover { border-color: #4a5266; }
.card:active { transform: scale(.98); }
.card .pic { aspect-ratio: 16/10; background: var(--card2); position: relative; overflow: hidden; }
.card .pic img { width: 100%; height: 100%; object-fit: cover; }
.card .flag { position: absolute; top: 6px; left: 6px; font-size: 20px; line-height: 1; filter: drop-shadow(0 1px 2px #000); }
.card .badge { position: absolute; top: 6px; right: 6px; background: var(--accent2); color: #111; font-weight: 700; font-size: 12px; border-radius: 999px; padding: 2px 8px; }
.card .info { padding: 8px 10px 10px; display: grid; gap: 3px; }
.card .info b { font-size: 15px; line-height: 1.2; }
.card .info span { font-size: 12px; color: var(--muted); }
.card .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }

.placeholder { width: 100%; height: 100%; display: grid; place-items: center; text-align: center; padding: 8px; font-family: var(--head); font-weight: 800; font-size: clamp(14px, 4cqi, 30px); line-height: 1; text-transform: uppercase; color: rgba(255,255,255,.55); container-type: inline-size; position: relative; }
.placeholder::before { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(45deg, transparent 0 10px, rgba(255,255,255,.035) 10px 20px); }
.placeholder span { font-size: clamp(11px, 12cqi, 30px); }

.detail-hero { position: relative; aspect-ratio: 16/8; margin: -12px -14px 12px; background: var(--card2); }
.detail-hero img { width: 100%; height: 100%; object-fit: cover; }
.detail-hero.contain img { object-fit: contain; background: #fff; }
.section { margin: 16px 0 8px; font-family: var(--head); font-size: 18px; text-transform: uppercase; letter-spacing: .04em; }
.layout-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.layout-tabs .chip { white-space: nowrap; }
.car-list { display: grid; gap: 6px; }
.car { display: flex; gap: 10px; align-items: center; background: var(--card); border-radius: 10px; padding: 6px; }
.car .thumb { width: 76px; height: 48px; border-radius: 8px; overflow: hidden; flex: none; background: var(--card2); }
.car .thumb img { width: 100%; height: 100%; object-fit: cover; }
.car b { display: block; font-size: 14px; }
.car span { font-size: 12px; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(120px); background: #2b2f3b; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 100; transition: transform .25s; max-width: calc(100vw - 32px); }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--accent); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.settings-grid { display: grid; gap: 14px; }
.player-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.switch { display: flex; gap: 6px; }
