/* The page's colours, type and layout (SPEC 10). The sheets take their
   colours from the picture, as these variables (SPEC 10.2). Page text is in
   the device's own font; headings and buttons are in capitals with wide
   letter-spacing, as the picture's lettering is (SPEC 7.6). No web font. */
:root {
  --night: #070b1a;
  --edge: #1c2547;
  --ink: #e9ecfb;
  --soft: #8f97b5;
  --gold: #f8d666;
  --wood: #553923;
  --wood-ink: #ffebb8;
  --right: #7ff28f;
  --wrong: #f2756f;
  --foot: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--night);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

h1, h2, h3, h4 { font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
h2 { color: var(--gold); font-size: 1.125rem; margin: 20px 0 8px; }
h3 { color: var(--gold); font-size: 0.9375rem; margin: 22px 0 8px; }
h4 { color: var(--c, var(--gold)); font-size: 0.8125rem; margin: 14px 0 6px; }

a { color: var(--gold); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Visually hidden, still read (SPEC 14 item 1). */
.vh {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- the stage: fills the window above the footer, and never moves (SPEC 10.1) ---- */
#stage {
  position: relative;
  height: calc(100vh - var(--foot));
  height: calc(100dvh - var(--foot));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#scene {
  display: block;
  image-rendering: pixelated;
  touch-action: pinch-zoom;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

/* The mirror lies over the canvas's box. Its buttons take keyboard and
   assistive presses; pointer taps pass through to the canvas (SPEC 14). */
#mirror {
  position: absolute;
  pointer-events: none;
}
#mirror .controls { position: absolute; inset: 0; }
#mirror .ctl {
  position: absolute;
  margin: 0; padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  pointer-events: none;
}
#mirror .ctl:focus-visible { outline: 2px solid var(--gold); outline-offset: 0; }

/* The question's picture, fitted inside its box without cropping (SPEC 10.4). */
#pic {
  position: absolute;
  object-fit: contain;
  cursor: zoom-in;
  image-rendering: auto;
}
#plain .pic-slot #pic { position: static; display: block; width: 100%; height: 9rem; margin: 6px 0; }

/* ---- Plain text (SPEC 10.4): the sign and the plaques as page text ---- */
#plain {
  position: absolute;
  overflow-y: auto;
  padding: 10px 12px;
  background: rgba(7, 11, 26, 0.94);
  border: 1px solid var(--edge);
  border-radius: 6px;
  font-size: 1rem;
}
#plain p { margin: 0 0 6px; }
#plain .top { color: var(--soft); font-size: 0.875rem; }
#plain .big { color: var(--gold); font-size: 1.5rem; font-weight: 700; }
#plain .q { font-weight: 600; }
#plain .choices { display: grid; gap: 6px; margin: 8px 0; }
#plain .choice {
  display: block; width: 100%; text-align: left;
  min-height: 44px; padding: 8px 10px;
  border: 1px solid var(--edge); border-radius: 6px;
  background: #101733; color: var(--ink); font: inherit;
}
#plain .choice .n { display: inline-block; min-width: 1.4em; color: var(--gold); font-weight: 700; }
#plain .choice:disabled { opacity: 0.6; }
#plain .choice.right { opacity: 1; border-color: var(--right); }
#plain .choice.wrong { opacity: 1; border-color: var(--wrong); }
#plain .choice.right .n, #plain .choice.right .word { color: var(--right); }
#plain .choice.wrong .n, #plain .choice.wrong .word { color: var(--wrong); }
#plain .line.right { color: var(--gold); }
#plain .line.wrong { color: var(--wrong); }
#plain .crowd { color: var(--soft); }

/* ---- buttons ---- */
.btn {
  display: inline-block;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid #7a5434;
  border-radius: 4px;
  background: var(--wood);
  color: var(--wood-ink);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-decoration: none;
  cursor: pointer;
}
.btn.gold { border-color: var(--gold); }
.btn:hover { filter: brightness(1.12); }

button.link {
  min-height: 32px;
  padding: 4px 6px;
  border: 0;
  background: none;
  color: var(--gold);
  font: inherit;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}

/* ---- the sheet (SPEC 10.1): over the stage; on the phone from 34% of its
   height down, so the lit tree shows above it; on the wide layout a 560 px
   column with 16 px above and below. It scrolls inside itself. ---- */
#sheet.sheet {
  position: absolute;
  z-index: 5;
  left: 0; right: 0; top: 34%; bottom: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 18px 28px;
  background: var(--night);
  border-top: 1px solid var(--edge);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
  animation: sheet-up 0.22s ease-out;
}
body.wide #sheet.sheet {
  left: 50%; right: auto; top: 16px; bottom: 16px;
  width: 560px; max-width: calc(100% - 16px);
  transform: translateX(-50%);
  border: 1px solid var(--edge);
  border-radius: 8px;
  animation: sheet-in 0.22s ease-out;
}
/* It slides; it never fades, so a page that stalls an animation still shows a solid sheet. */
@keyframes sheet-up { from { transform: translateY(24px); } to { transform: none; } }
@keyframes sheet-in { from { transform: translate(-50%, 24px); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { #sheet.sheet, body.wide #sheet.sheet { animation: none; } }

#sheet .top { position: sticky; top: 0; z-index: 1; margin: 0 -18px 4px; padding: 10px 18px 6px; background: var(--night); }
#sheet .body p { margin: 6px 0; }
#sheet ul, #sheet ol { margin: 0; padding: 0; list-style: none; }
.soft { color: var(--soft); }

/* the results (SPEC 10.7) */
#sheet .rank { font-size: 1.75rem; margin: 10px 0 2px; }
#sheet .total { font-size: 1.25rem; font-weight: 700; margin: 0; }
#sheet .rows .row { padding: 8px 0; border-bottom: 1px solid var(--edge); }
#sheet .row .who b { color: var(--c); }
#sheet .dot { display: inline-block; width: 0.7em; height: 0.7em; margin-right: 0.4em; border-radius: 2px; background: var(--c); }
#sheet .row .crowd, #sheet .row .next { color: var(--soft); }
#sheet .marks .m { font-weight: 700; margin-right: 2px; }
#sheet .m.right, #sheet li.right > .m { color: var(--right); }
#sheet .m.wrong, #sheet li.wrong > .m { color: var(--wrong); }
#sheet .strong { color: var(--gold); }
#sheet .recap li { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--edge); }
#sheet .recap .m { font-weight: 700; }
#sheet .recap .q { font-weight: 600; }
#sheet .recap .big { color: var(--gold); font-weight: 700; }
#sheet .recap .note, #sheet .recap .gotthis, #sheet .recap .credit { color: var(--soft); }
#sheet .recap .pic img { display: block; max-width: 160px; max-height: 100px; object-fit: contain; }
#sheet .recap .credit { font-size: 0.8125rem; }
#sheet .copied { color: var(--right); }
.more-games {
  margin: 18px 0;
  padding: 10px 12px;
  border: 1px dashed var(--edge);
  border-radius: 6px;
  color: var(--soft);
  text-align: center;
}
#sheet .stats dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 12px; margin: 0; }
#sheet .stats dt { color: var(--soft); font-size: 0.8125rem; }
#sheet .stats dd { margin: 0; font-size: 1.25rem; font-weight: 700; }
#sheet .profile li { padding: 5px 0; }
#sheet .profile b { color: var(--c); }
#sheet .bars { display: block; margin-top: 3px; }
#sheet .bar { display: block; height: 5px; margin: 2px 0; border-radius: 2px; }
#sheet .bar.you { background: #b8f5b0; }
#sheet .bar.all { background: var(--soft); }
#sheet .chart-box { max-width: 320px; margin: 4px auto; }
#sheet .chart { display: block; width: 100%; height: auto; font-size: 11px; }
#sheet .countdown { margin-top: 20px; color: var(--gold); }

/* the menu and its panels (SPEC 10.9) */
#sheet .menu { display: grid; gap: 8px; margin-top: 10px; }
#sheet .menu .btn { width: 100%; text-align: left; }
#sheet .how { list-style: decimal; padding-left: 1.25rem; }
#sheet .how li { margin: 6px 0; }
#sheet fieldset.setting { margin: 12px 0; padding: 8px 12px; border: 1px solid var(--edge); border-radius: 6px; }
#sheet legend { color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; font-size: 0.8125rem; }
#sheet fieldset label { display: block; padding: 4px 0; }
#sheet .carry .code { font: 700 1.25rem/1.3 ui-monospace, Consolas, monospace; letter-spacing: 0.06em; }
#sheet .carry input[type=text] {
  min-height: 40px; width: min(100%, 18rem);
  padding: 6px 8px;
  border: 1px solid var(--edge); border-radius: 4px;
  background: #0b1124; color: var(--ink);
  font: 1rem ui-monospace, Consolas, monospace;
}
#sheet .carry .confirm { margin: 8px 0; padding: 8px 10px; border: 1px solid var(--gold); border-radius: 6px; }
#sheet .carry .result { color: var(--gold); }

/* the picture viewer (SPEC 10.10): as large as the stage allows */
#sheet.viewer {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--night);
  cursor: zoom-out;
}
#sheet.viewer figure { margin: 0; display: flex; flex-direction: column; align-items: center; max-width: 100%; max-height: 100%; padding: 12px; }
#sheet.viewer img { max-width: 100%; max-height: calc(100dvh - var(--foot) - 60px); object-fit: contain; }
#sheet.viewer figcaption { margin-top: 8px; color: var(--soft); font-size: 0.875rem; }

/* the shelf couldn't be loaded (SPEC 10.6) */
.load-failed { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; text-align: center; }

/* ---- the footer: one line under every screen (SPEC 10.1) ---- */
footer {
  height: var(--foot);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 8px;
  border-top: 1px solid var(--edge);
  color: var(--soft);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
}

/* Below the fold, so the picture never moves to make room for it. */
#about { max-width: 640px; margin: 0 auto; padding: 24px 16px 48px; color: var(--ink); }
#about .how { padding-left: 1.25rem; }
#about .how li { margin: 6px 0; }
