/* FACE REVEAL: the look of the app.
   Colours are set once here, so they are easy to change. */
:root {
  --ink: #241a52;        /* deep indigo: main text and dark areas */
  --paper: #fff8ec;      /* warm white: page background */
  --wrap: #ff5d73;       /* gift-wrap pink: hidden pieces, main buttons */
  --gold: #ffc83d;       /* gold: highlights and the current points */
  --mint: #5ee6c0;       /* mint: success */
  --muted: #5d5683;
  --line: #e4dccb;
  --radius: 14px;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.5;
  color: var(--ink); background: var(--paper);
}
[hidden] { display: none !important; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 6vw, 3.4rem); letter-spacing: -.02em; }
h2 { font-size: 1.4rem; }
p { margin: 0 0 .75em; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--ink); color: var(--paper);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px;
  background: conic-gradient(var(--wrap) 0 25%, var(--gold) 0 50%, var(--wrap) 0 75%, var(--gold) 0);
}
.badge {
  font: inherit; font-size: .9rem; border: 2px solid var(--gold); color: var(--gold);
  background: transparent; border-radius: 999px; padding: 4px 12px; cursor: pointer;
}
.badge.on { background: var(--mint); border-color: var(--mint); color: var(--ink); }

/* buttons */
.btn {
  font: inherit; font-weight: 700; min-height: 46px; padding: 10px 18px;
  border-radius: var(--radius); border: 2px solid var(--ink);
  background: #fff; color: var(--ink); cursor: pointer;
}
.btn:hover:not(:disabled) { background: #f3ecff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--wrap); border-color: var(--wrap); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #f0475f; }
.btn.danger { border-color: #b3261e; color: #b3261e; }
.btn.danger:hover { background: #fde8e6; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: .95rem; }
.btn.big { font-size: 1.2rem; min-height: 58px; }
.btn.round { width: 46px; padding: 0; border-radius: 50%; font-size: 1.5rem; }
.link { font: inherit; background: none; border: 0; color: #b3261e; text-decoration: underline; cursor: pointer; padding: 4px; }

.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.wrap { flex-wrap: wrap; }
.count { font-weight: 700; color: var(--muted); }
.count.big { font-size: 1.5rem; color: var(--ink); min-width: 1.6em; text-align: center; }
.hint { color: var(--muted); font-size: .95rem; }
.privacy { font-weight: 700; color: #1f7a5e; }

/* form fields */
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-weight: 700; margin-bottom: 4px; }
input[type=text], select {
  font: inherit; width: 100%; padding: 10px 12px; min-height: 46px;
  border: 2px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input[type=text]:focus, select:focus { border-color: var(--ink); outline: none; }
input[type=range] { width: 100%; accent-color: var(--wrap); height: 32px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--wrap); flex: none; margin-top: 2px; }
.consent { background: #fff; border: 2px solid var(--gold); border-radius: 10px; padding: 10px 12px; font-weight: 700; }
output { font-weight: 400; color: var(--muted); margin-left: 6px; }

/* hero */
.hero { display: grid; gap: 20px; align-items: center; margin: 12px 0 28px; }
.hero p { font-size: 1.1rem; max-width: 34em; }
#heroDemo { width: min(320px, 80vw); height: auto; border-radius: 18px; justify-self: center;
  box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 4px var(--gold); }
@media (min-width: 760px) { .hero { grid-template-columns: 1.3fr 1fr; } }

/* numbered setup steps (they really are a sequence) */
.step { display: flex; gap: 14px; padding: 18px 0; border-top: 2px dashed var(--line); }
.step-num {
  flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--ink); color: var(--gold);
  font-weight: 800; font-size: 1.2rem; display: grid; place-items: center;
}
.step-body { flex: 1; min-width: 0; }

/* photo grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; margin: 14px 0; }
.tile { display: flex; flex-direction: column; gap: 6px; }
.tile-thumb { position: relative; padding: 0; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; cursor: pointer; background: #ddd; aspect-ratio: 1; }
.tile-thumb canvas { width: 100%; height: 100%; display: block; }
.tag { position: absolute; left: 6px; top: 6px; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--ink); color: #fff; }
.tag.free { background: var(--mint); color: var(--ink); }
.tile-name { min-height: 40px !important; padding: 6px 8px !important; }
.tile-meta { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--muted); gap: 4px; }

/* segmented buttons (difficulty, slice style) */
.seg { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.seg-btn {
  font: inherit; font-weight: 700; min-height: 46px; padding: 8px 16px; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 999px; background: #fff; color: var(--ink);
}
.seg-btn.on { background: var(--ink); color: var(--gold); }
.blurb { font-weight: 700; }
.ladder-note p { margin: 2px 0; font-size: .95rem; }
.bulk { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.bulk .field { flex: 1; min-width: 200px; margin-bottom: 0; }

.player-names { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.play-area { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.foot { padding: 24px 0 40px; border-top: 2px dashed var(--line); }

/* editor */
.ed-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.ed-nav { display: flex; align-items: center; gap: 8px; }
.ed-layout { display: grid; gap: 18px; }
@media (min-width: 820px) { .ed-layout { grid-template-columns: minmax(0, 480px) 1fr; } }
.ed-stage canvas { width: 100%; max-width: 480px; height: auto; display: block; border-radius: 12px; border: 3px solid var(--ink); touch-action: none; }
#edCanvas.dragging-ok { cursor: grab; }
#edCanvas.tap-ok { cursor: pointer; touch-action: manipulation; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--ink); margin: 12px 0; }
.tabs button {
  font: inherit; font-weight: 700; flex: 1; min-height: 46px; cursor: pointer;
  border: 2px solid var(--ink); border-bottom: 0; border-radius: 10px 10px 0 0; background: #fff; color: var(--ink);
}
.tabs button.on { background: var(--ink); color: var(--gold); }

/* game: dark, big, readable across a room */
body[data-screen="screen-game"], body[data-screen="screen-results"] { background: var(--ink); color: var(--paper); }
body[data-screen="screen-game"] .topbar { display: none; }
.game-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.g-progress { font-weight: 700; font-size: 1.1rem; color: var(--gold); }
.game-body { display: grid; gap: 16px; }
@media (min-width: 900px) and (orientation: landscape) {
  .game-body { grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); align-items: start; }
  .game-stage canvas { max-height: calc(100vh - 90px); width: auto; max-width: 100%; }
}
.game-stage { display: flex; justify-content: center; }
.game-stage canvas { width: 100%; max-width: 720px; height: auto; border-radius: 16px; box-shadow: 0 0 0 4px var(--gold); }
.g-status { font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 800; line-height: 1.1; }
.g-sub { font-size: 1.15rem; margin: 6px 0 12px; }
.ladder { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.rung { min-width: 44px; padding: 6px 10px; text-align: center; border-radius: 10px; font-weight: 800; font-size: 1.2rem; border: 2px solid rgba(255,248,236,.4); }
.rung.now { background: var(--gold); color: var(--ink); border-color: var(--gold); transform: scale(1.12); }
.rung.past { opacity: .35; }
.g-timer { font-size: 1.4rem; font-weight: 800; color: var(--mint); margin-bottom: 10px; }
.g-timer.up { color: var(--wrap); }
.g-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.screen#screen-game .btn:not(.primary), #screen-results .btn:not(.primary) { background: transparent; color: var(--paper); border-color: var(--paper); }
.screen#screen-game .btn:not(.primary):hover:not(:disabled) { background: rgba(255,255,255,.1); }
.g-who-label { font-weight: 700; color: var(--gold); margin-top: 8px; }
.players { display: grid; gap: 8px; }
.player { display: flex; gap: 6px; }
.player-main {
  flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  font: inherit; font-size: 1.25rem; font-weight: 700; min-height: 56px; padding: 8px 16px; cursor: pointer;
  background: rgba(255,255,255,.08); color: var(--paper); border: 2px solid rgba(255,248,236,.5); border-radius: 12px;
}
.player-main:not(:disabled):hover { background: var(--mint); color: var(--ink); }
.player-main:disabled { cursor: default; }
.player.won .player-main { background: var(--mint); color: var(--ink); border-color: var(--mint); }
.player-score { font-size: 1.6rem; }
.player-wrong { font: inherit; font-weight: 700; padding: 0 12px; border-radius: 12px; border: 2px solid var(--wrap); background: transparent; color: var(--wrap); cursor: pointer; }
.keys { color: rgba(255,248,236,.6); }
@media (hover: none) { .keys { display: none; } }

/* results */
#screen-results { text-align: center; padding-top: 30px; }
#rTitle { color: var(--gold); }
.rank { list-style: none; padding: 0; max-width: 520px; margin: 20px auto; }
.rank li { display: flex; justify-content: space-between; padding: 14px 18px; margin: 8px 0; border-radius: 12px; background: rgba(255,255,255,.08); font-size: 1.3rem; font-weight: 700; }
.rank li.top { background: var(--gold); color: var(--ink); }
.upsell { max-width: 520px; margin: 0 auto 20px; padding: 16px; border: 2px dashed var(--gold); border-radius: 12px; }
#screen-results .row { justify-content: center; }

/* pop-up windows and messages */
.modal-back { position: fixed; inset: 0; background: rgba(20,14,48,.6); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--paper); color: var(--ink); border-radius: 18px; padding: 22px; max-width: 460px; width: 100%; box-shadow: 0 0 0 4px var(--ink); }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.price { font-size: 1.2rem; font-weight: 800; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px;
  max-width: calc(100vw - 32px); box-shadow: 0 0 0 3px var(--gold); font-weight: 700;
}
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Phase 2: links and guest view */
.link-box { background: #fff; border: 3px solid var(--ink); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 18px; box-shadow: 6px 6px 0 var(--gold); }
.link-box input { flex: 1; min-width: 0; font-size: .9rem; }
.link-label { font-weight: 800; margin: 0; }
.link-row + .link-row { margin-top: 12px; padding-top: 12px; border-top: 2px dashed var(--line); }
body.guest .host-only { display: none !important; }
body.guest .step { border-top: 0; }
.notice { max-width: 560px; margin: 40px auto; text-align: center; }
body.guest .step-num { display: none; }
.notice a.btn { text-decoration: none; display: inline-flex; align-items: center; }
body[data-screen="screen-none"] #lockBadge { display: none; }

/* prizes */
.prize-rows { display: grid; gap: 8px; margin: 8px 0 4px; }
.prize-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; font-weight: 700; }
@media (max-width: 480px) { .prize-row { grid-template-columns: 1fr; gap: 4px; } }
.g-prize { display: block; font-size: .6em; color: var(--gold); margin-top: 4px; }
.rung { display: inline-flex; flex-direction: column; align-items: center; }
.rung small { font-size: .62rem; font-weight: 700; max-width: 7em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li { flex-direction: column; }
.rank-main { display: flex; justify-content: space-between; width: 100%; }
.rank-prizes { margin: 6px 0 0; font-size: 1rem; font-weight: 700; text-align: left; }
.rank li.grand { background: transparent; border: 2px dashed var(--gold); color: var(--gold); }

/* brand and legal footer */
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-owner { font-size: .72rem; font-weight: 600; color: var(--gold); }
.site-foot { max-width: 1100px; margin: 0 auto; padding: 8px 16px 28px; color: var(--muted); font-size: .85rem; }
body[data-screen="screen-game"] .site-foot { display: none; }
