/* Play (SG-87; SAGE-MAKEOVER-PLAN.html §06): the deep green field a round runs on, and what sits on it.
   js/play.js builds the field and its shapes and runs the gear change, the score tick, confetti and sound.
   A page gives each round screen class="play p-col" and lists it in ROUND beside show(). Quizzes is the first
   module here; Games (its first game, Garden) and Vocab follow it. Play is the same in light and dark, so a few colours are fixed. */

/* ---- the gear's tokens: white text, solid tiles. On any element, so a dialog can wear them too. ---- */
.play {
  --ink:#FFFFFF; --ink-2:rgba(255,255,255,.92); --panel:var(--tile-play); --panel-2:rgba(255,255,255,.24);
  --owl:#C49A6C;   /* the Soren owl: a walnut body is invisible on this green (SG-156) */
  --leaf-soft:rgba(255,255,255,.16); --leaf-text:#FFFFFF; --edge:rgba(255,255,255,.55); --tile-edge:rgba(255,255,255,.16);
  /* an answer that has turned white */
  --p-ink:#18221C; --p-tint:#D5E7D8; --p-green:#1F6039;
  color:var(--ink);
}
.pf[hidden] { display:none !important; }

/* ---- the field: fixed behind the round, with two paper-cut shapes (js/shapes.js) ---- */
.pf { position:fixed; inset:0; z-index:0; overflow:hidden; background:var(--field); pointer-events:none; }
.pf-sh { position:absolute; transform:rotate(var(--rot, 0deg)); }
.pf-sh1 { width:340px; right:-156px; top:-64px; color:var(--shape-1); --shape-cut:var(--shape-2); --rot:22deg; }
.pf-sh2 { width:220px; left:-96px; bottom:-34px; color:var(--shape-2); --shape-cut:var(--shape-1); --rot:-48deg; --dx:12px; --dy:-10px; }
@media (min-width:900px) {
  .pf-sh1 { width:560px; right:-220px; top:-150px; }
  .pf-sh2 { width:380px; left:-150px; bottom:-120px; }
}

/* While a round is on. sg-play sets the layout as the field starts to rise; sg-field paints the page once it has. */
html body.sg-play .wrap { position:relative; z-index:1; max-width:none; padding:0; }   /* "html" so it beats the shell's .wrap rules in chrome.css whatever the link order */
body.sg-field { background:var(--field); }

/* The browser's own gestures stay off the field (SG-375). In the installed window a double-tap on a tile would zoom the page and a long
   press on a button would raise the callout, with no browser bar to undo either. Panning and pinch stay; text fields stay selectable. */
body.play, body.sg-play { touch-action:manipulation; }
body.play :is(button, a, [role="button"], .p-tile, svg), body.sg-play :is(button, a, [role="button"], .p-tile, svg) {
  -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }
body.play :is(input, textarea, [contenteditable]), body.sg-play :is(input, textarea, [contenteditable]) { -webkit-user-select:text; user-select:text; }

/* ---- a round screen: one column, full height on a phone, centred on a laptop ---- */
.p-col { min-height:100vh; min-height:100dvh; max-width:632px; margin:0 auto; display:flex; flex-direction:column;
  padding:max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); font-size:16px; line-height:1.4; }
.play :focus-visible { outline:2px solid #fff; outline-offset:2px; box-shadow:0 0 0 6px #0B2416; }
.p-tile { background:var(--tile-play); box-shadow:inset 0 0 0 1px var(--tile-edge); }

.p-top { display:flex; align-items:center; gap:10px; min-height:44px; margin-bottom:14px; }
.p-x .ic-slot { margin:0; }
.p-x { position:relative; flex:none; width:40px; height:40px; border-radius:50%; border:0; padding:0; display:grid; place-items:center; cursor:pointer; color:#fff;
  transition:transform .25s var(--ease-press); }
.p-x::after { content:""; position:absolute; inset:-4px; }   /* a 48px target */
.p-ttl { flex:1; min-width:0; font:600 14.5px var(--font-head); letter-spacing:-.01em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.p-cnt { font:600 13px var(--font-head); color:var(--ink-2); font-variant-numeric:tabular-nums; white-space:nowrap; }
/* Progress: one step per question, each a 44px-tall target around a thin bar. Answered is white; the current one is marigold and taller. */
.p-prog { flex:1; display:flex; gap:4px; min-width:0; }
.p-seg { position:relative; flex:1; min-width:0; height:44px; border:0; padding:0; background:none; cursor:pointer; }
.p-seg::before { content:""; position:absolute; left:0; right:0; top:50%; height:6px; margin-top:-3px; border-radius:var(--r-pill); background:var(--panel-2); }
.p-seg.done::before { background:#fff; }
.p-seg.cur::before { background:var(--marigold); height:10px; margin-top:-5px; }

.p-chip { align-self:flex-start; display:inline-flex; align-items:center; gap:6px; font-size:13px; font-weight:600; padding:4px 10px; border-radius:var(--r-pill);
  background:var(--leaf-soft); color:#fff; }
.p-q { font:700 22px/1.14 var(--font-head); letter-spacing:-.02em; margin:10px 0 16px; text-wrap:balance; }
.p-q:focus { outline:none; }
.p-q .blank { border-bottom-color:var(--marigold); }   /* the page draws a cloze blank; on the field its rule is marigold */
.p-hint { margin:0 0 16px; font-size:14.5px; color:var(--ink-2); }
.p-lbl { display:block; font-size:13px; font-weight:600; color:var(--ink-2); margin:14px 0 6px; }
.p-fb { margin:14px 0 0; font-size:15.5px; color:var(--ink-2); }
.p-fb b { color:#fff; }
.p-err { margin:18px 0 0; padding:14px 16px; border-radius:var(--r-ctl); background:var(--coral); color:var(--p-ink); font-size:15px; font-weight:500; }

/* Options and rows are solid tiles. The one she picks turns white; once checked, the right one carries a check and a wrong pick turns coral with a cross. */
.p-opts { display:flex; flex-direction:column; gap:8px; }
.p-opts.two { display:grid; grid-template-columns:1fr 1fr; }
.p-opt { display:flex; align-items:center; gap:10px; width:100%; min-height:56px; padding:12px 14px; border:0; border-radius:var(--r-ctl); text-align:left;
  font:inherit; font-weight:500; color:#fff; background:var(--tile-play); box-shadow:inset 0 0 0 1px var(--tile-edge);
  transition:transform .25s var(--ease-press); }
.p-opt .l { flex:none; width:28px; height:28px; border-radius:8px; display:grid; place-items:center; font:700 13px var(--font-head); background:rgba(255,255,255,.16); }
.p-opt .t { flex:1; min-width:0; overflow-wrap:anywhere; }
.p-opt .t small { display:block; font-size:13.5px; font-weight:400; }
.p-opt .mk { flex:none; display:grid; }
.p-opt .mk svg { stroke-width:3; }
.p-opt.sel, .p-opt.right { background:#fff; color:var(--p-ink); box-shadow:none; font-weight:600; }
.p-opt.sel .l, .p-opt.right .l { background:var(--p-tint); color:var(--p-green); }
.p-opt.right .mk { color:var(--p-green); }
.p-opt.wrong { background:var(--coral); color:var(--p-ink); box-shadow:none; }
.p-opt.wrong .l { background:rgba(24,34,28,.14); }
button.p-opt { cursor:pointer; }   /* the rows of an order or a match are tiles too, but only a button presses */
button.p-opt:disabled { cursor:default; }
ol.p-opts { list-style:none; margin:0; padding:0; }
/* Put in order: a row with its place and two arrows. */
.p-opt .mv { flex:none; width:44px; height:44px; margin:-6px 0; border:0; border-radius:var(--r-sm); background:rgba(255,255,255,.16); color:#fff; font:inherit; font-size:17px; cursor:pointer; }
.p-opt .mv + .mv { margin-left:-4px; }
.p-opt .mv:disabled { opacity:.35; cursor:default; }
/* Matching: the definition over a picker; once checked, over the term she picked. */
.p-opt.stack { flex-direction:column; align-items:stretch; gap:8px; }
.p-row { display:flex; align-items:flex-start; gap:10px; }

.p-in { display:block; width:100%; min-height:52px; padding:13px 14px; border:0; border-radius:var(--r-ctl); font:inherit; font-size:17px; color:#fff; caret-color:var(--marigold);
  background:var(--tile-play); box-shadow:inset 0 0 0 1.5px var(--edge); resize:vertical; color-scheme:dark; }
.p-in::placeholder { color:rgba(255,255,255,.72); }
.play .p-in:focus-visible { outline:none; box-shadow:inset 0 0 0 2px #fff, 0 0 0 4px #0B2416; }
.p-in[readonly] { box-shadow:inset 0 0 0 1px var(--tile-edge); }
select.p-in { min-height:48px; padding:0 12px; font-size:16px; cursor:pointer; }

.p-btn { display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:48px; padding:12px 18px; border:0; border-radius:var(--r-ctl); cursor:pointer;
  font:700 15px var(--font-head); letter-spacing:-.01em; background:var(--marigold); color:var(--on-marigold); transition:transform .25s var(--ease-press); }
.p-btn.ghost { background:var(--tile-play); color:#fff; box-shadow:inset 0 0 0 1px var(--tile-edge); }
.p-btn:disabled { opacity:.5; cursor:default; }
.p-btn:active:not(:disabled), button.p-opt:active:not(:disabled), .p-x:active { transform:scale(.97); }
/* The actions sit at the foot of the screen, in thumb reach. */
.p-stick { margin-top:auto; padding-top:18px; display:flex; flex-direction:column; gap:8px; }
.p-acts { display:flex; gap:8px; }
.p-acts .p-btn { flex:2; }
.p-acts .p-back { flex:1; }

/* ---- waiting on Claude: a title, a moving bar, the seconds so far, and Stop ---- */
.p-load-h { font:700 24px/1.15 var(--font-head); letter-spacing:-.02em; margin:22px 0 6px; }
.p-wait { margin-top:10px; padding:16px; border-radius:var(--r-card); display:flex; flex-direction:column; gap:10px; font-size:14.5px; font-variant-numeric:tabular-nums; }
.p-owl { display:flex; justify-content:center; margin:26px 0 0; }   /* the owl above a wait's title (SG-160); the title and the line under it centre with it */
.p-owl[hidden] { display:none; }
.p-score .p-owl { margin:6px 0 10px; }   /* above Your Score (SG-161) */
.p-owl:not([hidden]) + .p-load-h { margin-top:14px; }
#wait.play .p-load-h, #wait.play .p-hint { text-align:center; }
.p-bar { height:8px; border-radius:var(--r-pill); background:var(--panel-2); overflow:hidden; }
.p-bar i { display:block; width:40%; height:100%; border-radius:var(--r-pill); background:var(--marigold); }

/* ---- the score ---- */
.p-score { text-align:center; margin:18px 0 6px; }
.p-kicker { display:block; font-size:13.5px; font-weight:600; color:var(--ink-2); }
.p-big { font:800 104px/.95 var(--font-head); letter-spacing:-.05em; font-variant-numeric:tabular-nums; }
.p-big small { font-size:40px; font-weight:700; letter-spacing:-.02em; opacity:.7; }
.p-msg { margin:8px 0 0; font-size:16px; text-wrap:balance; }
.p-dots { display:flex; flex-wrap:wrap; justify-content:center; gap:8px; margin:16px 0; padding:0; list-style:none; }
.p-dots li { width:32px; height:32px; border-radius:50%; display:grid; place-items:center; background:#fff; color:var(--p-green); }
.p-dots li.half { background:var(--marigold); color:var(--on-marigold); }
.p-dots li.no { background:var(--coral); color:var(--p-ink); }
.p-dots svg { stroke-width:3; }
.p-confetti { position:fixed; inset:0; z-index:6; pointer-events:none; overflow:hidden; }
.p-cf { position:absolute; top:-30px; left:var(--x); width:var(--s); height:var(--s); color:var(--cc); opacity:0; }
.p-cf svg { display:block; width:100%; height:100%; }

@media (min-width:720px) {
  .p-opts.wide { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
}
@media (min-width:900px) {
  .p-col { min-height:min(100dvh, 660px); padding-top:22px; }
  .p-q { font-size:30px; line-height:1.12; letter-spacing:-.025em; margin:10px 0 20px; }
  .p-big { font-size:118px; }
  .p-acts { justify-content:flex-end; }
  .p-acts .p-btn { flex:none; min-width:200px; }
  .p-acts .p-back { min-width:120px; }
  .p-stick.mid { align-items:center; }
  .p-stick.mid .p-btn { width:380px; }
}

/* ---- motion: all of it off under reduced motion, and nothing needs it to be understood ---- */
@keyframes pf-drift { from { transform:translate(0, 0) rotate(var(--rot, 0deg)); } to { transform:translate(var(--dx, 10px), var(--dy, -14px)) rotate(calc(var(--rot, 0deg) + 7deg)); } }
@keyframes pf-rise { from { clip-path:circle(0 at var(--ox, 50%) var(--oy, 100%)); } to { clip-path:circle(150vmax at var(--ox, 50%) var(--oy, 100%)); } }
@keyframes pf-fall { from { clip-path:inset(0 0 0 0); } to { clip-path:inset(100% 0 0 0); } }
@keyframes p-slide { from { transform:translateX(-100%); } to { transform:translateX(250%); } }
@keyframes p-fall { 0% { opacity:1; transform:translateY(0) rotate(0); } 85% { opacity:1; } 100% { opacity:0; transform:translateY(108vh) rotate(var(--r)); } }
@media (prefers-reduced-motion: no-preference) {
  /* Drift: 16s out and 16s back, then the shapes rest. Paused while the tab is hidden. */
  .pf.drift .pf-sh { animation:pf-drift 16s ease-in-out 2 alternate both; }
  .pf.paused .pf-sh { animation-play-state:paused; }
  /* The gear change: the field rises from the button she pressed and falls away on the way out. */
  .pf.rise { animation:pf-rise .34s cubic-bezier(.3, 0, .3, 1) both; }
  .pf.fall { z-index:9; animation:pf-fall .28s cubic-bezier(.5, 0, .8, .5) both; }
  .p-bar i { animation:p-slide 1.3s ease-in-out infinite alternate; }
  .p-cf { animation:p-fall var(--d) var(--dl) cubic-bezier(.25, .5, .6, 1) both; }
}
@media (prefers-reduced-motion: reduce) {
  .p-btn, .p-opt, .p-x { transition:none; }
  .p-btn:active:not(:disabled), button.p-opt:active:not(:disabled), .p-x:active { transform:none; }
}
