:root {
  --green: #059669;
  --green-dark: #047857;
  --green-soft: #D1FAE5;
  --blue: #0284C7;
  --amber: #D97706;
  --red: #DC2626;
  --ink: #0F172A;
  --muted: #475569;
  --bg: #F4F7F6;
  --arcade: 'Press Start 2P', 'Courier New', monospace;
  --round: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--round);
  color: var(--ink);
  background: linear-gradient(180deg, #ECFDF5 0%, var(--bg) 60%, #E0F2FE 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.bar {
  flex: 0 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
  background: #FFFFFF;
  border-bottom: 2px solid var(--green-soft);
}
.bar a.back { color: var(--green-dark); font-weight: 700; text-decoration: none; font-size: 0.92rem; }
.bar .ttl { font-weight: 700; letter-spacing: 0.06em; color: var(--ink); font-size: 0.98rem; }
.bar button {
  font-family: var(--round);
  border: 2px solid var(--green-soft);
  background: #FFFFFF;
  border-radius: 999px;
  font-size: 1.05rem;
  padding: 4px 12px;
  cursor: pointer;
}
.wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0 4px;
}
.stage {
  position: relative;
  width: min(100vw, calc((100dvh - 52px - 44px) * 480 / 760));
  aspect-ratio: 480 / 760;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.24);
  border: 3px solid #FFFFFF;
  background: #0F172A;
}
canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ui { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 16px; background: rgba(15, 23, 42, 0.62); pointer-events: none; }
.ui.hidden { display: none; }
.ui > * { pointer-events: auto; }
.panel {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.97);
  border: 3px solid #0F172A;
  border-radius: 18px;
  padding: 15px 15px 17px;
  box-shadow: 0 8px 0 rgba(15, 23, 42, 0.28);
  text-align: center;
}
.panel h1, .panel h2 { margin: 0 0 4px; line-height: 1.08; color: var(--ink); }
.panel h1 { font-size: clamp(1.65rem, 6.8vw, 2.2rem); }
.panel .sub { color: var(--muted); font-weight: 600; margin: 0 0 10px; font-size: 0.88rem; line-height: 1.3; }
.legend {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  background: #F8FAFC;
  border: 2px solid var(--green-soft);
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: left;
  margin-bottom: 12px;
}
.legend b.g { color: var(--green-dark); }
.legend b.b { color: var(--blue); }
.legend b.a { color: var(--amber); }
.btn {
  font-family: var(--round);
  font-weight: 700;
  border: 3px solid #0F172A;
  border-radius: 14px;
  cursor: pointer;
  padding: 10px 22px;
  font-size: 1.05rem;
  box-shadow: 0 4px 0 #0F172A;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0F172A; }
.btn.primary { background: var(--green); color: #FFFFFF; font-size: 1.2rem; padding: 11px 28px; }
.btn.alt { background: #FFFFFF; color: var(--ink); font-size: 0.9rem; padding: 8px 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 10px 0; }
.stat { background: #F0FDF4; border: 2px solid var(--green-soft); border-radius: 10px; padding: 6px; }
.stat.big { grid-column: 1 / -1; background: #FEF3C7; border-color: #FCD34D; }
.stat small { display: block; color: var(--muted); font-size: 0.66rem; font-weight: 700; text-transform: uppercase; }
.stat strong { font-family: var(--arcade); font-size: 0.85rem; color: var(--ink); }
.stat.big strong { font-size: 1.1rem; }
.hint { font-size: 0.74rem; color: var(--muted); margin-top: 8px; font-weight: 600; }

/* Shared Daily High Scores & Name/Locality Form (matches Cranky Bin Road Grump) */
.panel { touch-action: pan-y; }
label.nm { display: block; font-family: var(--arcade); font-size: 0.56rem; margin: 7px 0 4px; color: var(--green-dark); }
input#nameInput {
  font-family: var(--arcade);
  font-size: 0.96rem;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.12em;
  width: 100%;
  padding: 8px 6px;
  border: 3px solid var(--green);
  border-radius: 12px;
  background: #FFFFFF;
  color: var(--ink);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
input#nameInput:focus, input#localityInput:focus { box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.25); }
.loc-row { display: flex; gap: 6px; align-items: stretch; }
input#localityInput {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--round);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  padding: 7px 10px;
  border: 2.5px solid #94A3B8;
  border-radius: 12px;
  background: #FFFFFF;
  color: var(--ink);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.geo-btn {
  flex: 0 0 auto;
  font-family: var(--round);
  font-weight: 700;
  font-size: 0.84rem;
  padding: 0 10px;
  border: 2.5px solid var(--green);
  border-radius: 12px;
  background: #ECFDF5;
  color: var(--green-dark);
  cursor: pointer;
}
.geo-btn:disabled { opacity: 0.55; cursor: wait; }
.geo-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  color: #065F46;
  background: #ECFDF5;
  border: 1.5px solid #A7F3D0;
  border-radius: 999px;
  padding: 2px 10px;
  margin: 4px 0 2px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.err { color: var(--red); font-weight: 700; font-size: 0.78rem; min-height: 1.1em; margin: 4px 0; }
.board h2 { font-size: clamp(1.15rem, 5.2vw, 1.5rem); }
.period-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  margin: 4px 0 3px;
  background: #F1F5F9;
  border: 2px solid #0F172A;
  border-radius: 999px;
}
.period-btn {
  font-family: var(--round);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 13px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #334155;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.period-btn.on {
  background: var(--green);
  color: #FFFFFF;
  box-shadow: 0 2px 0 #0F172A;
}
.board-pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; margin: 2px 0; }
.reset-pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: #92400E;
  background: #FEF3C7;
  border: 1.5px solid #FCD34D;
  border-radius: 999px;
  padding: 2px 9px;
  margin: 4px 0 2px;
  white-space: nowrap;
}
.reset-pill.alltime {
  color: #1E40AF;
  background: #DBEAFE;
  border-color: #93C5FD;
}
.area-filter {
  margin: 6px 0 4px;
  padding: 6px 7px;
  background: #F8FAFC;
  border: 2px solid var(--green-soft);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.area-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.area-chip {
  font-family: var(--round);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1.5px solid #CBD5E1;
  background: #FFFFFF;
  color: #334155;
  cursor: pointer;
  line-height: 1.2;
}
.area-chip.on { background: var(--green); border-color: var(--green-dark); color: #FFFFFF; }
.area-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.area-controls select, .area-controls input {
  width: 100%;
  min-width: 0;
  font-family: var(--round);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 8px;
  border: 1.5px solid #CBD5E1;
  border-radius: 9px;
  background: #FFFFFF;
  color: var(--ink);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.area-controls select:focus, .area-controls input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.18); }
table.scores { width: 100%; border-collapse: collapse; margin: 6px 0; font-family: var(--arcade); font-size: clamp(0.5rem, 2.5vw, 0.68rem); }
table.scores th { color: var(--muted); font-size: 0.52rem; text-align: left; padding: 4px 5px; border-bottom: 2px solid var(--green-soft); }
table.scores td { padding: 5px; text-align: left; border-bottom: 1px dashed #E2E8F0; vertical-align: middle; }
table.scores td.sc, table.scores th.sc { text-align: right; white-space: nowrap; }
table.scores td.pl { max-width: 240px; }
table.scores .p-nm { line-height: 1.2; }
table.scores .p-loc { font-family: var(--round); font-size: 0.72rem; font-weight: 600; color: #475569; margin-top: 2px; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.scores tr.me td { background: #FEF3C7; color: #92400E; font-weight: 700; }
table.scores tr.me .p-loc { color: #92400E; }
table.scores tr.gap td { text-align: center; color: var(--muted); border-bottom: none; padding: 2px; }
.src { font-size: 0.72rem; font-weight: 600; color: var(--muted); margin: 2px 0 4px; }

/* Bottom touch / arcade bar inside 480x760 stage */
.controls {
  position: absolute;
  left: 0; right: 0; bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  pointer-events: none;
}
.controls button {
  pointer-events: auto;
  height: 58px;
  border-radius: 15px;
  border: 3px solid #0F172A;
  font-family: var(--round);
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 4px 0 #0F172A;
  cursor: pointer;
}
.controls button:active { transform: translateY(2px); box-shadow: 0 1px 0 #0F172A; }
.controls .mv { width: 88px; background: rgba(255, 255, 255, 0.92); font-size: 1.4rem; }
.controls .slam { flex: 1 1 auto; background: #FACC15; color: #0F172A; font-size: 1.05rem; letter-spacing: 0.03em; }
.controls .slam:active { background: #FEF08A; }

footer { flex: 0 0 auto; height: 44px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 0 12px; font-size: 0.68rem; color: #64748B; line-height: 1.2; }
footer a { color: var(--green-dark); font-weight: 700; text-decoration: none; }
@media (max-height: 600px) { footer { display: none; } .stage { width: min(100vw, calc((100dvh - 52px - 8px) * 480 / 760)); } }
