/* The page's look: a cozy tavern. Panels are framed dark wood; the wall,
   sign and lanterns are pixel art drawn by render-scenery.js.
   theme.test.js checks every tier color against --panel, so change the
   colors here and the test re-checks contrast. */

:root {
  --wall: #2a190d;
  --panel: #2b1a10;
  --panel-edge: #3d2615;
  --outline: #120a05;
  --rim: #8a5a2b;
  --text: #f3e6c8;
  --muted: #c9b48f;
  --gold: #f2c14e;
  --focus: #ffe27a;
  --shelf: #6b4224;
  --gap: 16px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  background-color: var(--wall);
  color: var(--text);
  /* A crisp monospace for the game feel; no web font to download. */
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 15px;
  line-height: 1.4;
}

h1, h2, p, ol, ul, dl, dd { margin: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A clear focus ring on everything, for keyboard players. */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* ---------- Layout: desktop ----------
   Everything on one screen, in reading order left to right: the counter
   (box and reveal), the trophy shelf, then stats. #records only groups the
   two record panels for main.js, so it steps out of the way of the layout. */

#game {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(440px, 500px) 230px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "sign  sign      sign"
    "play  trophies  stats";
  gap: var(--gap);
  height: 100dvh;
  max-width: 1320px;
  margin: 0 auto;
  padding: var(--gap);
}

#records { display: contents; }
#play { grid-area: play; }
#trophy-case { grid-area: trophies; }
#stats { grid-area: stats; }
.tabs { display: none; }

/* ---------- Layout: phone ----------
   One panel at a time, picked with the tab bar at the bottom (in reach of
   a thumb): Play, Trophies, Stats. */

@media (max-width: 760px) {
  :root { --gap: 8px; }
  #game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "sign" "panel" "tabs";
  }
  #play, #trophy-case, #stats { grid-area: panel; }
  #trophy-case, #stats { overflow-y: auto; }
  #game:not([data-tab="play"]) #play,
  #game:not([data-tab="trophies"]) #trophy-case,
  #game:not([data-tab="stats"]) #stats { display: none; }
  .tabs { display: flex; grid-area: tabs; gap: var(--gap); }
  .tabs [role="tab"] { flex: 1; }
  .hint { display: none; } /* No Space bar on a phone. */
}

/* ---------- The sign ---------- */

.sign-row {
  grid-area: sign;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  line-height: 0;
}

.lantern { position: relative; margin-top: 4px; }
/* Warm light around each lantern, flickering gently. */
.lantern::before {
  content: "";
  position: absolute;
  inset: -40px;
  background: radial-gradient(circle at 50% 60%, rgb(255 200 90 / 0.35), transparent 60%);
  animation: flicker 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  40% { opacity: 0.75; }
  55% { opacity: 0.95; }
  70% { opacity: 0.8; }
}

.sign-row canvas, .lantern canvas { image-rendering: pixelated; position: relative; }

/* ---------- Panels: framed dark wood ---------- */

.panel {
  min-height: 0;
  padding: 20px;
  background: var(--panel);
  border: 4px solid var(--outline);
  box-shadow:
    inset 0 0 0 4px var(--rim),
    inset 0 0 0 8px var(--panel-edge),
    0 6px 0 rgb(0 0 0 / 0.45);
}

.panel h2 {
  color: var(--gold);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding-bottom: 6px;
  margin-bottom: 10px;
  border-bottom: 2px dashed var(--panel-edge);
}

/* Heading on the left, a note or button on the right, one rule under both. */
.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 4px 12px;
  padding-bottom: 6px;
  margin-bottom: 10px;
  border-bottom: 2px dashed var(--panel-edge);
}
.panel-head h2 { padding: 0; margin: 0; border: 0; }

small, .note { color: var(--muted); font-size: 0.85rem; }

/* ---------- Buttons: chunky pixel blocks ---------- */

button {
  font: inherit;
  font-weight: bold;
  min-height: 44px; /* Tap target size. */
  padding: 8px 18px;
  color: var(--outline);
  background: #d9a066;
  border: 4px solid var(--outline);
  border-radius: 0;
  box-shadow: inset -4px -4px 0 #a86f3a, inset 4px 4px 0 #f0c48f;
  cursor: pointer;
}
button:active { box-shadow: inset 4px 4px 0 #a86f3a; }
button[aria-disabled="true"] { cursor: progress; }

#open-button {
  font-size: 1.4rem;
  padding: 10px 36px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--gold);
  box-shadow: inset -4px -4px 0 #c18a1f, inset 4px 4px 0 #fff0b3;
}
#open-button:active { box-shadow: inset 4px 4px 0 #c18a1f; }

/* The phone tab that's showing: gold like the Open button, and pressed in. */
[role="tab"][aria-selected="true"] {
  background: var(--gold);
  box-shadow: inset 4px 4px 0 #c18a1f;
}

/* ---------- The counter: box, lute and reveal ---------- */

#play {
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Keeps effects (the beam sits at z-index -1) above the panel's
     background, and clips them to the panel. */
  isolation: isolate;
  overflow: hidden;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

/* Fills whatever height is left; main.js fits the lute to it. Centered
   both ways, so effects placed at 50% land on the lute. */
#stage {
  position: relative;
  /* Its own layer, so the beam (z-index -1) draws over this background
     but still behind the lute. */
  z-index: 0;
  flex: 1;
  min-height: 0;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Pale stone, per Ryan: light and not warm, so brown wood (most common
     lutes) stands out, while still fitting the tavern. */
  background: radial-gradient(ellipse at 50% 55%, #e4e2dc, #b9b4a8 80%);
  box-shadow: inset 0 0 0 4px var(--outline);
  /* Clicking or tapping here opens a box too (main.js). */
  cursor: pointer;
  touch-action: manipulation; /* No double-tap zoom when tapping fast. */
}

/* The wooden counter the box sits on. */
.counter {
  flex: none;
  height: 16px;
  margin: -12px -12px 0;
  background: linear-gradient(var(--rim) 0 4px, var(--shelf) 4px 12px, var(--outline) 12px);
}

#reveal { min-height: 4.4em; text-align: center; }
#reveal [data-field="name"] { color: var(--gold); font-size: 1.2rem; }
#reveal p + p { display: inline-block; margin: 4px 8px 0; }

[data-field="odds"], .trophy .odds { text-decoration: underline dotted; cursor: help; }

#config-error { color: #ff9a8a; font-weight: bold; }

/* ---------- Stats ---------- */

#stats dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px 16px;
}
#stats dt { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
#stats .wide { grid-column: 1 / -1; }
#tier-counts { display: flex; flex-wrap: wrap; gap: 2px 14px; padding: 0; list-style: none; }
#storage-note { margin-bottom: 8px; }

/* ---------- Trophy case: a shelf ---------- */

#trophy-case { display: flex; flex-direction: column; }

#trophies {
  flex: 1;
  min-height: 0;
  overflow-y: auto; /* Only if the window is too small for all ten. */
  margin: 6px 0 10px;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  align-content: start;
  gap: 8px 12px;
}

/* Each trophy stands on its own bit of shelf. */
.trophy {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: end;
  gap: 10px;
  padding: 4px 4px 6px;
  border-bottom: 6px solid var(--shelf);
  box-shadow: 0 2px 0 var(--outline);
  font-size: 0.75rem;
  line-height: 1.25;
}
.trophy strong { display: block; font-size: 0.8rem; }
.trophy .odds { white-space: nowrap; } /* Never split "1 in 62,500". */
.trophy time { display: block; color: var(--muted); }

/* main.js draws trophies small enough to fit this box (see look.js). */
.trophy-sprite {
  height: 56px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#reset-button { margin-top: 16px; font-size: 0.8rem; padding: 6px 12px; }

@media (prefers-reduced-motion: reduce) {
  .lantern::before { animation: none; }
}

/* ---------- Layout overrides ----------
   Last in the file so they win over the base rules above. */

/* A narrower window: stats move under the counter. */
@media (min-width: 761px) and (max-width: 1099px) {
  #game {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 460px);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "sign   sign"
      "play   trophies"
      "stats  trophies";
  }
  /* Too much to fit on one screen here, so the page scrolls instead. */
  #game { height: auto; min-height: 100dvh; }
  #stats dl { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #stage { min-height: 320px; }
}

/* A short window can't fit it all: let the page scroll instead of squashing. */
@media (min-width: 761px) and (max-height: 640px) {
  #game { height: auto; min-height: 100dvh; }
  #stage { min-height: 260px; }
}
