/* Rexy and the Lost Rainbow — mobile-first, big touch targets, friendly type. */
:root {
  --bg: #fffaf0;
  --ink: #2b2240;
  --muted: #6b6483;
  --card: #ffffff;
  --primary: #ff6b4a;
  --primary-ink: #ffffff;
  --accent: #4a9dff;
  --ok: #2e9e5b;
  --warn: #c97a00;
  --line: #eadfce;
  --radius: 22px;
  --rainbow: linear-gradient(90deg, #ff5e5e, #ffa94d, #ffd43b, #69db7c, #4dabf7, #9775fa);
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Trebuchet MS", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1a2b; --ink: #f6f1ff; --muted: #b9b0d4; --card: #2a2540; --line: #3b3456;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; position: relative;
}
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--rainbow); }
.brand { font-weight: 800; font-size: 1.05rem; }
.brand span { white-space: nowrap; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; font-size: .9rem; text-decoration: underline; cursor: pointer; padding: 8px; }

.steps { list-style: none; display: flex; justify-content: center; gap: 8px; padding: 14px 16px 0; margin: 0; }
.steps li {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); border: 2px solid var(--line); font-weight: 800; color: var(--muted);
}
.steps li.done { background: #d9f5e3; border-color: var(--ok); color: var(--ok); }
.steps li.current { background: var(--primary); border-color: var(--primary); color: #fff; transform: scale(1.1); }

main { max-width: 760px; margin: 0 auto; padding: 8px 16px 40px; }
.screen { display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
h1 { font-size: clamp(1.6rem, 6vw, 2.4rem); line-height: 1.15; margin: 12px 0 0; }
.story { font-size: 1.2rem; line-height: 1.5; max-width: 34em; margin: 0; }
.hint { color: var(--muted); font-size: 1.05rem; margin: 0; max-width: 36em; }
.hint.warn { color: var(--warn); font-weight: 700; }
.status { font-size: 1.1rem; font-weight: 700; margin: 0; }

.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 60px; padding: 14px 26px; border-radius: 999px; border: 3px solid var(--ink);
  background: var(--card); color: var(--ink); font: inherit; font-size: 1.2rem; font-weight: 800;
  text-decoration: none; cursor: pointer; box-shadow: 0 5px 0 var(--ink); transition: transform .08s, box-shadow .08s;
  -webkit-tap-highlight-color: transparent;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.big-btn.primary { background: var(--primary); color: var(--primary-ink); }
.big-btn:disabled { opacity: .45; cursor: not-allowed; }
.big-btn:focus-visible, .link-btn:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }
.btn-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.btn-col { display: flex; flex-direction: column; gap: 16px; width: min(100%, 360px); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

.tips { text-align: left; font-size: 1.15rem; line-height: 1.5; background: var(--card); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 18px 22px 18px 18px; margin: 0; list-style: none; display: grid; gap: 8px; max-width: 34em; }
.tips.small { font-size: 1.02rem; }

.rexy-stage { width: min(100%, 420px); }
.rexy-stage svg { width: 100%; height: auto; display: block; overflow: visible; }
.rexy-stage.small { width: min(100%, 300px); }
.rexy-stage.live { width: min(100%, 520px); }
.rexy-stage.grey { filter: grayscale(1); opacity: .9; }

.paper-preview { width: min(100%, 320px); background: #fff; border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.paper-preview svg { width: 100%; height: auto; display: block; }

canvas.photo, video { max-width: 100%; max-height: 60vh; border-radius: 14px; border: 3px solid var(--line); background: #000; }
canvas.tap { cursor: crosshair; touch-action: manipulation; }
.tap-wrap { position: relative; }

.spinner { width: 70px; height: 70px; border-radius: 50%; border: 10px solid var(--line); border-top-color: var(--primary);
  animation: spin 1s linear infinite; margin-top: 20px; }
@keyframes spin { to { transform: rotate(360deg); } }

.review-grid { display: grid; gap: 18px; width: 100%; justify-items: center; }
@media (min-width: 680px) { .review-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.regions { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; width: 100%; }
.region-row {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 12px; text-align: left;
  background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 8px 12px;
}
.region-row.picking { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.region-row input[type=color] { width: 56px; height: 48px; border: 2px solid var(--ink); border-radius: 12px; padding: 0; background: none; cursor: pointer; }
.region-row .name { font-weight: 800; font-size: 1.05rem; }
.chip { display: inline-block; font-size: .78rem; font-weight: 800; border-radius: 999px; padding: 2px 8px; margin-top: 2px; }
.chip.high { background: #d9f5e3; color: #1d6b3e; }
.chip.medium { background: #fff1c2; color: #7a5a00; }
.chip.low, .chip.uncolored { background: #ffe0dc; color: #9b2c1c; }
.chip.manual { background: #dfeaff; color: #1f4f9b; }
.pick-btn { background: none; border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; font: inherit; font-weight: 700; cursor: pointer; color: var(--ink); }
.photo-details { width: 100%; text-align: left; }
.photo-details summary { cursor: pointer; font-weight: 700; color: var(--accent); padding: 8px 0; }
.photo-details canvas { width: 100%; height: auto; cursor: crosshair; background: #fff; }

.celebrate-msg { background: var(--rainbow); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: clamp(1.7rem, 7vw, 2.8rem); }
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
#confetti i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@media (prefers-reduced-motion: reduce) { #confetti { display: none; } .screen { animation: none; } }

dialog { max-width: min(92vw, 560px); border: 3px solid var(--ink); border-radius: var(--radius); background: var(--card); color: var(--ink); padding: 20px 24px; }
dialog::backdrop { background: rgba(20, 10, 40, .55); }
dialog ul { padding-left: 1.1em; line-height: 1.5; }
dialog form { text-align: center; }

#print-area { display: none; }
@media print {
  @page { size: 8.5in 11in; margin: 0; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  #print-area svg { width: 8.5in; height: 11in; display: block; }
  html, body { background: #fff; }
}
h1:focus { outline: none; }

/* ---- Diagnostic mode (V1.2-diag, only visible with ?debug) ---- */
.diag { width: 100%; margin-top: 28px; padding: 16px; background: #fff; color: #111; border: 3px dashed #ff6d00;
  border-radius: 16px; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.diag h2 { margin: 0; font-size: 1.3rem; }
.diag-badge { margin-left: 8px; background: #ff6d00; color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 6px; vertical-align: middle; }
.diag-legend { font-size: .85rem; color: #444; margin: 0; }
.diag-canvas { width: 100%; height: auto; border: 1px solid #ccc; border-radius: 8px; background: #fff; }
.diag-t { border-collapse: collapse; font-size: .8rem; width: 100%; }
.diag-t th, .diag-t td { border: 1px solid #ddd; padding: 4px 6px; vertical-align: top; text-align: left; }
.diag-t th { background: #f4f1ea; }
.diag-scroll { overflow-x: auto; }
.diag-sw { display: inline-block; width: 14px; height: 14px; border: 1px solid #000; border-radius: 3px; margin-right: 4px; vertical-align: middle; }
