/* ==========================================================================
   Yolk Yeet — UI chrome.
   The game itself is canvas; this styles the shell around it.

   Mobile-first and deliberately plain: no framework, no build step, system
   fonts only (a web font is a render-blocking request on the exact devices
   least able to afford one).
   ========================================================================== */

:root {
  --ink: #231a2e;
  --paper: #fff8e8;
  --yolk: #ffc21e;
  --yolk-deep: #f08a15;
  --plum: #2a1a3e;
  --plum-soft: #3b2b4f;
  --steel: #c9d4dc;
  --good: #4ee39a;
  --danger: #ff4d5e;

  --panel: rgba(30, 20, 44, 0.82);
  --card: #2f2340;
  --card-edge: rgba(255, 255, 255, 0.09);

  --radius: 18px;
  --radius-sm: 12px;

  /* Safe areas, so nothing hides under a notch or a home indicator. */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--plum);
  color: var(--paper);
  font-family: var(--font);
  /* Kill the mobile browser behaviours that make a canvas game feel broken. */
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  /* dvh tracks the collapsing mobile URL bar; vh does not. */
  height: 100dvh;
  width: 100vw;
}

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

/* The UI layer never eats a tap unless a panel is actually open. */
#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: absolute;
  top: calc(var(--sat) + 10px);
  left: calc(var(--sal) + 10px);
  right: calc(var(--sar) + 10px);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 3;
}
.topbar .spacer { flex: 1; }

.chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--card-edge);
  background: rgba(20, 12, 30, 0.55);
  backdrop-filter: blur(8px);
  color: var(--paper);
  font: 700 14px/1 var(--font);
  padding: 9px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:active { transform: scale(0.94); }
.chip[data-muted='true'] { opacity: 0.45; }

.coin-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, var(--yolk) 60%, #e09b12);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25) inset;
}

/* ------------------------------------------------------------------ panels */

.panel {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  display: flex;
  z-index: 4;
}
.panel[hidden] { display: none; }

.panel.center {
  align-items: center;
  justify-content: center;
  padding: calc(var(--sat) + 16px) 16px calc(var(--sab) + 16px);
  background: var(--panel);
  backdrop-filter: blur(10px);
}

/* The death screen keeps the game visible behind it — you see the splat you
   just made, which is both funnier and more motivating than a black scrim. */
.panel.death {
  align-items: flex-end;
  justify-content: center;
  padding: 0 12px calc(var(--sab) + 12px);
  background: linear-gradient(180deg, rgba(20, 12, 30, 0) 0%, rgba(20, 12, 30, 0.55) 45%, rgba(20, 12, 30, 0.86) 100%);
  animation: fade-in 160ms ease-out;
}

.panel.sheet {
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  animation: rise 200ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

.death-card { padding: 16px; }

.sheet-card {
  width: min(520px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: calc(var(--sab) + 20px);
}

/* -------------------------------------------------------------- typography */

.logo {
  margin: 0 0 4px;
  font: 900 40px/0.95 var(--font);
  letter-spacing: -0.03em;
  text-align: center;
  color: var(--yolk);
  text-shadow: 0 3px 0 var(--yolk-deep), 0 6px 14px rgba(0, 0, 0, 0.5);
}
.logo span { display: block; color: var(--paper); text-shadow: 0 3px 0 #8b4a6b; }

.lede {
  margin: 0 0 18px;
  text-align: center;
  font-size: 14px;
  opacity: 0.72;
}

h2 { margin: 0; font-size: 19px; }
h3 { margin: 0 0 8px; font-size: 16px; }

.micro { font-size: 12px; opacity: 0.6; margin: 0; }
.micro.fine { margin-top: 12px; text-align: center; }
.hint { font-size: 12px; min-height: 16px; margin: 6px 2px; color: var(--danger); }

/* ----------------------------------------------------------------- buttons */

.btn {
  pointer-events: auto;
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: 700 15px/1 var(--font);
  padding: 14px 16px;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  /* 44px minimum touch target — smaller than this and mis-taps spike. */
  min-height: 46px;
  transition: transform 60ms ease-out, filter 120ms;
}
.btn:active { transform: scale(0.97); filter: brightness(1.1); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: linear-gradient(180deg, #ffd257, var(--yolk) 55%, var(--yolk-deep));
  color: #3a2408;
  box-shadow: 0 4px 0 #b4650a, 0 10px 22px rgba(240, 138, 21, 0.3);
}
.btn-primary:active { box-shadow: 0 2px 0 #b4650a; transform: translateY(2px) scale(0.99); }

.btn-revive {
  background: linear-gradient(180deg, #63f0ae, var(--good) 60%, #26b877);
  color: #06301d;
  box-shadow: 0 4px 0 #1a8a58;
}

.btn-ghost { background: rgba(255, 255, 255, 0.07); border-color: var(--card-edge); }
.btn-text { background: none; width: 100%; opacity: 0.6; font-weight: 600; }
.btn-block { width: 100%; }
.btn-big { font-size: 18px; padding: 17px; }

.row { display: flex; gap: 10px; margin-top: 10px; }
.row .btn { flex: 1; }

.icon-btn {
  pointer-events: auto;
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--paper);
  font-size: 18px;
  opacity: 0.7;
  cursor: pointer;
  padding: 6px 10px;
}

.kbd {
  font-size: 11px;
  opacity: 0.55;
  font-weight: 600;
  margin-left: 6px;
  border: 1px solid currentColor;
  border-radius: 5px;
  padding: 2px 5px;
}

.ad-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 4px;
  padding: 3px 5px;
  margin-right: 6px;
  vertical-align: 1px;
}

/* ------------------------------------------------------------------- input */

.input {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-edge);
  background: rgba(0, 0, 0, 0.28);
  color: var(--paper);
  font: 700 17px var(--font);
  padding: 14px;
  text-align: center;
  letter-spacing: 0.02em;
}
.input:focus { outline: 2px solid var(--yolk); outline-offset: 1px; }

/* -------------------------------------------------------------- death card */

.score-row { display: flex; align-items: flex-end; margin-bottom: 6px; }
.score-row .right { margin-left: auto; text-align: right; }
.big-score { margin: 0; font: 900 52px/1 var(--font); color: var(--yolk); letter-spacing: -0.03em; }
.big-best { margin: 0; font: 800 24px/1.2 var(--font); opacity: 0.8; }

.rank-line {
  margin: 8px 0 2px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--steel);
  min-height: 19px;
}
.rank-line b { color: var(--paper); }
.coins-line { margin: 2px 0 14px; font-size: 13px; color: var(--yolk); min-height: 18px; }

/* ------------------------------------------------------------ leaderboard */

.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.wallet {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 14px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px; padding: 6px 11px;
}

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  pointer-events: auto;
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  color: var(--paper);
  border-radius: 999px;
  padding: 10px 8px;
  font: 700 13px var(--font);
  cursor: pointer;
  opacity: 0.65;
}
.tab.is-active { opacity: 1; background: rgba(255, 194, 30, 0.16); border-color: rgba(255, 194, 30, 0.4); }

.board-body { min-height: 180px; }

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.lb-row + .lb-row { margin-top: 4px; }
.lb-row:nth-child(odd) { background: rgba(255, 255, 255, 0.035); }
.lb-row.is-me { background: rgba(255, 194, 30, 0.16); outline: 1px solid rgba(255, 194, 30, 0.35); }
.lb-rank { width: 34px; font-weight: 800; opacity: 0.65; font-variant-numeric: tabular-nums; }
.lb-rank.top { color: var(--yolk); opacity: 1; }
.lb-handle { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-gap { font-size: 12px; opacity: 0.6; margin-left: 6px; }
.lb-row.is-raceable { cursor: pointer; }
.lb-row.is-raceable:active { background: rgba(255, 194, 30, 0.14); }
.lb-race { font-size: 11px; font-weight: 800; color: var(--yolk); opacity: 0.75; white-space: nowrap; }

.empty { text-align: center; padding: 26px 10px; opacity: 0.6; font-size: 13px; line-height: 1.5; }

/* -------------------------------------------------------------------- shop */

.skins {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.skin {
  pointer-events: auto;
  text-align: left;
  border: 1px solid var(--card-edge);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  padding: 10px;
  color: var(--paper);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.skin.is-equipped { border-color: var(--yolk); background: rgba(255, 194, 30, 0.12); }
.skin.is-locked { opacity: 0.82; }
.skin canvas { width: 56px; height: 56px; align-self: center; }
.skin-name { font-weight: 800; font-size: 13px; }
.skin-blurb { font-size: 11px; opacity: 0.6; line-height: 1.35; }
.skin-price { font-size: 12px; font-weight: 700; color: var(--yolk); margin-top: auto; }
.skin-price.owned { color: var(--good); }

.store-block {
  border: 1px solid rgba(255, 194, 30, 0.3);
  background: rgba(255, 194, 30, 0.08);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.perks { margin: 0 0 12px; padding-left: 18px; font-size: 13px; line-height: 1.6; opacity: 0.85; }

/* ------------------------------------------------------------------- modes */

.modes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: 100%;
  border: 1px solid var(--card-edge);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  color: var(--paper);
  padding: 12px;
  cursor: pointer;
}
.mode-card.is-current { border-color: var(--yolk); background: rgba(255, 194, 30, 0.12); }
.mode-icon { font-size: 26px; line-height: 1; flex: none; width: 32px; text-align: center; }
.mode-text { flex: 1; min-width: 0; }
.mode-name { font-weight: 800; font-size: 14.5px; }
.mode-blurb { font-size: 11.5px; opacity: 0.6; line-height: 1.4; margin-top: 2px; }
.mode-best {
  flex: none; text-align: right; font-weight: 800; font-size: 16px;
  font-variant-numeric: tabular-nums; color: var(--yolk);
}
.mode-best small { display: block; font-size: 9.5px; font-weight: 700; opacity: 0.5; color: var(--paper); }

/* Board selector chips inside the leaderboard sheet. */
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips .chip-sm {
  pointer-events: auto;
  flex: none;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  color: var(--paper);
  border-radius: 999px;
  padding: 7px 12px;
  font: 700 12px var(--font);
  cursor: pointer;
  opacity: 0.6;
  white-space: nowrap;
}
.chips .chip-sm.is-active {
  opacity: 1;
  background: rgba(255, 194, 30, 0.16);
  border-color: rgba(255, 194, 30, 0.4);
}

/* ---------------------------------------------------------------- missions */

.missions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }

.mission {
  border: 1px solid var(--card-edge);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  padding: 12px;
}
.mission.is-done { border-color: rgba(78, 227, 154, 0.45); background: rgba(78, 227, 154, 0.1); }
.mission-top { display: flex; align-items: baseline; gap: 8px; }
.mission-text { flex: 1; font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.mission-reward { font-size: 12px; font-weight: 800; color: var(--yolk); white-space: nowrap; }
.mission.is-done .mission-reward { color: var(--good); }

.mission-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  margin-top: 9px;
  overflow: hidden;
}
.mission-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--yolk-deep), var(--yolk));
  transition: width 400ms cubic-bezier(0.2, 0.9, 0.3, 1);
}
.mission.is-done .mission-fill { background: var(--good); }
.mission-count { font-size: 11px; opacity: 0.55; margin-top: 5px; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 999px;
  padding: 2px 6px;
  margin-left: 4px;
  vertical-align: 1px;
}
.badge.is-complete { background: var(--good); color: #06301d; }

/* ------------------------------------------------------------ achievements */

.achievements { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.ach {
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid var(--card-edge);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  padding: 11px;
}
.ach.is-done { border-color: rgba(78, 227, 154, 0.4); background: rgba(78, 227, 154, 0.09); }
.ach-icon {
  font-size: 24px; line-height: 1; flex: none; width: 30px; text-align: center;
  filter: grayscale(1) opacity(0.5);
}
.ach.is-done .ach-icon { filter: none; }
.ach-body { flex: 1; min-width: 0; }
/* These are spans (so the markup stays valid inside a flex row), which makes
   them inline by default — and `height` is ignored on inline elements, so the
   progress bar would silently collapse to nothing. */
.ach-name { display: block; font-weight: 800; font-size: 13.5px; }
.ach-desc { display: block; font-size: 11.5px; opacity: 0.6; line-height: 1.35; margin-top: 1px; }
.ach-reward { flex: none; font-size: 12px; font-weight: 800; color: var(--yolk); }
.ach.is-done .ach-reward { color: var(--good); }
.ach-bar {
  display: block;
  height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.1);
  margin-top: 7px; overflow: hidden;
}
.ach-fill { display: block; height: 100%; border-radius: 2px; background: var(--yolk); }
.ach.is-done .ach-fill { background: var(--good); }

/* ------------------------------------------------------------ login streak */

.streak-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 122, 47, 0.14);
  border: 1px solid rgba(255, 122, 47, 0.32);
  font-size: 12.5px;
  font-weight: 700;
}
.streak-strip[hidden] { display: none; }
.streak-strip b { color: #ffab6b; }

.streak-flame { text-align: center; font-size: 54px; margin: 4px 0 0; line-height: 1; }
.checkin-mult {
  text-align: center; margin: 2px 0 10px;
  font: 900 30px var(--font); color: var(--yolk);
}

/* --------------------------------------------------------------- challenge */

.challenge-kicker {
  text-align: center; margin: 0; font-size: 12px; font-weight: 800;
  letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.55;
}
.challenge-who {
  text-align: center; margin: 6px 0 0;
  font: 900 30px/1.1 var(--font); color: var(--paper);
  overflow-wrap: anywhere;
}
.challenge-score {
  text-align: center; margin: 2px 0 10px;
  font: 900 62px/1 var(--font); color: var(--yolk);
  text-shadow: 0 3px 0 var(--yolk-deep);
}

/* ---------------------------------------------------------------- settings */

.setting-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--card-edge);
}
.setting-name { font-weight: 700; font-size: 14.5px; }
.setting-desc { font-size: 12px; opacity: 0.6; margin-top: 2px; }
.setting-row .btn, .setting-row a.btn {
  margin-left: auto; flex: none; min-height: 38px; padding: 9px 14px;
  font-size: 13px; text-decoration: none; display: inline-flex; align-items: center;
}

.danger-zone {
  margin-top: 22px; padding: 14px;
  border: 1px solid rgba(255, 77, 94, 0.35);
  background: rgba(255, 77, 94, 0.07);
  border-radius: var(--radius-sm);
}
.danger-zone h3 { color: var(--danger); margin-bottom: 6px; }
.btn-danger {
  background: rgba(255, 77, 94, 0.16);
  border-color: rgba(255, 77, 94, 0.5);
  color: #ffb3bb;
  margin-top: 12px;
}
.btn-danger:active { background: rgba(255, 77, 94, 0.3); }
.delete-warn { color: #ffb3bb !important; opacity: 1 !important; margin-top: 12px; line-height: 1.5; }

/* ------------------------------------------------------------------- pause */

.pause-btn {
  position: absolute;
  top: calc(var(--sat) + 10px);
  left: calc(var(--sal) + 10px);
  z-index: 5;
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--card-edge);
  background: rgba(20, 12, 30, 0.5);
  backdrop-filter: blur(8px);
  color: var(--paper);
  font: 700 12px/1 var(--font);
  letter-spacing: 1px;
  cursor: pointer;
  opacity: 0.55;
}
.pause-btn:active { transform: scale(0.92); opacity: 1; }
.pause-btn[hidden] { display: none; }

.pause-title {
  text-align: center; margin: 0;
  font: 900 30px/1 var(--font); letter-spacing: -0.02em;
}
.pause-score {
  text-align: center; margin: 4px 0 2px;
  font: 900 62px/1 var(--font); color: var(--yolk);
  text-shadow: 0 3px 0 var(--yolk-deep);
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--sab) + 22px);
  transform: translateX(-50%);
  background: rgba(20, 12, 30, 0.94);
  border: 1px solid var(--card-edge);
  color: var(--paper);
  font: 600 13px var(--font);
  padding: 11px 16px;
  border-radius: 999px;
  z-index: 10;
  pointer-events: none;
  animation: rise 180ms ease-out;
  max-width: 88vw;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.is-bad { border-color: rgba(255, 77, 94, 0.6); }

/* -------------------------------------------------- stubbed ad / IAP sheet */

.ad-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 4, 14, 0.9);
  animation: fade-in 140ms ease-out;
}
.ad-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
}
.ad-tag {
  font-size: 10px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase;
  opacity: 0.5; margin-bottom: 12px;
}
.ad-art {
  height: 120px; display: grid; place-items: center; font-size: 56px;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0 12px, transparent 12px 24px);
  border-radius: var(--radius-sm); margin-bottom: 14px;
}
.ad-copy { font-size: 12.5px; opacity: 0.6; line-height: 1.5; }
.ad-copy code { background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 4px; }
.ad-price { font: 900 30px var(--font); color: var(--yolk); margin: 4px 0 10px; }
.ad-actions { display: flex; gap: 10px; margin-top: 16px; }
.ad-actions .btn { flex: 1; }

/* --------------------------------------------------------------- a11y prefs */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
