:root { --ink:#111; --pink:#ff5fa2; --blue:#4fc3f7; --paper:#fff8f0; --gold:#ffd23f; }
* { box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }
html, body { background:#1b1030; color:#fff; font-family:"Helvetica Neue", Arial, sans-serif; }
html { height:100%; }
body { height:100vh; height:100dvh; display:flex; flex-direction:column; align-items:center; overscroll-behavior:none;
  touch-action:manipulation; -webkit-user-select:none; user-select:none; -webkit-touch-callout:none;
  padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
header.bar { flex:0 0 auto; width:100%; max-width:960px; display:flex; align-items:center; justify-content:space-between; padding:.6rem .9rem; gap:.5rem; }
header.bar a.back { color:#fff; text-decoration:none; font-weight:700; font-size:.95rem; white-space:nowrap; }
header.bar h1 { white-space:nowrap; font-family:"Arial Black", Impact, sans-serif; font-size:clamp(.78rem, 3.6vw, 1.4rem); letter-spacing:.03em; text-transform:uppercase;
  background:var(--pink); color:#111; padding:.15rem .6rem; transform:rotate(-1.5deg); box-shadow:4px 4px 0 var(--blue); }
header.bar .tools { display:flex; gap:.2rem; flex:0 0 auto; }
@media (max-width:400px) { header.bar { padding:.5rem .5rem; } header.bar h1 { font-size:.74rem; padding:.15rem .4rem; box-shadow:3px 3px 0 var(--blue); } header.bar button { font-size:1.2rem; padding:.2rem; } }
header.bar button { background:none; border:0; font-size:1.4rem; cursor:pointer; padding:.2rem .3rem; color:#fff; }
.stage { flex:1 1 auto; min-height:0; width:100%; max-width:1100px; display:flex; align-items:center; justify-content:center; position:relative; padding:.2rem .4rem; }
canvas { display:block; border:4px solid #111; border-radius:6px; box-shadow:0 0 0 3px var(--pink), 8px 8px 0 3px #000;
  touch-action:none; user-select:none; -webkit-user-select:none; background:#87c8f0; }
.pad { flex:0 0 auto; display:none; width:100%; max-width:960px; gap:.6rem; padding:.6rem .6rem .9rem; }
.pad button { flex:1; -webkit-touch-callout:none; touch-action:none; font:900 1.15rem "Arial Black", Impact, sans-serif; padding:1.1rem 0; border:4px solid #111; border-radius:10px;
  background:var(--gold); color:#111; box-shadow:5px 5px 0 #000; touch-action:none; user-select:none; -webkit-user-select:none; }
.pad button:active, .pad button.on { transform:translate(3px,3px); box-shadow:2px 2px 0 #000; }
.pad button.alt { background:var(--blue); }
@media (pointer:coarse) { .pad { display:flex; } }
.help { flex:0 0 auto; max-width:960px; font-size:.85rem; opacity:.75; padding:.3rem 1rem .8rem; text-align:center; }
.rotate-tip { display:none; flex:0 0 auto; font-weight:700; font-size:.85rem; padding:.2rem 1rem .5rem; color:var(--gold); text-align:center; }

/* ---------- Phones & tablets ---------- */
@media (pointer:coarse) {
  .help { display:none; }
  canvas { border-width:3px; box-shadow:0 0 0 2px var(--pink); border-radius:4px; }
  .pad button { padding:1.25rem 0; font-size:1.25rem; }
}
@media (pointer:coarse) and (orientation:portrait) {
  .rotate-tip.for-portrait { display:block; }
}
/* Phone held sideways: overlay header + buttons so the game gets the full height */
@media (pointer:coarse) and (orientation:landscape) and (max-height:520px) {
  header.bar { position:fixed; top:0; left:0; right:0; max-width:none; z-index:5; padding:.25rem .6rem; pointer-events:none;
    padding-left:max(.6rem, env(safe-area-inset-left)); padding-right:max(.6rem, env(safe-area-inset-right)); }
  header.bar a, header.bar button { pointer-events:auto; background:rgba(17,17,17,.55); border-radius:8px; padding:.25rem .5rem; font-size:.9rem; }
  header.bar h1 { display:none; }
  .stage { padding:0; max-width:none; }
  canvas { border:0; border-radius:0; box-shadow:none; }
  .pad { display:none !important; position:fixed; left:0; right:0; bottom:0; z-index:4; justify-content:space-between; pointer-events:none; max-width:none;
    padding:0 max(.8rem, env(safe-area-inset-right)) max(.8rem, env(safe-area-inset-bottom)) max(.8rem, env(safe-area-inset-left)); }
  .pad button { pointer-events:auto; flex:0 0 26%; padding:1.4rem 0; opacity:.82; }
  .rotate-tip.for-landscape { display:block; position:fixed; bottom:.4rem; left:0; right:0; z-index:4; pointer-events:none; text-shadow:0 1px 3px #000; }
}

#over { position:fixed; inset:0; -webkit-user-select:text; user-select:text; background:rgba(10,5,30,.82); display:flex; z-index:10; padding:1rem; overflow:auto; -webkit-overflow-scrolling:touch; }
#over .card { margin:auto; }
#over[hidden] { display:none; }
.card { background:var(--paper); color:#111; border:5px solid #111; border-radius:10px; box-shadow:10px 10px 0 var(--pink);
  width:min(420px, 100%); padding:1.2rem 1.2rem 1rem; text-align:center; }
.ov-title { font:900 1.7rem "Arial Black", Impact, sans-serif; text-transform:uppercase; color:#e0245e; }
.ov-sub { font-weight:700; margin:.2rem 0 .6rem; }
.ov-score { font:900 3rem "Arial Black", Impact, sans-serif; line-height:1; }
.ov-best { font-weight:700; color:#7a3fbf; margin:.2rem 0 .8rem; }
.card form { display:flex; gap:.4rem; margin-bottom:.4rem; }
.card input { flex:1; min-width:0; font:700 1rem inherit; padding:.6rem; border:3px solid #111; border-radius:6px; }
.card form button, .ov-retry { font:900 1rem "Arial Black", Impact, sans-serif; padding:.6rem .9rem; border:3px solid #111; border-radius:6px;
  background:var(--gold); box-shadow:3px 3px 0 #111; cursor:pointer; }
.ov-retry { width:100%; margin-top:.8rem; background:var(--pink); font-size:1.15rem; padding:.8rem; }
.ov-status { min-height:1.2em; font-size:.85rem; font-weight:700; color:#555; }
.lb-wrap h3 { font:900 .95rem "Arial Black", Impact, sans-serif; text-transform:uppercase; margin:.6rem 0 .3rem; }
.lb { list-style:none; text-align:left; font-size:.92rem; }
.lb li { display:flex; gap:.5rem; padding:.28rem .4rem; border-bottom:2px dashed #ddd; }
.lb li.me { background:#ffe36e; font-weight:700; }
.lb .rk { width:1.6rem; font-weight:900; }
.lb .nm { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.lb .lv { opacity:.6; font-size:.8rem; align-self:center; }
.lb .sc { font-weight:900; }
.lb-empty { justify-content:center; opacity:.7; }
.card .home { display:inline-block; margin-top:.7rem; color:#111; font-weight:700; font-size:.9rem; }
@media (max-width:340px) { header.bar .lbl { display:none; } header.bar h1 { font-size:.7rem; } }

@media (max-height:500px) {
  #over { padding:.5rem; }
  .card { padding:.7rem 1rem .7rem; width:min(560px, 100%); }
  .ov-title { font-size:1.2rem; } .ov-sub { font-size:.85rem; margin:.1rem 0 .3rem; }
  .ov-score { font-size:2rem; } .ov-best { margin:.1rem 0 .4rem; font-size:.9rem; }
  .lb-wrap h3 { margin:.3rem 0 .2rem; } .lb li { padding:.15rem .4rem; font-size:.85rem; }
  .ov-retry { margin-top:.5rem; padding:.55rem; }
}
