/* Prism Chain — prototype styles. Placeholder look; layout is the real deliverable.
   Phone portrait: board on top, mission + rainbow order underneath.
   Desktop / any wide window: board on the left, mission panel on the right. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #ffffff;
  --muted: #d9ccff;
  --panel: rgba(24, 10, 58, 0.82);
  --panel-line: rgba(255, 255, 255, 0.22);
  --accent: #ffd54a;
  --accent2: #ff6bb3;
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%; width: 100%; overflow: hidden; overscroll-behavior: none;
  background: #1c0d3f; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* backdrop: cover-fit (never stretched), dimmed so the board stays readable */
#bg {
  position: fixed; inset: 0; z-index: 0;
  background: #2a1458 center / cover no-repeat;
  filter: brightness(0.78) saturate(1.05);
}
#bg-shade { position: fixed; inset: 0; z-index: 0; background: linear-gradient(180deg, rgba(20,8,48,.35), rgba(20,8,48,.1) 40%, rgba(20,8,48,.55)); pointer-events: none; }
@media (min-aspect-ratio: 5/4) {
  /* The temporary backdrop is portrait art: on wide screens blur it so upscaling never shows */
  #bg { filter: blur(9px) brightness(0.62) saturate(1.1); transform: scale(1.1); }
}

#app {
  position: relative; z-index: 1; height: 100%; width: 100%; max-width: 1240px; margin: 0 auto;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  display: flex; flex-direction: column;
}
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- buttons ---------- */
.btn {
  display: block; width: 100%; min-height: 52px; padding: 12px 18px; margin: 8px 0;
  border: 2px solid var(--panel-line); border-radius: 16px; cursor: pointer;
  background: var(--panel); color: var(--ink); font: 700 1.05rem/1.2 var(--font); touch-action: manipulation;
}
.btn.primary { background: linear-gradient(135deg, #ff6bb3, #ffb347); border-color: rgba(255,255,255,.7); color: #2a1458; box-shadow: 0 5px 0 rgba(0,0,0,.25); }
.btn.big { min-height: 64px; font-size: 1.3rem; }
.btn:active { transform: translateY(2px); }
.btn:focus-visible, .icon-btn:focus-visible, .toggle:focus-visible, #board:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.icon-btn {
  min-width: 48px; height: 48px; padding: 0 12px; border-radius: 14px; cursor: pointer;
  border: 2px solid var(--panel-line); background: var(--panel); color: var(--ink);
  font: 800 1.35rem/1 var(--font); touch-action: manipulation;
}
.icon-btn[hidden] { display: none; }
.icon-btn.off { opacity: 0.55; text-decoration: line-through; }
#btn-skip { font-size: 0.95rem; }

.toggle {
  flex: 1; min-height: 46px; padding: 8px 10px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--panel-line); background: var(--panel); color: var(--ink); font: 700 0.9rem/1.2 var(--font);
}
.toggle[aria-checked="true"] { border-color: var(--accent); }

/* ---------- menu ---------- */
.menu-wrap { margin: auto; width: 100%; max-width: 380px; padding: 18px 20px; text-align: center; }
.logo {
  font-size: clamp(2.2rem, 9vw, 3.2rem); letter-spacing: 0.06em; font-weight: 900;
  text-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 24px rgba(255,150,220,.55);
}
.logo span { background: linear-gradient(120deg, #ff6b7a, #ffcc33, #3ee0d6, #a87aff); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 3px 0 rgba(0,0,0,.35)); }
.tag { margin: 6px 0 14px; color: var(--muted); font-size: 1.02rem; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.menu-legend { display: flex; justify-content: center; align-items: center; gap: 4px; margin: 6px 0 18px; }
.best { margin: 8px 0 4px; color: var(--accent); font-weight: 800; min-height: 1.4em; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.toggles { display: flex; gap: 8px; margin: 10px 0 6px; }
.proto-note { margin-top: 12px; font-size: 0.78rem; color: var(--muted); }
.credit { margin-top: 6px; font-size: 0.68rem; color: rgba(217, 204, 255, 0.8); line-height: 1.35; }

/* ---------- level map ---------- */
.levels-wrap { margin: 0 auto; width: 100%; max-width: 760px; padding: 10px 14px 12px; display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }
.levels-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.levels-head h2 { font-size: 1.45rem; text-shadow: 0 2px 6px rgba(0,0,0,.6); }
.levels-summary { flex: 1 1 100%; margin: 2px 0 0; color: var(--accent); font-weight: 800; font-size: 0.92rem; text-shadow: 0 1px 4px rgba(0,0,0,.7); }
.world-bar {
  display: flex; align-items: center; gap: 10px; margin: 8px 0; padding: 8px 10px; border-radius: 18px;
  background: rgba(24, 10, 58, 0.78); border: 2px solid var(--panel-line);
}
.world-title { flex: 1; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.world-title b { font-size: 1.12rem; }
.world-title span { font-size: 0.82rem; color: var(--muted); font-weight: 700; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.map {
  position: relative; flex: 1; min-height: 440px; border-radius: 22px; overflow: hidden;
  background: rgba(24, 10, 58, 0.5); border: 2px solid rgba(255,255,255,.22);
  box-shadow: inset 0 0 40px rgba(20, 8, 48, .5);
}
#map-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#map-svg .trail { fill: none; stroke: rgba(255,255,255,.4); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 2 12; }
#map-svg .trail.done { stroke: var(--accent); stroke-width: 7; stroke-dasharray: none; filter: drop-shadow(0 0 5px rgba(255,213,74,.8)); }
#map-nodes { position: absolute; inset: 0; }
.map-node {
  position: absolute; transform: translate(-50%, -54%); width: 74px; padding: 0; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink); font-family: var(--font); touch-action: manipulation;
}
.map-node .gem {
  position: relative; display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.3), rgba(36,16,82,.88) 70%); border: 3px solid rgba(255,255,255,.55);
  box-shadow: 0 4px 10px rgba(0,0,0,.45);
}
.map-node .gem img { position: absolute; width: 74%; height: 74%; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.map-node .num { position: relative; font-size: 1.15rem; font-weight: 900; text-shadow: 0 2px 4px rgba(0,0,0,.95), 0 0 6px rgba(0,0,0,.9); }
.map-node .nstars { font-size: 0.92rem; letter-spacing: 1px; color: var(--accent); text-shadow: 0 1px 3px rgba(0,0,0,.9); line-height: 1; }
.map-node.won .gem { border-color: var(--accent); box-shadow: 0 0 12px rgba(255,213,74,.7), 0 4px 10px rgba(0,0,0,.45); }
.map-node.current .gem { border-color: var(--accent2); animation: nodepulse 1.4s ease-in-out infinite; }
.map-node.boss { width: 86px; }
.map-node.boss .gem { width: 72px; height: 72px; border-width: 4px; }
.map-node.locked .gem { background: rgba(24, 10, 58, .95); border-color: rgba(255,255,255,.25); }
.map-node.locked .gem img { filter: grayscale(1) brightness(.5); }
.map-node.locked .num { opacity: .9; font-size: 1rem; transform: translateY(-9px); }
.map-node.locked .lock { position: absolute; width: 20px; height: 20px; bottom: 9px; color: rgba(255,255,255,.85); }
.map-node.locked { cursor: not-allowed; }
.map-node.shake .gem { animation: nodeshake .35s; }
.map-node:focus-visible { outline: none; }
.map-node:focus-visible .gem { outline: 3px solid var(--accent); outline-offset: 3px; }
@keyframes nodepulse { 50% { box-shadow: 0 0 0 7px rgba(255,107,179,.45), 0 4px 10px rgba(0,0,0,.45); transform: scale(1.07); } }
@keyframes nodeshake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (min-aspect-ratio: 5/4) and (max-height: 560px) {
  .map-node { width: 56px; } .map-node .gem { width: 44px; height: 44px; } .map-node.boss .gem { width: 52px; height: 52px; }
  .map-node .num { font-size: 0.95rem; } .map-node .nstars { font-size: 0.75rem; }
  .map { min-height: 190px; } .levels-head h2 { font-size: 1.15rem; } .world-bar { margin: 4px 0; padding: 4px 8px; }
}
@media (prefers-reduced-motion: reduce) { .map-node.current .gem { animation: none; } }
body.reduce-motion .map-node.current .gem { animation: none; }

/* ---------- celebration ---------- */
.overlay-card { position: relative; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; border-radius: 24px; }
.confetti span { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; opacity: 0; animation: confall 2s ease-in forwards; }
@keyframes confall { 0% { opacity: 1; transform: translate(0, 0) rotate(0); } 100% { opacity: 0; transform: translate(var(--dx, 0), 480px) rotate(540deg); } }

/* ---------- play layout ---------- */
.hud { display: flex; align-items: center; gap: 8px; padding: 8px 10px 4px; flex-shrink: 0; }
.hud .spacer { flex: 1; }
.pill {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 78px; height: 48px; padding: 0 12px; border-radius: 14px; background: var(--panel); border: 2px solid var(--panel-line);
}
.pill .lbl { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); line-height: 1; }
.pill b { font-size: 1.35rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.pill.moves b { font-size: 1.6rem; }
.pill.low { border-color: #ff7a7a; animation: lowpulse 1s ease-in-out infinite; }
@keyframes lowpulse { 50% { box-shadow: 0 0 0 4px rgba(255,122,122,.35); } }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 10px 10px; gap: 8px; }
.board-area { position: relative; flex: 1; min-height: 0; min-width: 0; }
#board { position: absolute; left: 0; top: 0; display: block; touch-action: none; -webkit-user-select: none; user-select: none; outline-offset: -3px; }

.caption {
  /* lives in the free strip under the board, so it can never cover a jewel */
  position: absolute; left: 50%; bottom: 3px; transform: translateX(-50%); z-index: 3; pointer-events: none;
  width: max-content; max-width: calc(100% - 12px); padding: 7px 16px; border-radius: 18px; text-align: center;
  background: rgba(25, 10, 58, 0.92); border: 2px solid var(--accent); color: #fff; font: 800 1.05rem/1.2 var(--font);
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
/* while a chain preview badge is showing, it takes the caption's place */
.board-area:has(.chain-badge:not([hidden])) .caption { visibility: hidden; }
.caption[hidden], .chain-badge[hidden] { display: none; }
.caption.bump { animation: bump .35s ease-out; }
@keyframes bump { 30% { transform: translateX(-50%) scale(1.08); } }
.chain-badge {
  position: absolute; left: 50%; bottom: 3px; transform: translateX(-50%); z-index: 3; pointer-events: none;
  padding: 7px 16px; border-radius: 18px; white-space: normal; text-align: center;
  width: max-content; max-width: calc(100% - 12px);
  background: rgba(25, 10, 58, 0.9); border: 2px solid rgba(255,255,255,.7); font: 800 1rem/1.2 var(--font);
}

.side { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.card { background: var(--panel); border: 2px solid var(--panel-line); border-radius: 18px; padding: 10px 12px; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.mission-title { font-weight: 900; font-size: 1.15rem; margin-bottom: 6px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }

.energy { position: relative; height: 38px; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.35); }
.energy-fill { height: 100%; width: 0%; border-radius: 999px; background: linear-gradient(90deg, #ff6b7a, #ffcc33, #3dd68c, #3ee0d6, #5b8dff, #a87aff); transition: width .25s ease-out; }
.energy.full { border-color: var(--accent); box-shadow: 0 0 16px rgba(255, 213, 74, .85); }
.energy-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font: 800 1.08rem/1 var(--font); text-shadow: 0 1px 4px rgba(0,0,0,.95), 0 0 2px rgba(0,0,0,.8); }

.stars { list-style: none; display: flex; gap: 6px; margin-top: 8px; }
.stars li { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; min-height: 52px; padding: 4px 8px; border-radius: 12px; background: rgba(255,255,255,.12); font-size: 0.92rem; font-weight: 800; line-height: 1.15; }
.stars .star { font-size: 1.8rem; line-height: 1; color: rgba(255,255,255,.35); }
.stars li.done { background: rgba(255, 213, 74, .22); }
.stars li.done .star { color: var(--accent); text-shadow: 0 0 10px rgba(255, 213, 74, .9); }
.stars li.pop .star { animation: starpop .6s ease-out; }
@keyframes starpop { 0% { transform: scale(0.4) rotate(-40deg); } 60% { transform: scale(1.7) rotate(10deg); } 100% { transform: scale(1); } }
.stars .gt { display: block; font-weight: 700; color: var(--muted); font-size: 0.8rem; }

.legend-title { font-size: 0.78rem; letter-spacing: 0.08em; font-weight: 700; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; text-align: center; }
.legend, .menu-legend { display: flex; align-items: center; justify-content: center; gap: 2px; }
.chip { position: relative; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; border: 2px solid transparent; transition: transform .12s; }
.chip canvas { display: block; }
.chip-arrow { color: var(--muted); font-weight: 900; font-size: 0.95rem; width: 12px; text-align: center; }
.chip.tap { border-color: #fff; background: rgba(255,255,255,.18); }
.chip.next { border-color: var(--accent); background: rgba(255, 213, 74, .25); transform: scale(1.12); animation: nextglow 0.8s ease-in-out infinite; }
.chip.cur { border-color: #fff; background: rgba(255,255,255,.3); transform: scale(1.12); }
.chip.in-chain::after {
  content: attr(data-n); position: absolute; right: -5px; top: -7px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 4px;
  background: #fff; color: #2a1458; font: 900 0.82rem/20px var(--font); text-align: center;
}
.chip.next::before, .chip.tap::before {
  position: absolute; left: 50%; bottom: -17px; transform: translateX(-50%); font: 900 0.72rem/1 var(--font); letter-spacing: 0.06em; white-space: nowrap; color: #fff;
}
.chip.next::before { content: 'NEXT'; color: var(--accent); }
.chip.tap::before { content: 'TAP'; }
@keyframes nextglow { 50% { box-shadow: 0 0 14px rgba(255, 213, 74, .95); } }
.legend-card { padding-bottom: 24px; }

/* mission/tutorial states */
#screen-play.lesson .stars, #screen-play.lesson .energy { display: none; }
#screen-play:not(.lesson) #btn-skip { display: none; }

/* ---------- overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 5, 38, 0.7); }
.overlay[hidden] { display: none; }
.overlay-card { width: 100%; max-width: 380px; max-height: 100%; overflow: auto; padding: 22px 20px 16px; text-align: center; border-radius: 24px; background: rgba(36, 16, 82, 0.96); border: 2px solid rgba(255,255,255,.4); box-shadow: 0 18px 50px rgba(0,0,0,.5); }
.overlay-card h2 { font-size: 1.6rem; margin-bottom: 6px; }
.ov-stars { display: flex; justify-content: center; gap: 6px; font-size: 3rem; line-height: 1.1; margin: 4px 0; }
.ov-stars span { color: rgba(255,255,255,.28); }
.ov-stars span.on { color: var(--accent); text-shadow: 0 0 14px rgba(255,213,74,.9); animation: starpop .7s ease-out both; }
.ov-line { color: var(--muted); margin: 4px 0 8px; font-weight: 700; }
.ov-goals { list-style: none; text-align: left; margin: 6px 0 10px; font-size: 1.02rem; font-weight: 800; }
.ov-goals li { padding: 5px 4px; display: flex; gap: 8px; }
.ov-goals li.ok { color: #9dffbf; }
.ov-goals li.no { color: rgba(255,255,255,.62); }
.ov-crystal { display: flex; align-items: center; gap: 14px; justify-content: center; margin: 8px 0 10px; padding: 10px; border-radius: 16px; background: rgba(255,255,255,.1); text-align: left; }
.ov-crystal[hidden] { display: none; }
.crystal-gem {
  width: 56px; height: 64px; flex-shrink: 0; clip-path: polygon(50% 0, 100% 35%, 80% 100%, 20% 100%, 0 35%);
  background: conic-gradient(from 0deg, #ff6b7a, #ffcc33, #3dd68c, #3ee0d6, #5b8dff, #a87aff, #ff6b7a);
  animation: gemspin 3s linear infinite; /* placeholder for Nova's crystal art */
}
@keyframes gemspin { to { filter: hue-rotate(360deg); } }

/* ---------- wide layout (desktop / landscape): board left, mission panel right ---------- */
@media (min-aspect-ratio: 5/4) {
  .hud { padding: 12px 18px 6px; }
  .stage { flex-direction: row; padding: 0 18px 16px; gap: 18px; }
  .side { width: min(340px, 32vw); justify-content: center; }
  .stars { flex-direction: column; }
  .stars li { min-height: 52px; font-size: 0.95rem; }
  .card { padding: 14px 16px; }
  .chip { width: 40px; height: 40px; }
}
/* short landscape phones: keep the side panel compact */
@media (min-aspect-ratio: 5/4) and (max-height: 520px) {
  .side { overflow-y: auto; justify-content: flex-start; }
  .stars li { min-height: 36px; font-size: 0.8rem; }
  .card { padding: 8px 10px; }
  .pill { height: 42px; }
  .icon-btn { height: 42px; }
}
/* very narrow phones */
@media (max-width: 380px) {
  .stars li { font-size: 0.82rem; padding: 4px 5px; gap: 4px; }
  .stars .star { font-size: 1.5rem; }
  .chip { width: 40px; height: 40px; }
}
/* shorter portrait phones (iPhone SE / mini and browsers with toolbars): give the board the room.
   The mission name is redundant with the HUD there, so it is dropped; paddings shrink. */
@media (max-aspect-ratio: 5/4) and (max-height: 780px) {
  #screen-play:not(.lesson) .mission-title { display: none; }
  .stage { gap: 6px; padding-bottom: 6px; }
  .side { gap: 6px; }
  .card { padding: 8px 10px; }
  .stars { margin-top: 6px; }
  .stars li { min-height: 46px; }
  .energy { height: 34px; }
  .legend-card { padding-bottom: 22px; }
  .legend-title { margin-bottom: 2px; }
  .hud { padding-top: 6px; }
}

/* reduced motion (OS setting or in-game toggle) */
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
