:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #eef1f8;
  --text: #1c2333;
  --dim: #63708c;
  --accent: #16a06d;
  --accent-2: #d98a00;
  --bad: #e0453c;
  --line: #d9dfea;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #e4ecff 0, var(--bg) 60%), var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.3px;
}
.scene-meta {
  display: flex;
  gap: 12px;
  align-items: baseline;
  font-size: 14px;
}

/* Play header: humanized scene title + a counter pill */
.scene-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px 4px;
}
.scene-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0.2px;
}
.scene-counter {
  flex: none;
  font-size: 13px;
  color: var(--dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-variant-numeric: tabular-nums;
}
.scene-counter b { color: var(--text); }
.dim {
  color: var(--dim);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
}
.stat {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 14px;
  min-width: 78px;
}
.stat .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--dim);
}
.stat span:last-child {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.controls {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}
.btn {
  background: var(--accent);
  color: #06251a;
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:hover {
  filter: brightness(1.06);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.ghost {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

/* Mode tabs */
.modes {
  display: flex;
  gap: 6px;
}
.tab {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: var(--accent);
  color: #06251a;
  border-color: transparent;
}

/* Credits (betting) bar */
.credit-bar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  margin: 0 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
body.mode-credits .credit-bar {
  display: flex;
}
body.mode-credits .casual-only {
  display: none;
}
.stake-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stakes {
  display: flex;
  gap: 6px;
}
.stake {
  min-width: 46px;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
.stake.selected {
  background: var(--accent-2);
  color: #3a2600;
  border-color: transparent;
}
.stake.unaffordable {
  opacity: 0.4;
}
.stake:disabled {
  cursor: not-allowed;
}
#net.ok {
  color: var(--accent);
}
#net.bad {
  color: var(--bad);
}
#timer.urgent {
  color: var(--bad);
  animation: pulse 0.8s ease-in-out infinite;
}

/* Result modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 26, 40, 0.55);
  z-index: 20;
}
.modal.hidden {
  display: none;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 30px;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-card h2 {
  margin: 0 0 10px;
}
.modal-card h2.win {
  color: var(--accent);
}
.modal-card h2.bad {
  color: var(--bad);
}
.modal-card p {
  margin: 0 0 18px;
  color: var(--text);
  line-height: 1.5;
}

.message {
  margin: 4px 20px 10px;
  min-height: 22px;
  font-size: 15px;
  color: var(--dim);
}
.message.ok {
  color: var(--accent);
}
.message.bad {
  color: var(--bad);
}
.message.hint {
  color: var(--accent-2);
}
.message.win {
  color: var(--accent);
  font-weight: 700;
}

.stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 20px 24px;
  max-width: 1600px;
  margin: 0 auto;
}
.pane {
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
.pane figcaption {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--dim);
  margin-bottom: 8px;
}
.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 720 / 520;
  border-radius: 10px;
  overflow: hidden;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background: var(--panel-2);
  touch-action: manipulation; /* fast taps, no double-tap zoom on tablets */
}
.markers {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Magnifier lens — round, follows the cursor/finger on both panes. */
.magnifier {
  position: absolute;
  display: none;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(20, 26, 40, 0.35), 0 8px 24px rgba(20, 26, 40, 0.3);
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 6;
}
/* On touch devices the lens is bigger so a finger can aim it comfortably. */
@media (pointer: coarse) {
  .magnifier { width: 200px; height: 200px; border-width: 4px; }
}
/* Active toggle state for a control (magnifier on). */
.controls .btn.active {
  background: var(--accent-2, #f39c12);
  color: #3a2600;
  box-shadow: inset 0 0 0 2px var(--text, #1c2333);
}

.marker {
  fill: none;
  stroke-width: 4;
}
.marker.found {
  stroke: var(--accent);
  animation: pop 0.35s ease-out;
}

/* Found difference: soft highlight of the object's mask shape + a check badge.
   (Legacy scenes without an outline fall back to the .marker.found ring.) */
.found-shape {
  fill: var(--accent);
  fill-opacity: 0.16;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linejoin: round;
  animation: found-in 0.3s ease-out;
}
.found-badge {
  transform-box: fill-box;
  transform-origin: center;
  animation: badge-pop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.found-badge circle { fill: var(--accent); stroke: #fff; stroke-width: 2.5; }
.found-badge path { fill: none; stroke: #fff; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
@keyframes found-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes badge-pop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .found-shape, .found-badge { animation: none; }
}
/* Hint: a magnifying-glass icon that blinks over the target area, then vanishes. */
.hint-icon { animation: hint-blink 0.55s ease-in-out infinite; }
.hint-icon .hint-halo { fill: var(--accent-2); opacity: 0.18; }
.hint-icon .hint-lens-bg { fill: none; stroke: #fff; stroke-width: 8; }
.hint-icon .hint-handle-bg { stroke: #fff; stroke-width: 8; stroke-linecap: round; }
.hint-icon .hint-lens { fill: none; stroke: var(--accent-2); stroke-width: 4; }
.hint-icon .hint-handle { stroke: var(--accent-2); stroke-width: 4; stroke-linecap: round; }
@keyframes hint-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.15; } }
@media (prefers-reduced-motion: reduce) { .hint-icon { animation: none; } }
.marker.miss {
  stroke: var(--bad);
  stroke-width: 5;
  animation: fade 0.5s ease-out forwards;
}

@keyframes pop {
  from {
    stroke-width: 10;
    opacity: 0;
  }
  to {
    stroke-width: 4;
    opacity: 1;
  }
}
@keyframes pulse {
  0%, 100% {
    opacity: 0.4;
    stroke-width: 3;
  }
  50% {
    opacity: 1;
    stroke-width: 6;
  }
}
@keyframes fade {
  from {
    opacity: 1;
    stroke-width: 6;
  }
  to {
    opacity: 0;
    stroke-width: 1;
  }
}

/* How to play — lives inside the Play view, as a tidy card. */
.play-help {
  margin: 18px 20px 40px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--dim);
  font-size: 14px;
}
.play-help summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  list-style: none;
}
.play-help summary::before { content: '💡 '; }
.play-help ul {
  margin: 10px 0 4px;
  padding-left: 20px;
  line-height: 1.6;
}
kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
}

@media (max-width: 780px) {
  .stage {
    grid-template-columns: 1fr;
  }
  .controls {
    width: 100%;
  }
}

/* =========================================================================
   PLAY — full-screen, tablet-first, finger-friendly, no distractions.
   Activated by body.playing (set by the router while the Play view is open).
   ========================================================================= */

/* One compact bar, all on a single line: scene · live stats · tools.
   The scene title is the only flexible item — it ellipsizes so the rest fits. */
.play-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.play-bar__scene {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}
.play-bar__scene .scene-title {
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.play-bar__stats {
  display: flex;
  gap: 8px;
  flex: none;
}
.play-bar__stats .stat {
  min-width: 0;
  padding: 4px 10px;
}
.play-bar__stats .stat .label { font-size: 10px; }
.play-bar__stats .stat span:last-child { font-size: 15px; }
.play-bar__tools {
  margin-left: 0;
  gap: 6px;
  flex: none;
}
/* Exit-to-menu — the way out of full-screen play. */
.play-exit {
  flex: none;
  font-weight: 600;
}

/* Full-screen frame: the stage owns the viewport; distractions step aside. */
body.playing {
  overflow: hidden;
}
body.playing #view-play {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
body.playing .topbar {
  display: none; /* the game takes the whole screen — brand/nav is a distraction here */
}
body.playing .stage {
  flex: 1 1 auto;
  min-height: 0;
  align-items: center;
  padding: 14px 20px;
  max-width: none;
}
body.playing .pane {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.playing .pane figcaption {
  flex: none;
}
/* Fit each picture to the available height, preserving its aspect ratio. */
body.playing .canvas-wrap {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  width: auto;
  max-width: 100%;
  margin: 0 auto;
}
/* Hide everything that isn't the puzzle while playing. */
body.playing .history,
body.playing .play-help {
  display: none;
}

/* Floating status line — a pill over the stage, never shifts the layout. */
body.playing .message {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(92vw, 640px);
  text-align: center;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(20, 26, 40, 0.14);
  z-index: 7;
  pointer-events: none;
}
body.playing .message:empty {
  display: none;
}

/* Finger-sized controls: every tool stays a comfortable touch target while
   the bar keeps to one line. */
body.playing .play-bar .btn {
  min-height: 46px;
  padding: 0 12px;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
body.playing .play-bar .btn[aria-label] {
  min-width: 46px;
  padding: 0 10px;
  font-size: 17px;
}

/* Tablet portrait / phones: stack the panes; the bar may wrap to two rows
   (one line is not practical at these widths). */
@media (max-width: 900px) {
  body.playing .stage {
    grid-template-columns: 1fr;
    align-items: stretch;
    overflow-y: auto;
  }
  body.playing #view-play {
    height: 100dvh;
  }
  body.playing .canvas-wrap {
    width: 100%;
    height: auto;
    flex: none;
  }
  body.playing .pane {
    height: auto;
  }
  body.playing .play-bar {
    flex-wrap: wrap;
    overflow: visible;
  }
  .play-bar__tools {
    width: 100%;
    justify-content: space-between;
  }
  body.playing .play-bar .btn {
    flex: 1 1 auto;
  }
}

/* Art-style info pill + card (taste-building). Pill sits by the scene title;
   the card explains the movement so a player builds their taste while playing. */
.style-pill {
  flex: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--dim);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-family: var(--font-label, inherit);
  cursor: pointer;
  white-space: nowrap;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.style-pill:hover { color: var(--text); border-color: var(--accent-2); }
body.playing .style-pill { min-height: 34px; }

.style-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(20, 26, 40, 0.16);
  color: var(--text);
}
.style-card h4 { margin: 0 0 4px; font-size: 16px; }
.style-card__meta {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--dim);
  font-family: var(--font-label, inherit);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.style-card p { margin: 6px 0; font-size: 14px; line-height: 1.5; }
.style-card__look { color: var(--dim); }
.style-card__look b { color: var(--text); }
.style-card__link {
  display: inline-block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.style-card__link:hover { text-decoration: underline; }
/* Play-screen popover: floats under the bar, never shifts the layout. */
body.playing .style-card {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  width: min(92vw, 420px);
}
.style-card__x {
  position: absolute;
  top: 8px;
  right: 10px;
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.style-card__x:hover { color: var(--text); }
/* Result screen: a static card, not a popover. */
.style-card--inline { margin: 12px 0 4px; max-width: none; box-shadow: none; }

/* ---- auth widget + modal (PocketBase) ---- */
.auth { display: flex; gap: 8px; align-items: center; }
.auth-btn { padding: 6px 12px; font-size: 13px; }
.auth-who { font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.auth-role { font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  background: var(--accent); color: #fff; border-radius: 20px; padding: 1px 7px; }
.auth-card { text-align: left; width: 340px; max-width: 92vw; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.auth-tab { flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; font: inherit; }
.auth-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.auth-field { display: grid; gap: 4px; font-size: 13px; margin-bottom: 12px; color: var(--muted, #667085); }
.auth-field.hidden { display: none; }
.auth-field input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit; }
.auth-msg { min-height: 18px; margin: 0 0 12px; font-size: 12px; color: var(--bad, #d3455b); }
.auth-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- profile view + creator credits ---- */
.profile-view { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; overflow-y: auto; background: rgba(20, 26, 40, 0.55); }
.profile-view.hidden { display: none; }
.profile-card { position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px 30px; width: 520px; max-width: 94vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.profile-card h2 { margin: 0 0 4px; }
.profile-sub { margin: 0 0 18px; color: var(--muted, #667085); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.profile-close { position: absolute; top: 14px; right: 16px; border: 0; background: transparent;
  font-size: 18px; cursor: pointer; color: var(--muted, #667085); }
.auth-role.player { background: #667085; }
.credit-panel { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 18px; }
.credit-balance { display: flex; align-items: baseline; justify-content: space-between; }
.credit-label { color: var(--muted, #667085); font-size: 13px; }
.credit-value { font-size: 26px; }
.credit-note { margin: 8px 0 14px; font-size: 12px; color: var(--muted, #667085); line-height: 1.5; }
.buy-panel { border: 1px dashed var(--accent); border-radius: 12px; padding: 16px; margin-bottom: 18px; }
.buy-panel.hidden { display: none; }
.buy-panel h3 { margin: 0 0 10px; font-size: 14px; }
.packages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.package { display: grid; gap: 4px; padding: 14px 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); cursor: pointer; font: inherit; text-align: center; }
.package:hover { border-color: var(--accent); }
.pkg-credits { font-size: 16px; font-weight: 700; }
.pkg-price { font-size: 12px; color: var(--muted, #667085); }
.pay-placeholder { margin: 12px 0 0; font-size: 12px; color: var(--muted, #667085); line-height: 1.5; }
.ledger-h { font-size: 13px; margin: 0 0 8px; }
.ledger { display: grid; gap: 4px; }
.ledger-row { display: grid; grid-template-columns: 60px 1fr auto; gap: 10px; font-size: 13px;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; align-items: center; }
.ledger-delta.pos { color: var(--accent); font-weight: 700; }
.ledger-delta.neg { color: var(--bad, #d3455b); font-weight: 700; }
.ledger-date { font-size: 11px; }

/* ---- create-a-scene: one guided flow ---- */
.create-page { max-width: 720px; margin: 0 auto; padding: 26px 20px 48px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding-bottom: 18px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.page-title { margin: 0 0 6px; font-size: 26px; letter-spacing: 0.2px; }
.page-sub { margin: 0; color: var(--dim); font-size: 14px; line-height: 1.55; max-width: 560px; }
.panel-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: 0 1px 2px rgba(20, 26, 40, 0.04); }

/* how it works — three steps: what happens + what's needed */
.how-strip { list-style: none; margin: 0 0 20px; padding: 0; display: grid;
  grid-template-columns: repeat(3, 1fr); gap: 14px; }
.how-strip li { display: flex; gap: 10px; align-items: flex-start; }
.how-n { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #06251a; font-weight: 700; font-size: 13px; }
.how-strip li > div { display: grid; gap: 2px; }
.how-strip b { font-size: 13.5px; color: var(--text); }
.how-strip li span:not(.how-n) { font-size: 12.5px; color: var(--dim); line-height: 1.45; }

/* Surprise me — the hero (the one obvious action) */
.surprise-hero { text-align: center; padding: 30px 24px 22px; margin-bottom: 20px;
  background: linear-gradient(180deg, oklch(from var(--accent) l c h / 0.14) 0%, var(--panel) 62%); }
.surprise-hero .surprise-die { font-size: 46px; line-height: 1; }
.surprise-hero h3 { margin: 8px 0 4px; font-size: 22px; }
.surprise-hero p { margin: 0 auto 18px; color: var(--dim); font-size: 14px; line-height: 1.5; max-width: 360px; }
.btn-lg { font-size: 17px; padding: 14px 34px; white-space: nowrap; }
.make-cost { margin: 14px 0 0; color: var(--dim); font-size: 13px; }
.make-cost b { color: var(--accent-2); font-variant-numeric: tabular-nums; }

/* Difficulty — a segmented Easy/Normal/Hard control (maps to the diff count) */
.difficulty { display: inline-flex; margin: 6px 0 4px; border: 1px solid var(--line);
  border-radius: 999px; overflow: hidden; background: var(--panel); }
.diff-opt { border: 0; background: transparent; color: var(--dim); font: inherit; font-weight: 600;
  font-size: 13px; padding: 8px 18px; cursor: pointer; transition: background 140ms, color 140ms; }
.diff-opt + .diff-opt { border-left: 1px solid var(--line); }
.diff-opt.active { background: var(--accent); color: #06251a; }
.diff-opt:focus-visible { outline: 3px solid var(--color-focus, #2563eb); outline-offset: -3px; }
.diff-note { margin: 4px 0 14px; color: var(--dim); font-size: 12.5px; }

/* Describe-your-own — secondary, collapsed by default */
.write-own { margin-top: 16px; }
.write-own > summary { cursor: pointer; list-style: none; text-align: center; color: var(--dim);
  font-size: 13px; padding: 8px; text-decoration: underline; text-underline-offset: 3px; }
.write-own > summary::-webkit-details-marker { display: none; }
.write-own__body { display: grid; gap: 14px; margin-top: 12px; padding: 18px 20px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.write-own .auth-field { display: grid; gap: 6px; font-size: 13px; color: var(--dim); font-weight: 500; }
.write-own textarea, .write-own input[type=file] { width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit; }
.write-own textarea { resize: vertical; min-height: 74px; line-height: 1.5; }
.write-own textarea:focus-visible, .write-own input:focus-visible { outline: 3px solid var(--color-focus, #2563eb); outline-offset: 1px; border-color: transparent; }
.write-own .btn { justify-self: start; }
.req { color: var(--dim); font-weight: 400; }
.photo-preview img { max-width: 150px; border-radius: 8px; margin-top: 2px; border: 1px solid var(--line); }

/* Generating — full-screen focus, centred, no scrolling */
.gen-page { max-width: 520px; }
.gen-focus { text-align: center; padding: 24px 0; }
.gen-emoji { font-size: 48px; line-height: 1; margin-bottom: 8px; }
.gen-focus .page-sub { margin: 0 auto 18px; max-width: 420px; }
.gen-focus .gen-steps { display: inline-grid; text-align: left; margin: 0 auto 16px; }
.gen-focus .btn { margin-top: 14px; }

/* Result — full-screen focus */
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
#createResult:not(:empty) { margin-top: 22px; }
.ab { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 0; }
.ab figure { margin: 0; }
.ab img { width: 100%; border-radius: 8px; display: block; border: 1px solid var(--line); }
.ab figcaption { font-size: 11px; color: var(--dim); margin-top: 5px; text-align: center; }

/* generating: skeleton cards + progress + step log */
.skeleton { width: 100%; aspect-ratio: 1 / 1; border-radius: 8px; border: 1px solid var(--line);
  background: linear-gradient(100deg, var(--panel-2) 30%, #f6f8fd 50%, var(--panel-2) 70%);
  background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
.skeleton.failed { animation: none; background: #fbeaea; border-color: var(--bad); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.gen-bar { height: 4px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin: 4px 0 12px; }
.gen-bar span { display: block; height: 100%; width: 40%; border-radius: 999px; background: var(--accent);
  animation: indet 1.4s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.gen-steps { list-style: none; margin: 0 0 4px; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.gen-steps li { color: var(--dim); padding-left: 22px; position: relative; }
.gen-steps li::before { content: '○'; position: absolute; left: 4px; color: var(--line); }
.gen-steps li.active { color: var(--text); font-weight: 500; }
.gen-steps li.active::before { content: '◐'; color: var(--accent); animation: spin 1s linear infinite; display: inline-block; }
.gen-steps li.done { color: var(--dim); }
.gen-steps li.done::before { content: '✓'; color: var(--accent); }
.gen-steps li.bad { color: var(--bad); }
.gen-steps li.bad::before { content: '✗'; color: var(--bad); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 620px) {
  .create-page { padding: 18px 16px 40px; }
  .how-strip { grid-template-columns: 1fr; gap: 10px; }
  .surprise-hero { padding: 24px 18px 20px; }
  .surprise-hero .btn-lg { width: 100%; }
  .result-actions .btn { flex: 1 1 100%; }
}

/* ---- app shell: nav + views ---- */
.mainnav { display: flex; gap: 6px; }
.navbtn { padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px; background: transparent;
  color: var(--text); cursor: pointer; font: inherit; font-size: 14px; }
.navbtn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.view.hidden { display: none; }

/* ---- landing ---- */
.landing-page { display: grid; place-items: center; padding: 60px 20px; }
.hero { max-width: 680px; text-align: center; }
.hero h2 { font-size: 34px; line-height: 1.15; margin: 0 0 14px; }
.hero-sub { color: var(--muted, #667085); font-size: 16px; line-height: 1.6; margin: 0 0 26px; }
.hero-cta { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---- manage scenes ---- */
.manage-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.manage-head h2 { margin: 0; }
.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; padding: 16px 20px; }
.scene-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel);
  display: flex; flex-direction: column; }
.scene-card .thumb { aspect-ratio: 4/3; background: #eef1f6; display: grid; place-items: center; }
.scene-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.scene-card .scene-meta { padding: 10px 12px; display: grid; gap: 3px; }
.scene-card .scene-name { font-weight: 600; font-size: 14px; }
.scene-card .btn { margin: 0 12px 12px; }
.small { font-size: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2);
  color: var(--dim); border: 1px solid var(--line); }
.card-actions { display: flex; gap: 8px; align-items: center; margin: 0 12px 12px; flex-wrap: wrap; }
.card-actions .btn { margin: 0; }
.shared-badge { font-size: 12px; color: var(--accent); font-weight: 600; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- play: history ---- */
.history { padding: 8px 20px 24px; }
.history h3 { margin: 0 0 8px; font-size: 14px; }
.past-list { display: grid; gap: 6px; }
.past-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: baseline;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.past-scene { font-weight: 600; }
@media (max-width: 640px) { .past-row { grid-template-columns: 1fr; gap: 2px; } }

/* ---- profile: change name ---- */
.name-panel { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 16px; flex-wrap: wrap; }
.name-panel .auth-field { flex: 1; min-width: 160px; margin: 0; }
.name-msg { font-size: 12px; color: var(--muted, #667085); }

/* ---- create options ---- */
.create-opts { display: flex; gap: 12px; }
.create-opts .auth-field { flex: 1; margin-bottom: 12px; }
.create-opts input, .create-opts select { padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; }

/* ============ Art-history timeline (js/styles.js) ============ */
.styles-page { max-width: 1120px; margin: 0 auto; padding: 26px 20px 56px; }
.styles-loading { padding: 40px 20px; text-align: center; }
.eyebrow { margin: 0 0 6px; font-family: var(--font-label, inherit); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.style-dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.style-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); }
.style-dots i.on { background: var(--accent); border-color: var(--accent); }
.wiki-credit { margin: 22px 0 0; font-size: 13px; color: var(--dim); }
.wiki-credit a, .wiki-src a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.wiki-src { margin-top: 12px !important; font-size: 12.5px !important; color: var(--dim); }
.seg { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.seg__btn { flex: 1; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.seg__btn.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }

.gen-stage { margin: 4px 0 2px; font-weight: 600; }
.gen-stage.bad { color: var(--bad); }
.gen-detail { margin: 0 0 14px; font-size: 13px; min-height: 1.4em; }
.gen-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* end-of-game panel (over the play view) */
.end-panel { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(20, 20, 20, .38); }
.end-panel[hidden] { display: none; }
.end-card { position: relative; width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--panel); border-radius: var(--radius); padding: 20px 20px 18px; box-shadow: 0 18px 50px rgba(0, 0, 0, .25); }
.end-x { position: absolute; top: 8px; right: 10px; width: 40px; height: 40px; border: 0; background: none; font-size: 24px; color: var(--dim); cursor: pointer; }
.end-title { margin: 0; font-family: var(--font-display, inherit); font-size: 24px; }
.end-stats { margin: 2px 0 14px; color: var(--dim); font-size: 14px; }
.end-quiz h4, .end-recap h4 { margin: 0 0 8px; font-size: 18px; }
.quiz-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quiz-opt { min-height: 48px; }
.quiz-result { margin: 0 0 12px; font-weight: 600; }
.quiz-result.ok { color: var(--accent); }
.quiz-result.bad { color: var(--bad); }
.end-recap p { margin: 0 0 8px; font-size: 14px; line-height: 1.5; }
.end-progress { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.end-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.end-actions .btn { min-height: 46px; }
.end-actions #endNext { flex: 1 1 100%; }

@media (max-width: 760px) {
  .styles-page { padding: 18px 16px 40px; }
  .quiz-opts { grid-template-columns: 1fr; }
}

/* the path */
.tl-page { max-width: 1240px; margin: 0 auto; padding: 26px 20px 64px; }
.tl-head { max-width: 720px; margin-left: auto; margin-right: auto; }
.tl-layout { display: block; }
.tl-main { max-width: 460px; margin: 0 auto; }
@media (min-width: 1000px) {
  .tl-layout { display: grid; grid-template-columns: minmax(360px, 440px) minmax(0, 1fr); gap: 40px; align-items: start; }
  .tl-main { margin: 0; }
  .tl-panel {
    position: sticky; top: 84px; max-height: calc(100dvh - 104px); display: flex; flex-direction: column; overflow: hidden;
    background: var(--panel); border: 1px solid var(--line); border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .05);
  }
  .tl-panel .lesson-learn { padding: 32px 36px 28px; }
  .tl-panel .lesson-action { padding: 12px 20px 14px; }
}
@media (max-width: 999px) { .tl-panel { display: none; } }
.tl-node.is-selected .tl-dot { outline: 3px solid var(--text); outline-offset: 5px; }
.tl-head { text-align: center; margin-bottom: 18px; }
.tl-head .page-sub { margin: 0 auto 10px; }
.tl-stats { margin: 0 0 12px; color: var(--dim); font-size: 14px; }
.tl-stats b { color: var(--text); }
.tl-resume { min-height: 46px; }
.tl-finished { font-weight: 600; }
.tl-path { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.tl-chapter {
  width: 100%; margin: 26px 0 14px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); display: grid; gap: 2px; text-align: center;
}
.tl-chapter:first-child { margin-top: 4px; }
.tl-chapter__n { font-family: var(--font-label, inherit); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.tl-chapter b { font-family: var(--font-display, inherit); font-size: 19px; }
.tl-chapter__years { font-size: 13px; color: var(--dim); }
.tl-node { position: relative; display: flex; flex-direction: column; align-items: center; width: 180px; padding: 6px 0;
  transform: translateX(calc(var(--x, 0) * 58px)); }
.tl-dot {
  position: relative; width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; font: inherit; color: #fff;
  background: var(--color-mint-deep, var(--accent)); box-shadow: 0 6px 0 rgba(0, 0, 0, .18);
  transition: transform .12s, box-shadow .12s;
}
.tl-dot:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
.tl-dot:focus-visible { outline: 3px solid var(--color-focus, var(--accent)); outline-offset: 4px; }
.tl-icon { font-size: 28px; line-height: 1; font-weight: 700; }
.tl-node.is-current { margin-top: 30px; }
.tl-node.is-current .tl-dot { background: var(--color-accent, var(--accent-2)); color: var(--text); }
.tl-node.is-locked .tl-dot { background: var(--panel-2); color: var(--dim); box-shadow: 0 6px 0 var(--line); }
.tl-node.is-locked .tl-icon { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tl-node.is-checkpoint .tl-dot { width: 88px; height: 88px; border-radius: 26px; }
.tl-node.is-checkpoint.is-done .tl-dot { background: var(--color-accent, var(--accent-2)); color: var(--text); }
.tl-ring { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); transform: rotate(-90deg); pointer-events: none; }
.tl-ring__bg { fill: none; stroke: var(--line); stroke-width: 5; }
.tl-ring__fg { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; }
.tl-label { margin-top: 10px; text-align: center; font-weight: 600; font-size: 14px; line-height: 1.25; }
.tl-label small { display: block; font-weight: 400; font-size: 12px; color: var(--dim); }
.tl-node.is-locked .tl-label { color: var(--dim); }
.tl-bubble {
  position: absolute; top: -26px; z-index: 1; padding: 4px 12px; border-radius: 10px; font-size: 13px; font-weight: 700;
  background: var(--panel); border: 2px solid var(--color-accent, var(--accent-2)); color: var(--text); white-space: nowrap;
  animation: tl-bob 1.4s ease-in-out infinite;
}
.tl-bubble::after { content: ''; position: absolute; left: 50%; bottom: -7px; width: 10px; height: 10px; margin-left: -5px;
  background: var(--panel); border-right: 2px solid var(--color-accent, var(--accent-2)); border-bottom: 2px solid var(--color-accent, var(--accent-2)); transform: rotate(45deg); }
@keyframes tl-bob { 50% { transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .tl-bubble { animation: none; } .tl-dot { transition: none; } }

/* lesson sheet: bottom sheet on phones, a centred card on wider screens */
.sheet { position: fixed; inset: 0; z-index: 60; display: grid; align-items: end; justify-items: center; background: rgba(20, 20, 20, .38); }
.sheet[hidden] { display: none; }
.sheet-card { position: relative; width: min(560px, 100%); max-height: 88dvh; display: flex; flex-direction: column; overflow: hidden; background: var(--panel);
  border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .2); }
.sheet-card .lesson-learn { padding: 22px 20px 20px; }
.sheet-card .lesson-action { padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 761px) { .sheet { align-items: center; padding: 16px; } .sheet-card { border-radius: 22px; } }
.sheet-x { position: absolute; top: 8px; right: 10px; z-index: 2; width: 40px; height: 40px; border: 0; background: none; font-size: 24px; color: var(--dim); cursor: pointer; }
.sheet-card p { line-height: 1.5; }
.sheet-play { width: 100%; min-height: 48px; }
.sheet-note { margin: 8px 0 0; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.chip { padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; }

@media (max-width: 760px) {
  .tl-page { padding: 18px 16px 48px; }
  .tl-node { transform: translateX(calc(var(--x, 0) * 38px)); width: 150px; }
}

/* the lesson — shared by the study panel and the bottom sheet.
   Readability: 17 px body, 1.7 line height, about 62 characters per line,
   clear spacing between blocks, one display face for titles. */
.lesson { font-size: 17px; line-height: 1.7; color: var(--text); display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.lesson-learn { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.lesson-learn > * { max-width: 62ch; }
.lesson-learn > :first-child { margin-top: 0; }

/* the ACTION block: a compact bar for playing, in its own place at the bottom */
.lesson-action {
  flex: none; display: grid; gap: 8px; font-size: 14px; line-height: 1.4;
  background: color-mix(in oklch, var(--color-accent, #f5d443) 16%, var(--panel));
  border-top: 2px solid var(--color-accent, var(--accent-2));
}
.action-top { display: flex; align-items: center; gap: 10px; }
.action-label { font-family: var(--font-label, inherit); font-size: 11.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text); }
.action-progress { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dim); }
.action-progress b { color: var(--text); }
.action-price { margin-left: auto; font-size: 12.5px; color: var(--dim); white-space: nowrap; }
.action-row { display: flex; align-items: center; gap: 8px; }
.seg--sm { flex: 1 1 auto; margin: 0; gap: 4px; flex-wrap: nowrap; }
.seg--sm .seg__btn { min-height: 38px; padding: 4px 8px; font-size: 13px; }
.action-row .sheet-play { flex: none; min-height: 42px; min-width: 112px; width: auto; padding: 8px 18px; }
.action-locked { margin: 0; padding: 8px 10px; border-radius: 10px; background: var(--panel); font-size: 13.5px; }
.lesson .eyebrow { font-size: 12px; letter-spacing: .1em; margin-bottom: 8px; }
.lesson-title { margin: 0 0 12px; font-family: var(--font-display, inherit); font-size: clamp(26px, 3vw, 34px); line-height: 1.12; letter-spacing: -0.015em; }
.lesson-blurb { margin: 0 0 22px; font-size: 19px; line-height: 1.55; color: var(--text); }
.lesson h4 { margin: 30px 0 10px; font-family: var(--font-label, inherit); font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.lesson p { margin: 0 0 1em; }
.lesson-wiki p { font-size: 16.5px; line-height: 1.75; }
.lesson-wiki p.lead { font-size: 18px; line-height: 1.65; }
.lesson .wiki-src { font-size: 13px; line-height: 1.5; color: var(--dim); margin-top: 18px; }
.lesson .chips { margin: 4px 0 20px; }

.lesson-hero { margin: 0 0 6px; }
.lesson-hero__frame { display: grid; place-items: center; background: var(--panel-2); border-radius: 16px; overflow: hidden; aspect-ratio: 4 / 3; }
.lesson-hero__frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lesson-hero figcaption { display: grid; gap: 2px; margin-top: 10px; }
.lesson-hero__cap { font-size: 15px; font-weight: 600; line-height: 1.4; }
.lesson-hero__credit { font-size: 12.5px; line-height: 1.45; color: var(--dim); }
.lesson-hero__credit a, .lesson .wiki-src a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.lesson-thumbs { display: flex; gap: 8px; margin: 12px 0 0; flex-wrap: wrap; }
.lesson-thumb { width: 64px; height: 64px; padding: 0; border: 2px solid transparent; border-radius: 12px; overflow: hidden; background: var(--panel-2); cursor: pointer; }
.lesson-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lesson-thumb.is-on { border-color: var(--text); }
.lesson-thumb:focus-visible { outline: 3px solid var(--color-focus, var(--accent)); outline-offset: 2px; }
.sheet-card .lesson-learn > * { max-width: none; }

/* "look for" — a short note inside the lesson text */
.lesson-look { margin: 0 0 22px; padding: 12px 16px; border-left: 4px solid var(--color-accent, var(--accent-2)); border-radius: 0 12px 12px 0;
  background: var(--panel-2); font-size: 16px; line-height: 1.55; }
.lesson-look b { font-weight: 600; }

/* waiting screen: a small status card + the whole lesson to study */
.gen-wide { max-width: 1180px; margin: 0 auto; padding: 24px 20px 56px; display: grid; gap: 24px; }
.gen-status { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 22px 22px 18px; text-align: center; }
.gen-status .gen-emoji { font-size: 34px; line-height: 1; margin-bottom: 8px; }
.gen-title { margin: 0 0 4px; font-family: var(--font-display, inherit); font-size: 20px; line-height: 1.25; }
.gen-time { margin: 0 0 10px; font-size: 13.5px; color: var(--dim); }
.gen-status .gen-actions { margin-top: 12px; }
.gen-lesson { max-width: 760px; }
.gen-lesson .lesson-learn { overflow: visible; }
@media (min-width: 1000px) {
  .gen-wide { grid-template-columns: 300px minmax(0, 1fr); gap: 40px; align-items: start; }
  .gen-status { position: sticky; top: 84px; }
}
/* checkpoint review: the chapter's styles side by side */
.cp-review { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 8px; }
@media (max-width: 560px) { .cp-review { grid-template-columns: 1fr; } }
.cp-card { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.cp-card__img { position: relative; aspect-ratio: 4 / 3; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; }
.cp-card__img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.cp-card__img--none { font-family: var(--font-display, inherit); font-size: 40px; color: var(--dim); }
.cp-card figcaption { display: grid; gap: 4px; padding: 12px 14px 14px; }
.cp-card figcaption b { font-size: 16px; }
.cp-card figcaption span { font-size: 14px; line-height: 1.45; }
.cp-card figcaption small { font-size: 11.5px; color: var(--dim); line-height: 1.4; }
.cp-card figcaption small a { color: inherit; }
