:root {
  --red: #ff5252; --blue: #4aa3ff; --ink: #eef0f4; --dim: #9aa1ad;
  --glass: rgba(16, 18, 23, .62); --line: rgba(255, 255, 255, .1);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9a9a9; color: var(--ink); font-family: system-ui, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

#panel {
  position: fixed; left: 0; top: 0; bottom: 0; width: min(400px, 100%);
  padding: clamp(18px, 4vh, 40px) clamp(18px, 3vw, 34px);
  background: var(--glass); backdrop-filter: blur(18px) saturate(1.15); -webkit-backdrop-filter: blur(18px) saturate(1.15);
  border-right: 1px solid var(--line); overflow-y: auto; touch-action: pan-y; z-index: 5; display: flex; flex-direction: column;
}
.brand { margin-bottom: clamp(16px, 4vh, 34px); }
.brand h1 { margin: 0; font-size: clamp(44px, 9vh, 76px); line-height: 1.08; font-weight: 900; letter-spacing: -2px; }
.brand h1 b { background: linear-gradient(90deg, var(--red), var(--blue)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand p { margin: 8px 0 0 3px; color: var(--dim); letter-spacing: 4px; text-transform: uppercase; font-size: 12px; }
.page { display: flex; flex-direction: column; gap: 10px; }
label { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 2px; }
input, select {
  background: rgba(0, 0, 0, .35); border: 1px solid var(--line); color: var(--ink); border-radius: 8px;
  padding: 12px 14px; font-size: 16px; font-family: inherit; outline: none; width: 100%; user-select: text; -webkit-user-select: text;
}
select { cursor: pointer; font-weight: 700; } select option { background: #1b1d22; }
input:focus, select:focus { border-color: rgba(255, 255, 255, .4); }
input[type=range] { padding: 0; accent-color: #4aa3ff; }
.slide { display: flex; justify-content: space-between; align-items: baseline; margin-top: 2px; } .slide b { font-size: 18px; }
#codeIn { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; text-align: center; }
button {
  font: inherit; font-weight: 700; color: var(--ink); background: rgba(255, 255, 255, .09); border: 1px solid var(--line);
  border-radius: 8px; padding: 11px 14px; cursor: pointer; transition: background .12s, transform .08s;
}
button:hover:not(:disabled) { background: rgba(255, 255, 255, .17); }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .35; cursor: not-allowed; }
button.big { padding: 16px; font-size: 18px; letter-spacing: 1px; background: rgba(255, 255, 255, .13); }
button.back { margin-top: 6px; background: transparent; color: var(--dim); }
.row { display: flex; gap: 8px; } .row > * { flex: 1; } .row #codeIn { flex: 2; }
.or { text-align: center; color: var(--dim); font-size: 13px; margin: 6px 0 2px; }
.note { color: var(--dim); font-size: 13px; margin: 0; } .center { text-align: center; }
.acct { font-size: 13px; color: var(--dim); min-height: 18px; display: flex; align-items: center; gap: 8px; }
.mapline, .roomline { display: flex; align-items: center; gap: 10px; background: rgba(0, 0, 0, .3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 8px 8px 14px; }
.mapline span, .roomline b { flex: 1; font-weight: 700; }
.roomline span { color: var(--dim); font-size: 12px; letter-spacing: 2px; }
.roomline b { font-size: 26px; letter-spacing: 6px; }
.mapline button, .roomline button { padding: 7px 10px; font-size: 13px; }

#plist { display: flex; flex-direction: column; gap: 4px; max-height: 26vh; overflow-y: auto; }
.pl { display: flex; align-items: center; gap: 10px; padding: 7px 10px; background: rgba(0, 0, 0, .25); border-radius: 7px; font-weight: 600; }
.pl i { width: 12px; height: 12px; border-radius: 3px; background: #666; flex: none; }
.pl.t0 i { background: var(--red); } .pl.t1 i { background: var(--blue); } .pl.ffa i { background: #cfcfcf; }
.pl span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl em { font-style: normal; color: var(--dim); font-size: 12px; }
.teams { display: flex; gap: 8px; }
.team { flex: 1; padding: 16px 8px; font-size: 17px; font-weight: 800; }
.team.t0 { border-color: rgba(255, 82, 82, .5); } .team.t1 { border-color: rgba(74, 163, 255, .5); }
.team.t0.on { background: rgba(255, 82, 82, .45); } .team.t1.on { background: rgba(74, 163, 255, .45); }
.status { text-align: center; color: var(--dim); font-size: 14px; min-height: 20px; }
.status.go { color: #ffd24a; font-weight: 800; font-size: 18px; }
.how { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; font-size: 14px; color: #cfd3da; }
.how b { color: #fff; display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; }

/* rank badge: hexagon with the rank number */
.badge { --c: #999; --s: 38px; width: var(--s); height: calc(var(--s) * 1.1); flex: none; background: var(--c); display: grid; place-items: center; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); position: relative; }
.badge::before { content: ""; position: absolute; inset: 3px; background: linear-gradient(160deg, rgba(255, 255, 255, .45), rgba(0, 0, 0, .35)); clip-path: inherit; }
.badge span { position: relative; font-weight: 900; font-size: calc(var(--s) * .42); color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.badge.sm { --s: 22px; }

.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal .card { background: #1a1c21; border: 1px solid var(--line); border-radius: 14px; width: min(980px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.modal .card.narrow { width: min(560px, 100%); }
.modal .hd { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal h2 { margin: 0; font-size: 18px; }
.modal .body { overflow-y: auto; padding: 16px 18px 20px; touch-action: pan-y; display: flex; flex-direction: column; gap: 14px; }
#mapGrid { overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; touch-action: pan-y; }
.mc { background: #111317; border: 2px solid transparent; border-radius: 10px; padding: 6px; cursor: pointer; text-align: center; font-size: 12px; font-weight: 700; }
.mc:hover { border-color: rgba(255, 255, 255, .35); } .mc.sel { border-color: #ffd24a; }
.mc canvas { width: 100%; height: auto; aspect-ratio: 4 / 3; image-rendering: pixelated; border-radius: 6px; display: block; margin-bottom: 5px; }

/* profile */
.ph { display: flex; align-items: center; gap: 16px; }
.ph .nm { font-size: 24px; font-weight: 900; } .ph .rk { font-weight: 700; }
.bar { height: 10px; background: rgba(255, 255, 255, .1); border-radius: 6px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #4aa3ff, #b266ff); border-radius: 6px; transition: width 1.2s cubic-bezier(.2, .8, .2, 1); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: rgba(255, 255, 255, .05); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; } .stat span { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.ladder { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lad { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--dim); text-align: center; padding: 6px 2px; border-radius: 8px; opacity: .45; }
.lad.got { opacity: 1; color: var(--ink); } .lad.cur { background: rgba(255, 255, 255, .1); outline: 2px solid #ffd24a; opacity: 1; }
.sec { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 2px; margin-bottom: -6px; }
.lb { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.lb div { display: flex; gap: 10px; padding: 5px 8px; background: rgba(255, 255, 255, .04); border-radius: 6px; align-items: center; }
.lb span { flex: 1; } .lb em { font-style: normal; color: var(--dim); }
.tabs { display: flex; gap: 8px; } .tabs button.on { background: rgba(255, 255, 255, .22); }
.err { color: #ff7b7b; font-size: 13px; min-height: 18px; }

/* settings */
.sg { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 2px; margin: 6px 0 -4px; }
.si { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.si .lb2 { flex: 1; } .si .lb2 small { display: block; color: var(--dim); font-size: 12px; }
.si select { width: auto; padding: 7px 10px; font-size: 14px; } .si input[type=range] { width: 150px; padding: 0; accent-color: #4aa3ff; }
.si .val { width: 44px; text-align: right; color: var(--dim); font-size: 13px; }
.tg { width: 46px; height: 26px; border-radius: 13px; padding: 0; position: relative; background: rgba(255, 255, 255, .15); flex: none; }
.tg::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.tg.on { background: #3b82f6; } .tg.on::after { left: 23px; }

#gameBtns { position: fixed; top: 12px; right: 12px; z-index: 6; display: flex; gap: 8px; }
#gameBtns button { width: 42px; height: 42px; padding: 0; font-size: 20px; line-height: 1; background: rgba(16, 18, 23, .65); backdrop-filter: blur(6px); }

/* victory */
#victory { position: fixed; inset: 0; z-index: 12; background: radial-gradient(ellipse at center, rgba(8, 9, 12, .72), rgba(8, 9, 12, .92)); overflow-y: auto; touch-action: pan-y; animation: fade .5s both; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.vwrap { position: relative; max-width: 820px; margin: 0 auto; padding: max(12px, 4vh) 16px 30px; text-align: center; }
#vTitle { margin: 0; font-size: clamp(34px, min(11vw, 16vh), 96px); font-weight: 900; letter-spacing: 3px; animation: pop .8s cubic-bezier(.2, 1.5, .4, 1) both; }
#vTitle.win { background: linear-gradient(100deg, #ffd24a, #fff2a8, #ffb020, #ffd24a); background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: pop .8s cubic-bezier(.2, 1.5, .4, 1) both, shimmer 2.5s linear infinite; filter: drop-shadow(0 0 18px rgba(255, 190, 40, .5)); }
#vTitle.lose { color: #ff6464; animation: pop .8s cubic-bezier(.2, 1.5, .4, 1) both, shake .5s .6s; }
#vTitle.draw { color: #e8eaee; }
#vSub { color: var(--dim); margin: 4px 0 18px; font-size: 18px; animation: slideUp .5s .35s both; }
#vAwards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.aw { background: rgba(255, 255, 255, .07); border: 1px solid var(--line); border-radius: 12px; padding: 12px 8px; animation: slideUp .55s both; animation-delay: calc(.6s + var(--i) * .13s); }
.aw.mvp { background: linear-gradient(160deg, rgba(255, 210, 74, .28), rgba(255, 150, 30, .1)); border-color: rgba(255, 210, 74, .6); box-shadow: 0 0 24px rgba(255, 190, 40, .25); }
.aw .ic { font-size: 26px; } .aw .t { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; margin: 2px 0; }
.aw .n { font-weight: 800; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .aw .v { color: var(--dim); font-size: 13px; }
#vBoard { background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 18px; text-align: left; font-size: 14px; }
.tr { display: grid; grid-template-columns: 26px 1fr 44px 44px 64px 64px 54px; gap: 6px; padding: 8px 12px; align-items: center; animation: slideUp .4s both; animation-delay: calc(1.2s + var(--i) * .07s); }
.tr.h { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; animation: none; background: rgba(255, 255, 255, .05); }
.tr.me { background: rgba(74, 163, 255, .18); } .tr .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.tr .sq { width: 12px; height: 12px; border-radius: 3px; }
#vRank { margin-bottom: 16px; animation: slideUp .5s 1.6s both; }
.rkbox { background: rgba(255, 255, 255, .06); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; display: flex; align-items: center; gap: 16px; text-align: left; }
.rkbox .mid { flex: 1; } .rkbox .d { font-size: 28px; font-weight: 900; } .rkbox .d.up { color: #4ade80; } .rkbox .d.dn { color: #ff7b7b; }
.rkup { color: #ffd24a; font-weight: 900; letter-spacing: 2px; animation: pulse 1s infinite; }
#vBtns { max-width: 420px; margin: 0 auto; animation: slideUp .5s 1.8s both; } #vBtns .note { align-self: center; }

@keyframes pop { 0% { transform: scale(.2) rotate(-6deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes slideUp { from { transform: translateY(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { to { background-position: -250% 0; } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-12px); } 40% { transform: translateX(10px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes pulse { 50% { opacity: .55; } }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); opacity: 0; background: rgba(12, 13, 17, .92); border: 1px solid var(--line); padding: 11px 18px; border-radius: 10px; z-index: 30; pointer-events: none; transition: all .2s; font-weight: 600; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-height: 520px) {
  #panel { padding-top: 10px; padding-bottom: 10px; }
  .brand p { display: none; } .brand h1 { font-size: 40px; } .brand { margin-bottom: 8px; }
  button.big { padding: 11px; font-size: 16px; }
  .page { gap: 6px; } input, select { padding: 8px 12px; font-size: 15px; } button { padding: 8px 12px; }
  .roomline b { font-size: 20px; } .roomline, .mapline { padding: 4px 6px 4px 12px; }
  #plist { max-height: 90px; gap: 2px; } .pl { padding: 3px 10px; } .team { padding: 10px 8px; font-size: 15px; }
  .acct { font-size: 12px; } .modal .hd { padding: 8px 14px; } .modal .body { padding: 10px 14px 14px; gap: 10px; }
}
@media (max-width: 560px) {
  .tr { grid-template-columns: 22px 1fr 34px 34px 52px 0 0; } .tr > :nth-child(6), .tr > :nth-child(7) { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); } .ladder { grid-template-columns: repeat(3, 1fr); }
}
