:root {
  --wood: #5a3a1f; --wood-d: #3b2412; --wood-l: #7a5230;
  --cream: #f7e8c3; --cream-d: #e3cd96; --ink: #3a2412;
  --green: #5f9c3f; --green-d: #3f7a2a; --gold: #e9b949; --red: #c8442f; --blue: #3f7fbf;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Fredoka', ui-rounded, system-ui, sans-serif;
  background: var(--wood-d); color: var(--ink); overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100dvh; display: grid; grid-template-rows: auto 1fr; }

/* ---------- top bar ---------- */
#hud {
  position: relative; z-index: 2100; /* stays above the popups so the stats/help buttons always work */
  display: flex; align-items: center; gap: 22px;
  padding: 8px 16px; background: var(--wood); color: var(--cream);
  border-bottom: 4px solid var(--wood-d);
}
#hud h1 { margin: 0 auto 0 0; font-size: 23px; font-weight: 700; letter-spacing: .3px; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.1; min-width: 56px; }
.stat small { font-size: 11px; opacity: .75; text-transform: uppercase; letter-spacing: 1px; }
.stat b { font-size: 21px; font-variant-numeric: tabular-nums; }
#timer-bar { position: absolute; left: 0; bottom: -4px; height: 4px; width: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); }
#hud.warn #time { color: #ff9a85; }
#hud-btns { display: flex; gap: 6px; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; font: 600 18px 'Fredoka', sans-serif; color: var(--cream); background: var(--wood-l); border: 2px solid var(--wood-d); border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--gold); color: var(--ink); }
#hud.warn #timer-bar { background: var(--red); }

/* ---------- layout ---------- */
#stage { display: grid; grid-template-columns: minmax(280px, 36%) 1fr; gap: 10px; padding: 10px; min-height: 0; }
#shot-wrap, #map-wrap {
  position: relative; min-height: 0; min-width: 0; overflow: hidden;
  border: 6px solid var(--wood); border-radius: 8px; box-shadow: 0 0 0 3px var(--wood-d), 0 6px 18px rgba(0,0,0,.4);
}
#shot-wrap { background: #111; display: flex; cursor: zoom-in; }
#shot { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
#shot-hint {
  position: absolute; left: 8px; bottom: 8px; font-size: 12px; padding: 3px 8px;
  background: rgba(59,36,18,.8); color: var(--cream); border-radius: 4px; pointer-events: none;
}
.shot-big #shot-wrap { position: fixed; inset: 56px 0 0 0; z-index: 1500; border-radius: 0; cursor: zoom-out; }
#map-wrap { background: #2b4a63; }

/* ---------- map viewer ---------- */
.viewer { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: crosshair; user-select: none; background: #2b4a63; }
.v-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.v-img { display: block; max-width: none; image-rendering: auto; }
.v-img.pix { image-rendering: pixelated; }
.v-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.v-line-bg { stroke: rgba(0,0,0,.55); stroke-width: 6; stroke-linecap: round; }
.v-line { stroke: #fff; stroke-width: 3; stroke-dasharray: 2 9; stroke-linecap: round; }
.v-marks { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.v-pin { position: absolute; transform: translate(-50%, -50%); }
.v-pin.guess, .v-pin.answer, .v-pin.edit {
  width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.7); color: #fff; text-align: center; font: 700 16px/24px sans-serif;
}
.v-pin.guess { background: var(--red); }
.v-pin.answer { background: var(--green-d); }
.v-pin.edit { background: var(--blue); }
.v-pin.door {
  pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 5px;
  background: var(--cream); color: var(--ink); border: 3px solid var(--wood-d); border-radius: 18px;
  padding: 2px 10px 2px 6px; font-size: 14px; box-shadow: 0 2px 6px rgba(0,0,0,.5); white-space: nowrap;
}
.v-pin.door:hover { background: #fff6da; }

/* ---------- buttons & floating controls ---------- */
.btn {
  font: inherit; font-size: 18px; color: #fff; background: var(--green);
  border: 3px solid var(--wood-d); border-radius: 8px; padding: 9px 22px; cursor: pointer;
  box-shadow: 0 4px 0 var(--wood-d); transition: transform .05s, box-shadow .05s;
}
.btn:hover:not(:disabled) { background: #6cae49; }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-d); }
.btn:disabled { background: #8b8070; color: #d8cfbd; cursor: not-allowed; }
.btn.big { font-size: 20px; padding: 11px 28px; }
.btn.small { font-size: 15px; padding: 5px 12px; background: var(--cream); color: var(--ink); }
.btn.small:hover:not(:disabled) { background: #fff6da; }
.btn.alt { background: var(--wood-l); }

#tabs { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; z-index: 10; flex-wrap: wrap; max-width: calc(100% - 80px); }
#tabs button { font: inherit; font-size: 15px; padding: 5px 12px; color: var(--cream); background: rgba(59,36,18,.88); border: 2px solid var(--wood-d); border-radius: 16px; cursor: pointer; }
#tabs button.on { background: var(--gold); color: var(--ink); }
#tabs .crumb { color: var(--cream); background: rgba(59,36,18,.88); padding: 5px 12px; border-radius: 16px; font-size: 15px; }
#back { position: absolute; top: 48px; left: 10px; z-index: 10; }

/* area picker: picture buttons floating on the map, just above the guess button */
#areas {
  position: absolute; left: 0; right: 0; bottom: 84px; z-index: 9; pointer-events: none;
  display: flex; justify-content: center; gap: 8px; padding: 0 8px;
}
#areas:empty { display: none; }
.area {
  position: relative; flex: 0 1 72px; aspect-ratio: 1; min-width: 0; padding: 0; overflow: hidden; cursor: pointer; pointer-events: auto;
  border: 3px solid var(--wood-d); border-radius: 8px; background: var(--wood-d); box-shadow: 0 3px 8px rgba(0,0,0,.45);
}
.area img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: .8; transition: opacity .15s; }
.area span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 3px; font: 600 11px/1.15 'Fredoka', sans-serif;
  color: var(--cream); background: rgba(30,18,8,.78); text-align: center;
}
.area:hover img { opacity: 1; }
.area.on { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.area.on img { opacity: 1; }
.area.on span { background: var(--gold); color: var(--ink); }
#zoom { position: absolute; top: 10px; right: 10px; z-index: 10; display: flex; flex-direction: column; gap: 6px; }
#zoom .btn { width: 38px; padding: 4px 0; font-size: 20px; }
#guess-btn { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 10; white-space: nowrap; }
#guess-btn:active:not(:disabled) { transform: translateX(-50%) translateY(3px); }

#result {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 10;
  width: min(440px, calc(100% - 24px)); padding: 14px 18px 16px; text-align: center;
  background: var(--cream); border: 4px solid var(--wood); border-radius: 10px; box-shadow: 0 0 0 3px var(--wood-d), 0 8px 20px rgba(0,0,0,.5);
}
#result .r-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
#result strong { font-size: 24px; }
#r-pts { font-size: 24px; color: var(--green-d); font-weight: 600; }
#result p { margin: 6px 0 12px; line-height: 1.35; }

/* ---------- overlay cards ---------- */
#overlay { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(30,18,8,.82); }
#overlay[hidden] { display: none; }
#card {
  width: min(520px, 100%); max-height: 100%; overflow: auto; text-align: center; padding: 26px 28px 28px;
  background: var(--cream); border: 6px solid var(--wood); border-radius: 12px; box-shadow: 0 0 0 4px var(--wood-d), 0 12px 30px rgba(0,0,0,.6);
}
#card h2 { margin: 0 0 8px; font-size: 32px; font-weight: 700; }
#card p { line-height: 1.45; margin: 8px 0; }
#card .row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
#card .big-score { font-size: 44px; font-weight: 600; color: var(--green-d); margin: 4px 0 10px; }
#card ol { list-style: none; padding: 0; margin: 12px 0 0; text-align: left; }
#card li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 2px; border-bottom: 2px dotted var(--cream-d); }
#card li span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.muted { opacity: .7; font-size: 14px; }
#card h3 { margin: 18px 0 8px; font-size: 17px; }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.tile { flex: 1 1 80px; max-width: 100px; display: flex; flex-direction: column; align-items: center; }
.tile b { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile small { font-size: 12px; opacity: .75; line-height: 1.2; }
.dist { text-align: left; }
.bar-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.bar-row span { width: 70px; flex: none; text-align: right; }
.bar { background: var(--wood-l); color: var(--cream); font-weight: 600; text-align: right; padding: 1px 7px; border-radius: 4px; min-width: 24px; }
.bar.on { background: var(--green); }
#card ol.help { text-align: left; list-style: decimal; padding-left: 22px; }
.credit { margin: 16px 0 0 !important; font-size: 13px; opacity: .75; }
.credit a { color: var(--green-d); font-weight: 600; }
#card .privacy { font-size: 12px; margin: 14px 0 0; line-height: 1.35; }
.privacy a { color: inherit; }
#card ol.help li { display: list-item; border: 0; padding: 4px 0; line-height: 1.4; }

/* ---------- admin mode (?admin=1) ---------- */
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 12px 0 4px; }
.chip { font: inherit; font-size: 16px; padding: 6px 14px; color: var(--ink); background: var(--cream-d); border: 3px solid var(--wood-d); border-radius: 20px; cursor: pointer; }
.chip.on { background: var(--gold); box-shadow: 0 2px 0 var(--wood-d); }
.admin-box { margin-top: 20px; padding: 12px 14px 6px; border: 3px dashed var(--wood); border-radius: 10px; background: #fff8e4; }
.admin-box h3 { margin: 0; }
.admin-box .row { margin-top: 10px !important; align-items: center; }
.admin-box a.btn { text-decoration: none; }
.adm-day input { width: 70px; font: inherit; padding: 4px 6px; border: 2px solid var(--wood); border-radius: 4px; }
#admin-quit { display: none; }
body.admin #admin-quit { display: inline-block; margin-left: 8px; }
#card.wide { width: min(1100px, 100%); }
.adm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 14px; text-align: left; }
.adm-grid figure { margin: 0; padding: 6px; background: #fff8e4; border: 2px solid var(--cream-d); border-radius: 8px; cursor: pointer; }
.adm-grid figure:hover { border-color: var(--wood); }
.adm-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; image-rendering: pixelated; background: #111; border-radius: 4px; }
.adm-grid figcaption { font-size: 13px; margin-top: 4px; line-height: 1.3; }

/* ---------- editor mode (?edit=1) ---------- */
#editor { position: fixed; top: 70px; right: 14px; width: min(340px, calc(100% - 28px)); z-index: 1800; padding: 14px 16px; background: var(--cream); border: 4px solid var(--wood); border-radius: 10px; font-size: 14px; max-height: calc(100dvh - 84px); overflow: auto; }
#editor[hidden] { display: none; }
#editor h3 { margin: 0 0 6px; }
#editor p { margin: 6px 0; line-height: 1.35; }
#editor label { display: block; margin: 8px 0 2px; }
#editor input[type=file] { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 13px; }
#editor pre { white-space: pre-wrap; word-break: break-all; background: #fff8e4; padding: 8px; border: 2px dashed var(--cream-d); margin: 8px 0; font-size: 12px; }
#editor .bad { color: var(--red); }
#ed-list { list-style: none; margin: 8px 0; padding: 0; max-height: 34vh; overflow: auto; border-top: 2px dotted var(--cream-d); }
#ed-list li { display: flex; gap: 6px; align-items: center; padding: 4px 0; border-bottom: 2px dotted var(--cream-d); }
#ed-list .n { min-width: 30px; height: 28px; border-radius: 14px; border: 2px solid #fff; background: var(--blue); color: #fff; font: inherit; font-size: 13px; cursor: pointer; }
#ed-list .lbl { flex: 1; min-width: 0; font: inherit; padding: 3px 6px; border: 2px solid var(--wood); border-radius: 4px; }
#ed-list .x { width: 26px; height: 26px; border: 0; background: transparent; color: var(--red); font-size: 20px; cursor: pointer; }
body.edit #areas { bottom: 16px; }
body.edit #shot-wrap, body.edit #guess-btn, body.edit .stat, body.edit #timer-bar { display: none; }
body.edit #stage { grid-template-columns: 1fr; }
.v-pin.edit { width: 26px; height: 26px; font-size: 13px !important; line-height: 20px !important; }


/* ---------- phones / narrow windows ---------- */
@media (max-width: 860px) {
  #stage { grid-template-columns: 1fr; grid-template-rows: minmax(120px, 36%) 1fr; gap: 8px; padding: 8px; }
  #hud { gap: 12px; padding: 6px 10px; }
  #hud h1 { font-size: 17px; }
  .stat b { font-size: 18px; }
  .shot-big #shot-wrap { inset: 48px 0 0 0; }
  #card { padding: 20px 18px 22px; }
  #areas { bottom: 76px; gap: 6px; }
  .area { flex-basis: 60px; }
  .area span { font-size: 10px; }
  body.admin #hud { gap: 6px; }
  body.admin #hud h1 { font-size: 14px; }
  body.admin .stat { min-width: 44px; }
  body.admin #admin-quit { margin-left: 0; padding: 4px 6px; font-size: 12px; }
}

/* no broken-image icon before the first round */
#shot:not([src]) { visibility: hidden; }
