:root {
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Varela Round", "Trebuchet MS", system-ui, sans-serif;
  --ink: #4a2e12;
  --cream: #fffaf0;
  --green: #4cb45c;
  --green-dark: #2f8a3f;
  --gold: #ffc83d;
  --gold-dark: #e8a417;
  --sky: #bfe6ff;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  font-family: var(--font);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
}
body { position: fixed; inset: 0; }

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

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

.pill {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 22px 6px 8px;
  background: var(--cream);
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(74, 46, 18, 0.18), 0 8px 18px rgba(0, 0, 0, 0.12);
  font-weight: 900;
  font-size: clamp(26px, 5.2vmin, 40px);
  min-width: 120px;
  justify-content: center;
}
.pill.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 0% { scale: 1; } 40% { scale: 1.14; } 100% { scale: 1; } }

.coin {
  display: inline-block;
  width: 1.15em; height: 1.15em;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #ffe08a 0 38%, var(--gold) 40% 100%);
  box-shadow: 0 0.12em 0 var(--gold-dark), inset 0 0 0 0.06em #fff3c4;
  position: relative;
  flex: none;
}
.coin::after {
  content: "★";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.62em; color: var(--gold-dark);
}
.coin.small { width: 0.95em; height: 0.95em; }

.card {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: calc(10px + var(--safe-l));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  background: var(--cream);
  border-radius: 22px;
  box-shadow: 0 4px 0 rgba(74, 46, 18, 0.18), 0 8px 18px rgba(0, 0, 0, 0.12);
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.2s;
}
.card.ready { animation: glow 1.1s ease-in-out infinite; }
@keyframes glow {
  0%, 100% { box-shadow: 0 4px 0 rgba(74, 46, 18, 0.18), 0 0 0 0 rgba(255, 200, 61, 0.9); }
  50% { box-shadow: 0 4px 0 rgba(74, 46, 18, 0.18), 0 0 0 8px rgba(255, 200, 61, 0); }
}
.goal-icon {
  width: clamp(48px, 9vmin, 66px); height: clamp(48px, 9vmin, 66px);
  border-radius: 16px;
  background: #e9f7df;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.goal-icon img { width: 100%; height: 100%; object-fit: contain; }
.goal-body { display: flex; flex-direction: column; gap: 6px; min-width: clamp(80px, 16vmin, 120px); }
.goal-bar { height: 14px; border-radius: 8px; background: #e6dccb; overflow: hidden; }
#goal-fill { height: 100%; width: 0%; background: linear-gradient(#7ed38a, var(--green)); border-radius: 8px; transition: width 0.25s; }
.card.ready #goal-fill { background: linear-gradient(#ffe08a, var(--gold)); }
.goal-price { display: flex; align-items: center; gap: 6px; font-weight: 900; font-size: clamp(18px, 3.6vmin, 26px); }

#gear {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: rgba(255, 250, 240, 0.55);
  pointer-events: auto;
  padding: 9px;
  cursor: pointer;
  touch-action: none;
}
#gear svg { width: 100%; height: 100%; fill: rgba(74, 46, 18, 0.55); }
#gear .ring { position: absolute; inset: 0; width: 44px; height: 44px; transform: rotate(-90deg); }
#gear .ring circle { fill: none; stroke: var(--gold-dark); stroke-width: 4; stroke-dasharray: 107; stroke-dashoffset: 107; }
#gear.holding .ring circle { transition: stroke-dashoffset 1s linear; stroke-dashoffset: 0; }

/* Edge arrow: points at the next job when it is off screen. */
#edge {
  position: fixed;
  width: 54px; height: 54px;
  margin: -27px 0 0 -27px;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(circle, #fff 0 58%, transparent 60%);
  border-radius: 50%;
}
#edge::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  border: 14px solid transparent;
  border-left: 22px solid #ff8a1f;
  transform: translate(-30%, -50%);
}

/* ---------- touch joystick ---------- */
#joy {
  position: fixed;
  width: 120px; height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 3px solid rgba(255, 255, 255, 0.55);
  z-index: 6;
  pointer-events: none;
}
#joy-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}

/* ---------- first-time control hint ---------- */
#hint {
  position: fixed;
  left: 50%;
  bottom: calc(14% + var(--safe-b));
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
}
.hint-touch { width: 150px; height: 90px; position: relative; display: none; }
.touch .hint-touch { display: block; }
.touch .hint-keys { display: none; }
.finger {
  position: absolute; left: 20px; top: 20px;
  width: 54px; height: 54px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.35);
  animation: drag 1.6s ease-in-out infinite;
}
@keyframes drag { 0%, 15% { transform: translate(0, 0); } 60%, 75% { transform: translate(70px, -6px); } 100% { transform: translate(0, 0); } }
.hint-keys { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: nudge 1.4s ease-in-out infinite; }
.hint-keys .row { display: flex; gap: 6px; }
.k {
  width: 50px; height: 50px; border-radius: 12px;
  background: var(--cream); color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 900;
  box-shadow: 0 4px 0 rgba(74, 46, 18, 0.25);
}
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

/* ---------- start screen ---------- */
#start {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 250, 235, 0.55), rgba(143, 208, 106, 0.55) 70%);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.45s;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
}
#start.gone { opacity: 0; pointer-events: none; }
.start-inner { display: flex; flex-direction: column; align-items: center; gap: clamp(14px, 3.5vmin, 30px); }
.logo {
  margin: 0;
  font-size: clamp(40px, 9vmin, 84px);
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.01em;
  text-align: center;
  line-height: 1;
  text-shadow: 0 4px 0 #d9473c, 0 8px 0 rgba(74, 46, 18, 0.25);
  -webkit-text-stroke: 2px #d9473c;
  animation: float 3s ease-in-out infinite;
}
.logo span { display: block; font-size: 0.55em; color: #ffe08a; -webkit-text-stroke: 2px #e8a417; text-shadow: 0 3px 0 #e8a417; }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-6px) rotate(1deg); } }
.who { display: flex; gap: clamp(10px, 2.5vmin, 22px); flex-wrap: wrap; justify-content: center; }
.who button {
  width: clamp(72px, 15vmin, 120px); height: clamp(72px, 15vmin, 120px);
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.7);
  background: #fffaf0;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  box-shadow: 0 5px 0 rgba(74, 46, 18, 0.18);
}
.who button img { width: 100%; height: 100%; object-fit: cover; }
.who button[aria-checked="true"] { border-color: var(--gold); transform: scale(1.1); box-shadow: 0 0 0 5px rgba(255, 200, 61, 0.45), 0 5px 0 rgba(74, 46, 18, 0.18); }
#play {
  width: clamp(110px, 22vmin, 170px); height: clamp(110px, 22vmin, 170px);
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 50% 35%, #7ed38a, var(--green) 60%, var(--green-dark));
  box-shadow: 0 8px 0 #1f6a2d, 0 14px 26px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  animation: breathe 1.6s ease-in-out infinite;
}
#play:disabled { filter: grayscale(0.7); animation: none; opacity: 0.7; }
#play svg { width: 55%; height: 55%; fill: #fff; margin-left: 8%; }
#play:active { transform: translateY(4px); box-shadow: 0 4px 0 #1f6a2d; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.start-note { margin: 0; font-weight: 800; color: rgba(74, 46, 18, 0.7); font-size: 16px; min-height: 1.2em; }

/* ---------- grown-ups panel ---------- */
#parent, #oops {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(30, 40, 30, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.panel {
  background: var(--cream);
  border-radius: 24px;
  padding: 22px 22px 18px;
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  -webkit-user-select: text; user-select: text;
  touch-action: pan-y;
}
.panel h2 { margin: 0 0 12px; font-size: 26px; }
.toggles { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.toggles label { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.toggles input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--green); }
.toggles .select { justify-content: space-between; }
.toggles select { font: inherit; font-size: 16px; padding: 4px 8px; border-radius: 10px; border: 2px solid #e2d6c0; background: #fff; }
.stats { background: #f3ead8; border-radius: 14px; padding: 10px 14px; font-size: 15px; line-height: 1.6; margin-bottom: 10px; }
.about { font-size: 14px; line-height: 1.45; color: rgba(74, 46, 18, 0.8); margin: 8px 0; }
.buttons { display: flex; gap: 10px; justify-content: space-between; margin-top: 14px; flex-wrap: wrap; }
.panel button {
  font: inherit; font-weight: 800; font-size: 16px;
  border: 0; border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  background: #e9dfcc; color: var(--ink);
}
.panel button.primary { background: var(--green); color: #fff; }
.panel button.danger { background: #f6d5d0; color: #9b2c22; }
.confirm { margin-top: 12px; padding: 12px; border-radius: 14px; background: #fbe7e3; }
.confirm p { margin: 0 0 10px; font-weight: 700; }
.confirm button { margin-right: 8px; }

/* ---------- small phones ---------- */
@media (max-width: 560px) {
  .pill {
    left: auto;
    right: calc(62px + var(--safe-r));
    transform: none;
    min-width: 0;
    padding: 5px 16px 5px 6px;
    font-size: 26px;
  }
  .card { padding: 5px 10px 5px 5px; border-radius: 18px; }
  .goal-icon { width: 46px; height: 46px; border-radius: 13px; }
  .goal-body { min-width: 64px; }
  .goal-price { font-size: 18px; }
}
@media (max-height: 430px) {
  .pill { font-size: 24px; padding: 4px 16px 4px 5px; top: calc(6px + var(--safe-t)); }
  .card { top: calc(6px + var(--safe-t)); }
  .goal-icon { width: 42px; height: 42px; }
  #gear { top: calc(8px + var(--safe-t)); }
}

/* Aces Education: a quiet way back to the Games page from the grown-ups menu. */
.panel .leave { display: block; margin-top: 14px; text-align: center; font-weight: 700; color: var(--green); }
