:root {
  --bg: #0d0f0e;
  --bg2: #141716;
  --panel: #191d1b;
  --panel2: #202523;
  --line: #2a302d;
  --text: #ece6d6;          /* board cream */
  --mute: #8d9590;
  --red: #d83a34;
  --red-d: #8f1f1b;
  --green: #2f8a57;
  --green-d: #1b5536;
  --gold: #e8b64c;
  --blue: #4aa3df;
  --sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; }

.view { position: fixed; inset: 0; }

/* subtle felt texture: layered radial noise */
#view-auth, #view-shell {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(216,58,52,.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(47,138,87,.10), transparent 60%),
    var(--bg);
}

/* ───────── buttons / inputs ───────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 12px; font-weight: 700; letter-spacing: .01em;
  border: 1px solid var(--line); background: var(--panel2); transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--red); border-color: transparent; color: #fff; box-shadow: 0 6px 24px -8px rgba(216,58,52,.7); }
.btn.go { background: var(--green); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  background: rgba(13,15,14,.55); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.07); }
.icon-btn svg { width: 22px; height: 22px; }

label { display: block; font-size: 13px; color: var(--mute); font-weight: 500; }
label input { display: block; width: 100%; margin-top: 6px; padding: 13px 14px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text); font-size: 16px; outline: none; }
label input:focus { border-color: var(--red); }

.seg { display: flex; padding: 4px; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.seg button { flex: 1; padding: 9px 8px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--mute); }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 -2px 0 var(--red); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; }

/* ───────── auth ───────── */
.auth-wrap { height: 100%; overflow: auto; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 28px 20px; gap: 26px; }
.brand-big { text-align: center; }
.brand-mark { width: 64px; height: 64px; color: var(--text); }
.brand-mark.sm { width: 22px; height: 22px; }
.brand-big h1 { font-family: var(--mono); font-weight: 800; font-size: 44px; letter-spacing: .28em; margin: 10px 0 6px 0.28em; }
.brand-big p { color: var(--mute); max-width: 260px; margin: 0 auto; line-height: 1.4; }
.auth-card { width: 100%; max-width: 380px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.auth-card:not(.signup) .only-signup { display: none; }
.form-msg { color: #ff8a80; font-size: 14px; min-height: 0; }
.form-msg:empty { display: none; }
.first-note { font-size: 13px; color: var(--gold); text-align: center; }

/* ───────── shell ───────── */
#view-shell { display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(12px + var(--safe-t)) 18px 10px; }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--mono); font-weight: 800; letter-spacing: .22em; font-size: 15px; }
.conn { width: 7px; height: 7px; border-radius: 50%; background: var(--mute); margin-right: auto; transition: background .3s; }
.conn.on { background: var(--green); box-shadow: 0 0 10px var(--green); }
.me-chip { font-size: 13px; font-weight: 700; color: var(--mute); padding: 6px 10px; border: 1px solid var(--line); border-radius: 99px; }

#page { flex: 1; overflow-y: auto; padding: 6px 16px calc(96px + var(--safe-b)); max-width: 720px; width: 100%; margin: 0 auto; }

.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b));
  display: flex; gap: 2px; padding: 6px; border-radius: 22px; background: rgba(25,29,27,.82);
  backdrop-filter: blur(16px); border: 1px solid var(--line); box-shadow: 0 12px 40px -10px #000; }
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 16px;
  border-radius: 16px; color: var(--mute); font-size: 11px; font-weight: 700; }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--text); background: var(--panel2); }
.tabbar a.on svg { color: var(--red); }
.badge { position: absolute; top: 4px; right: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--red); color: #fff; font: 700 11px/18px var(--mono); font-style: normal; text-align: center; }
.badge:empty { display: none; }

.page-h { display: flex; align-items: baseline; justify-content: space-between; margin: 14px 2px 12px; }
.page-h h2 { font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.sect { margin: 22px 2px 10px; font: 700 11px var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--mute);
  display: flex; align-items: center; gap: 10px; }
.sect::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.sect.hot { color: var(--red); }
.empty { color: var(--mute); padding: 26px 8px; text-align: center; line-height: 1.5; }
.empty b { color: var(--text); }

/* ───────── match rows: scoreboard strips ───────── */
.mrow { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 14px 16px;
  margin-bottom: 10px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line);
  position: relative; overflow: hidden; }
.mrow::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line); }
.mrow.turn::before { background: var(--red); box-shadow: 0 0 18px var(--red); }
.mrow.turn { border-color: rgba(216,58,52,.45); background: linear-gradient(90deg, rgba(216,58,52,.10), var(--panel) 45%); }
.mrow.won::before { background: var(--green); }
.mrow.lost::before { background: #555; }
.mrow .who { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mrow .who b { font-size: 17px; display: flex; align-items: center; gap: 7px; }
.mrow .who small { color: var(--mute); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #444; flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.mrow .scores { font-family: var(--mono); font-weight: 800; font-size: 22px; display: flex; align-items: center; gap: 6px; }
.mrow .scores .vs { color: var(--mute); font-size: 13px; font-weight: 500; }
.mrow .scores .mine { color: var(--text); }
.mrow .scores .theirs { color: var(--mute); }
.mrow .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.pill { font: 700 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; padding: 3px 7px; border-radius: 6px;
  background: var(--panel2); color: var(--mute); }
.pill.red { background: rgba(216,58,52,.18); color: #ff8b84; }
.pill.green { background: rgba(47,138,87,.2); color: #7bd3a0; }
.pill.gold { background: rgba(232,182,76,.16); color: var(--gold); }
.newdot { color: var(--gold); font-weight: 700; }

/* friends */
.add-friend { display: flex; gap: 8px; }
.add-friend input { flex: 1; padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); outline: none; font-size: 16px; }
.add-friend input:focus { border-color: var(--red); }
.frow { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.frow:last-child { border-bottom: 0; }
.frow .nm { flex: 1; min-width: 0; }
.frow .nm b { display: block; font-size: 16px; }
.frow .nm small { color: var(--mute); font-size: 12px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font: 800 15px var(--mono);
  background: var(--panel2); border: 1px solid var(--line); position: relative; flex: none; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; border: 2px solid var(--panel); width: 11px; height: 11px; }
.list { padding: 0; overflow: hidden; }

/* toggles */
.toggle-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; cursor: pointer; color: var(--text); font-size: 15px; }
.toggle-row span { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.toggle-row small { color: var(--mute); font-size: 12.5px; font-weight: 400; line-height: 1.35; }
.toggle-row input { display: none; }
.switch { width: 46px; height: 28px; border-radius: 99px; background: #333; position: relative; transition: background .2s; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #ddd; transition: transform .2s; }
.toggle-row input:checked + .switch { background: var(--green); }
.toggle-row input:checked + .switch::after { transform: translateX(18px); background: #fff; }
.field-row { padding: 14px 16px; border-top: 1px solid var(--line); }
.field-row .inline { display: flex; gap: 8px; margin-top: 6px; }
.field-row .inline input { margin-top: 0; font-family: var(--mono); }
.kv { display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv span { color: var(--mute); }
.kv:last-child { border-bottom: 0; }

/* dialogs */
dialog { margin: auto; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); color: var(--text); width: min(92vw, 400px); }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg h3 { font-size: 20px; }
.dlg .toggle-row { padding: 6px 0; }
.field-label { font-size: 13px; color: var(--mute); margin-bottom: -6px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* toasts */
#toasts { position: fixed; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 16px; border-radius: 14px; background: rgba(32,37,35,.94); border: 1px solid var(--line);
  backdrop-filter: blur(12px); box-shadow: 0 10px 30px -10px #000; font-weight: 500; font-size: 14px;
  animation: tin .25s ease-out; display: flex; align-items: center; gap: 10px; }
.toast::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); flex: none; }
.toast.err::before { background: var(--red); }
.toast.out { animation: tout .25s ease-in forwards; }
@keyframes tin { from { opacity: 0; transform: translateY(-10px); } }
@keyframes tout { to { opacity: 0; transform: translateY(-10px); } }

/* ───────── match view ───────── */
#view-match { background: #070807; touch-action: none; user-select: none; -webkit-user-select: none; }
#board-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(10px + var(--safe-t)) 10px 0; pointer-events: none;
  background: linear-gradient(#070807e6, #07080700); }
.hud-top { display: flex; align-items: flex-start; gap: 8px; }
.hud-top > * { pointer-events: auto; }
.plates { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.plate { position: relative; padding: 8px 10px 9px; border-radius: 14px; background: rgba(20,23,22,.78);
  border: 1px solid rgba(255,255,255,.06); backdrop-filter: blur(10px); transition: all .3s; overflow: hidden; }
.plate .nm { font-size: 12.5px; font-weight: 700; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--mute); }
.plate .sc { font: 800 34px/1 var(--mono); letter-spacing: -.02em; margin-top: 3px; }
.plate .meta { font: 500 10.5px var(--mono); color: var(--mute); margin-top: 4px; letter-spacing: .02em; }
.plate .flight { width: 10px; height: 10px; border-radius: 3px; transform: rotate(45deg); flex: none; }
.plate.active { border-color: var(--pc); box-shadow: 0 0 0 1px var(--pc), 0 8px 30px -8px var(--pc); }
.plate.active .nm { color: var(--text); }
.plate.active::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--pc); box-shadow: 0 0 12px var(--pc); }
.plate .eye { font-size: 10px; color: var(--gold); }
.visit { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.visit .slot { min-width: 54px; padding: 6px 8px; text-align: center; border-radius: 10px; font: 800 15px var(--mono);
  background: rgba(20,23,22,.7); border: 1px dashed rgba(255,255,255,.12); color: var(--mute); }
.visit .slot.f { border-style: solid; color: var(--text); border-color: rgba(255,255,255,.14); }
.visit .slot.t { color: #ff8b84; } .visit .slot.d { color: #7bd3a0; } .visit .slot.b { color: var(--gold); }
.visit .tot { min-width: 54px; padding: 6px 8px; text-align: center; font: 800 15px var(--mono); color: var(--text); }
.checkout { text-align: center; margin-top: 8px; font: 700 12px var(--mono); color: var(--gold); letter-spacing: .06em; min-height: 16px; }

.live-chip { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-b)); padding: 6px 12px;
  border-radius: 99px; background: rgba(20,23,22,.8); border: 1px solid var(--line); font: 700 11px var(--mono); letter-spacing: .08em;
  display: flex; align-items: center; gap: 8px; pointer-events: none; white-space: nowrap; }
.live-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.banner { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); padding: 14px 26px; border-radius: 16px;
  background: rgba(13,15,14,.86); border: 1px solid var(--line); backdrop-filter: blur(10px); text-align: center; pointer-events: none;
  font-weight: 800; font-size: 22px; animation: bin .3s ease-out; }
.banner small { display: block; font: 600 12px var(--mono); color: var(--mute); margin-top: 4px; letter-spacing: .06em; }
.banner.red { border-color: var(--red); } .banner.green { border-color: var(--green); }
@keyframes bin { from { opacity: 0; transform: translate(-50%, -40%) scale(.96); } }

.hit-pop-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; transform: translate(-50%, -130%); font: 800 20px var(--mono); padding: 3px 9px; border-radius: 8px;
  background: rgba(0,0,0,.75); animation: pop 1.6s ease-out forwards; white-space: nowrap; }
.pop.t { color: #ff8b84; } .pop.d { color: #7bd3a0; } .pop.b { color: var(--gold); } .pop.m { color: var(--mute); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -90%) scale(.7); } 12% { opacity: 1; transform: translate(-50%, -130%) scale(1.08); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -190%); } }

.bottom-hint { position: absolute; left: 0; right: 0; bottom: calc(22px + var(--safe-b)); text-align: center; font-size: 13px; color: var(--mute); pointer-events: none; transition: opacity .2s; }
.power { position: absolute; left: 50%; bottom: calc(50px + var(--safe-b)); transform: translateX(-50%); width: 160px; height: 6px; border-radius: 4px;
  background: #222; overflow: hidden; opacity: 0; transition: opacity .15s; pointer-events: none; }
.power.on { opacity: 1; }
#power-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--gold), var(--red)); }

.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 72%; display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; z-index: 20;
  box-shadow: 0 -20px 50px -10px #000; animation: sup .25s ease-out; padding-bottom: var(--safe-b); }
@keyframes sup { from { transform: translateY(30%); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.sheet-head h3 { font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 0 12px 10px; }
.sheet-foot { padding: 10px 16px 14px; display: flex; gap: 10px; border-top: 1px solid var(--line); }
.lrow { display: grid; grid-template-columns: 30px 1fr auto auto; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.lrow .no { font: 600 11px var(--mono); color: var(--mute); }
.lrow .ds { font: 700 13px var(--mono); display: flex; gap: 8px; color: var(--text); }
.lrow .ds .t { color: #ff8b84; } .lrow .ds .d { color: #7bd3a0; } .lrow .ds .b { color: var(--gold); } .lrow .ds .m { color: var(--mute); }
.lrow .who { font-size: 12px; color: var(--mute); display: flex; align-items: center; gap: 6px; }
.lrow .vs { font: 800 15px var(--mono); text-align: right; min-width: 52px; }
.lrow .vs.bust { color: var(--red); font-size: 11px; letter-spacing: .1em; }
.lrow button { color: var(--mute); width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); }
.lrow button svg { width: 14px; height: 14px; }

.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 30; padding: 20px; }
.end-card { width: min(100%, 380px); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 24px 20px 20px; text-align: center; }
.end-kicker { font: 700 11px var(--mono); letter-spacing: .2em; color: var(--mute); }
.end-card h2 { font-size: 34px; font-weight: 800; margin: 6px 0 16px; }
.end-card.win h2 { color: var(--gold); }
.end-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.end-stats div { background: var(--bg2); border-radius: 12px; padding: 10px; }
.end-stats b { display: block; font: 800 20px var(--mono); }
.end-stats small { color: var(--mute); font-size: 11px; }
.end-actions { display: flex; gap: 10px; justify-content: center; }

.replay-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b)); z-index: 15;
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-radius: 14px; background: rgba(20,23,22,.9);
  border: 1px solid var(--gold); font-size: 13px; font-weight: 600; white-space: nowrap; }

@media (min-width: 760px) {
  .plates { max-width: 520px; margin: 0 auto; }
  .plate .sc { font-size: 42px; }
}
