/* Self-hosted so the game works offline and behind school web filters.
   Variable font (SIL Open Font License), latin subset. */
@font-face {
  font-family: 'Baloo 2';
  font-weight: 400 800;
  font-display: swap;
  src: url(../fonts/baloo2.woff2) format('woff2');
}

:root {
  --ink: #2b2118;
  --brown: #7a4f1e;
  --brown-dark: #573611;
  --gold: #f2b52a;
  --red: #c0392b;
  --paper: rgba(255, 251, 242, 0.94);
  --panel: rgba(43, 33, 24, 0.72);
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e6dccb; color: var(--ink); }
button, select { font: inherit; }
[hidden] { display: none !important; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* ---------- Scene ---------- */
#viewport, #stage { position: fixed; inset: 0; overflow: hidden; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.goal-label {
  position: absolute; left: 0; top: 0;
  transform: translate(0.6vh, -50%);
  padding: 0 0.6vh;
  border-left: 0.5vh solid var(--red);
  background: var(--paper);
  color: var(--red);
  font-size: clamp(14px, 2.6vh, 34px); font-weight: 800; line-height: 1.3;
  white-space: nowrap;
}
body.fun .goal-label { display: none; }
.prize-label {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -100%) scale(0.2);
  opacity: 0;
  padding: 0 2vh;
  border-radius: 6px;
  background: var(--gold);
  color: var(--ink);
  font-size: clamp(32px, 9vh, 120px); font-weight: 800; line-height: 1.15;
  box-shadow: 0 0.6vh 0 #b9831a;
  transition: transform 0.4s cubic-bezier(.2, .9, .3, 1.5), opacity 0.2s;
}
.prize-label.show { transform: translate(-50%, -100%) scale(1); opacity: 1; }
.prize-label.gone { transform: translate(-50%, -100%) scale(0.2); opacity: 0; }

/* ---------- Toolbar ---------- */
#toolbar { position: fixed; left: 2vw; top: 2vh; z-index: 30; display: flex; gap: 0.6vh; }
#toolbar button {
  width: 5.2vh; height: 5.2vh; min-width: 36px; min-height: 36px;
  display: grid; place-items: center;
  border-radius: 6px;
  border: none;
  background: var(--panel);
  backdrop-filter: blur(6px);
  font-size: 2.6vh;
  cursor: pointer;
  color: #fff;
}
#toolbar button:hover { background: rgba(43, 33, 24, 0.9); }
body.menu #toolbar { display: none; }

/* ---------- The count ---------- */
#count {
  position: fixed; top: 2vh; left: 50%; z-index: 10;
  transform: translateX(-50%);
  display: flex; align-items: baseline; gap: 1.6vh;
  padding: 0.4vh 3vh 0.8vh;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 0.8vh 2.4vh rgba(60, 40, 20, 0.15);
  white-space: nowrap;
}
#count b {
  font-size: clamp(44px, 11vh, 150px); line-height: 1; font-weight: 800;
  color: var(--brown);
  font-variant-numeric: tabular-nums;
}
#count span { font-size: clamp(18px, 3.6vh, 48px); font-weight: 700; color: #5b4a3a; }
#count.goal b { color: #d9960f; }
#count.goal b::before { content: '★ '; font-size: 0.6em; vertical-align: 0.2em; }
#count b.pop { animation: pop 0.35s cubic-bezier(.2, .9, .3, 1.5); }
@keyframes pop { from { transform: scale(1.15); } to { transform: scale(1); } }
body.fun #count, body.menu #count { display: none; }

#hint {
  position: fixed; left: 50%; bottom: 4vh; z-index: 10;
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 1vh 3vh 1.2vh;
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: clamp(18px, 3.8vh, 52px); font-weight: 700; line-height: 1.2;
  text-align: center;
  visibility: hidden;
}
#hint.show { visibility: visible; }
body.menu #hint { display: none; }

/* ---------- Fun time ---------- */
#fun {
  position: fixed; right: 5vw; top: 50%; z-index: 10;
  transform: translateY(-50%);
  width: min(46vw, 80vh);
  padding: 3vh 4vh 4vh;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 2vh 6vh rgba(60, 40, 20, 0.2);
  text-align: center;
}
body.menu #fun { display: none; }
#fun h2 { margin: 0; font-size: clamp(24px, 6vh, 80px); line-height: 1.1; color: var(--brown); }
#fun-clock {
  margin: 1vh 0 0;
  font-size: clamp(60px, 20vh, 280px); font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums;
}
#fun.paused #fun-clock { opacity: 0.45; }
#fun-line { margin: 1vh 0 3vh; font-size: clamp(16px, 3vh, 40px); color: #5b4a3a; }
.fun-buttons { display: flex; gap: 2vh; justify-content: center; }
#fun button {
  padding: 1vh 3vh;
  border: 2px solid #d8ccb5;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: clamp(16px, 3vh, 40px); font-weight: 700;
  cursor: pointer;
}
#fun button.primary { border-color: var(--brown); background: var(--brown); color: #fff; }

/* ---------- Teacher menu ---------- */
#setup {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex;
  padding: 3vh 4vw;
  overflow: auto;
  background: linear-gradient(90deg, rgba(40, 28, 16, 0.45), rgba(40, 28, 16, 0) 65%);
}
.panel {
  width: min(540px, 92vw);
  margin: auto 0;
  background: rgba(255, 252, 245, 0.97);
  border-radius: 10px;
  padding: 22px 30px 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
}
.logo { margin: 0; font-size: 44px; line-height: 1; font-weight: 800; color: var(--brown); letter-spacing: -0.5px; }
.tagline { margin: 6px 0 14px; font-size: 17px; line-height: 1.35; color: #5b4a3a; }
.week {
  padding: 8px 14px 10px;
  margin-bottom: 14px;
  border-radius: 6px;
  background: #f1e8d6;
}
.week-total { font-size: 18px; }
.week-total b { font-size: 30px; color: var(--brown); margin-right: 4px; }
.week p { margin: 2px 0 0; font-size: 16px; color: #5b4a3a; }
.panel h2 { margin: 0 0 8px; font-size: 18px; }
.choices { display: flex; gap: 8px; margin-bottom: 12px; }
.choices button {
  flex: 1;
  padding: 6px 0;
  border: 2px solid #d8ccb5;
  border-radius: 6px;
  background: #fff;
  font-size: 22px; font-weight: 800;
  color: var(--ink);
  cursor: pointer;
}
.choices button[aria-checked="true"] { border-color: var(--brown); background: #f6ead6; color: var(--brown-dark); }
.row { display: flex; gap: 16px; margin-bottom: 10px; }
.row label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 17px; }
select { padding: 6px 10px; border-radius: 6px; border: 2px solid #d8ccb5; background: #fff; font-size: 17px; }
.buttons { display: flex; gap: 10px; margin-top: 14px; }
.buttons button {
  flex: 1;
  padding: 8px 16px;
  border: 2px solid var(--brown);
  border-radius: 6px;
  background: #fff;
  color: var(--brown-dark);
  font-size: 19px; font-weight: 800;
  cursor: pointer;
}
.buttons button.primary { background: var(--brown); color: #fff; }
.buttons button:disabled { opacity: 0.5; cursor: default; }
.small-buttons { display: flex; gap: 16px; margin-top: 10px; }
.small-buttons button {
  padding: 0;
  border: none;
  background: none;
  color: var(--brown-dark);
  font-size: 16px; font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}
.small-buttons button:disabled { color: #a99a87; text-decoration: none; cursor: default; }
#empty:not(:disabled) { color: var(--red); }
.error { color: #b3261e; font-weight: 700; }
#offline-status { margin: 10px 0 0; font-size: 14px; font-weight: 700; color: #3d7a4a; }
.help { margin-top: 14px; font-size: 16px; line-height: 1.4; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; margin: 8px 0 0; }
.help li { margin-bottom: 6px; }

@media (max-width: 700px) {
  #setup { padding: 12px; justify-content: center; background: rgba(40, 28, 16, 0.4); }
  .panel { padding: 20px; }
  .logo { font-size: 40px; }
  #fun { right: 50%; transform: translate(50%, -50%); width: 90vw; top: 62%; }
}
