/* Trace the Ghost: end-of-lesson mini game for "Ghosts in the Ice".
   Everything is scoped under .ghost-game and uses tokens.css only. */

.ghost-game{
  container-type:inline-size;
  position:relative;
  color:var(--text);
  font-family:var(--display);
  background:var(--nebula);
  border:1px solid var(--line);
  border-radius:var(--r-lg);
  padding:clamp(14px,3vw,28px);
  overflow:hidden;
  isolation:isolate;
}
.ghost-game *,.ghost-game *::before,.ghost-game *::after{box-sizing:border-box}
.ghost-game [hidden]{display:none!important}
.ghost-game > section{padding:0;border:0;margin:0} /* neutralise the site's generic section styles */
.ghost-game :focus-visible{outline:2px solid var(--teal);outline-offset:3px}

/* ---------- shared bits ---------- */
.ghost-game .gg-eyebrow{font-family:var(--display);font-weight:600;font-size:.72rem;letter-spacing:var(--wide);text-transform:uppercase;color:var(--teal);margin:0}
.ghost-game .gg-btn{
  font-family:var(--display);font-weight:600;font-size:.95rem;line-height:1;
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  min-height:44px;padding:12px 20px;border-radius:999px;
  border:1px solid var(--line);background:var(--panel);color:var(--text);cursor:pointer;
  transition:border-color var(--t-tap) var(--e-out),background var(--t-tap) var(--e-out),transform var(--t-tap) var(--e-out),opacity var(--t-tap) var(--e-out);
  -webkit-tap-highlight-color:transparent;touch-action:manipulation;user-select:none;-webkit-user-select:none
}
.ghost-game .gg-btn:hover{border-color:var(--teal)}
.ghost-game .gg-btn:active{transform:scale(.96)}
.ghost-game .gg-btn:disabled{opacity:.4;cursor:default;transform:none;border-color:var(--line)}
.ghost-game .gg-btn.gg-primary{background:var(--teal);border-color:var(--teal);color:var(--void)}
.ghost-game .gg-btn.gg-primary:hover{background:var(--teal-glow);border-color:var(--teal-glow)}
.ghost-game .gg-btn.gg-primary:disabled{background:var(--teal-deep);border-color:var(--teal-deep);color:var(--text)}
.ghost-game .gg-btn.gg-icon{width:48px;padding:0;font-size:1.25rem}
.ghost-game .gg-btn.gg-big{font-size:1.15rem;min-height:56px;padding:16px 40px}

.ghost-game .gg-star{display:inline-block;width:1em;height:1em;color:var(--line);vertical-align:-.12em}
.ghost-game .gg-star svg{width:100%;height:100%;display:block;fill:currentColor}
.ghost-game .gg-star.is-on{color:var(--rose);filter:drop-shadow(0 0 6px color-mix(in srgb,var(--rose) 55%,transparent))}

/* screen entrance: one thing at a time */
.ghost-game .gg-enter{animation:gg-in var(--t-reveal) var(--e-out) both}
@keyframes gg-in{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}

/* ---------- start screen ---------- */
.ghost-game .gg-start{display:flex;flex-direction:column;align-items:center;text-align:center;gap:14px;padding:clamp(12px,4vw,40px) 4px clamp(8px,3vw,24px)}
.ghost-game .gg-start neu-mascot,.ghost-game .gg-end neu-mascot{--size:clamp(110px,24cqi,150px);margin-top:44px}
.ghost-game .gg-title{font-family:var(--display);font-size:var(--step-3);font-weight:800;letter-spacing:-.02em;line-height:1.05;margin:0;color:var(--text)}
.ghost-game .gg-pitch{font-family:var(--read);font-size:var(--step-1);line-height:1.4;color:var(--text-2);max-width:34ch;margin:0}
.ghost-game .gg-start .gg-btn.gg-big{margin-top:8px}
.ghost-game .gg-meta{font-family:var(--mono);font-size:.78rem;color:var(--dim);margin:0}
.ghost-game .gg-meta b{color:var(--rose);font-weight:600}

/* ---------- play screen layout ---------- */
.ghost-game .gg-play{
  display:grid;gap:12px 24px;
  grid-template-columns:minmax(0,1fr);
  grid-template-areas:"hud" "talk" "stage" "legend" "result" "controls";
  align-content:start;
}
@container (min-width:760px){
  .ghost-game .gg-play{
    grid-template-columns:minmax(0,1.25fr) minmax(250px,1fr);
    grid-template-rows:auto auto auto auto 1fr;
    grid-template-areas:"hud hud" "stage talk" "stage legend" "stage result" "stage controls";
  }
  .ghost-game .gg-controls{align-self:end}
}
.ghost-game .gg-hud{grid-area:hud;display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
.ghost-game .gg-hud h3{font-family:var(--display);font-size:var(--step-1);font-weight:700;margin:2px 0 0;color:var(--text)}
.ghost-game .gg-hud-right{display:flex;align-items:center;gap:14px}
.ghost-game .gg-pips{display:flex;gap:6px;list-style:none;margin:0;padding:0}
.ghost-game .gg-pips li{width:22px;height:6px;border-radius:99px;background:var(--line);transition:background var(--t-reveal) var(--e-out),width var(--t-reveal) var(--e-out)}
.ghost-game .gg-pips li.is-done{background:var(--teal-deep)}
.ghost-game .gg-pips li.is-now{background:var(--teal);width:34px}
.ghost-game .gg-score{font-family:var(--mono);font-weight:600;font-size:.95rem;display:inline-flex;align-items:center;gap:6px;padding:6px 12px;border:1px solid var(--line);border-radius:999px;background:var(--panel)}
.ghost-game .gg-score .gg-star{color:var(--rose)}
.ghost-game .gg-score.is-bump{animation:gg-bump var(--t-celebrate) var(--e-spring)}
@keyframes gg-bump{30%{transform:scale(1.22)}100%{transform:none}}

/* Neu + speech */
.ghost-game .gg-talk{grid-area:talk;display:flex;align-items:flex-start;gap:12px;min-height:96px}
.ghost-game .gg-talk neu-mascot{--size:clamp(62px,12cqi,92px);flex:none}
.ghost-game .gg-speech{
  position:relative;flex:1;margin:4px 0 0;
  background:var(--panel);border:1px solid color-mix(in srgb,var(--teal) 45%,var(--line));
  border-radius:var(--r-md);padding:12px 14px;
  font-family:var(--display);font-size:.95rem;line-height:1.45;color:var(--text)
}
.ghost-game .gg-speech::before{
  content:"";position:absolute;left:-7px;top:20px;width:12px;height:12px;background:var(--panel);
  border-left:1px solid color-mix(in srgb,var(--teal) 45%,var(--line));border-bottom:1px solid color-mix(in srgb,var(--teal) 45%,var(--line));transform:rotate(45deg)
}
.ghost-game .gg-speech b{color:var(--teal);font-weight:700}
.ghost-game .gg-speech em{color:var(--rose);font-style:normal;font-weight:600}
.ghost-game .gg-speech.is-new{animation:gg-in var(--t-reveal) var(--e-out) both}

/* stage: canvas + dial overlay */
.ghost-game .gg-stage{grid-area:stage;position:relative;min-width:0;align-self:start;aspect-ratio:1/1;border-radius:var(--r-md);overflow:hidden;background:var(--void);border:1px solid var(--line)}
.ghost-game .gg-stage canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
.ghost-game .gg-dial{position:absolute;inset:0;border-radius:var(--r-md);touch-action:pan-y;outline:none}
.ghost-game .gg-dial:focus-visible{box-shadow:inset 0 0 0 2px var(--teal)}
.ghost-game .gg-dial.is-aim{cursor:grab;touch-action:none}
.ghost-game .gg-dial.is-drag{cursor:grabbing}
.ghost-game .gg-dial.is-pick{cursor:pointer;touch-action:manipulation}

.ghost-game .gg-alert{
  position:absolute;left:50%;top:22%;transform:translateX(-50%);
  display:flex;flex-direction:column;align-items:center;gap:6px;text-align:center;pointer-events:none;
  padding:14px 18px;border-radius:var(--r-md);background:color-mix(in srgb,var(--void) 82%,transparent);border:1px solid var(--rose);
  width:max-content;max-width:calc(100% - 28px)
}
.ghost-game .gg-alert b{font-family:var(--mono);font-weight:600;font-size:clamp(.8rem,3.4cqi,1.05rem);letter-spacing:.18em;color:var(--rose);display:flex;align-items:center;gap:10px}
.ghost-game .gg-alert b::before{content:"";width:10px;height:10px;border-radius:50%;background:var(--rose);box-shadow:0 0 12px var(--rose);animation:gg-blink .9s steps(2) infinite}
.ghost-game .gg-alert span{font-family:var(--mono);font-size:.74rem;color:var(--text-2)}
.ghost-game .gg-alert.gg-enter{animation-name:gg-alert-in}
@keyframes gg-alert-in{from{opacity:0;transform:translate(-50%,10px)}to{opacity:1;transform:translate(-50%,0)}}
@keyframes gg-blink{50%{opacity:.25}}

.ghost-game .gg-card{
  grid-area:result;
  padding:14px 16px;border-radius:var(--r-md);
  background:var(--panel);border:1px solid var(--teal);
  box-shadow:0 0 32px color-mix(in srgb,var(--teal) 18%,transparent)
}
.ghost-game .gg-card h4{font-family:var(--display);font-size:var(--step-1);font-weight:800;margin:4px 0 6px;color:var(--text)}
.ghost-game .gg-card p{font-family:var(--read);font-size:var(--step-0);line-height:1.45;color:var(--text-2);margin:0}
.ghost-game .gg-card p + p{margin-top:6px}
.ghost-game .gg-card p b{color:var(--text)}
.ghost-game .gg-card .gg-eyebrow{font-family:var(--display);font-size:.7rem;color:var(--teal)}
.ghost-game .gg-card .gg-date{font-family:var(--mono);font-size:.8rem;color:var(--rose)}

/* legend */
.ghost-game .gg-legend{grid-area:legend;display:flex;flex-wrap:wrap;align-items:center;gap:8px 16px;font-family:var(--mono);font-size:.76rem;color:var(--dim)}
.ghost-game .gg-legend .gg-ramp{display:inline-flex;align-items:center;gap:8px}
.ghost-game .gg-legend .gg-bar{width:64px;height:8px;border-radius:99px;background:linear-gradient(90deg,var(--rose),var(--blush),var(--teal))}
.ghost-game .gg-legend .gg-sizes{display:inline-flex;align-items:center;gap:5px}
.ghost-game .gg-legend .gg-sizes i{display:inline-block;border-radius:50%;background:var(--blush)}
.ghost-game .gg-legend .gg-sizes i:nth-child(1){width:4px;height:4px}
.ghost-game .gg-legend .gg-sizes i:nth-child(2){width:7px;height:7px}
.ghost-game .gg-legend .gg-sizes i:nth-child(3){width:11px;height:11px}

/* round result */
.ghost-game .gg-result{grid-area:result;display:flex;align-items:center;gap:16px;flex-wrap:wrap;padding:12px 16px;border-radius:var(--r-md);background:var(--panel);border:1px solid var(--line)}
.ghost-game .gg-err{display:flex;align-items:baseline;gap:8px;font-family:var(--mono);color:var(--dim);font-size:.8rem}
.ghost-game .gg-err b{font-size:1.9rem;font-weight:600;color:var(--text);font-variant-numeric:tabular-nums;line-height:1}
.ghost-game .gg-stars{display:flex;gap:6px;font-size:1.9rem}
.ghost-game .gg-result.is-word .gg-err b{font-family:var(--display);font-size:1.3rem;font-weight:700}
.ghost-game .gg-stars .gg-star{transform:scale(.6);opacity:.6;transition:transform var(--t-celebrate) var(--e-spring),opacity var(--t-tap) var(--e-out),color var(--t-tap) var(--e-out)}
.ghost-game .gg-stars .gg-star.is-on,.ghost-game .gg-stars .gg-star.is-off{transform:none;opacity:1}

/* controls */
.ghost-game .gg-controls{grid-area:controls;display:flex;flex-wrap:wrap;align-items:center;gap:10px}
.ghost-game .gg-aimread{font-family:var(--mono);font-size:.8rem;color:var(--text-2);min-width:0;flex:1 1 100%;order:-1}
.ghost-game .gg-aimread b{color:var(--blush);font-weight:600}
.ghost-game .gg-controls .gg-grow{flex:1 1 auto}
.ghost-game .gg-pickrow{display:flex;gap:10px;flex:1 1 100%}
.ghost-game .gg-pickrow .gg-btn{flex:1}

/* ---------- end screen ---------- */
.ghost-game .gg-end{display:flex;flex-direction:column;align-items:center;text-align:center;gap:12px;padding:clamp(8px,3vw,28px) 0}
.ghost-game .gg-rank{font-family:var(--display);font-size:var(--step-3);font-weight:800;letter-spacing:-.02em;line-height:1.05;margin:0;color:var(--text);text-shadow:0 0 28px color-mix(in srgb,var(--rose) 45%,transparent)}
.ghost-game .gg-total{font-family:var(--mono);color:var(--dim);display:flex;align-items:baseline;gap:8px;margin:0}
.ghost-game .gg-total b{font-size:clamp(2.4rem,9cqi,3.4rem);color:var(--rose);font-weight:600;line-height:1;font-variant-numeric:tabular-nums}
.ghost-game .gg-recap{list-style:none;margin:6px 0 0;padding:0;width:100%;max-width:460px;display:grid;gap:6px}
.ghost-game .gg-recap li{display:grid;grid-template-columns:1fr auto auto;align-items:center;gap:12px;padding:8px 14px;border-radius:var(--r-sm);background:var(--panel);border:1px solid var(--line);font-size:.88rem;text-align:left}
.ghost-game .gg-recap li .gg-stars-s{font-size:1rem;display:flex;gap:2px}
.ghost-game .gg-recap li .gg-deg{font-family:var(--mono);font-size:.8rem;color:var(--dim);min-width:4.5ch;text-align:right}
.ghost-game .gg-compare{width:100%;max-width:460px;display:grid;gap:10px;margin-top:6px;text-align:left}
.ghost-game .gg-compare-row{display:grid;gap:4px}
.ghost-game .gg-compare-row span{font-family:var(--mono);font-size:.78rem;color:var(--text-2)}
.ghost-game .gg-compare-row span b{color:var(--text)}
.ghost-game .gg-track{height:10px;border-radius:99px;background:var(--raise);overflow:hidden}
.ghost-game .gg-fill{height:100%;border-radius:99px;width:0;transition:width var(--t-morph) var(--e-out)}
.ghost-game .gg-fill.is-you{background:linear-gradient(90deg,var(--blush),var(--rose))}
.ghost-game .gg-fill.is-ice{background:var(--teal)}
.ghost-game .gg-best{font-family:var(--mono);font-size:.8rem;color:var(--dim);margin:0}
.ghost-game .gg-best .gg-new{color:var(--void);background:var(--ok);border-radius:999px;padding:2px 8px;margin-left:6px;font-weight:600}
.ghost-game .gg-endline{font-family:var(--read);font-size:var(--step-0);color:var(--text-2);max-width:40ch;margin:0}

/* footnote */
.ghost-game .gg-foot{margin:18px 0 0;padding-top:12px;border-top:1px solid var(--line);font-family:var(--read);font-size:.8rem;line-height:1.5;color:var(--dim)}

/* Neu fallback if sfn.js is missing */
.ghost-game neu-mascot.gg-neu-fallback{display:inline-block;width:var(--size,80px);aspect-ratio:1;border-radius:50%;background:radial-gradient(circle at 38% 32%,var(--teal-glow),var(--teal) 45%,var(--teal-deep));box-shadow:0 0 24px color-mix(in srgb,var(--teal) 50%,transparent)}

@container (max-width:420px){
  .ghost-game .gg-speech{font-size:.9rem;padding:10px 12px}
  .ghost-game .gg-talk{min-height:84px}
  .ghost-game .gg-btn{padding:12px 16px}
  .ghost-game .gg-pips li{width:16px}
  .ghost-game .gg-pips li.is-now{width:26px}
}

@media (prefers-reduced-motion: reduce){
  .ghost-game .gg-enter,.ghost-game .gg-speech.is-new,.ghost-game .gg-score.is-bump,.ghost-game .gg-alert b::before{animation:none!important}
  .ghost-game .gg-fill,.ghost-game .gg-stars .gg-star,.ghost-game .gg-pips li{transition:none!important}
}

/* ---- "Review this" links back into the lesson ---- */
.ghost-game .gg-learn{font-family:var(--display);font-size:.88rem;color:var(--teal);text-decoration:underline;text-decoration-color:rgba(143,211,220,.4);text-underline-offset:3px;margin-right:auto;align-self:center}
.ghost-game .gg-learn:hover{text-decoration-color:var(--teal)}
.ghost-game .gg-recap-learn{margin-left:auto;margin-right:10px;font-family:var(--mono);font-size:.72rem;color:var(--teal)}
/* floating pill that brings the reader back to the game after reviewing */
.gg-backpill{position:fixed;left:50%;bottom:calc(18px + env(safe-area-inset-bottom,0px));transform:translateX(-50%);z-index:60;display:inline-flex;align-items:center;gap:8px;padding:11px 18px;border-radius:999px;background:var(--teal);color:var(--void);font:600 .92rem/1 var(--display);text-decoration:none;box-shadow:0 12px 30px rgba(0,0,0,.45);animation:gg-pill-in .45s var(--e-spring,ease-out)}
.gg-backpill[hidden]{display:none}
@keyframes gg-pill-in{from{opacity:0;transform:translate(-50%,16px)}to{opacity:1;transform:translate(-50%,0)}}
@media (prefers-reduced-motion: reduce){.gg-backpill{animation:none}}
