:root {
  --paper: #f3eee1;
  --card: #fbf8f0;
  --ink: #1d2619;
  --muted: #5e6656;
  --line: #d8cfba;
  --moss: #3d6a27;
  --moss-soft: #dfe8cf;
  --leaf: #b8561f;
  --leaf-soft: #f4dccb;
  --shadow: 0 1px 0 rgba(60, 50, 20, .06), 0 6px 18px -8px rgba(60, 50, 20, .25);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121710;
    --card: #1a2117;
    --ink: #e9e5d6;
    --muted: #a3a893;
    --line: #2f3a2a;
    --moss: #8dc06a;
    --moss-soft: #22321a;
    --leaf: #e58a54;
    --leaf-soft: #3a2518;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 20px -10px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 460px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px 40px;
}

header { margin-bottom: 18px; }
.kicker {
  margin: 0;
  font: 600 12px/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--moss);
}
h1 {
  margin: 6px 0 6px;
  font: 600 30px/1.1 var(--serif);
  letter-spacing: -.01em;
}
.lede { margin: 0; color: var(--muted); }
.streak { margin: 8px 0 0; font-weight: 600; color: var(--moss); min-height: 1.5em; }

/* ---- the card ---- */
.card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.sq {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  background: transparent center / cover no-repeat;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  transition: transform .12s ease, border-color .12s ease;
}
.sq:hover { border-color: var(--moss); }
.sq:active { transform: scale(.97); }
.sq:focus-visible { outline: 3px solid var(--moss); outline-offset: 2px; }
.sq .emoji { font-size: 30px; line-height: 1; }
.sq .name { font-size: 12.5px; line-height: 1.2; text-align: center; color: var(--muted); }
.sq.center { border-style: solid; border-color: var(--moss); background-color: var(--moss-soft); }
.sq.center .name { color: var(--moss); font-weight: 600; }

.sq.done { border: 0; }
.sq.done::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,.55));
}
.sq.done .emoji { display: none; }
.sq.done .name {
  position: absolute; left: 6px; right: 6px; bottom: 6px; z-index: 1;
  color: #fff; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.stamp {
  position: absolute; top: 8px; right: -4px; z-index: 1;
  padding: 2px 8px;
  border: 2px solid currentColor;
  border-radius: 4px;
  color: #e9f5dc;
  background: rgba(61, 106, 39, .85);
  font: 700 10px/1.3 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
  transform: rotate(8deg);
}
.sq.line { box-shadow: 0 0 0 3px var(--leaf); }

.sq.wiggle { animation: wiggle .5s ease-in-out infinite alternate; border-color: var(--leaf); }
@keyframes wiggle { from { transform: rotate(-1.5deg); } to { transform: rotate(1.5deg); } }
@media (prefers-reduced-motion: reduce) { .sq.wiggle { animation: none; } }

.tally { margin: 12px 2px 0; font: 600 15px/1.4 var(--serif); }

/* ---- controls ---- */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
button, .camera {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: 600 15px/1 var(--sans);
  padding: 12px 16px;
  border-radius: 999px;
  cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--moss); border-color: var(--moss); color: #fff; }
@media (prefers-color-scheme: dark) { .primary { color: #10170c; } }
button.link {
  border: 0; background: none; padding: 0;
  color: var(--moss); font: inherit; text-decoration: underline; text-underline-offset: 2px;
}

.model {
  margin-top: 22px;
  padding: 16px;
  border-radius: 12px;
  background: var(--leaf-soft);
  border: 1px solid color-mix(in srgb, var(--leaf) 30%, transparent);
}
.model p { margin: 0 0 12px; }
progress { width: 100%; height: 8px; margin-top: 12px; accent-color: var(--moss); }
.small { font-size: 13.5px; color: var(--muted); }
.load-label:empty { display: none; }

footer { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
footer p { margin: 0 0 8px; font-size: 13.5px; color: var(--muted); }
footer a, .credit a { color: var(--moss); }

/* ---- the sheet ---- */
dialog {
  width: min(460px, 100vw);
  max-height: 92vh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
@media (min-width: 520px) { dialog { margin: auto; border-radius: 18px; } }
dialog::backdrop { background: rgba(20, 25, 15, .45); }
.sheet-inner { position: relative; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); }
.close {
  position: absolute; top: 12px; right: 12px;
  width: 36px; height: 36px; padding: 0;
  font-size: 22px; line-height: 1;
}
.emoji.big { font-size: 40px; line-height: 1; }
.sheet-inner h2 { margin: 8px 0 4px; font: 600 24px/1.15 var(--serif); }
.hint { margin: 0 0 16px; color: var(--muted); }
#preview { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; margin-bottom: 8px; }
.credit { margin: 0 0 12px; }
.camera { display: inline-flex; align-items: center; gap: 8px; }
.camera input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.camera:focus-within { outline: 3px solid var(--moss); outline-offset: 2px; }

.verdict { padding: 14px 16px; border-radius: 12px; }
.verdict h3 { margin: 0 0 4px; font: 600 19px/1.25 var(--serif); }
.verdict > p { margin: 0; }
.verdict.yes { background: var(--moss-soft); }
.verdict.yes h3 { color: var(--moss); }
.verdict.no { background: var(--leaf-soft); }
.verdict.no h3 { color: var(--leaf); }
.verdict.pending { background: var(--paper); }
.verdict.pending h3::after { content: ""; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.bars { margin-top: 12px; display: grid; gap: 6px; }
.bars:empty { display: none; }
.bar { display: grid; grid-template-columns: 7.5em 1fr 3em; gap: 8px; align-items: center; font-size: 13.5px; }
.bar > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar > span:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.track { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--ink) 10%, transparent); overflow: hidden; }
.track > span { display: block; height: 100%; background: var(--moss); border-radius: 3px; }
.verdict.no .track > span { background: var(--leaf); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-weight: 700; letter-spacing: .04em;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
