@font-face {
  font-family: "Lilita One";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/lilita-one.woff2") format("woff2");
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
  src: url("fonts/nunito.woff2") format("woff2");
}
:root {
  --bg: #2b1d17;
  --panel: #3b2a20;
  --edge: #140c08;
  --ink: #f6efe2;
  --muted: #cdb79c;
  --accent: #ff9a3c;
  --leaf: #8ad35a;
  --rose: #ff6f61;
  --gold: #ffd23f;
  --btn: #f6efe2;
  --btn-ink: #2b1d17;
  --font-pixel: "Lilita One", "Trebuchet MS", system-ui, sans-serif;
  --font-text: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }
body {
  background-color: var(--bg);
  background-image: url("garden.png");
  background-size: 144px 144px;
  image-rendering: pixelated;
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}
button { font: inherit; }

/* one column on phones: header, day, board, controls, footer */
.wrap {
  --bw: 600px;
  max-width: 980px;
  margin: 0 auto;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.top, .daynav, .panel, .foot { width: min(100%, var(--bw)); }
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.top .icons { justify-self: end; display: flex; gap: 6px; }
.logo {
  margin: 0;
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  line-height: 1;
  letter-spacing: 0.03em;
  color: var(--accent);
  text-shadow: 0 3px 0 var(--edge);
}
.logo span { color: var(--leaf); }
.icon-btn {
  min-width: 44px; height: 40px;
  padding: 0 9px;
  font-family: var(--font-pixel);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--edge);
  box-shadow: 0 3px 0 var(--edge);
  cursor: pointer;
}
.top #helpBtn { justify-self: start; }
.daynav { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; }
.day { font-family: var(--font-pixel); font-size: 1.1rem; color: var(--gold); text-align: center; line-height: 1.3; }
.day small { display: block; color: var(--muted); font-family: var(--font-text); font-size: 0.85rem; }
.navbtn { font-family: var(--font-pixel); font-size: 1rem; color: var(--ink); background: none; border: 0; padding: 8px 2px; cursor: pointer; white-space: nowrap; }
.navbtn:first-child { justify-self: start; }
.navbtn:last-child { justify-self: end; }
.navbtn:disabled { opacity: 0.3; cursor: default; }

.stage { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
#boardWrap { width: 100%; display: flex; justify-content: center; }
#board { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; }
.panel { display: flex; flex-direction: column; gap: 10px; }

.bar { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; text-align: center; }
.bar > div { background: var(--panel); border: 2px solid var(--edge); padding: 4px 4px 6px; }
.bar span { display: block; font-size: 0.72rem; letter-spacing: 0.06em; color: var(--muted); text-transform: uppercase; }
.bar b { display: block; font-family: var(--font-pixel); font-weight: 400; font-size: 1.8rem; line-height: 1.15; }
#score { color: var(--accent); }
#score.neg { color: var(--rose); }
#score.bump { animation: bump 0.22s ease-out; }
#score.hit { animation: hit 0.3s ease-out; }
@keyframes bump { 40% { transform: scale(1.3); } }
@keyframes hit { 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }
@media (prefers-reduced-motion: reduce) { #score.bump, #score.hit { animation: none; } }

/* fixed height, so the buttons below never jump when the text changes */
.status { margin: 0; height: 2.6em; display: flex; align-items: center; justify-content: center; text-align: center; text-wrap: balance; overflow: hidden; }
.status .bad { color: var(--rose); }
.status .gold { color: var(--gold); }

.plan { display: grid; gap: 10px; }
.buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.buttons.small .pbtn { flex: 1; min-width: 0; padding: 9px 10px 7px; font-size: 0.95rem; }
.buttons.main .pbtn { flex: 1; min-width: 0; font-size: 1.25rem; padding: 14px 12px 12px; }
.pbtn {
  font-family: var(--font-pixel);
  font-size: 1.05rem;
  min-width: 96px;
  padding: 12px 14px 10px;
  color: var(--btn-ink);
  background: var(--btn);
  border: 2px solid var(--edge);
  box-shadow: 0 4px 0 var(--edge);
  cursor: pointer;
}
.pbtn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.pbtn.go { background: var(--accent); }
.pbtn.try { background: var(--leaf); }
.pbtn.wide { width: 100%; }
.pbtn:disabled { opacity: 0.45; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.seg { display: flex; border: 2px solid var(--edge); box-shadow: 0 3px 0 var(--edge); }
.seg button { flex: 1; font-family: var(--font-pixel); font-size: 1rem; padding: 9px 8px 7px; color: var(--muted); background: var(--bg); border: 0; cursor: pointer; }
.seg button + button { border-left: 2px solid var(--edge); }
.seg button[aria-pressed="true"] { color: var(--btn-ink); background: var(--btn); }
.seg #segBest[aria-pressed="true"] { background: var(--gold); }
.seg button:disabled { cursor: not-allowed; opacity: 0.6; }

.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; font-size: 0.95rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 3px; }
.legend canvas { width: 28px; height: 28px; image-rendering: pixelated; }
.legend b { font-family: var(--font-pixel); font-weight: 400; }
.legend .pos b { color: var(--leaf); }
.legend .neg b { color: var(--rose); }

.foot { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 6px 20px; margin-top: 6px; color: var(--muted); font-size: 0.95rem; }
.next b { display: inline-block; min-width: 4.9em; text-align: left; font-family: var(--font-pixel); font-weight: 400; color: var(--ink); }
.link { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }

/* overlays */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(12, 7, 4, 0.72); }
.sheet {
  position: relative;
  width: min(100%, 420px);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 3px solid var(--edge);
  box-shadow: 0 6px 0 var(--edge);
  padding: 20px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet h2 { margin: 0; font-family: var(--font-pixel); font-weight: 400; font-size: 1.6rem; color: var(--accent); }
.close { position: absolute; top: 6px; right: 8px; width: 36px; height: 36px; font-family: var(--font-pixel); font-size: 1.2rem; color: var(--muted); background: none; border: 0; cursor: pointer; }
.close:hover { color: var(--ink); }

.result { align-items: center; text-align: center; }
.result .medal { font-size: 2.6rem; line-height: 1; margin-top: 4px; }
.result h2 { color: var(--gold); }
.result p { margin: 0; }
.result .nums { font-family: var(--font-pixel); font-size: 1.2rem; }
.result .tip { color: var(--muted); }
.crowd { width: 100%; display: grid; gap: 4px; padding-top: 10px; border-top: 2px dashed rgba(0, 0, 0, 0.45); }
.crowd-head { font-family: var(--font-pixel); font-size: 1.2rem; }
.crowd-head b { color: var(--gold); font-weight: 400; }
.crowd-sub { font-size: 0.9rem; color: var(--muted); }
.hist { display: flex; align-items: flex-end; gap: 3px; height: 70px; padding: 0 2px; border-bottom: 3px solid var(--edge); }
.hist div { flex: 1; min-height: 3px; background: #a0703f; box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.18); }
.hist div.empty { background: rgba(0, 0, 0, 0.25); box-shadow: none; }
.hist div.top { background: #4fb3ff; }
.hist div.me { background: var(--gold); outline: 2px solid var(--edge); }
.hist-axis { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); }
.share { width: 100%; display: grid; gap: 8px; padding-top: 10px; border-top: 2px dashed rgba(0, 0, 0, 0.45); }
.share-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.sbtn { font-family: var(--font-pixel); font-size: 0.95rem; padding: 7px 10px 5px; color: var(--ink); background: var(--bg); border: 2px solid var(--edge); cursor: pointer; }
.sbtn:hover { background: #4a3528; }
.share-note { font-size: 0.82rem; color: var(--muted); }
.result .buttons, .tut .buttons { width: 100%; flex-wrap: nowrap; }
.result .buttons .pbtn, .tut .buttons .pbtn { flex: 1; min-width: 0; }

.tut { text-align: center; align-items: center; }
.tut p { margin: 0; }
.tut-step { font-size: 0.85rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.tut-stage { width: 100%; display: flex; justify-content: center; }
.tut-stage canvas { display: block; image-rendering: pixelated; cursor: pointer; }
.tut-text { min-height: 4em; text-wrap: balance; }
.tut .buttons { width: 100%; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stats b { display: block; font-family: var(--font-pixel); font-weight: 400; font-size: 1.7rem; }
.stats span { font-size: 0.85rem; color: var(--muted); line-height: 1; }
.history { display: flex; flex-wrap: wrap; gap: 4px; }
.sq { width: 22px; height: 22px; display: grid; place-items: center; font-size: 0.8rem; border: 2px solid var(--edge); background: #4a3528; }
.sq.cur { outline: 2px solid var(--ink); outline-offset: 1px; }
.sheet textarea { width: 100%; font: 1rem/1.2 var(--font-text); color: var(--btn-ink); background: var(--btn); border: 2px solid var(--edge); padding: 6px; }
