/* ===================================================================
   Doodle Duel — styles
   Kid-friendly, big touch targets, works landscape & portrait.
   =================================================================== */

:root {
  --bg1: #6C4CE0;
  --bg2: #B14CE0;
  --bg3: #E04C9B;
  --ink: #2b2350;
  --ink-soft: #6b6390;
  --card: #ffffff;
  --paper: #ffffff;
  --primary: #6C4CE0;
  --primary-d: #5636c4;
  --secondary: #14b8a6;
  --accent: #ff8a3d;
  --good: #22c55e;
  --shadow: 0 10px 30px rgba(40, 20, 90, .18);
  --radius: 22px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Baloo 2", "Nunito", "Segoe UI Rounded", "Comic Sans MS", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  background: linear-gradient(135deg, var(--bg1), var(--bg2) 55%, var(--bg3));
  background-attachment: fixed;
}

#app { position: fixed; inset: 0; }

/* ---------- screens ----------
   Every screen can scroll vertically when its content is taller than the
   viewport. Content is centred with `margin:auto` on its inner wrapper, which
   (unlike justify-content:center) degrades to top-aligned + scrollable when tall.
*/
.screen {
  position: absolute; inset: 0;
  display: none;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: calc(14px + var(--safe-t)) calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
}
.screen.active { display: flex; }
/* the single content wrapper inside each scrollable screen */
.home-scroll, .handoff-inner, .vote-inner, .gallery-inner, .result-inner { margin: auto; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 800;
  border: none; border-radius: 999px;
  padding: 16px 26px;
  font-size: clamp(16px, 2.4vw, 22px);
  cursor: pointer;
  transition: transform .08s ease, box-shadow .12s ease, background .15s ease;
  color: #fff;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px) scale(.99); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); box-shadow: 0 6px 0 var(--primary-d); }
.btn-primary:active { box-shadow: 0 2px 0 var(--primary-d); }
.btn-secondary { background: var(--secondary); box-shadow: 0 6px 0 #0e8a7c; }
.btn-secondary:active { box-shadow: 0 2px 0 #0e8a7c; }
.btn-ghost { background: rgba(255,255,255,.85); color: var(--primary-d); box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.btn-big { font-size: clamp(20px, 3.4vw, 30px); padding: 20px 36px; }

/* ===================================================================
   HOME
   =================================================================== */
[data-screen="home"] { justify-content: center; }
.home-scroll {
  width: 100%; max-width: 720px;
  display: flex; flex-direction: column; gap: 16px;
  padding: 6px;
}
.brand { text-align: center; color: #fff; margin-top: 6px; }
.brand-logo { font-size: clamp(46px, 9vw, 76px); line-height: 1; filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.brand-title { margin: 4px 0 2px; font-size: clamp(34px, 8vw, 60px); letter-spacing: .5px; text-shadow: 0 4px 0 rgba(0,0,0,.15); }
.brand-tag { margin: 0; font-weight: 700; opacity: .95; font-size: clamp(14px, 2.6vw, 18px); }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card-h { margin: 0 0 12px; font-size: clamp(18px, 3vw, 24px); color: var(--ink); }
.hint { margin: 10px 2px 0; color: var(--ink-soft); font-size: 14px; font-weight: 600; }

.player-list { display: flex; flex-wrap: wrap; gap: 10px; }
.player-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 999px;
  font-weight: 800; font-size: clamp(15px, 2.4vw, 19px);
  border: 3px solid transparent; cursor: pointer;
  background: #eef; color: var(--ink);
  transition: transform .08s ease, opacity .15s ease, filter .15s ease;
}
.player-chip:active { transform: scale(.97); }
.player-chip .pdot { width: 16px; height: 16px; border-radius: 50%; flex: 0 0 auto; }
.player-chip.off { opacity: .38; filter: grayscale(.6); }
.player-chip .pedit { font-size: 14px; opacity: .6; padding: 2px 4px; }
.player-chip .premove { font-size: 15px; opacity: .55; font-weight: 900; padding: 0 2px; }
.btn-add { margin-top: 12px; }

.subject-row { position: relative; display: flex; align-items: center; }
.subject-input {
  flex: 1; font: inherit; font-weight: 700;
  font-size: clamp(17px, 3vw, 22px);
  padding: 16px 44px 16px 18px;
  border: 3px solid #e6e2f7; border-radius: 16px;
  background: #faf9ff; color: var(--ink); width: 100%;
  -webkit-user-select: text; user-select: text;
}
.subject-input:focus { outline: none; border-color: var(--primary); background: #fff; }
.subject-clear {
  position: absolute; right: 8px; border: none; background: #e9e6f7;
  width: 30px; height: 30px; border-radius: 50%; color: var(--ink-soft);
  font-weight: 900; cursor: pointer; font-size: 15px;
}
.btn-random {
  margin-top: 12px; width: 100%;
  background: linear-gradient(135deg, var(--accent), #ff5f8f);
  box-shadow: 0 6px 0 #d94a76;
}
.btn-random:active { box-shadow: 0 2px 0 #d94a76; }
.idea-cat { margin: 10px 2px 0; font-weight: 800; color: var(--primary-d); font-size: 14px; }

.btn-start { width: 100%; font-size: clamp(20px, 3.6vw, 28px); padding: 20px; }

.home-footer { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 4px 0 10px; }
.chip-btn {
  font: inherit; font-weight: 800; font-size: 14px;
  background: rgba(255,255,255,.22); color: #fff;
  border: 2px solid rgba(255,255,255,.5); border-radius: 999px;
  padding: 8px 16px; cursor: pointer; backdrop-filter: blur(4px);
}

/* ===================================================================
   HAND-OFF
   =================================================================== */
.handoff-inner {
  background: var(--card); border-radius: 28px; box-shadow: var(--shadow);
  padding: clamp(22px, 5vw, 46px); text-align: center;
  max-width: 560px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.handoff-emoji { font-size: clamp(52px, 12vw, 96px); line-height: 1; }
.handoff-pass { margin: 4px 0 0; font-weight: 700; color: var(--ink-soft); font-size: clamp(16px, 3vw, 22px); }
.handoff-name { margin: 0; font-size: clamp(40px, 11vw, 78px); color: var(--primary-d); line-height: 1; }
.handoff-sub { margin: 2px 0 6px; font-weight: 700; font-size: clamp(16px, 3vw, 22px); }
.handoff-subject {
  background: #f3f0ff; border-radius: 16px; padding: 12px 20px;
  font-size: clamp(18px, 3.4vw, 26px);
}
.handoff-subject-label { color: var(--ink-soft); font-weight: 700; margin-right: 6px; }
.handoff-subject strong { color: var(--ink); }
.btn-big { margin-top: 10px; }
.handoff-secret { margin: 6px 0 0; color: var(--ink-soft); font-weight: 700; font-size: 14px; }

/* ===================================================================
   DRAW  (canvas fills the space; tools sit at the bottom in portrait,
   and move to a side rail on a roomy landscape screen like the tablet)
   =================================================================== */
[data-screen="draw"] { flex-direction: column; padding: 0; overflow: hidden; }
.draw-topbar {
  display: flex; align-items: center; gap: 10px;
  /* extra right padding reserves the corner for the fixed "new duel" button */
  padding: calc(8px + var(--safe-t)) calc(60px + var(--safe-r)) 8px calc(10px + var(--safe-l));
  background: rgba(255,255,255,.96); box-shadow: 0 2px 10px rgba(0,0,0,.12);
  flex-wrap: nowrap; overflow: visible; z-index: 3; flex: 0 0 auto;
}
.btn-submit { margin-left: auto; } /* keep Done pinned to the right */
.draw-who { display: flex; align-items: center; gap: 6px; font-weight: 800; white-space: nowrap; flex: 0 1 auto; min-width: 0; overflow: hidden; }
.who-dot { width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.draw-who-name { font-size: clamp(15px, 2.4vw, 20px); overflow: hidden; text-overflow: ellipsis; }
.draw-subject { color: var(--ink-soft); font-weight: 700; font-size: clamp(13px, 2vw, 17px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-submit { flex: 0 0 auto; padding: 12px 20px; font-size: clamp(15px, 2.4vw, 20px); }

.draw-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.pad-wrap { flex: 1 1 auto; position: relative; background: var(--paper); min-height: 0; min-width: 0; }
#pad {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; display: block; background: #fff;
}

/* --- tool bar (bottom in portrait) --- */
.draw-tools {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  gap: 10px 16px; flex-wrap: wrap;
  padding: 10px calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
  background: rgba(255,255,255,.98); box-shadow: 0 -3px 12px rgba(0,0,0,.12);
  max-height: 42vh; overflow-y: auto;
}
.tool-group { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
/* Colours are ordered light,dark,light,dark… — this 2-row column-flow grid puts
   each LIGHT on the top row with its matching DARK directly beneath it. */
.tool-group.colours {
  position: relative;
  display: grid;
  grid-template-rows: repeat(2, auto);
  grid-auto-flow: column;
  gap: 6px;
  justify-content: center;
}
.tool-group.colours::after {  /* subtle divider between colours and the rest */
  content: ""; position: absolute; right: -8px; top: 10%; height: 80%; width: 2px;
  background: #eceaf6;
}
.swatch {
  width: clamp(26px, 8.4vw, 42px); height: clamp(26px, 8.4vw, 42px);
  border-radius: 50%; cursor: pointer;
  border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.12);
  flex: 0 0 auto; transition: transform .08s ease; padding: 0;
}
.swatch:active { transform: scale(.9); }
.swatch.sel { transform: scale(1.2); box-shadow: 0 0 0 3px var(--ink); }
.sizes { display: flex; gap: 6px; align-items: center; }
.size-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 2px solid #e2ddf3;
  background: #fff; cursor: pointer; display: grid; place-items: center; flex: 0 0 auto; padding: 0;
}
.size-btn .dot { background: var(--ink); border-radius: 50%; }
.size-btn.sel { border-color: var(--primary); background: #f2eeff; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 42px; padding: 0 14px; border-radius: 12px; border: 2px solid #e2ddf3;
  background: #fff; cursor: pointer; font: inherit; font-weight: 800; color: var(--ink); flex: 0 0 auto;
}
.tool-btn .tb-ico { font-size: 20px; line-height: 1; }
.tool-btn .tb-lbl { font-size: 14px; }
.tool-btn[aria-pressed="true"] { border-color: var(--accent); background: #fff2e8; color: var(--accent); }

/* --- roomy landscape (tablet): tools become a scrollable side rail --- */
@media (orientation: landscape) and (min-height: 480px) {
  .draw-body { flex-direction: row; }
  .draw-tools {
    flex-direction: column; flex-wrap: nowrap; justify-content: flex-start;
    width: auto; min-width: 92px; max-height: none; height: 100%;
    box-shadow: -3px 0 12px rgba(0,0,0,.12);
    padding: 14px 10px calc(14px + var(--safe-b));
    gap: 14px;
  }
  .tool-group { flex-direction: column; }
  /* side rail: each ROW is a light/dark pair, sitting next to each other */
  .tool-group.colours {
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: none;
    grid-auto-flow: row; gap: 8px;
  }
  .tool-group.colours::after { display: none; }
  .tool-group.extras { gap: 10px; width: 100%; }
  .sizes { flex-direction: row; }
  .tool-btn { width: 100%; justify-content: center; }
}

/* ===================================================================
   VOTE
   =================================================================== */
.vote-inner { width: 100%; max-width: 1100px; display: flex; flex-direction: column; gap: 12px; }
.vote-head { text-align: center; color: #fff; }
.vote-head h2 { margin: 0; font-size: clamp(22px, 5vw, 38px); text-shadow: 0 3px 0 rgba(0,0,0,.14); }
.vote-head .vote-sub { margin: 4px 0 0; font-weight: 700; opacity: .95; }
.vote-grid {
  width: 100%;
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.vote-card {
  background: #fff; border-radius: 18px; overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer; position: relative;
  border: 5px solid transparent; transition: transform .1s ease, border-color .12s ease;
}
.vote-card img { width: 100%; height: auto; background: #fff; display: block; pointer-events: none; }
.vote-card:active { transform: scale(.97); }
.vote-card.mine { cursor: not-allowed; }
.vote-card .mine-tag {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(108,76,224,.72); color: #fff; font-weight: 900;
  font-size: clamp(16px, 3vw, 22px); text-align: center; padding: 10px;
}
.vote-card.mine.show-mine .mine-tag { display: flex; }

/* ===================================================================
   RESULT
   =================================================================== */
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.result-inner {
  position: relative; z-index: 2; text-align: center; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  max-width: 760px; width: 100%;
}
.result-crown { margin: 0; font-weight: 900; font-size: clamp(22px, 5vw, 34px); text-shadow: 0 3px 0 rgba(0,0,0,.18); letter-spacing: .5px; }
.result-stage { display: flex; align-items: flex-start; justify-content: center; gap: clamp(12px, 3vw, 30px); flex-wrap: wrap; width: 100%; }
.winner-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
/* shared trophies: scale everything down so two (or three) fit side by side */
.result-stage.multi .trophy-svg { width: clamp(130px, 33vw, 210px); }
.result-stage.multi .winner-art .frame { width: clamp(105px, 26vw, 170px); }
.result-stage.multi .tap-hint { font-size: 11px; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
/* only the safe translate-based bob (a frozen frame is still fully visible) */
.trophy { animation: floaty 3s ease-in-out infinite; }
.trophy-svg { width: clamp(200px, 46vw, 320px); height: auto; aspect-ratio: 220 / 278; filter: drop-shadow(0 16px 22px rgba(0,0,0,.38)); }
.winner-art {
  border: none; background: none; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.winner-art .frame { width: clamp(150px, 32vw, 250px); }
.tap-hint { color: #fff; font-weight: 800; font-size: 13px; opacity: .9; text-shadow: 0 1px 2px rgba(0,0,0,.3); }
.result-prompt { margin: 4px 0 0; font-weight: 700; font-size: clamp(15px, 3vw, 20px); opacity: .96; }
.result-prompt strong { color: #fff; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }

@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }

/* ---------- shared picture frame (winner + gallery + viewer) ---------- */
.frame {
  display: block; padding: clamp(10px, 2.1vw, 17px); border-radius: 7px;
  background:
    linear-gradient(135deg, #fbe9a8 0%, #dcb056 16%, #b6862f 50%, #dcb056 84%, #8a6320 100%);
  box-shadow:
    0 16px 34px rgba(0,0,0,.42),                  /* drop shadow */
    inset 0 2px 2px rgba(255,255,255,.65),        /* top-light bevel */
    inset 0 -3px 4px rgba(80,52,8,.6),            /* bottom-dark bevel */
    inset 0 0 0 2px rgba(255,247,214,.55),        /* bright outer fillet */
    inset 0 0 0 4px rgba(120,84,22,.65),          /* carved groove */
    inset 0 0 0 13px rgba(184,138,46,.4),         /* inner gold band */
    inset 0 0 0 15px rgba(90,60,14,.5);           /* inner groove */
}
.frame-inner {
  /* The frame hugs the drawing's real shape. Play is locked to portrait, so
     these come out portrait; a stray landscape drawing gets a landscape frame
     of its own rather than being letterboxed inside a fixed 4:3 box. */
  display: block; width: 100%; height: auto;
  background: #fdfbf3; border: 8px solid #fdfbf3;         /* warm paper mount/mat */
  border-radius: 1px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.1),            /* mat inner line */
              inset 0 0 12px rgba(0,0,0,.16);            /* image sits inside */
}

/* ===================================================================
   GALLERY
   =================================================================== */
.gallery-inner { width: 100%; max-width: 1100px; display: flex; flex-direction: column; gap: 14px; }
.gallery-head { text-align: center; color: #fff; }
.gallery-head h2 { margin: 0; font-size: clamp(22px, 5vw, 34px); }
.gallery-subject { margin: 4px 0 0; font-weight: 700; opacity: .95; }
.gallery-grid {
  width: 100%;
  display: grid; gap: clamp(16px, 3vw, 26px); align-content: start;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.gallery-item { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.gallery-item .frame { width: 100%; }
.gallery-item.is-winner .frame {
  background: linear-gradient(135deg, #fff4c2 0%, #f4cf5a 16%, #d29e2a 50%, #f4cf5a 84%, #a9781a 100%);
  box-shadow:
    0 16px 34px rgba(0,0,0,.45),
    inset 0 2px 2px rgba(255,255,255,.8),
    inset 0 -3px 4px rgba(120,84,10,.6),
    inset 0 0 0 2px rgba(255,252,225,.7),
    inset 0 0 0 4px rgba(150,105,20,.7),
    inset 0 0 0 13px rgba(220,170,60,.45),
    inset 0 0 0 15px rgba(120,84,14,.5);
}
.gallery-item img { cursor: pointer; }
.gallery-name { text-align: center; font-weight: 800; color: #fff; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: clamp(15px, 2.6vw, 19px); text-shadow: 0 1px 3px rgba(0,0,0,.3); }
.gallery-name .crown { font-size: 20px; }
.gallery-back { align-self: center; margin-top: 6px; }

/* ===================================================================
   MODAL + TOAST
   =================================================================== */
.modal { position: fixed; inset: 0; background: rgba(30,16,70,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 22px; padding: 22px; width: min(92vw, 380px); box-shadow: var(--shadow); }
.modal-box h3 { margin: 0 0 14px; font-size: 22px; }
.confirm-msg { margin: 0 0 4px; color: var(--ink-soft); font-weight: 600; font-size: 16px; }
.modal-input {
  width: 100%; font: inherit; font-weight: 700; font-size: 20px;
  padding: 14px 16px; border: 3px solid #e6e2f7; border-radius: 14px; background: #faf9ff;
  -webkit-user-select: text; user-select: text;
}
.modal-input:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(30,16,70,.94); color: #fff; font-weight: 800;
  padding: 12px 22px; border-radius: 999px; z-index: 60; font-size: 16px;
  box-shadow: var(--shadow); animation: toastIn .2s ease;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- drawing timer ---------- */
.timer-row { display: flex; align-items: center; justify-content: center; gap: 16px; }
.timer-btn {
  width: 56px; height: 56px; border-radius: 50%; border: 3px solid #e6e2f7;
  background: #faf9ff; color: var(--primary-d); font: inherit; font-size: 30px; font-weight: 900;
  cursor: pointer; display: grid; place-items: center; line-height: 1; flex: 0 0 auto;
}
.timer-btn:active { transform: scale(.93); }
.timer-btn:disabled { opacity: .35; cursor: not-allowed; }
.timer-value {
  font-weight: 900; font-size: clamp(30px, 8vw, 44px); color: var(--ink);
  min-width: 4.2ch; text-align: center; font-variant-numeric: tabular-nums;
}
.timer-value.off { color: var(--ink-soft); font-size: clamp(24px, 6vw, 34px); }

.draw-timer {
  flex: 0 0 auto; font-weight: 900; font-variant-numeric: tabular-nums;
  font-size: clamp(17px, 3vw, 24px); color: var(--ink);
  background: #f1eeff; border-radius: 999px; padding: 6px 14px; margin-left: auto;
}
.draw-timer[hidden] { display: none; }
.draw-timer.warn { background: #ffe9e2; color: #c0392b; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.09); } }
/* when the timer is showing, Done no longer needs the auto margin */
.draw-timer:not([hidden]) ~ .btn-submit { margin-left: 10px; }

/* ---------- coin flip (2 players) ---------- */
.coin-inner {
  margin: auto; background: var(--card); border-radius: 28px; box-shadow: var(--shadow);
  padding: clamp(22px, 5vw, 44px); text-align: center; max-width: 520px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.coin-title { margin: 0; font-size: clamp(24px, 6vw, 36px); color: var(--primary-d); }
.coin-sub { margin: 0; font-weight: 700; color: var(--ink-soft); }
.coin-names {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  font-weight: 900; font-size: clamp(17px, 4vw, 24px);
}
.coin-vs { color: var(--ink-soft); font-weight: 700; font-size: .8em; }
.coin-stage { height: clamp(120px, 30vw, 170px); display: grid; place-items: center; }
.coin {
  font-size: clamp(84px, 22vw, 130px); line-height: 1;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,.28));
}
.coin.spinning { animation: coinspin .45s linear infinite; }
@keyframes coinspin {
  0%   { transform: rotateY(0deg)   scale(1); }
  50%  { transform: rotateY(180deg) scale(1.14); }
  100% { transform: rotateY(360deg) scale(1); }
}
.coin-result { margin: 4px 0 0; font-size: clamp(30px, 8vw, 46px); color: var(--primary-d); }
.coin-result[hidden], .coin-inner .btn[hidden] { display: none; }

/* ---------- AI judge screen (2 players) ---------- */
.judge-thinking { display: grid; place-items: center; gap: 8px; padding: 10px 0 4px; }
.judge-thinking[hidden] { display: none; }
.judge-face {
  font-size: clamp(64px, 18vw, 104px); line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,.22)); animation: ponder 2.4s ease-in-out infinite;
}
@keyframes ponder {
  0%, 100% { transform: rotate(-5deg) translateY(0); }
  50%      { transform: rotate(5deg)  translateY(-6px); }
}
.judge-dots { display: flex; gap: 8px; }
.judge-dots i {
  width: 11px; height: 11px; border-radius: 50%; background: var(--primary);
  animation: dotpop 1.1s ease-in-out infinite;
}
.judge-dots i:nth-child(2) { animation-delay: .18s; }
.judge-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes dotpop { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-7px); } }
.judge-wait {
  margin: 0; font-weight: 700; color: var(--ink-soft);
  min-height: 1.4em; transition: opacity .22s ease;
}

.judge-notes { display: grid; gap: 8px; width: 100%; }
.judge-notes[hidden] { display: none; }
.judge-note {
  display: flex; align-items: center; gap: 12px;
  margin: 0; background: #f7f5ff; border-radius: 14px; padding: 10px 12px;
  font-weight: 600; font-size: clamp(14px, 3.4vw, 17px); color: var(--ink); line-height: 1.35;
}
.judge-note strong { font-weight: 900; }
.note-text { margin: 0; flex: 1 1 auto; min-width: 0; }
.note-thumb {
  flex: 0 0 auto; width: clamp(56px, 15vw, 82px); height: clamp(56px, 15vw, 82px);
  padding: 3px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(145deg, #f6d45c, #c58c1e);
  box-shadow: 0 2px 6px rgba(0,0,0,.22);
}
.note-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  border-radius: 9px; background: #fff;
}
.note-thumb:active { transform: scale(.95); }

/* ---------- the Judge's Award (separate from the family vote) ---------- */
.judge-award, .solo-appraisal {
  width: 100%; max-width: 620px; margin: 16px auto 0;
  background: rgba(255,255,255,.14); border-radius: 22px;
  padding: 16px clamp(14px, 4vw, 24px) 20px;
  backdrop-filter: blur(2px);
  border: 2px solid rgba(255,255,255,.22);
}
.judge-award[hidden], .solo-appraisal[hidden] { display: none; }
.award-h {
  margin: 0 0 10px; text-align: center; color: #fff;
  font-size: clamp(18px, 4.4vw, 26px); text-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.award-stage { display: grid; place-items: center; }
.award-col .frame { max-width: 240px; }
.rosette { width: clamp(140px, 34vw, 200px); }
.rosette-svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 8px 14px rgba(0,0,0,.3)); }
.award-reason {
  margin: 12px auto 0; max-width: 46ch; text-align: center; color: #fff;
  font-weight: 700; font-size: clamp(15px, 3.6vw, 19px); line-height: 1.4;
  text-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.award-reason[hidden] { display: none; }

/* ---------- the judge's verdict ---------- */
.judge-verdict {
  width: 100%; max-width: 620px; margin: 16px auto 0;
  background: rgba(255,255,255,.16); border-radius: 22px;
  padding: 16px clamp(14px, 4vw, 24px) 20px;
  border: 2px solid rgba(255,255,255,.28); backdrop-filter: blur(2px);
}
.judge-verdict[hidden] { display: none; }
.verdict-text {
  margin: 0; color: #fff; font-weight: 600; line-height: 1.5; text-align: center;
  font-size: clamp(15px, 3.7vw, 20px); text-shadow: 0 1px 4px rgba(0,0,0,.22);
  font-style: italic;
}

/* ---------- solo appraisal ---------- */
.solo-text {
  margin: 0; color: #fff; font-weight: 600; line-height: 1.5;
  font-size: clamp(15px, 3.6vw, 19px); text-align: center;
  text-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.solo-tips { margin-top: 16px; }
.solo-tips[hidden] { display: none; }
.tips-h { margin: 0 0 8px; color: #fff; font-size: clamp(15px, 3.6vw, 19px); text-align: center; }
.solo-tips ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.solo-tips li {
  background: rgba(255,255,255,.18); border-radius: 14px; padding: 10px 14px;
  color: #fff; font-weight: 600; font-size: clamp(14px, 3.4vw, 17px); line-height: 1.4;
}
.solo-tips li::before { content: '✏️ '; }

/* ---------- the judge is asleep ---------- */
.asleep-scene { position: relative; display: grid; place-items: center; padding: 6px 0 0; }
.asleep-face {
  font-size: clamp(70px, 20vw, 110px); line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,.22)); animation: snooze 3.4s ease-in-out infinite;
}
@keyframes snooze {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  50%      { transform: rotate(-6deg) scale(1.05); }
}
.asleep-z {
  position: absolute; font-weight: 900; color: var(--primary);
  opacity: 0; animation: floatz 3.4s ease-in-out infinite;
}
.asleep-z.z1 { right: 22%; top: 30%; font-size: 20px; animation-delay: 0s; }
.asleep-z.z2 { right: 14%; top: 16%; font-size: 28px; animation-delay: .5s; }
.asleep-z.z3 { right: 6%;  top: 2%;  font-size: 38px; animation-delay: 1s; }
@keyframes floatz {
  0%   { opacity: 0; transform: translateY(10px); }
  30%  { opacity: .9; }
  70%  { opacity: .5; }
  100% { opacity: 0; transform: translateY(-22px); }
}
.asleep-line { margin: 0; font-weight: 800; color: var(--ink); font-size: clamp(15px, 3.8vw, 19px); }
.asleep-note {
  margin: 0; color: var(--ink-soft); font-weight: 600; line-height: 1.45;
  font-size: clamp(14px, 3.4vw, 17px); max-width: 34ch;
}

.result-verdict { display: grid; gap: 8px; width: 100%; max-width: 620px; margin: 16px auto 0; }
.result-verdict[hidden] { display: none; }
.result-verdict .judge-note {
  background: rgba(255,255,255,.16); color: #fff; backdrop-filter: blur(2px);
}
.result-verdict .judge-note strong { color: #fff !important; }

/* ---------- save & share ---------- */
.share-box { max-width: 460px; width: 100%; }
.share-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 4px 0 12px; }
.share-chip {
  border: 2px solid #e6e2f7; background: #faf9ff; color: var(--ink-soft);
  border-radius: 999px; padding: 8px 16px; font: inherit; font-weight: 800;
  font-size: 15px; cursor: pointer;
}
.share-chip.on { border-color: var(--primary); background: #f3efff; color: var(--primary-d); }
.share-chip:active { transform: scale(.96); }
.share-toggle {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  font-weight: 700; color: var(--ink); cursor: pointer; margin-bottom: 12px;
  font-size: clamp(14px, 3.4vw, 16px);
}
.share-toggle input { width: 22px; height: 22px; accent-color: var(--primary); }
.share-toggle input:disabled + span { opacity: .45; }
.share-preview-wrap {
  background: #f2eff9; border-radius: 16px; min-height: 140px; max-height: 42vh;
  overflow: auto; display: grid; place-items: center; padding: 10px; margin-bottom: 14px;
}
.share-preview { max-width: 100%; height: auto; border-radius: 8px; box-shadow: var(--shadow); }
.share-preview[hidden] { display: none; }
.share-busy { margin: 0; font-weight: 700; color: var(--ink-soft); }
.share-busy[hidden] { display: none; }
.share-actions { flex-wrap: wrap; }
.share-actions .btn[hidden] { display: none; }
.share-actions .btn:disabled { opacity: .45; cursor: not-allowed; }

.gallery-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }

/* ---------- persistent reset ("new duel") ---------- */
.reset-btn {
  position: fixed; top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r));
  z-index: 45; width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.7); background: rgba(30,16,70,.55); color: #fff;
  cursor: pointer; display: grid; place-items: center; padding: 0;
  box-shadow: 0 3px 12px rgba(0,0,0,.28); backdrop-filter: blur(4px);
}
.reset-ico { width: 24px; height: 24px; display: block; }
.reset-btn:active { transform: scale(.92) rotate(-40deg); }
.reset-btn[hidden] { display: none; }

/* ---------- fullscreen art viewer ---------- */
.art-viewer {
  position: fixed; inset: 0; z-index: 55; background: rgba(20,10,45,.9);
  display: grid; place-items: center; padding: 5vmin;
}
.art-viewer[hidden] { display: none; }
.art-viewer-frame { width: fit-content; max-width: 92vw; max-height: 92vh; margin: auto; }
/* height-led here so a tall portrait fits the screen; width follows the image */
.art-viewer-frame .frame-inner { width: auto; height: auto; max-width: 84vw; max-height: 80vh; }
.art-viewer-close {
  position: fixed; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r));
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.9); color: var(--ink); font-size: 22px; font-weight: 900; cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- small screens: keep tools tidy ---------- */
@media (max-width: 480px) {
  .btn-submit { padding: 12px 16px; }
}
/* very tight: hide tool-button text labels (icons + titles remain) */
@media (max-width: 360px) {
  .draw-subject { display: none; }
  .tool-btn .tb-lbl { display: none; }
  .tool-btn { padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
