/* =========================================================================
   Spot the Bug — tap the broken line (BuiltBy daily game)
   Neutral-dark BuiltBy chrome, rose accent, editor-style code card.
   ========================================================================= */

: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;
  --rose:#fb7185;
  --good:#34d399;
  --bad:#f87171;

  --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(--rose) 7%, 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; min-height:20px;}
.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-row.hearts{gap:3px;}
.hud-pill-row.hearts svg{margin-left:0; width:15px; height:15px; fill:var(--pill-c); transition:opacity .3s, transform .3s;}
.hud-pill-row.hearts svg.lost{fill:transparent; opacity:.35; transform:scale(.85);}
.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(--rose) 10%, var(--panel));
  border:1px solid color-mix(in srgb, var(--rose) 30%, var(--border));
}
.daily-chip svg{width:15px; height:15px; color:var(--rose); 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 / puzzle card ---------------- */
.stage{position:relative; flex:1; min-height:0; display:flex; align-items:center; justify-content:center;}
.puzzle{
  width:100%; max-width:720px; max-height:100%; display:flex; flex-direction:column;
  border-radius:var(--radius-md); background:#121215; border:1px solid var(--border);
  box-shadow:0 20px 50px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.05);
  overflow:hidden;
}
.puzzle-head{display:flex; align-items:center; gap:10px; padding:12px 14px 10px;}
.lang-badge{
  font-family:var(--font-mono); font-size:11px; font-weight:600; padding:4px 8px; border-radius:7px;
  background:color-mix(in srgb, var(--lang-c,#a78bfa) 16%, transparent); color:var(--lang-c,#a78bfa);
  border:1px solid color-mix(in srgb, var(--lang-c,#a78bfa) 35%, transparent); flex-shrink:0;
}
.puzzle-title{flex:1; min-width:0; font-size:13px; color:var(--text-1); font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.timer-num{font-family:var(--font-mono); font-weight:600; font-size:14px; color:#38bdf8; flex-shrink:0; min-width:28px; text-align:right;}
.timer-num.urgent{color:var(--bad); animation:blink .5s steps(2) infinite;}
@keyframes blink{50%{opacity:.4;}}
.timer-bar{height:4px; background:rgba(255,255,255,0.06);}
.timer-fill{height:100%; width:100%; background:#38bdf8; transition:width .25s linear, background .3s;}
.timer-fill.urgent{background:var(--bad);}

.code{
  font-family:var(--font-mono); font-size:14px; line-height:1.6; padding:10px 0 12px;
  overflow:auto; min-height:120px; counter-reset:line;
  background:#0e0e11;
}
.line{
  display:flex; align-items:stretch; cursor:pointer; white-space:pre; user-select:none; -webkit-user-select:none;
  border-left:3px solid transparent; transition:background .12s;
}
.line:hover{background:rgba(255,255,255,0.045);}
.line-no{
  width:44px; flex-shrink:0; text-align:right; padding-right:12px; color:var(--text-2); font-size:12px;
  opacity:.7; align-self:center;
}
.line-code{padding-right:18px; min-width:0;}
.line.correct{background:color-mix(in srgb, var(--good) 14%, transparent); border-left-color:var(--good);}
.line.wrong{background:color-mix(in srgb, var(--bad) 14%, transparent); border-left-color:var(--bad); animation:shake .4s var(--ease-out);}
.line.reveal{background:color-mix(in srgb, var(--good) 10%, transparent); border-left-color:var(--good); border-left-style:dashed;}
.code.locked .line{cursor:default;}
.code.locked .line:hover{background:transparent;}
.code.locked .line.correct:hover{background:color-mix(in srgb, var(--good) 14%, transparent);}
.code.locked .line.wrong:hover{background:color-mix(in srgb, var(--bad) 14%, transparent);}
.code.locked .line.reveal:hover{background:color-mix(in srgb, var(--good) 10%, transparent);}
@keyframes shake{10%,90%{transform:translateX(-1px);}20%,80%{transform:translateX(2px);}30%,50%,70%{transform:translateX(-4px);}40%,60%{transform:translateX(4px);}}

/* Syntax tints */
.tk-kw{color:#c792ea;}
.tk-str{color:#c3e88d;}
.tk-num{color:#f78c6c;}
.tk-com{color:#6b7280; font-style:italic;}
.tk-fn{color:#82aaff;}
.tk-tag{color:#ff8a80;}
.tk-op{color:#89ddff;}

/* Explanation strip */
.explain{
  display:none; align-items:center; gap:12px; padding:12px 14px;
  border-top:1px solid var(--border); background:#131316;
}
.explain.show{display:flex; animation:riseIn .3s var(--ease-out);}
@keyframes riseIn{from{opacity:0; transform:translateY(6px);} to{opacity:1; transform:none;}}
.explain-text{flex:1; min-width:0; font-size:12.5px; color:var(--text-1); line-height:1.5;}
.explain-text strong{display:block; font-family:var(--font-display); font-size:13.5px; margin-bottom:2px; color:var(--good);}
.explain.bad .explain-text strong{color:var(--bad);}
.btn-next{
  display:inline-flex; align-items:center; gap:6px; padding:9px 14px; border-radius:10px; flex-shrink:0;
  background:linear-gradient(135deg,#34d399,#10b981); color:#0a0a12; font-weight:600; font-size:13px;
}
.btn-next svg{width:14px; height:14px; stroke-width:2.4;}

/* ---------------- 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:420px; 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-icon{
  width:50px; height:50px; margin:0 auto 12px; border-radius:16px; display:grid; place-items:center;
  background:color-mix(in srgb, var(--rose) 16%, transparent); color:var(--rose);
}
.ov-icon svg{width:26px; height:26px;}
.ov-icon.gold{background:rgba(251,191,36,0.14); color:#fbbf24;}
.ov-icon.red{background:color-mix(in srgb, var(--bad) 14%, transparent); color:var(--bad);}

.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) ---------------- */
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 .stage{align-items:flex-start;}
@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;}
  .code{font-size:12.5px;}
  .line-no{width:34px; padding-right:8px;}
  .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;}
  .explain{flex-direction:column; align-items:stretch; gap:8px;}
  .btn-next{justify-content:center;}
}
@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;}
  .code{font-size:12.5px; line-height:1.45; padding:6px 0 8px;}
  .puzzle-head{padding:8px 12px 6px;}
  .explain{padding:8px 12px;}
  .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;}
  .ov-icon{width:36px; height:36px; 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;}
}
