/* 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: #9ccc5c; 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 ---------- */
#scene {
  position: fixed; inset: 0;
  display: flex; gap: 3vw;
  padding: 17vh 3vw 11vh 3vw;
  background: linear-gradient(#a9d8ef, #d9eff6 38%, #9ccc5c 38%, #7db446);
}
#fence {
  position: absolute; left: 0; right: 0; top: 24%; height: 15%;
  background:
    linear-gradient(transparent 22%, #c99c62 22%, #c99c62 32%, transparent 32%, transparent 68%, #c99c62 68%, #c99c62 78%, transparent 78%),
    repeating-linear-gradient(90deg, #e3c08a 0 3.2vh, transparent 3.2vh 4.4vh);
}
#bed-area { position: relative; z-index: 1; flex: 1; min-width: 0; }
/* Room on the left for the goal label */
#bed { position: absolute; top: 0; left: 10vh; width: calc(100% - 10vh); height: 100%; overflow: visible; }
.hole { fill: #4a2d17; }
.goal-label {
  position: absolute;
  transform: translate(-100%, -50%);
  padding: 0 0.8vh;
  border-right: 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, body.fun .goal-line { display: none; }
.flower { transform-box: fill-box; transform-origin: 50% 100%; }
.flower.grow { animation: grow 0.7s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes grow { from { transform: scale(0.05, 0); } to { transform: scale(1); } }
.flower.picked { animation: picked 1.1s ease-in forwards; }
@keyframes picked { to { transform: translateY(-60%) scale(0.6) rotate(-12deg); opacity: 0; } }

/* ---------- The scratch card ---------- */
#card-area { position: relative; z-index: 2; width: min(32vw, 54vh); display: grid; place-items: center; }
body.fun #card-area { visibility: hidden; }
#card {
  width: 100%;
  padding: 2.2vh 2.2vh 1.6vh;
  border-radius: 10px;
  background: #fffaf0;
  box-shadow: 0 1.2vh 3vh rgba(40, 60, 20, 0.3);
  text-align: center;
  transition: transform 0.5s cubic-bezier(.2, .9, .3, 1.15);
}
#card.dealing { transform: translateY(100vh) rotate(10deg); transition: none; }
#card.out { transform: translate(60vw, -10vh) rotate(16deg); transition: transform 0.6s ease-in; }
.card-top {
  margin-bottom: 1.6vh;
  padding: 0.6vh 0 0.9vh;
  border-radius: 6px;
  background: #3f7f2e;
  color: #fff;
  font-size: clamp(20px, 4.4vh, 60px); font-weight: 800; line-height: 1.1;
}
#card-window {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background: #fdf1d0;
  border: 2px dashed #e0c98f;
  overflow: hidden;
}
.prize { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#prize-number {
  font-size: clamp(48px, 15vh, 200px); font-weight: 800; line-height: 0.9;
  color: #3f7f2e;
}
#prize-words { font-size: clamp(16px, 3.4vh, 46px); font-weight: 800; line-height: 1; color: #5b4a3a; }
#prize-flowers { width: 80%; height: 30%; margin-top: 1vh; }
#card.won #prize-number { animation: won 0.5s cubic-bezier(.2, .9, .3, 1.6); }
@keyframes won { from { transform: scale(0.6); } to { transform: scale(1); } }
#scratch {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44'%3E%3Ccircle cx='22' cy='22' r='18' fill='%23f2b52a' stroke='%23b9831a' stroke-width='4'/%3E%3Ccircle cx='22' cy='22' r='10' fill='none' stroke='%23d9960f' stroke-width='2.5'/%3E%3C/svg%3E") 22 22, pointer;
  transition: opacity 0.5s;
}
#scratch.gone { opacity: 0; pointer-events: none; }
.card-foot { margin: 1.2vh 0 0; font-size: clamp(14px, 2.4vh, 32px); font-weight: 700; line-height: 1.2; color: #5b4a3a; }

#flying { position: fixed; inset: 0; pointer-events: none; z-index: 15; }
.seed {
  position: absolute; left: 0; top: 0;
  width: 2.4vh; height: 3.4vh; margin: -1.7vh 0 0 -1.2vh;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: #e2b46c;
  border: 0.35vh solid #8a5a2c;
}

/* ---------- 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%);
  width: max-content; 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: 3vw; top: 55%; z-index: 10;
  transform: translateY(-50%);
  width: min(36vw, 64vh);
  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(56px, 16vh, 240px); 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: 600px) {
  #count { top: calc(2vh + 48px); padding: 0 2vh 0.4vh; }
  #count b { font-size: 40px; }
  #count span { font-size: 18px; }
  #scene { padding-top: calc(4vh + 110px); }
}
@media (max-width: 700px) {
  #setup { padding: 12px; justify-content: center; background: rgba(40, 28, 16, 0.4); }
  .panel { padding: 20px; }
  .logo { font-size: 40px; }
}
@media (max-aspect-ratio: 1/1) {
  #scene { flex-direction: column; padding: 15vh 4vw 13vh; }
  #card-area { width: 100%; height: 36vh; }
  #card { width: auto; height: 100%; display: flex; flex-direction: column; }
  #card-window { flex: 1; aspect-ratio: auto; min-width: 40vh; }
  .card-foot { display: none; }
  #fun { right: 50%; transform: translate(50%, 0); width: 90vw; top: auto; bottom: 4vh; }
}
