:root {
  --sky: #72d8ff;
  --ink: #1b1b2a;
  --paper: #fffdf6;
  --ball: #d9e534;
  --liver: #6e4026;
  --hud-font: "Arial Black", "Helvetica Neue", Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  font-family: var(--hud-font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  outline: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  container-type: inline-size;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

/* ---- HUD -------------------------------------------------------------- */
.hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  color: #fff;
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink),
    0 6px 0 rgba(0, 0, 0, 0.35);
  letter-spacing: 0.04em;
  line-height: 1;
}
.hud .score { font-size: clamp(40px, 12cqi, 76px); font-weight: 900; }
.hud .best  { font-size: clamp(13px, 3.6cqi, 20px); font-weight: 900; margin-top: 8px; opacity: 0.95; }

.hud-right {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  color: var(--ball);
  font-size: clamp(24px, 7cqi, 44px);
  font-weight: 900;
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink);
  display: flex;
  align-items: center;
  gap: 0.3em;
}
.ball-icon {
  display: inline-block;
  width: 0.8em; height: 0.8em;
  border-radius: 50%;
  background: var(--ball);
  box-shadow: inset -0.12em -0.12em 0 rgba(0,0,0,0.18), 0 0 0 3px var(--ink);
  position: relative;
}

/* ---- Overlays ---------------------------------------------------------- */
.overlay[hidden], [hidden] { display: none !important; }
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 40, 0.35);
  pointer-events: none;
}
.card {
  text-align: center;
  color: #fff;
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink);
  font-weight: 900;
  line-height: 1.05;
  max-width: 100%;
  padding: 0 16px;
  box-sizing: border-box;
}
.card-title { font-size: clamp(36px, 12cqi, 80px); }
.card-score { font-size: clamp(56px, 22cqi, 140px); margin-top: 0.1em; }
.card-best  { font-size: clamp(15px, 4.2cqi, 26px); margin-top: 0.4em; opacity: 0.95; }
.card-new   { font-size: clamp(20px, 6cqi, 40px); color: var(--ball); margin-top: 0.4em; animation: pop 0.6s ease-out infinite alternate; }
.card-hint  { font-size: clamp(12px, 3.2cqi, 18px); margin-top: 1.4em; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.1em; }
@keyframes pop { from { transform: scale(1); } to { transform: scale(1.08); } }

/* ---- HUD buttons ------------------------------------------------------- */
.hud-buttons { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
.hud-btn, .big-btn, .small-btn, .chip {
  pointer-events: auto;
  cursor: pointer;
  font-family: var(--hud-font);
  font-weight: 900;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  transform: translateY(0);
  transition: transform 0.06s, box-shadow 0.06s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.hud-btn:active, .big-btn:active, .small-btn:active, .chip:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.hud-btn { width: 44px; height: 44px; font-size: 18px; line-height: 1; text-shadow: none; }
.hud-btn.off { opacity: 0.6; }
.big-btn { font-size: clamp(18px, 5.5cqi, 30px); padding: 0.5em 1.4em; margin-top: 0.8em; text-shadow: none; }
.small-btn { font-size: clamp(12px, 3cqi, 15px); padding: 0.5em 1.1em; margin-top: 1.2em; text-shadow: none; letter-spacing: 0.08em; }

/* ---- Title: logo at the top, picker at the bottom, Charlie in the clear --- */
.title-overlay { flex-direction: column; justify-content: space-between; background: rgba(20, 20, 40, 0.18); }
.title-top { padding-top: clamp(96px, 12cqi, 140px); }
.title-bottom { padding-bottom: max(4vh, 20px); }
.title-bottom .picker { margin-top: 0.8em; }
.title-bottom .card-hint { margin-top: 0; }
.logo { display: flex; flex-direction: column; align-items: center; line-height: 0.9; }
.logo span { font-size: clamp(40px, 15.5cqi, 108px); letter-spacing: 0.02em; }
.logo .logo-road { color: var(--ball); font-size: clamp(34px, 13cqi, 92px); }
.tagline { font-size: clamp(11px, 3.1cqi, 18px); margin-top: 0.8em; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.95; }
.title-stats { font-size: clamp(13px, 3.8cqi, 22px); margin-top: 0.9em; }
.title-stats .dot { margin: 0 0.5em; opacity: 0.7; }
.pulse { animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.55; } to { opacity: 1; } }

/* ---- Outfit picker -------------------------------------------------------- */
.picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 1.1em; }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 92px; padding: 8px 6px;
  font-size: 12px; text-shadow: none; line-height: 1.1;
}
.chip .swatch { width: 28px; height: 28px; border-radius: 8px; border: 3px solid var(--ink); }
.chip .chip-name { font-size: 13px; }
.chip .chip-cost { font-size: 11px; opacity: 0.75; }
.chip.on { background: var(--ball); }
.chip.on .chip-cost { opacity: 1; }
.chip.locked { opacity: 0.55; filter: grayscale(0.6); }
.chip.locked .swatch { background: #999 !important; }

.card-balls { font-size: clamp(15px, 4.5cqi, 28px); margin-top: 0.5em; color: var(--ball); display: flex; align-items: center; justify-content: center; gap: 0.35em; }
.ball-icon.small { width: 0.8em; height: 0.8em; }

/* ---- Bark button ------------------------------------------------------- */
.bark-btn {
  pointer-events: auto;
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: clamp(64px, 18cqi, 84px);
  height: clamp(64px, 18cqi, 84px);
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 0 5px 0 var(--ink);
  overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.06s, box-shadow 0.06s;
}
.bark-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.bark-btn .bark-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; background: var(--ball); transition: height 0.1s linear; }
.bark-btn .bark-face { position: relative; font-size: clamp(26px, 7cqi, 34px); line-height: 1; filter: grayscale(1) opacity(0.45); }
.bark-btn .bark-label { position: relative; font-size: 10px; font-weight: 900; letter-spacing: 0.1em; color: var(--ink); opacity: 0.55; }
.bark-btn.ready .bark-face { filter: none; animation: wag 0.6s ease-in-out infinite alternate; }
.bark-btn.ready .bark-label { opacity: 1; }
@keyframes wag { from { transform: rotate(-8deg); } to { transform: rotate(8deg); } }

/* ---- Controls line, first-run hint, toast, combo ------------------------- */
.controls { font-size: clamp(11px, 3cqi, 15px); margin-top: 0.7em; opacity: 0.95; letter-spacing: 0.06em; text-transform: uppercase; }
.hint-bar {
  position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 140px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(27, 27, 42, 0.72);
  color: #fff;
  font-size: clamp(11px, 3cqi, 14px);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast {
  position: absolute; left: 50%; top: 30%;
  transform: translate(-50%, -50%) scale(0.6);
  text-align: center;
  color: #fff;
  font-weight: 900;
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink);
  opacity: 0;
}
.toast.in { animation: toast-in 1.8s cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }
.toast-title { font-size: clamp(30px, 11cqi, 72px); color: var(--ball); line-height: 1; }
.toast-sub { font-size: clamp(14px, 4cqi, 24px); margin-top: 0.3em; }
@keyframes toast-in {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  12%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  20%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1); }
}
.combo {
  position: absolute; left: max(16px, env(safe-area-inset-left)); top: calc(max(14px, env(safe-area-inset-top)) + clamp(64px, 18cqi, 110px));
  color: var(--ball);
  font-size: clamp(18px, 5.5cqi, 34px);
  font-weight: 900;
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink);
}
.combo.in { animation: combo-in 1.4s ease-out forwards; }
@keyframes combo-in { 0% { transform: scale(0.6); opacity: 0; } 15% { transform: scale(1.15); opacity: 1; } 30% { transform: scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }

/* ---- Daily challenge and the card ----------------------------------------- */
.daily-tag { display: inline-block; margin-top: 8px; padding: 2px 8px; border-radius: 999px; background: var(--ball); color: var(--ink); font-size: clamp(11px, 3cqi, 14px); font-weight: 900; letter-spacing: 0.1em; text-shadow: none; }
.title-actions { margin-top: 0.8em; }
.daily-btn { margin-top: 0; }
.go-actions { display: flex; gap: 10px; justify-content: center; margin-top: 1.2em; }
.go-actions .small-btn { margin-top: 0; }
#cardview { background: rgba(20, 20, 40, 0.6); z-index: 20; }
.card-frame { pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: min(92cqi, 420px); }
.card-frame img { width: 100%; height: auto; border-radius: 18px; box-shadow: 0 14px 40px rgba(0,0,0,0.45); }
.card-actions { display: flex; gap: 10px; }
.card-actions .small-btn { margin-top: 0; text-decoration: none; display: inline-block; }

@container (max-width: 480px) {
  .chip { width: 76px; }
  .hud-btn { width: 40px; height: 40px; }
  .picker { gap: 8px; }
}

#debug {
  position: fixed;
  left: 8px;
  bottom: 8px;
  padding: 4px 8px;
  font: 12px/1.4 ui-monospace, Menlo, monospace;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  pointer-events: none;
  z-index: 50;
}
