/* Gridlock – an original block puzzle. Warm paper + ink look. */
:root {
  --bg: #f3ece0;
  --paper: #fffaf1;
  --ink: #2a2433;
  --muted: #74697d;
  --line: #ddd2c1;
  --board: #2e2838;
  --cell: #3b3447;
  --cell-edge: #453d52;
  --accent: #e2574c;
  --c1: #e2574c; /* coral   */
  --c2: #f0a83a; /* saffron */
  --c3: #3fae9a; /* teal    */
  --c4: #4d8fe0; /* cornflower */
  --c5: #9a6ad6; /* violet  */
  --c6: #7fb446; /* moss    */
  --c7: #e46f9f; /* rose    */
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(60,40,20,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17141c;
    --paper: #221e29;
    --ink: #efe9f2;
    --muted: #a99fb2;
    --line: #3a3343;
    --board: #0f0d13;
    --cell: #221e29;
    --cell-edge: #2c2735;
    --shadow: 0 1px 2px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
body.dragging { overflow: hidden; cursor: grabbing; user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top { max-width: 560px; margin: 0 auto; padding: 14px 14px 0; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.home-link { font-size: 13px; color: var(--muted); text-decoration: none; }
.home-link:hover { color: var(--ink); }
.logo { margin: 2px 0 0; display: flex; gap: 3px; font-size: 22px; line-height: 1; letter-spacing: 0; }
.logo span {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 7px;
  color: #fff; font-weight: 800; text-transform: uppercase;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18), inset 0 2px 0 rgba(255,255,255,.25);
}
.logo span:nth-child(7n+1) { background: var(--c1); }
.logo span:nth-child(7n+2) { background: var(--c2); }
.logo span:nth-child(7n+3) { background: var(--c3); }
.logo span:nth-child(7n+4) { background: var(--c4); }
.logo span:nth-child(7n+5) { background: var(--c5); }
.logo span:nth-child(7n+6) { background: var(--c6); }
.logo span:nth-child(7n+7) { background: var(--c7); }
.logo span:nth-child(8) { background: var(--c1); }
@media (max-width: 380px) { .logo span { width: 25px; height: 25px; font-size: 18px; border-radius: 6px; } }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.profile-chip { font-size: 14px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.profile-chip a { color: var(--ink); font-weight: 600; }
.profile-chip .sp-in, .profile-chip .sp-up { text-decoration: none; padding: 5px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); }
.profile-chip .sp-up { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.profile-chip .sp-or { color: var(--muted); }
.profile-chip .sp-out { font-size: 13px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; }

.ghost { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; padding: 6px 12px; }
.ghost:hover { border-color: var(--ink); }
.ghost.small { font-size: 13px; padding: 4px 10px; }
.ghost.armed { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 700; cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.primary:hover { filter: brightness(1.05); }
.primary.big { font-size: 18px; padding: 12px 26px; }

.tabs { display: flex; gap: 4px; margin-top: 12px; border-bottom: 1px solid var(--line); }
.tab { white-space: nowrap; background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--ink); border-color: var(--accent); }

main { max-width: 560px; margin: 0 auto; padding: 12px 14px 24px; }

/* ---------- HUD ---------- */
.hud { width: max(var(--bw), min(100%, 330px)); margin-left: auto; margin-right: auto; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.hud-box { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; text-align: center; box-shadow: var(--shadow); position: relative; }
.hud-lbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.hud-num { font-size: 24px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.combo-box.live { border-color: var(--c2); }
.combo-box.live .hud-num { color: var(--c2); }
.streak { display: flex; gap: 4px; justify-content: center; height: 6px; margin-top: 2px; }
.streak i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.streak i.on { background: var(--c2); }
.hud-num.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.25); } }

/* ---------- board ---------- */
#pane-play { --bw: min(100%, 440px, max(260px, calc(100vh - 350px))); }
@supports (height: 100dvh) { #pane-play { --bw: min(100%, 440px, max(260px, calc(100dvh - 350px))); } }
.board-wrap { position: relative; width: var(--bw); margin: 0 auto; }
.board {
  --gap: 3px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: var(--gap);
  background: var(--board); padding: 7px; border-radius: 14px;
  aspect-ratio: 1 / 1; touch-action: none;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.04);
}
.cell { border-radius: 5px; background: var(--cell); box-shadow: inset 0 0 0 1px var(--cell-edge); position: relative; }
.cell.f, .pc { box-shadow: inset 0 -3px 0 rgba(0,0,0,.2), inset 0 2px 0 rgba(255,255,255,.28); }
.f1, .k1 { background: var(--c1); } .f2, .k2 { background: var(--c2); } .f3, .k3 { background: var(--c3); }
.f4, .k4 { background: var(--c4); } .f5, .k5 { background: var(--c5); } .f6, .k6 { background: var(--c6); } .f7, .k7 { background: var(--c7); }
.cell.ghost-ok { opacity: .55; }
.cell.ghost-ok:not(.f) { background: var(--gc, #fff); box-shadow: none; }
.cell.will-clear::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: rgba(255,255,255,.38); animation: glow .8s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: .35; } to { opacity: 1; } }
.cell.pop { animation: pop .38s ease-out forwards; z-index: 1; }
@keyframes pop {
  0% { transform: scale(1); filter: brightness(1.6); }
  50% { transform: scale(1.15); filter: brightness(2); }
  100% { transform: scale(.2); opacity: 0; }
}
.cell.land { animation: land .18s ease-out; }
@keyframes land { 0% { transform: scale(.82); } 100% { transform: scale(1); } }
.board.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.float-txt {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  font-weight: 900; font-size: 22px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 12px rgba(0,0,0,.25);
  animation: rise 1.1s ease-out forwards;
}
.float-txt.big { font-size: 30px; color: var(--c2); }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -160%) scale(1); } }

/* ---------- game over ---------- */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(23,18,30,.62); border-radius: 14px; animation: fade .3s; backdrop-filter: blur(2px); }
@keyframes fade { from { opacity: 0; } }
.over-card { background: var(--paper); border-radius: 14px; padding: 18px 22px; text-align: center; width: min(86%, 320px); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.over-card h2 { margin: 0; font-size: 26px; }
.over-sub { margin: 0; color: var(--muted); font-size: 14px; }
.over-score { font-size: 46px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 6px; }
.over-best { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.over-best.new { color: var(--c1); font-weight: 800; font-size: 16px; }
.over-stats { display: flex; justify-content: center; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.over-stats b { color: var(--ink); }

/* ---------- tray + pieces ---------- */
.tray { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: max(var(--bw), min(100%, 330px)); margin: 14px auto 0; touch-action: none; }
.slot { height: 118px; display: grid; place-items: center; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); position: relative; }
.slot.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.piece { display: grid; gap: 2px; cursor: grab; touch-action: none; transition: opacity .2s, transform .15s; }
.piece .pc, .piece .px { width: var(--s, 18px); height: var(--s, 18px); border-radius: 4px; }
.piece .px { visibility: hidden; }
.piece.dead { opacity: .28; filter: grayscale(.7); }
.piece.lifted { opacity: 0; }
.piece.deal { animation: deal .28s ease-out backwards; }
@keyframes deal { from { transform: translateY(18px) scale(.6); opacity: 0; } }
.slot:nth-child(2) .piece.deal { animation-delay: .06s; }
.slot:nth-child(3) .piece.deal { animation-delay: .12s; }

.drag-piece { position: fixed; left: 0; top: 0; display: grid; pointer-events: none; z-index: 50; will-change: transform; filter: drop-shadow(0 8px 10px rgba(0,0,0,.3)); }
.drag-piece .pc, .drag-piece .px { border-radius: 5px; }
.drag-piece .px { visibility: hidden; }
.drag-piece.back { transition: transform .18s ease-in, opacity .18s; opacity: 0; }

.play-foot { display: flex; justify-content: space-between; align-items: center; width: max(var(--bw), min(100%, 330px)); margin: 12px auto 0; gap: 8px; }
.sync { font-size: 12px; color: var(--muted); }

/* ---------- cards / records ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 8px; font-size: 18px; }
.sync-line { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.stat { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.top-list { margin: 0; padding-left: 26px; }
.top-list li { padding: 3px 0; font-variant-numeric: tabular-nums; }
.top-list li span { color: var(--muted); font-size: 13px; margin-left: 8px; }
.recent { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.recent th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--line); padding: 4px 6px; }
.recent td { border-bottom: 1px solid var(--line); padding: 5px 6px; }
.empty { color: var(--muted); font-size: 14px; }
.howto h3 { margin: 16px 0 4px; font-size: 16px; }
.howto ul { margin: 4px 0; padding-left: 20px; }
.howto li { margin: 3px 0; }
.howto p { margin: 4px 0; }

footer { text-align: center; color: var(--muted); font-size: 13px; padding: 12px 16px 28px; }
footer a { color: var(--muted); }

@media (max-width: 560px) {
  .top { padding-top: 8px; }
  .title-row { align-items: center; }
  .home-link { font-size: 12px; }
  .profile-chip { font-size: 13px; }
  .profile-chip .sp-in, .profile-chip .sp-up { padding: 3px 8px; }
  .tabs { margin-top: 6px; }
  .tab { padding: 5px 7px; font-size: 15px; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  main { padding-top: 8px; }
  .hud { margin-bottom: 8px; }
  .hud-box { padding: 3px 8px; }
  .hud-lbl { font-size: 10px; }
  .hud-num { font-size: 20px; }
  .tray { margin-top: 10px; }
  .slot { height: 96px; }
  .play-foot { margin-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- leaderboard ---------- */
.lb-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lb-head h2 { margin: 0; }
.lb td:first-child, .lb th:first-child { width: 38px; text-align: center; }
.lb td:nth-child(3) { font-weight: 800; }
.lb tr.me td { background: color-mix(in srgb, var(--c2) 18%, transparent); font-weight: 700; }
.lb .medal { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: #fff; font-weight: 800; font-size: 13px; }
.lb .m1 { background: var(--c2); } .lb .m2 { background: #9aa3ad; } .lb .m3 { background: #c07a45; }
.lb .you { font-size: 11px; color: var(--muted); margin-left: 4px; font-weight: 600; }
.over-rank { margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--c4); min-height: 0; }
.over-rank:empty { display: none; }
@media (max-width: 420px) { .lb-x { display: none; } }
