:root {
  --ink: #3a2408;
  --panel: rgba(70, 38, 4, 0.62);
  --honey: #f4a21b;
  --deep: #c46a00;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfe8f7; color: #fff; }
button { font: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: #fff4dc;
  border: 1px solid #e8cf9a;
  color: var(--ink);
}

/* ---------- Scene ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800; font-size: 3.2vh; line-height: 1;
  white-space: nowrap;
  color: #fff;
  -webkit-text-stroke: 0.3vh #5a3300;
  paint-order: stroke;
  animation: float-up 1.1s ease-out both;
}
.pop-label.big { font-size: 5.4vh; color: #ffe17a; }
.pop-label.bonk { font-size: 5vh; color: #ff7b54; }
@keyframes float-up {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  15% { transform: translate(-50%, -80%) scale(1.1); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -260%) scale(1); opacity: 0; }
}

/* The touch stick: where the finger went down, and where it is now */
#stick {
  position: absolute;
  width: 22vmin; height: 22vmin;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 0.6vmin solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}
#knob {
  position: absolute; left: 50%; top: 50%;
  width: 9vmin; height: 9vmin;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe08a, var(--honey) 60%, var(--deep));
  box-shadow: 0 0.6vmin 1.4vmin rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -50%);
}

/* ---------- Top: toolbar, size, clock ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 2vw;
  padding: 2vh 2vw;
  z-index: 10;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#toolbar { display: flex; gap: 0.6vh; flex: 0 0 auto; width: 30vh; }
#toolbar button {
  width: 5.4vh; height: 5.4vh;
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  font-size: 2.8vh;
  cursor: pointer;
  color: #fff;
  display: grid; place-items: center;
}
#toolbar button:hover { background: rgba(70, 38, 4, 0.85); }

#meter {
  display: flex; flex-direction: column; align-items: center;
  background: var(--panel);
  border-radius: 3vh;
  padding: 0.4vh 3.5vh 1vh;
  pointer-events: none;
  min-width: 26vh;
}
#size { font-size: 7vh; line-height: 1.05; text-shadow: 0 0.4vh 0 rgba(0, 0, 0, 0.3); color: #ffd25e; }
#like { font-size: 2.6vh; font-weight: 700; line-height: 1; }
[data-phase='load'] #hud-top > #meter, [data-phase='menu'] #hud-top > #meter { visibility: hidden; }

#clock {
  width: 30vh; text-align: right;
  font-size: 6vh; font-weight: 800; line-height: 1;
  pointer-events: none;
}
#clock::before { content: ''; }
#clock { color: #fff; text-shadow: 0 0.4vh 0 rgba(0, 0, 0, 0.35), 0 0 2vh rgba(0, 0, 0, 0.25); }
#clock.low { color: #ff6b4a; animation: throb 1s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.12); } }
[data-phase='load'] #clock, [data-phase='menu'] #clock { visibility: hidden; }

/* ---------- Middle: messages ---------- */
#banner {
  position: fixed; left: 50%; top: 22vh;
  transform: translate(-50%, -50%) scale(0.6);
  max-width: 80vw;
  text-align: center;
  font-size: 4.4vh; font-weight: 800; line-height: 1.2;
  padding: 1vh 4vh;
  border-radius: 3vh;
  background: var(--panel);
  opacity: 0;
  pointer-events: none;
  z-index: 11;
  transition: opacity 0.3s, transform 0.3s;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); transition: opacity 0.2s, transform 0.35s cubic-bezier(.2, .9, .3, 1.5); }
#banner.grow { background: linear-gradient(180deg, #ffb52e, #e07b00); font-size: 5.2vh; box-shadow: 0 0.8vh 0 #9a5200; }
#banner b { color: #fff6c9; }

/* ---------- Bottom: what's next, and Dash ---------- */
#hud-bottom {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; align-items: flex-end;
  padding: 0 2vw 3vh;
  z-index: 10;
  pointer-events: none;
}
#next {
  background: var(--panel);
  border-radius: 2.4vh;
  padding: 0.8vh 2.4vh 1.4vh;
  width: min(60vw, 64vh);
  text-align: center;
}
#next-what { display: block; font-size: 2.8vh; font-weight: 700; line-height: 1.3; }
#next-bar { height: 2vh; border-radius: 999px; background: rgba(255, 255, 255, 0.22); overflow: hidden; }
#next-fill {
  height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffe08a, var(--honey));
  transition: width 0.3s;
}
#dash {
  position: fixed; right: 3vw; bottom: 3vh;
  width: 16vh; height: 16vh;
  border: none; border-radius: 50%;
  font-size: 4vh; font-weight: 800;
  background: radial-gradient(circle at 35% 30%, #ffe08a, var(--honey) 55%, var(--deep));
  color: #4a2600;
  box-shadow: 0 0.8vh 0 #8a4a00;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
}
#dash:active { transform: translateY(0.6vh); box-shadow: 0 0.2vh 0 #8a4a00; }
#hud-bottom { display: none; }
[data-phase='play'] #hud-bottom { display: flex; }
@media (hover: hover) and (pointer: fine) { #dash { display: none; } }

/* ---------- Menu and results ---------- */
#setup, #result {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  overflow: auto;
  padding: 3vh 2vw;
}
#setup { background: radial-gradient(ellipse at center, rgba(60, 30, 0, 0.15), rgba(40, 20, 0, 0.55)); }
#result { background: radial-gradient(ellipse at center, rgba(60, 30, 0, 0.05), rgba(40, 20, 0, 0.45)); animation: fade 0.5s both; }
@keyframes fade { from { opacity: 0; } }
.panel {
  width: min(860px, 94vw);
  background: rgba(255, 251, 240, 0.97);
  color: var(--ink);
  border-radius: 28px;
  padding: 26px 34px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
}
.logo { margin: 0; font-size: 56px; line-height: 1; font-weight: 800; color: var(--deep); letter-spacing: -0.5px; }
.tagline { margin: 8px 0 18px; font-size: 19px; line-height: 1.35; color: #6a4a20; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: 8px; }
.cards button {
  border: 3px solid #f0dfba;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.cards button:hover { transform: translateY(-2px); }
.cards button[aria-pressed='true'] { border-color: var(--deep); background: #fff3d6; }
.cards b { display: block; font-size: 22px; line-height: 1.1; }
.cards span { display: block; font-size: 15px; color: #7a5a30; line-height: 1.3; }
.cards span.best { font-weight: 800; color: var(--deep); margin-top: 2px; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 18px; }
.buttons button {
  border: none;
  border-radius: 999px;
  font-size: 22px; font-weight: 800;
  padding: 12px 34px;
  cursor: pointer;
}
.buttons .primary { background: var(--deep); color: #fff; box-shadow: 0 6px 0 #7a4100; }
.buttons .primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #7a4100; }
.buttons .primary:disabled { opacity: 0.5; cursor: wait; }
.buttons .secondary { background: #f3e3c0; color: var(--ink); box-shadow: 0 6px 0 #d1b98a; }
#loading { font-size: 17px; font-weight: 700; color: #8a6a3a; }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: #2e7d4a; }
.help { margin-top: 16px; font-size: 15px; color: #6a4a20; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.5; }

#result { place-items: center end; padding-right: 4vw; }
#result .panel { text-align: center; width: min(560px, 94vw); }
@media (max-aspect-ratio: 4/3) { #result { place-items: center; padding-right: 2vw; } }
#result p { margin: 0; }
.kicker { font-size: 22px; font-weight: 700; color: #8a6a3a; }
#result-size { font-size: 96px; font-weight: 800; line-height: 1; color: var(--deep); }
#result-like { font-size: 24px; font-weight: 700; }
.stars { font-size: 56px; line-height: 1.1; margin: 4px 0 !important; color: #e8d9b8; letter-spacing: 6px; }
.stars .on { color: #ffb400; text-shadow: 0 3px 0 #b36b00; display: inline-block; animation: star 0.5s cubic-bezier(.2, .9, .3, 1.6) both; }
.stars .on:nth-child(2) { animation-delay: 0.25s; }
.stars .on:nth-child(3) { animation-delay: 0.5s; }
@keyframes star { from { transform: scale(0) rotate(-90deg); } }
.stars:empty { display: none; }
#result-best { font-size: 18px; font-weight: 700; color: #2e7d4a; margin-bottom: 10px !important; }
#result-count, #result-biggest { font-size: 17px; color: #6a4a20; }
#result-list {
  list-style: none; padding: 0; margin: 8px 0 10px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
}
#result-list li { background: #fff0cc; border-radius: 999px; padding: 2px 12px; font-size: 16px; }
#result-list b { color: var(--deep); }
#result .buttons { justify-content: center; }
