:root{ --bg:#0f172a; --card:#1e293b; --line:#334155; --text:#e2e8f0; --accent:#38bdf8; }
*{ box-sizing:border-box; }
body{ margin:0; min-height:100vh; background:radial-gradient(1000px 500px at 70% -10%,#1e3a5f,var(--bg) 55%);
      color:var(--text); font:15px/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
      display:flex; flex-direction:column; align-items:center; gap:18px; padding:28px; }
h1{ font-size:30px; letter-spacing:.02em; margin:0; font-weight:800;
    background:linear-gradient(90deg,#22d3ee,#c084fc,#fb923c); -webkit-background-clip:text; background-clip:text; color:transparent; }
.arena{ display:flex; gap:18px; align-items:flex-start; justify-content:center; flex-wrap:wrap; }
.game{ display:flex; gap:18px; align-items:flex-start; }
.brand{ display:flex; align-items:center; justify-content:center; gap:12px; }
.brand-logo{ width:54px; height:54px; filter:drop-shadow(0 0 8px rgba(56,189,248,.3)); }
.btn-icon{ width:18px; height:18px; object-fit:contain; }
.editname{ font-size:11px; margin-left:8px; color:#64748b; }
.editname:hover{ color:var(--accent); }
.match-status{ color:#94a3b8; font-size:14px; }

/* --- Screens: start menu / lobby / waiting room --------------------------- */
.screen{ display:flex; flex-direction:column; align-items:center; gap:16px;
         background:var(--card); border:1px solid var(--line); border-radius:16px;
         padding:30px 34px; width:min(440px,92vw); }
.screen[hidden], #play-screen[hidden]{ display:none; }
.screen-title{ margin:0; font-size:22px; font-weight:800; }
.screen-sub{ margin:6px 0 0; font-size:12px; text-transform:uppercase; letter-spacing:.08em; color:#94a3b8; align-self:flex-start; }
.big-btn{ display:inline-flex; align-items:center; justify-content:center; gap:10px; width:100%;
          background:linear-gradient(90deg,#22d3ee,#38bdf8); color:#06283d; border:0; border-radius:11px;
          padding:16px 20px; font-weight:800; font-size:17px; cursor:pointer; }
.big-btn:hover{ filter:brightness(1.08); }
.big-btn.alt{ background:linear-gradient(90deg,#f87171,#fb923c); }
.create-row{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; justify-content:center; }
.create-row span{ color:#94a3b8; font-size:14px; }
.cap-btn{ background:#0b1220; border:1px solid var(--line); color:var(--text); border-radius:9px;
          padding:9px 16px; font:inherit; font-weight:700; cursor:pointer; }
.cap-btn:hover{ border-color:var(--accent); color:var(--accent); }
#games-list{ list-style:none; margin:0; padding:0; width:100%; }
#games-list li{ display:flex; align-items:center; gap:10px; padding:9px 4px; border-bottom:1px solid #243044; }
#games-list li:last-child{ border-bottom:0; }
#games-list li.muted{ color:#64748b; justify-content:center; border-bottom:0; }
.g-host{ flex:1; font-weight:700; }
.g-count{ font-variant-numeric:tabular-nums; }
.join-btn{ background:var(--accent); color:#06283d; border:0; border-radius:8px; padding:7px 16px; font-weight:700; cursor:pointer; }
.join-btn:hover{ filter:brightness(1.08); }
.wait-count{ font-size:34px; font-weight:800; font-variant-numeric:tabular-nums; color:var(--accent); }
.wait-list{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:6px; width:100%; text-align:center; }
.wait-list li{ background:#0b1220; border:1px solid var(--line); border-radius:8px; padding:8px; font-weight:600; }
.play-bar{ display:flex; align-items:center; justify-content:space-between; gap:14px; width:min(900px,92vw); margin-bottom:12px; }
.vpanel{ background:var(--card); border:1px solid var(--line); border-radius:12px; padding:14px; }
.vlabel{ font-size:12px; text-transform:uppercase; letter-spacing:.06em; color:#94a3b8; margin-bottom:10px; text-align:center; }
.vlabel span{ color:var(--bad,#f87171); font-weight:700; }
.opp-list{ display:flex; flex-direction:column; gap:14px; }
.opp-label{ font-size:11px; color:#94a3b8; margin-bottom:4px; text-align:center; }
.opp-board{ border:1px solid var(--line); border-radius:8px; display:block; }
.opp.dead{ opacity:.45; }
.opp.dead .opp-label::after{ content:" — out"; color:#f87171; }
.vresult-banner{ display:none; margin-top:14px; padding:12px; text-align:center; font-size:18px; font-weight:800;
                 background:rgba(2,6,23,.7); border:1px solid var(--line); border-radius:10px; }
.panel{ background:var(--card); border:1px solid var(--line); border-radius:12px; padding:14px 16px; min-width:130px; }
.panel h2{ font-size:11px; text-transform:uppercase; letter-spacing:.08em; color:#94a3b8; margin:14px 0 6px; }
.panel h2:first-child{ margin-top:0; }
.stat{ font-size:24px; font-weight:700; }
/* Grouped stat cells — a vertical list on desktop, a HUD strip on mobile. */
.stats{ display:flex; flex-direction:column; }
.statcell span{ display:block; font-size:11px; text-transform:uppercase; letter-spacing:.08em; color:#94a3b8; margin:14px 0 6px; }
.mini{ background:#0b1220; border:1px solid var(--line); border-radius:8px; display:block; }
.next-stack{ display:flex; flex-direction:column; gap:8px; }
#board{ border:1px solid var(--line); border-radius:8px; box-shadow:0 0 22px rgba(56,189,248,.12); }
.stage{ position:relative; }
#gameover{ position:absolute; inset:0; display:none; flex-direction:column; align-items:center; justify-content:center;
           background:rgba(2,6,23,.82); border-radius:8px; font-size:24px; font-weight:800; gap:14px; }
#gameover button{ background:var(--accent); color:#06283d; border:0; border-radius:9px; padding:12px 26px; font-weight:800; font-size:15px; cursor:pointer; }
#gameover button:hover{ filter:brightness(1.08); }
.hint{ color:#94a3b8; font-size:12px; }
.vol{ flex:1; accent-color:var(--accent); cursor:pointer; }
.volrow{ display:flex; align-items:center; gap:8px; margin-top:5px; }
.volrow span{ font-size:11px; color:#94a3b8; width:38px; }
.welcome{ max-height:0; opacity:0; overflow:hidden; width:min(560px,92vw); text-align:center; transition:all .4s ease; }
.welcome.show{ max-height:80px; opacity:1; padding:13px 16px; margin-bottom:4px;
               background:linear-gradient(90deg,rgba(34,211,238,.14),rgba(192,132,252,.14));
               border:1px solid var(--line); border-radius:12px; font-size:15px; }
.welcome strong{ color:var(--accent); }
.whoami{ margin:-8px 0 0; color:#94a3b8; font-size:13px; }
.whoami span{ color:var(--accent); font-weight:700; }
.lbpanel{ width:min(460px,90vw); background:var(--card); border:1px solid var(--line); border-radius:12px; padding:16px 18px; }
.lbpanel h2{ margin:0 0 10px; font-size:13px; text-transform:uppercase; letter-spacing:.08em; color:#94a3b8; }
.lbpanel ol{ list-style:none; margin:0; padding:0; }
.lbpanel li{ display:flex; align-items:center; gap:12px; padding:7px 4px; border-bottom:1px solid #243044; }
.lbpanel li:last-child{ border-bottom:0; }
.lbpanel .rank{ width:22px; color:#64748b; font-variant-numeric:tabular-nums; text-align:right; }
.lbpanel .lbname{ flex:1; font-weight:600; }
.lbpanel .lbscore{ font-variant-numeric:tabular-nums; color:var(--accent); font-weight:700; }
.lbpanel .muted{ color:#64748b; justify-content:center; }
/* discreet top-right account widget */
.account{ position:fixed; top:14px; right:16px; z-index:20; }
.account #acct-out, .account #acct-in{ display:flex; gap:8px; align-items:center; }
.account strong{ color:var(--accent); }
.linkbtn{ background:transparent; border:0; color:#94a3b8; font:inherit; font-size:13px; cursor:pointer; padding:6px 8px; border-radius:6px; }
.linkbtn:hover{ color:var(--text); }
.linkbtn.primary{ color:#06283d; background:var(--accent); font-weight:700; padding:6px 14px; }
.linkbtn.primary:hover{ filter:brightness(1.08); }

/* modal */
.modal{ position:fixed; inset:0; z-index:50; display:flex; align-items:center; justify-content:center;
        background:rgba(2,6,23,.72); backdrop-filter:blur(2px); }
.modal[hidden]{ display:none; }
.modal-card{ position:relative; width:min(360px,92vw); background:var(--card); border:1px solid var(--line);
             border-radius:14px; padding:26px 24px; display:flex; flex-direction:column; gap:10px;
             box-shadow:0 20px 60px rgba(0,0,0,.5); }
.modal-card h2{ margin:0 0 6px; font-size:20px; }
.modal-card input{ background:#0b1220; border:1px solid var(--line); color:var(--text); border-radius:9px; padding:11px 12px; font:inherit; width:100%; }
.modal-card #modal-submit{ margin-top:6px; background:var(--accent); color:#06283d; border:0; border-radius:9px; padding:12px; font-weight:700; font-size:15px; cursor:pointer; }
.modal-close{ position:absolute; top:10px; right:12px; background:transparent; border:0; color:#64748b; font-size:24px; line-height:1; cursor:pointer; }
.modal-close:hover{ color:var(--text); }
.modal-switch{ margin:4px 0 0; font-size:13px; color:#94a3b8; text-align:center; }
.modal-switch .linkbtn{ color:var(--accent); padding:2px 4px; }
.authmsg{ text-align:center; font-size:13px; min-height:16px; }
.authmsg.err{ color:#f87171; } .authmsg.ok{ color:#34d399; }

/* lower row: leaderboard + chat side by side */
.lower{ display:flex; gap:18px; align-items:flex-start; flex-wrap:wrap; justify-content:center; }
.lower .lbpanel{ width:300px; }
.chatpanel{ width:320px; background:var(--card); border:1px solid var(--line); border-radius:12px; padding:16px 18px; display:flex; flex-direction:column; }
.chatpanel h2{ margin:0 0 10px; font-size:13px; text-transform:uppercase; letter-spacing:.08em; color:#94a3b8; }
.online{ color:#34d399; font-weight:600; font-size:11px; letter-spacing:0; text-transform:none; }
.onlinenames{ color:#64748b; font-size:12px; margin:-4px 0 10px; min-height:14px; }
.chatmsgs{ height:150px; overflow-y:auto; display:flex; flex-direction:column; gap:5px; font-size:14px; margin-bottom:10px; }
.chatmsg .cn{ color:var(--accent); font-weight:700; margin-right:4px; }
.chatmsgs .muted{ color:#64748b; }
.chatform{ display:flex; gap:8px; }
.chatform input{ flex:1; background:#0b1220; border:1px solid var(--line); color:var(--text); border-radius:8px; padding:9px 11px; font:inherit; }
.chatform button{ background:var(--accent); color:#06283d; border:0; border-radius:8px; padding:9px 14px; font-weight:700; cursor:pointer; }
.lbtabs{ display:flex; gap:6px; margin-bottom:10px; }
.lbtab{ background:transparent; border:1px solid var(--line); color:#94a3b8; border-radius:8px; padding:6px 14px; font:inherit; font-weight:600; cursor:pointer; }
.lbtab.active{ background:var(--accent); color:#06283d; border-color:var(--accent); }

/* --- PWA install affordance ----------------------------------------------- */
.install-btn{ background:transparent; border:1px solid var(--line); color:#94a3b8; border-radius:10px;
              padding:10px 18px; font:inherit; font-weight:700; cursor:pointer; margin-top:4px; }
.install-btn:hover{ border-color:var(--accent); color:var(--accent); }
.ios-hint{ color:#94a3b8; font-size:13px; text-align:center; max-width:260px; line-height:1.5; }
.ios-hint strong{ color:var(--accent); }

/* --- On-screen touch controls (mobile only) ------------------------------- */
.touchpad{ display:none; }

/* --- Mobile / responsive layout ------------------------------------------- */
@media (max-width: 760px){
  body{ padding:16px 10px; gap:14px; }
  .account{ top:8px; right:8px; }
  .account .linkbtn{ font-size:12px; padding:5px 7px; }

  /* Single column; the board is the hero, controls right beneath it. */
  .arena{ flex-direction:column; align-items:center; gap:12px; width:100%; }
  .game{ flex-direction:column; align-items:center; gap:12px; width:100%; }
  .game > .stage{ order:1; }
  .game > #touchpad{ order:2; }
  .game > .panel:first-child{ order:3; }   /* Hold + Score/Level/Lines */
  .game > .panel:last-child{ order:4; }    /* Next + Volume */

  /* Scale the board to fit width AND height so the touchpad stays on-screen.
     The canvas keeps its 1:2 aspect ratio (intrinsic 300x600). */
  #board{ width:auto; height:auto; max-width:88vw; max-height:60vh; }

  /* Panels become tidy horizontal bars below the board + controls. */
  .panel{ display:flex; flex-flow:row wrap; align-items:center; justify-content:center;
          gap:10px 18px; width:min(380px,94vw); padding:12px 16px; box-shadow:0 4px 14px rgba(0,0,0,.25); }
  .panel > h2{ margin:0; font-size:11px; }
  .mini{ width:44px; height:44px; }
  .next-stack{ flex-direction:row; gap:8px; }
  .keyshelp{ display:none; }               /* keyboard hints are useless on touch */
  .volbox{ display:flex; flex-direction:column; align-items:stretch; gap:6px; flex:1 0 100%; }
  .volbox h2{ margin:0; }
  .volbox .volrow{ width:100%; margin-top:0; }
  .vol{ min-width:0; }                     /* let the range inputs shrink instead of overflowing */
  /* Score / Level / Lines become a full-width 3-cell HUD strip inside the bar. */
  .stats{ flex-flow:row nowrap; gap:8px; flex:1 0 100%; }
  .statcell{ flex:1; background:#0b1220; border:1px solid var(--line); border-radius:10px; padding:7px 4px; text-align:center; }
  .statcell span{ margin:0 0 2px; font-size:10px; }
  .statcell .stat{ font-size:20px; }
  .play-bar{ width:min(380px,94vw); }

  /* Opponents: a compact horizontal strip above the board. */
  #versus{ width:min(360px,92vw); }
  .opp-list{ flex-direction:row; gap:10px; overflow-x:auto; padding-bottom:4px; }
  .opp-board{ width:88px; height:auto; }

  /* Leaderboard + chat stack full-width below. */
  .lower{ flex-direction:column; align-items:center; }
  .lower .lbpanel, .chatpanel{ width:min(360px,92vw); }

  /* The control pad: 3 columns x 2 rows. */
  .touchpad{
    display:grid; grid-template-columns:repeat(3,1fr); gap:10px;
    width:min(360px,92vw); margin:4px auto 0;
  }
  .tbtn{
    -webkit-user-select:none; user-select:none; touch-action:none;
    background:linear-gradient(180deg,#243044,#1a2435); border:1px solid var(--line); color:var(--text);
    border-radius:14px; padding:16px 0; min-height:60px; font-size:22px; font-weight:800;
    cursor:pointer; box-shadow:0 2px 0 rgba(0,0,0,.35);
  }
  .tbtn:active{ background:#0b1220; border-color:var(--accent); color:var(--accent); transform:translateY(1px); box-shadow:none; }
  .tbtn.drop{ background:linear-gradient(90deg,#22d3ee,#38bdf8); color:#06283d; border:0; font-size:17px; box-shadow:0 2px 0 rgba(6,40,61,.4); }
}
