/* =========================================================================
   Snake II — Nokia-classic homage (BuiltBy daily game)
   Neutral-dark BuiltBy chrome around an LCD-green board.
   ========================================================================= */

:root{
  --bg-0:#0b0b0d;
  --panel:rgba(255,255,255,0.04);
  --panel-strong:rgba(255,255,255,0.07);
  --border:rgba(255,255,255,0.10);
  --border-strong:rgba(255,255,255,0.18);
  --text-0:#fafafa;
  --text-1:#b4b4b4;
  --text-2:#7c7c85;

  --accent-1:#34d399;
  --lcd:#b9cf7a;        /* classic LCD green */
  --lcd-dark:#1f2a14;   /* "pixel" ink */

  --radius-sm:14px;
  --radius-md:18px;

  --ease-out:cubic-bezier(.16,1,.3,1);

  --font-display:"Space Grotesk",-apple-system,ui-sans-serif,sans-serif;
  --font-body:"Inter",-apple-system,ui-sans-serif,sans-serif;
  --font-mono:"JetBrains Mono",ui-monospace,monospace;
}

*{margin:0;padding:0;box-sizing:border-box;}
*{scrollbar-width:none; -ms-overflow-style:none;}
*::-webkit-scrollbar{width:0;height:0;display:none;}
html,body{height:100%;}
body{
  background:
    radial-gradient(900px 520px at 8% -10%, color-mix(in srgb, var(--accent-1) 8%, transparent), transparent 60%),
    var(--bg-0);
  color:var(--text-0);
  font-family:var(--font-body);
  -webkit-font-smoothing:antialiased;
  height:100%;
  overflow:hidden;
}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit;}
button:focus-visible{outline:2px solid var(--accent-1); outline-offset:2px;}
[data-lucide]{display:inline-block;}

/* ---------------- Shell ---------------- */
.app-shell{
  display:grid;
  grid-template-columns:1fr 300px;
  grid-template-rows:minmax(0,1fr);
  gap:16px;
  max-width:1480px;
  margin:0 auto;
  padding:16px;
  height:100vh; height:100dvh;
  overflow:hidden;
}
.main-col{display:flex; flex-direction:column; gap:14px; min-width:0; min-height:0; height:100%;}

/* ---------------- Top bar ---------------- */
.topbar{display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap;}
.hud-pills{display:flex; gap:8px; flex-wrap:wrap;}
.hud-pill{
  padding:7px 12px; border-radius:12px; background:var(--panel); border:1px solid var(--border);
  min-width:78px;
}
.hud-pill-label{display:block; font-size:9.5px; font-weight:700; text-transform:uppercase; letter-spacing:0.06em; color:var(--pill-c); margin-bottom:2px;}
.hud-pill-row{display:flex; align-items:center; gap:7px;}
.hud-pill-value{font-family:var(--font-display); font-weight:700; font-size:15px;}
.hud-pill-value.mono{font-family:var(--font-mono); font-size:13.5px;}
.hud-pill-row svg{width:13px; height:13px; color:var(--pill-c); margin-left:auto; stroke-width:2;}
.hud-pill.pulse{animation:pillPulse .4s var(--ease-out);}
@keyframes pillPulse{50%{transform:scale(1.06); box-shadow:0 0 0 1px var(--pill-c), 0 0 18px color-mix(in srgb, var(--pill-c) 50%, transparent);}}

.daily-chip{
  display:flex; align-items:center; gap:9px; padding:7px 12px; border-radius:12px;
  background:color-mix(in srgb, var(--accent-1) 10%, var(--panel));
  border:1px solid color-mix(in srgb, var(--accent-1) 30%, var(--border));
}
.daily-chip svg{width:15px; height:15px; color:var(--accent-1); flex-shrink:0;}
.daily-chip-text{display:flex; flex-direction:column; gap:1px;}
.daily-chip-text strong{font-family:var(--font-display); font-size:13px; font-weight:600; line-height:1;}
.daily-chip-text small{font-size:9.5px; color:var(--text-2); white-space:nowrap;}

.topbar-actions{display:flex; gap:6px;}
.icon-btn{
  width:34px;height:34px;border-radius:10px;display:flex;align-items:center;justify-content:center;
  background:var(--panel); border:1px solid var(--border); color:var(--text-1);
  transition:all .25s var(--ease-out);
}
.icon-btn svg{width:15px;height:15px;stroke-width:1.9;}
.icon-btn:hover{color:var(--text-0); border-color:var(--border-strong); background:var(--panel-strong);}
.icon-btn-narrow{display:none;}

/* ---------------- Stage / LCD ---------------- */
.stage{position:relative; flex:1; min-height:0; display:flex; align-items:center; justify-content:center;}
.lcd{
  position:relative; border-radius:var(--radius-md); padding:10px;
  background:linear-gradient(160deg,#2a2d24,#15170f);
  border:1px solid var(--border-strong);
  box-shadow:0 20px 50px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
}
#game{
  display:block; border-radius:8px;
  background:var(--lcd);
  box-shadow:inset 0 0 0 2px rgba(0,0,0,0.25), inset 0 6px 18px rgba(0,0,0,0.25);
  image-rendering:auto;
  touch-action:none;
}
.bonus-bar{
  position:absolute; left:10px; right:10px; top:10px; height:6px; border-radius:0 0 4px 4px;
  background:rgba(0,0,0,0.25); overflow:hidden; opacity:0; transition:opacity .2s;
}
.bonus-bar.active{opacity:1;}
.bonus-fill{height:100%; width:100%; background:var(--lcd-dark); transition:width .12s linear;}

/* ---------------- D-pad (touch) ---------------- */
.dpad{
  position:absolute; left:50%; bottom:10px; transform:translateX(-50%);
  display:none; grid-template-columns:repeat(3,58px); grid-template-rows:repeat(3,58px); gap:6px;
  pointer-events:none; z-index:15;
}
body.touch .dpad{display:grid;}
.dp{
  pointer-events:auto; border-radius:14px; display:flex; align-items:center; justify-content:center;
  background:rgba(10,10,14,0.5); border:1.5px solid rgba(255,255,255,0.22); color:var(--text-0);
  backdrop-filter:blur(4px); touch-action:none; user-select:none; -webkit-user-select:none;
  transition:transform .08s ease, background .08s ease;
}
.dp svg{width:28px; height:28px; stroke-width:2.4;}
.dp.down{transform:scale(.92); background:color-mix(in srgb, var(--accent-1) 35%, rgba(10,10,14,0.5));}
.dp-up{grid-column:2; grid-row:1;}
.dp-left{grid-column:1; grid-row:2;}
.dp-right{grid-column:3; grid-row:2;}
.dp-down{grid-column:2; grid-row:3;}

/* ---------------- Overlays ---------------- */
.overlay{
  position:absolute; inset:0; z-index:20; display:none;
  align-items:center; justify-content:center; padding:16px;
  background:rgba(5,5,8,0.72); backdrop-filter:blur(6px);
  border-radius:var(--radius-md); overflow-y:auto;
}
.overlay.active{display:flex; animation:fadeIn .25s var(--ease-out);}
@keyframes fadeIn{from{opacity:0;}to{opacity:1;}}
.ov-card{
  width:100%; max-width:400px; text-align:center;
  background:#131316; border:1px solid var(--border); border-radius:var(--radius-md);
  padding:24px 24px 22px; box-shadow:0 20px 55px rgba(0,0,0,0.5);
}
.ov-card h2{font-family:var(--font-display); font-size:21px; font-weight:700; margin-bottom:8px;}
.ov-card p{font-size:13px; color:var(--text-1); line-height:1.55; margin-bottom:10px;}
.ov-keys{color:var(--text-2); font-size:12px;}
.ov-keys-touch{display:none;}
body.touch .ov-keys{display:none;}
body.touch .ov-keys-touch{display:block;}
kbd{
  display:inline-block; min-width:20px; padding:2px 6px; margin:0 2px;
  border-radius:6px; border:1px solid var(--border-strong); background:var(--panel-strong);
  font-family:var(--font-mono); font-size:10.5px;
}
.ov-snake{display:flex; gap:3px; justify-content:center; margin:0 auto 12px;}
.ov-snake span{width:14px; height:14px; border-radius:4px; background:var(--lcd); box-shadow:0 0 12px rgba(185,207,122,0.35);}
.ov-snake span:first-child{border-radius:7px 4px 4px 7px;}

.btn-primary{
  margin-top:8px; padding:11px 22px; border-radius:12px; font-size:14px; font-weight:600;
  background:linear-gradient(135deg,#34d399,#10b981); color:#0a0a12;
  box-shadow:0 8px 24px rgba(52,211,153,0.3); transition:transform .2s var(--ease-out);
}
.btn-primary:hover{transform:translateY(-2px);}

.win-grid{display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:14px 0 6px;}
.win-grid-3{grid-template-columns:repeat(3,1fr);}
.win-stat{
  background:var(--panel); border:1px solid var(--border); border-radius:12px;
  padding:10px 8px; display:flex; flex-direction:column; gap:2px;
}
.w-value{font-family:var(--font-display); font-weight:700; font-size:17px;}
.w-value.mono{font-family:var(--font-mono); font-size:15px;}
.w-label{font-size:9.5px; color:var(--text-2); text-transform:uppercase; letter-spacing:0.06em;}

/* ---------------- Right rail ---------------- */
.sidebar-right{display:flex; flex-direction:column; gap:14px; height:100%; overflow-y:auto;}
.panel{border-radius:var(--radius-md); background:var(--panel); border:1px solid var(--border);}
.panel-head{
  display:flex; align-items:center; justify-content:space-between; padding:15px 16px 10px;
  font-family:var(--font-display); font-weight:700; font-size:13.5px; color:var(--accent-1);
}
.panel-head span{display:flex; align-items:center; gap:8px;}
.panel-head svg{width:15px; height:15px;}
.panel-body{padding:0 16px 16px;}

.global-lb{list-style:none; display:flex; flex-direction:column; gap:6px;}
.glb-row{
  display:flex; align-items:center; gap:9px; padding:7px 9px; border-radius:10px;
  background:var(--panel); border:1px solid var(--border); font-size:12.5px;
}
.glb-row.you{
  border-color:color-mix(in srgb, var(--accent-1) 45%, var(--border));
  background:color-mix(in srgb, var(--accent-1) 8%, var(--panel));
}
.glb-rank{font-family:var(--font-mono); color:var(--text-2); width:16px; text-align:center; font-size:11px; flex-shrink:0;}
.glb-row:nth-child(1) .glb-rank{color:#fbbf24; font-weight:700;}
.glb-row:nth-child(2) .glb-rank{color:#cbd5e1;}
.glb-row:nth-child(3) .glb-rank{color:#d97706;}
.glb-avatar{width:22px; height:22px; border-radius:50%; object-fit:cover; flex-shrink:0;}
.glb-avatar-fallback{display:grid; place-items:center; background:var(--panel-strong); font-size:10px; font-weight:700; color:var(--text-1);}
.glb-name{flex:1; min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font-weight:600;}
.glb-name em{font-style:normal; color:var(--accent-1); font-size:10.5px;}
.glb-score{font-family:var(--font-display); font-weight:700; flex-shrink:0;}
.global-lb-note{font-size:11px; color:var(--text-2); margin-top:10px; line-height:1.45;}
.glb-tabs{display:flex; gap:4px; margin-bottom:10px; background:var(--panel); border:1px solid var(--border); border-radius:9px; padding:3px;}
.glb-tab{flex:1; padding:5px 8px; border-radius:7px; font-size:11px; font-weight:600; color:var(--text-2); transition:all .2s;}
.glb-tab.active{background:var(--panel-strong); color:var(--text-0);}
.glb-tab:hover{color:var(--text-0);}

.best-card{
  margin-top:auto; display:flex; align-items:center; gap:12px; padding:14px 16px;
  border-radius:var(--radius-md); background:var(--panel); border:1px solid var(--border);
}
.best-card svg{width:22px; height:22px; color:#fbbf24; flex-shrink:0;}
.best-meta{display:flex; flex-direction:column; gap:1px; min-width:0;}
.best-meta strong{font-family:var(--font-display); font-size:15px;}
.best-meta span{font-size:11px; color:var(--text-2);}

/* ---------------- Narrow screens (body.narrow, < 980px) ----------------
   Fixed-viewport layout so the board always fits; the rail becomes a
   slide-over behind the trophy button. Portrait fits the board by width and
   leaves room below it for the d-pad; landscape fits by height and floats
   the d-pad bottom-right. */
body.narrow .app-shell{grid-template-columns:1fr; padding:10px; gap:10px;}
body.narrow .main-col{gap:10px;}
body.narrow .icon-btn-narrow{display:flex;}
body.narrow .sidebar-right{
  position:fixed; top:0; right:0; bottom:0; width:min(300px, 84vw); z-index:40;
  padding:12px; padding-right:max(12px, env(safe-area-inset-right));
  background:#101014; border-left:1px solid var(--border);
  transform:translateX(100%); transition:transform .3s var(--ease-out);
  overflow-y:auto; height:100%;
}
body.narrow .sidebar-right.open{transform:none; box-shadow:-20px 0 50px rgba(0,0,0,0.5);}
body.narrow .best-card{margin-top:12px;}
body.narrow .panel-head{padding:10px 12px 8px;}
body.narrow.touch.portrait .stage{align-items:flex-start;}
body.narrow.touch.portrait .lcd{padding:7px;}
@media (max-width:640px){
  .hud-pills{gap:6px;}
  .hud-pill{min-width:0; padding:6px 10px;}
  .hud-pill-detail{display:none;}
  .daily-chip{padding:6px 10px;}
  .daily-chip-text small{display:none;}
  .topbar-actions{gap:4px;}
  .icon-btn{width:32px; height:32px;}
  .win-grid-3{grid-template-columns:repeat(2,1fr);}
  .ov-card{padding:18px 18px 16px;}
  .ov-card h2{font-size:18px;}
  .ov-card p{font-size:12px;}
}
@media (max-height:520px) and (orientation:landscape){
  body.narrow .app-shell{padding:8px 10px;}
  .topbar{flex-wrap:nowrap;}
  .hud-pills{flex-wrap:nowrap; overflow:hidden;}
  .hud-pill{padding:5px 9px;}
  .hud-pill-label{font-size:8.5px; margin-bottom:0;}
  .hud-pill-value{font-size:13px;}
  .hud-pill-detail{display:none;}
  .daily-chip-text small{display:none;}
  .icon-btn{width:30px; height:30px;}
  .lcd{padding:6px;}
  .dpad{left:auto; right:8px; bottom:8px; transform:none; grid-template-columns:repeat(3,48px); grid-template-rows:repeat(3,48px); gap:4px;}
  .dp svg{width:24px; height:24px;}
  .win-grid-3{grid-template-columns:repeat(3,1fr);}
  .ov-card{padding:14px 16px 12px;}
  .ov-card h2{font-size:17px; margin-bottom:4px;}
  .ov-card p{font-size:11.5px; margin-bottom:6px;}
  .win-grid{margin:8px 0 4px; gap:6px;}
  .win-stat{padding:6px;}
  .btn-primary{padding:9px 18px; font-size:13px; margin-top:4px;}
}
