:root {
  --bg: #140c26; --panel: #1e1338; --panel2: #281a48; --line: #3a2a5e;
  --text: #f4eeff; --dim: #a99cc8; --gold: #f1c75b; --gold2: #d9a531;
  --red: #ef476f; --green: #2ec4a0; --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
body { overscroll-behavior: none; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
h1, h2, .px { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; letter-spacing: .06em; text-transform: uppercase; }
h2 { font-size: 13px; color: var(--gold); margin: 0 0 10px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 12px 16px; font-weight: 700; min-height: 46px; }
.btn:active { transform: translateY(1px); }
.btn.gold { background: linear-gradient(#f6d576, var(--gold2)); color: #2a1a05; border-color: #b9851d; box-shadow: 0 3px 0 #8f6412; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; filter: grayscale(.5); }
input[type=text] { background: #100a1f; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; min-height: 46px; }
input[type=text]:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.dim { color: var(--dim); } .hint { color: var(--dim); font-size: 13px; margin: 8px 0 0; }
.tag { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); letter-spacing: .04em; }
.tag.os { background: #3b1f52; border-color: #7b4bb0; color: #e3ccff; }
.tag.warn { background: #4a3410; border-color: #b9851d; color: #ffe2a0; }
.chip { display: inline-flex; align-items: center; justify-content: center; min-width: 46px; padding: 3px 8px; border-radius: 8px; font-weight: 800; font-size: 12px; letter-spacing: .04em; }

#toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: #000d; border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- home ---------- */
.home { max-width: 460px; margin: 0 auto; padding: 16px 16px 40px; min-height: 100dvh; display: flex; flex-direction: column; gap: 12px; }
.hero { width: 100%; aspect-ratio: 16/9; border-radius: var(--radius); border: 2px solid var(--line); }
.home h1 { font-size: 24px; margin: 8px 0 0; color: var(--gold); text-shadow: 0 2px 0 #7a5410; }
.home .sub { margin: 0 0 4px; color: var(--dim); }
.row { display: flex; gap: 8px; } .row > input { flex: 1; min-width: 0; }
.note { font-size: 12px; color: var(--dim); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; }

/* ---------- top bar ---------- */
.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
  background: #140c26f2; border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
.bar .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 800; letter-spacing: .14em; color: var(--gold); }
.bar .sp { flex: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); flex: none; }
.dot.off { background: var(--red); animation: blink 1s infinite; } .dot.connecting { background: var(--gold); }
@keyframes blink { 50% { opacity: .3; } }
.purse { font-weight: 800; white-space: nowrap; }

/* ---------- lobby ---------- */
.lobby { max-width: 980px; margin: 0 auto; padding: 12px 12px 110px; display: grid; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tcard { text-align: left; border-radius: 12px; border: 2px solid transparent; padding: 10px; background: var(--panel2); display: grid; gap: 4px; min-height: 84px; }
.tcard.mine { border-color: var(--gold); box-shadow: 0 0 0 2px #f1c75b33; }
.tcard .who { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcard .nums { font-size: 12px; }
.hosts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.hcard { display: flex; gap: 10px; align-items: center; text-align: left; background: var(--panel2); border: 2px solid var(--line); border-radius: 12px; padding: 8px; }
.hcard.sel { border-color: var(--gold); }
.hcard canvas { width: 55px; height: 60px; border-radius: 8px; flex: none; }
.hcard b { display: block; } .hcard span { font-size: 12px; color: var(--dim); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 12px; min-height: 38px; font-weight: 700; color: var(--dim); }
.seg button.on { background: var(--gold); color: #2a1a05; }
.seg button:disabled { cursor: default; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; flex-wrap: wrap; }
.people { display: flex; flex-wrap: wrap; gap: 6px; }
.person { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); }
.person.off { opacity: .45; }
.cta { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 35%); z-index: 15; }
.cta .btn { width: 100%; max-width: 956px; margin: 0 auto; display: block; font-size: 17px; }

/* ---------- live ---------- */
.live { display: flex; flex-direction: column; gap: 10px; padding: 10px 10px 20px; max-width: 1280px; margin: 0 auto; }
.stage { order: 1; display: grid; gap: 10px; }
.teams { order: 2; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.side { order: 3; }
.trow { flex: none; width: 128px; text-align: left; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 7px 8px; display: grid; gap: 3px; }
.trow.lead { border-color: var(--gold); background: #33240f; }
.trow.me { box-shadow: inset 0 0 0 1px #ffffff55; }
.trow.out { opacity: .4; }
.trow .o { font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow .m { font-size: 12px; font-weight: 700; display: flex; justify-content: space-between; }
.host { display: flex; gap: 10px; align-items: flex-start; }
.host canvas { width: 55px; height: 60px; border-radius: 10px; border: 2px solid var(--line); flex: none; }
.bubble { position: relative; background: #fff8e6; color: #2a1a05; border-radius: 12px; padding: 9px 12px; font-weight: 600; min-height: 42px; flex: 1; }
.bubble::before { content: ''; position: absolute; left: -7px; top: 16px; border: 7px solid transparent; border-right-color: #fff8e6; border-left: 0; }
.card { position: relative; background: linear-gradient(160deg, #2b1c50, #1b1233); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; overflow: hidden; }
.card .lotno { font-size: 11px; color: var(--dim); letter-spacing: .1em; }
.card .pname { font-size: 26px; font-weight: 800; line-height: 1.1; margin: 4px 0 6px; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.stars { color: var(--gold); letter-spacing: 2px; font-size: 13px; }
.bidline { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: 14px; }
.bidline .lbl { font-size: 11px; color: var(--dim); letter-spacing: .1em; text-transform: uppercase; }
.bidline .amt { font-size: 38px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.bidline .amt.pop { animation: pop .25s; }
@keyframes pop { 40% { transform: scale(1.12); color: var(--gold); } }
.stamp { position: absolute; right: 12px; top: 12px; font-family: ui-monospace, Menlo, monospace; font-weight: 900; font-size: 20px; letter-spacing: .12em; padding: 4px 10px; border: 3px solid; border-radius: 8px; transform: rotate(8deg); animation: stamp .3s; }
.stamp.sold { color: var(--green); } .stamp.unsold { color: var(--red); }
@keyframes stamp { from { transform: rotate(8deg) scale(2.2); opacity: 0; } }
.timer { height: 12px; border-radius: 99px; background: #0d0718; border: 1px solid var(--line); overflow: hidden; position: relative; }
#tbar { height: 100%; width: 0; background: var(--green); border-radius: 99px; }
#tbar.hot { background: var(--red); }
.bidbox { position: sticky; bottom: 0; z-index: 10; background: linear-gradient(transparent, var(--bg) 22%); padding: 12px 0 calc(8px + env(safe-area-inset-bottom)); display: grid; gap: 6px; }
.btn.big { width: 100%; min-height: 64px; font-size: 22px; font-weight: 900; letter-spacing: .02em; }
.why { text-align: center; font-size: 13px; color: var(--dim); min-height: 18px; }
.hostctl { display: flex; gap: 8px; justify-content: center; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button { flex: 1; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px; font-weight: 700; color: var(--dim); min-height: 40px; }
.tabs button.on { color: var(--text); border-color: var(--gold); }
.list { display: grid; gap: 6px; }
.item { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; font-size: 14px; }
.item .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .p { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chatlog { display: grid; gap: 4px; max-height: 220px; overflow-y: auto; margin-bottom: 8px; font-size: 14px; }
.chatlog b { color: var(--gold); }
.paused { text-align: center; font-weight: 800; color: var(--gold); letter-spacing: .1em; }

@media (min-width: 900px) {
  .live { display: grid; grid-template-columns: 250px minmax(0, 1fr) 320px; align-items: start; gap: 14px; padding: 14px; }
  .teams { order: 0; flex-direction: column; overflow: visible; }
  .trow { width: auto; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; }
  .trow .o { grid-column: 2; } .trow .m { grid-column: 1 / -1; }
  .stage { order: 0; } .side { order: 0; }
  .bidbox { position: static; background: none; padding: 0; }
  .card .pname { font-size: 34px; } .bidline .amt { font-size: 52px; }
  .host canvas { width: 77px; height: 84px; }
}

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: #000a; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 18px 18px 0 0; width: 100%; max-width: 520px; max-height: 82dvh; overflow-y: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.sheet header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sheet header b { flex: 1; font-size: 18px; }

/* ---------- intro ---------- */
#intro { position: fixed; inset: 0; z-index: 50; background: #0a0614; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 12px; }
#intro canvas { width: min(100%, calc((100dvh - 150px) * 16 / 9)); aspect-ratio: 16/9; border-radius: 10px; border: 2px solid var(--line); }
#intro .bubble { flex: none; width: min(100%, 640px); min-height: 64px; font-size: 16px; visibility: hidden; }
#intro .bubble.on { visibility: visible; }
#intro .bubble::before { display: none; }
#intro .bubble b { display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: #8a5a10; }
#intro .skip { position: absolute; right: 12px; top: calc(12px + env(safe-area-inset-top)); }

/* ---------- results ---------- */
.done { max-width: 720px; margin: 0 auto; padding: 14px 12px 40px; display: grid; gap: 12px; }
.winner { text-align: center; padding: 20px 14px; border-radius: var(--radius); border: 2px solid var(--gold); background: radial-gradient(circle at 50% 0, #4a3410, #1e1338 70%); }
.winner .big { font-size: 30px; font-weight: 900; margin: 6px 0; }
details.sq { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
details.sq summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; font-weight: 700; }
details.sq summary::-webkit-details-marker { display: none; }
details.sq summary .r { margin-left: auto; font-variant-numeric: tabular-nums; }
details.sq .list { margin-top: 8px; }
.rank { width: 22px; color: var(--dim); font-weight: 800; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* role icons */
.ri { display: inline-flex; vertical-align: -4px; flex: none; }
.ri svg { display: block; }
.tag .ri { vertical-align: -5px; margin-right: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; color: var(--dim); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.split { display: flex; gap: 10px; font-size: 13px; }
.split span { display: inline-flex; align-items: center; gap: 3px; }
.rgroup { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-top: 1px solid var(--line); }
.rgroup .ri { margin-top: 1px; }
.rlabel { font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--gold); }
.rnames { font-size: 13px; color: var(--dim); line-height: 1.55; }
.rnames b { color: var(--text); }

.how ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; }
.how li::marker { color: var(--gold); }
