:root {
  --ink: #1f2a24;
  --panel: rgba(16, 40, 36, 0.66);
  --forward: #ffd23f;
  --back: #ff6fb5;
  --green: #2f7d6d;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe6f2; color: #fff; }
button, select, output { font: inherit; }
button { 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: #e4efe9;
  border: 1px solid #b9cfc4;
  color: var(--ink);
}

/* ---------- Scene ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* Labels pinned to the 3D scene by js/scene.js (with the translate property) */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.num {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, 0);
  font-size: var(--num, 4vh); font-weight: 800; line-height: 1;
  color: #1d3b33;
  text-shadow: 0 0 0.25em #fff, 0 0 0.25em #fff, 0 0 0.12em #fff;
  white-space: nowrap;
  transition: color 0.2s, scale 0.2s;
}
.num.zero { color: #0c4f8a; }
.num.whole { font-size: calc(var(--num, 4vh) * 1.08); }
.num.here { color: #b3530b; scale: 1.25; }
.num.fly, .num.guess {
  padding: 0 0.15em;
  border-radius: 0.25em;
  box-shadow: 0 0 0 0.09em currentColor;
}
.num.guess { color: #c1121f; }

.count, .leg {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -100%);
  font-weight: 800; line-height: 1;
  white-space: nowrap;
}
.count {
  min-width: 1.6em;
  padding: 0.12em 0.3em;
  border-radius: 0.6em;
  background: #fff;
  color: var(--ink);
  font-size: 3.6vh;
  text-align: center;
  box-shadow: 0 0.4vh 1.2vh rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.2s;
}
.count.show { opacity: 1; }
.leg {
  padding: 0.05em 0.35em;
  border-radius: 0.4em;
  background: var(--c);
  color: var(--ink);
  font-size: 3.4vh;
  box-shadow: 0 0.3vh 0.8vh rgba(0, 0, 0, 0.25);
}

/* ---------- Top: toolbar, task and sum, flies caught ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; gap: 2vw;
  padding: 2vh 2vw;
  z-index: 10;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#toolbar { display: flex; gap: 0.5vw; flex: 0 0 auto; width: 18vh; }
#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(16, 40, 36, 0.85); }

#board { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1vh; }
#task, #sum {
  text-align: center;
  font-weight: 800;
  line-height: 1.15;
  border-radius: 3vh;
  background: var(--panel);
  text-shadow: 0 0.25vh 0 rgba(0, 0, 0, 0.3);
}
#task { font-size: clamp(20px, 4.2vh, 60px); padding: 0.6vh 2.4vw; max-width: 64vw; }
#sum {
  font-size: clamp(22px, 5.4vh, 76px);
  padding: 0.2vh 2vw;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  text-shadow: none;
  font-variant-numeric: tabular-nums;
}
#task:empty, #sum:empty { visibility: hidden; }
#task.pop { animation: pop 0.45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { from { transform: scale(0.85); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }

#score {
  flex: 0 0 auto; width: 18vh;
  display: flex; align-items: center; justify-content: flex-end; gap: 0.6vw;
  font-weight: 800;
}
#score svg { width: 5.4vh; }
#score b { font-size: 5vh; line-height: 1; text-shadow: 0 0.3vh 0 rgba(0, 0, 0, 0.3); }
#score span { font-size: 2.2vh; text-shadow: 0 0.2vh 0 rgba(0, 0, 0, 0.3); }
#score.bump b { display: inline-block; animation: bump 0.8s cubic-bezier(.2, .9, .3, 1.5); }
@keyframes bump { 0% { transform: scale(0.4); } 60% { transform: scale(1.6); } 100% { transform: scale(1); } }
body:not(.mode-fly) #score { visibility: hidden; }

/* ---------- Bottom: making orders ---------- */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; align-items: flex-end; gap: 1.6vw;
  padding: 0 2vw 2vh;
  z-index: 10;
}
#maker, #plan {
  background: var(--panel);
  border-radius: 2.4vh;
  padding: 1.2vh;
}
#maker { display: flex; flex-direction: column; gap: 1vh; }
#keys { display: flex; gap: 0.7vh; }
#keys button, .dir, #typed, #plan-buttons button {
  height: 7vh;
  border: none;
  border-radius: 1.6vh;
  font-size: 4vh; font-weight: 800; line-height: 1;
  cursor: pointer;
}
#keys button {
  width: 6.6vh;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 0.5vh 0 #a8c2b8;
}
#keys button:active, .dir:active, #plan-buttons button:active { transform: translateY(0.4vh); box-shadow: none; }
#keys [data-key=del] { background: #dfe9e4; }
body.whole #point { display: none; }
#dirs { display: flex; gap: 1vh; }
.dir { flex: 1; padding: 0 2vh; color: var(--ink); white-space: nowrap; }
#back { background: var(--back); box-shadow: 0 0.5vh 0 #c2407f; }
#forward { background: var(--forward); box-shadow: 0 0.5vh 0 #c99a12; }
#typed {
  width: 14vh;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.16);
  border: 0.35vh dashed rgba(255, 255, 255, 0.6);
  color: #fff;
  cursor: default;
}

#plan { flex: 1; display: flex; flex-direction: column; gap: 1vh; min-height: 17.4vh; }
#orders { flex: 1; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 0.8vh; }
#orders:empty::before {
  content: attr(data-empty);
  font-size: 2.6vh; opacity: 0.8;
  padding: 0.6vh 0.4vh;
}
.chip {
  padding: 0.3vh 1.4vh;
  border-radius: 1.4vh;
  font-size: 3.4vh; font-weight: 800;
  color: var(--ink);
  background: var(--forward);
}
.chip.back { background: var(--back); }
body.mode-predict .chip { font-size: 4.6vh; padding: 0.4vh 2vh; }
.chip.active { outline: 0.5vh solid #fff; }
.chip.dropped { opacity: 0.35; text-decoration: line-through; }
.chip.done { opacity: 0.75; }
#hint { margin: 0; min-height: 3vh; font-size: 2.5vh; font-weight: 700; color: #ffe08a; }
#plan-buttons { display: flex; gap: 1vh; justify-content: flex-end; }
#clear { padding: 0 2.4vh; background: rgba(255, 255, 255, 0.2); color: #fff; font-size: 3vh; }
#go {
  min-width: 22vh; padding: 0 3vh;
  background: #5fd068; color: #0e3a1a;
  box-shadow: 0 0.5vh 0 #2f8f3a;
}
#controls button:disabled { opacity: 0.45; cursor: default; transform: none; }
body.mode-predict #maker, body.mode-predict #clear { display: none; }

/* ---------- Setup menu ---------- */
#setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(10, 30, 26, 0.5), rgba(5, 16, 14, 0.85));
  overflow: auto;
  padding: 3vh 2vw;
}
.panel {
  width: min(900px, 94vw);
  background: rgba(252, 255, 250, 0.97);
  color: var(--ink);
  border-radius: 28px;
  padding: 26px 34px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.logo { margin: 0; font-size: 50px; line-height: 1; font-weight: 800; color: var(--green); letter-spacing: -0.5px; }
.tagline { margin: 8px 0 18px; font-size: 19px; line-height: 1.35; color: #3f5249; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
.cards.modes { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.cards button {
  border: 3px solid #d5e3dc;
  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(--green); background: #eaf6f0; }
.cards b { display: block; font-size: 24px; line-height: 1.1; }
.cards span { display: block; font-size: 15px; color: #5a6b63; line-height: 1.3; }
.modes b { font-size: 20px; }
.row { display: flex; gap: 18px; flex-wrap: wrap; }
.row label { flex: 1; max-width: 340px; display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 16px; }
.row select { padding: 8px 10px; border-radius: 12px; border: 2px solid #cfe0d7; background: #fff; font-size: 16px; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.buttons button, #reset-flies {
  border: 2px solid var(--green);
  background: #fff;
  color: var(--green);
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 19px; font-weight: 800;
  cursor: pointer;
}
.buttons button.primary { background: var(--green); color: #fff; font-size: 22px; padding: 12px 34px; box-shadow: 0 6px 0 #1d5248; }
.buttons button.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #1d5248; }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: var(--green); }
.help { margin-top: 16px; font-size: 15px; color: #3f5249; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.5; }
#reset-flies { font-size: 14px; padding: 6px 14px; border-color: #b3261e; color: #b3261e; }
