/* weave.css — Prime Weave. Loom theme: threads carry the colour, tiles stay neutral
   so eligibility lives on the threads (see docs/merge-resolution.md §4). */

:root {
  --bg: #1d1633;
  --bg2: #2a1f4a;
  --ink: #f4efe6;
  --muted: #b9aed6;
  --board: #15102a;
  --cell: 72px;            /* set by JS from board width */
  --gap: 10px;
  --tile: #efe7d4;         /* parchment tile face */
  --tile-ink: #2a2140;
  --accent: #ffd86b;       /* loom-gold */
  --good: #7fe7c4;
  --radius: 12px;
  --dur: 150ms;            /* movement duration; zeroed under reduced-motion */
  --pulse: 1;              /* set to 0 under reduced-motion to stop thread pulse */
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg2), var(--bg));
  color: var(--ink);
  font-family: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: clamp(10px, 3vw, 20px) 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}

/* ── header ─────────────────────────────────────────────── */
.pw-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pw-title { display: flex; flex-direction: column; }
.pw-title b {
  font-family: "Orbitron", "Rubik", sans-serif;
  font-weight: 800; font-size: clamp(1.2rem, 5vw, 1.6rem); letter-spacing: .5px;
  background: linear-gradient(90deg, var(--accent), var(--good));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.pw-title small { color: var(--muted); font-size: .72rem; letter-spacing: .3px; }
.pw-scores { display: flex; gap: 8px; }
.pw-score {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px; padding: 6px 12px; text-align: center; min-width: 64px;
}
.pw-score span { display: block; font-size: .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.pw-score b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* ── goals / posted targets ─────────────────────────────── */
.pw-goals { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pw-goals__label { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.pw-targets { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.pw-target {
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px; padding: 4px 10px; font-weight: 700; font-size: .9rem;
  font-variant-numeric: tabular-nums; color: var(--ink); transition: background .2s, transform .2s;
}
.pw-target.done { background: var(--good); color: #10241d; border-color: var(--good); }
.pw-btn--go { background: var(--accent); color: #2a2140; border-color: var(--accent); font-weight: 700; }

/* ── board ──────────────────────────────────────────────── */
.pw-boardwrap { position: relative; width: 100%; }
.pw-board {
  position: relative;
  width: min(92vw, 460px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: var(--board);
  border-radius: 18px;
  padding: var(--gap);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05), 0 18px 40px rgba(0,0,0,.4);
  touch-action: none;             /* we own the gestures (drag-peek) */
  user-select: none;
}
.pw-board.bump { animation: board-bump 220ms ease; }
@keyframes board-bump { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.pw-layer { position: absolute; inset: var(--gap); }   /* cells + tiles share this frame */
.pw-threads { position: absolute; inset: var(--gap); pointer-events: none; overflow: visible; }

.cell-bg, .tile {
  position: absolute; top: 0; left: 0;
  width: var(--cell); height: var(--cell);
  border-radius: var(--radius);
}
.cell-bg { background: rgba(255,255,255,.04); }

.tile {
  display: grid; place-items: center;
  background: var(--tile);
  color: var(--tile-ink);
  font-weight: 800;
  font-size: clamp(1.1rem, calc(var(--cell) * .42), 2rem);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 3px 0 rgba(0,0,0,.18), inset 0 0 0 1px rgba(0,0,0,.06);
  transition: transform var(--dur) ease, opacity var(--dur) ease;
}
/* gentle magnitude ramp — aesthetic only, NOT an eligibility signal */
.tile[data-mag="1"] { background: #efe7d4; }
.tile[data-mag="2"] { background: #f3dca8; }
.tile[data-mag="3"] { background: #f6c98a; }
.tile[data-mag="4"] { background: #f4ad7a; color: #2a2140; }
.tile[data-mag="5"] { background: #e98aa0; color: #2a1430; }
.tile[data-mag="6"] { background: #b98ce0; color: #fff; }
.tile[data-mag="7"] { background: #7f9cff; color: #fff; }

/* Entrance is OPACITY-ONLY — never scales the position transform. A tile captured
   mid-animation (or with animations paused) still renders full-size and correctly
   placed; only the merge "pop" briefly scales, and it always settles back to 1. */
.tile.in   { animation: tile-in 200ms ease; }
.tile.pop  { animation: tile-pop 220ms ease; }
.tile.out  { opacity: 0; }
.tile.harvest { animation: tile-harvest 360ms ease forwards; z-index: 4; }
@keyframes tile-in  { from { opacity: 0; } }
@keyframes tile-pop { 30% { transform: var(--t) scale(1.16); } }
@keyframes tile-harvest {              /* gold burst when a target is harvested */
  0%   { transform: var(--t) scale(1); }
  35%  { transform: var(--t) scale(1.22); box-shadow: 0 0 0 7px var(--good), 0 0 18px var(--good); }
  100% { transform: var(--t) scale(.3); opacity: 0; }
}

/* threads (SVG) */
.thread { filter: drop-shadow(0 0 4px currentColor); }
.thread.pulse { animation: thread-pulse 900ms ease-in-out infinite; }
@keyframes thread-pulse { 0%, 100% { opacity: .78; } 50% { opacity: 1; } }

/* during peek, dim resting tiles a touch so threads/ghosts read clearly */
.pw-board.peeking .tile:not(.ghost) { filter: brightness(.9); }
.tile.dim { opacity: .28; }                    /* the two tiles that will be consumed */
.tile.ghost {                                  /* the result you'll get — prominent */
  opacity: .96; box-shadow: 0 0 0 3px rgba(255,216,107,.5);
  outline: 2px dashed rgba(255,255,255,.7); z-index: 3;
}

/* ── toolbar ────────────────────────────────────────────── */
.pw-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pw-btn {
  background: rgba(255,255,255,.08); color: var(--ink);
  border: 1px solid rgba(255,255,255,.12); border-radius: 10px;
  padding: 9px 14px; font: inherit; font-size: .85rem; font-weight: 600;
  cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; gap: 6px;
}
.pw-btn:hover { background: rgba(255,255,255,.14); }
.pw-btn[aria-pressed="true"] { background: var(--accent); color: #2a2140; border-color: var(--accent); }
.pw-btn:focus-visible { outline: 3px solid var(--good); outline-offset: 2px; }

.pw-hint { text-align: center; color: var(--muted); font-size: .82rem; min-height: 1.2em; }

/* ── overlay (game over / milestone) ────────────────────── */
.pw-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(10,6,24,.74); border-radius: 18px; text-align: center; padding: 20px;
  animation: fade 200ms ease both;
}
.pw-overlay h2 { margin: 0 0 6px; font-family: "Orbitron", sans-serif; }
.pw-overlay p { margin: 0 0 16px; color: var(--muted); }
.pw-overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.pw-over-wisp { display: flex; justify-content: center; margin-bottom: 4px; }

/* ── teaching (Wisp coachmarks) ─────────────────────────── */
.pw-teach {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(10,6,24,.82); border-radius: 18px; padding: 16px; z-index: 5;
  animation: fade 200ms ease both;
}
.pw-teach__card {
  background: var(--bg2); border: 1px solid rgba(255,255,255,.12); border-radius: 16px;
  padding: 18px; max-width: 340px; text-align: center; box-shadow: 0 18px 40px rgba(0,0,0,.5);
}
.pw-teach__wisp { display: flex; justify-content: center; margin-bottom: 6px; }
.pw-teach__say { color: var(--ink); font-size: .98rem; line-height: 1.5; margin: 6px 4px 14px; }
.pw-teach__say b { color: var(--accent); }
.pw-teach__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pw-teach__dots { display: flex; gap: 6px; }
.pw-teach__dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.25); display: block; }
.pw-teach__dots i.on { background: var(--accent); }

/* Wisp idle bob + talk flap (respect reduced-motion via the global rule) */
.wisp { display: block; }
.wisp--talk { animation: wisp-bob 1.6s ease-in-out infinite; }
@keyframes wisp-bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-5px) rotate(2deg); } }
.wisp__thread { stroke-dasharray: 3 4; }

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

/* ── accessibility ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  :root { --dur: 1ms; --pulse: 0; }
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
  .tile { transition: none; }
}
@media (prefers-contrast: more) {
  :root { --tile: #ffffff; --tile-ink: #000; --ink: #fff; --muted: #e6e0f5; }
  .tile { box-shadow: inset 0 0 0 2px #000; }
  .cell-bg { background: rgba(255,255,255,.1); }
}
