:root {
  --ink: #3b2414;
  --cream: #fff7e6;
  --cream-2: #ffeccc;
  --salsa: #e4472f;
  --salsa-dark: #b3301c;
  --lime: #5fae36;
  --lime-dark: #3f7f20;
  --shell: #f4c04e;
  --muted: #8a6a4f;
  --sky: #8fd6ff;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  align-items: flex-start;
  pointer-events: none;
}
#hud .hud-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: flex-end;
}
#hud button { pointer-events: auto; }
#hud-boosts { letter-spacing: 2px; }
#hud-boosts .pip { color: #ff6a1a; }
#hud-boosts .pip.used { color: rgba(59, 36, 20, 0.25); }
@media (max-width: 560px) {
  #hud-day { display: none; }
}

.chip {
  background: rgba(255, 247, 230, 0.92);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
}
.chip.big { font-size: 22px; padding: 4px 16px; font-variant-numeric: tabular-nums; }
.icon-btn { cursor: pointer; font-family: inherit; color: var(--ink); }

#hint {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 999px;
  pointer-events: none;
  animation: bob 1.6s ease-in-out infinite;
  white-space: nowrap;
}
@keyframes bob { 50% { transform: translate(-50%, -6px); } }

#rotate {
  position: fixed;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 56px);
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: var(--cream);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 700;
  font-size: 14px;
}
#rotate span { flex: 1; }
#rotate button {
  background: none;
  border: 0;
  color: var(--cream);
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
}

/* ---------- Panels ---------- */
.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink), 0 18px 40px rgba(59, 36, 20, 0.35);
  padding: 22px 22px 20px;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
.panel.wide { width: min(460px, calc(100vw - 32px)); }

.logo {
  margin: 0 0 6px;
  font-size: 56px;
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: var(--shell);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  transform: rotate(-3deg);
}

h2 { margin: 0; font-size: 24px; font-weight: 900; }
.sub { margin: 10px 0 4px; font-size: 18px; font-weight: 800; }
.small { margin: 4px 0; font-size: 14px; color: var(--muted); font-weight: 700; }
.error { margin: 10px 0 4px; color: var(--salsa-dark); font-weight: 800; }
.posted { margin: 10px 0 4px; font-weight: 800; color: var(--lime-dark); font-size: 17px; white-space: pre-line; }

.big-points {
  margin: 0;
  font-size: 54px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.big-points small { font-size: 22px; }

.row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.row.tight { margin-top: 6px; flex-wrap: nowrap; }

.btn {
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  color: var(--ink);
  background: var(--cream-2);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 11px 18px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  min-height: 48px;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--salsa); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:focus-visible, .tab:focus-visible, input:focus-visible, .close:focus-visible, .chip:focus-visible {
  outline: 3px solid #2f7fd8;
  outline-offset: 2px;
}

#start-form { margin-top: 12px; }
#start-form label { display: block; text-align: left; }
input#name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  -webkit-user-select: text;
  user-select: text;
}
#play { white-space: nowrap; padding-inline: 18px; }
#post-fix { margin-top: 8px; }

/* ---------- Leaderboard ---------- */
.board-head { display: flex; align-items: center; justify-content: space-between; }
.close {
  background: none;
  border: 0;
  font-size: 22px;
  font-weight: 900;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 10px;
}
.tabs {
  display: flex;
  margin: 12px 0 6px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  overflow: hidden;
}
.tab {
  flex: 1;
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  background: var(--cream-2);
  color: var(--ink);
  border: 0;
  padding: 10px;
  cursor: pointer;
}
.tab + .tab { border-left: 3px solid var(--ink); }
.tab[aria-selected="true"] { background: var(--shell); }

.rows { list-style: none; margin: 8px 0 0; padding: 0; text-align: left; }
.rows li {
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 800;
}
.rows li:nth-child(odd) { background: rgba(244, 192, 78, 0.18); }
.rows li.me { background: var(--lime); color: #fff; }
.rows .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.rows li.me .rank { color: #fff; }
.rows .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .pts { font-variant-numeric: tabular-nums; text-align: right; }
.rows .when { display: block; font-size: 12px; font-weight: 700; color: var(--muted); }
.rows li.me .when { color: #eaffdd; }
.rows .empty { display: block; text-align: center; color: var(--muted); padding: 18px; }

/* Short screens: phones held sideways */
@media (max-height: 480px) {
  .panel { padding: 12px 18px 14px; border-radius: 18px; }
  .logo { font-size: 40px; }
  .sub { margin: 6px 0 2px; font-size: 16px; }
  .big-points { font-size: 40px; }
  .row { margin-top: 10px; }
  .btn { min-height: 44px; padding: 8px 16px; }
  #start-form { margin-top: 6px; }
  .shop li { padding: 6px 8px; }
  .rows li { padding: 5px 10px; }
  .panel.wide { width: min(520px, calc(100vw - 32px)); }
}

/* ---------- Upgrades ---------- */
.shop { list-style: none; margin: 10px 0 0; padding: 0; text-align: left; }
.shop li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
}
.shop li:nth-child(odd) { background: rgba(244, 192, 78, 0.18); }
.shop .what { font-weight: 900; }
.shop .blurb { display: block; font-size: 13px; font-weight: 700; color: var(--muted); }
.shop .pips { grid-column: 1; display: flex; gap: 4px; }
.shop .pip {
  width: 16px;
  height: 10px;
  border-radius: 4px;
  border: 2px solid var(--ink);
  background: var(--cream);
}
.shop .pip.on { background: var(--salsa); }
.shop button { grid-column: 2; grid-row: 1 / span 2; min-height: 44px; font-size: 15px; padding: 8px 12px; white-space: nowrap; }
#result { width: min(500px, calc(100vw - 32px)); }

/* Phones held sideways: upgrades side by side so all four fit without scrolling */
@media (max-height: 480px) and (min-width: 520px) {
  #shop { width: min(760px, calc(100vw - 32px)); }
  #shop .shop { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  #shop .shop li:nth-child(odd) { background: none; }
  #shop .shop li { background: rgba(244, 192, 78, 0.18); }
  #shop .sub { margin-top: 0; }
  #shop .small { margin: 0; }
}

#toast {
  position: fixed;
  left: 50%;
  top: calc(max(10px, env(safe-area-inset-top)) + 54px);
  transform: translateX(-50%);
  background: var(--salsa-dark);
  color: #fff;
  font-weight: 800;
  padding: 10px 16px;
  border-radius: 12px;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 5;
}

/* ---------- Music and sound switches ---------- */
#sound {
  position: fixed;
  top: calc(max(10px, env(safe-area-inset-top)) + 50px);
  left: max(10px, env(safe-area-inset-left));
  display: flex;
  gap: 8px;
}
.round {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: rgba(255, 247, 230, 0.92);
  box-shadow: 0 3px 0 var(--ink);
  color: var(--ink);
  cursor: pointer;
}
.round:focus-visible { outline: 3px solid #2f7fd8; outline-offset: 2px; }
.round svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.round .fill { fill: currentColor; }
.round .slash { display: none; stroke: var(--salsa-dark); stroke-width: 2.8; }
.round[aria-pressed="false"] { background: rgba(230, 220, 200, 0.92); }
.round[aria-pressed="false"] .slash { display: inline; }
.round[aria-pressed="false"] .wave { display: none; }
