/* Boggle (public/arcade/boggle.js). Arcade tokens come from arcade.css; everything is scoped to its stage.
   The tray is the bold thing: felt red with the cabinets' hard darker side, sixteen warm-white dice with ink letters in
   Jersey 10. A traced die goes black with your colour; a white thread joins them under the letters. A pixel sand timer. */
.ag-stage[data-kind="boggle"] .bg {
  --felt: #3340a0; --side: #1f2766; --die: #f5f5f2; --lip: #9ea3c6; --ink: #0a0b1a; --pink: #b3bcff; --mute: #9ea3c6;
  --t: min(calc(100cqw - 36px), calc(100cqh - 250px), 460px);
  position: absolute; inset: 0; display: flex; flex-direction: column; color: var(--die);
  font-family: var(--ac-pixel, "Jersey 10"); container: bg / size;
}
.ag-stage[data-kind="boggle"] .bg [hidden] { display: none !important; }
.ag-stage[data-kind="boggle"] .bg p, .ag-stage[data-kind="boggle"] .bg h3 { margin: 0; }

/* ---------- top row: the sand timer (solo: words to find); the scores are on the bar beside Back ---------- */
.ag-stage[data-kind="boggle"] .bg-hud { grid-area: hud; flex: none; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 10px 14px 0; }
.ag-stage[data-kind="boggle"] .bg-clock { display: flex; align-items: center; gap: 8px; }
.ag-stage[data-kind="boggle"] .bg-hg svg { display: block; width: 18px; height: 30px; }
.ag-stage[data-kind="boggle"] .bg-hgf { fill: var(--lip); }
.ag-stage[data-kind="boggle"] .bg-hgs { fill: var(--die); }
.ag-stage[data-kind="boggle"] .bg-time { font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; }
.ag-stage[data-kind="boggle"] .bg-clock.low .bg-time { color: #7b8cff; animation: bg-blink 1s steps(1) infinite; }
.ag-stage[data-kind="boggle"] .bg-clock.low .bg-hgs { fill: #7b8cff; }
@keyframes bg-blink { 50% { opacity: .35; } }
@keyframes bg-pop { from { transform: scale(1.5); color: #7b8cff; } }
.ag-stage[data-kind="boggle"] .bg-them { justify-self: end; display: flex; align-items: center; gap: 6px; font-size: 22px; line-height: 1; text-align: right; }
.ag-stage[data-kind="boggle"] .bg-total { color: var(--mute); font-size: 20px; }

/* ---------- the word being traced, or how the last one went ---------- */
.ag-stage[data-kind="boggle"] .bg-word { grid-area: word; flex: none; height: 70px; display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 0 12px; overflow: hidden; white-space: nowrap; }
.ag-stage[data-kind="boggle"] .bg-w { font-size: min(48px, calc(100cqw / 11)); line-height: 1; letter-spacing: .08em; }
.ag-stage[data-kind="boggle"] .bg-msg { font-size: 26px; line-height: 1; color: #7b8cff; }
.ag-stage[data-kind="boggle"] .bg-word.tracing .bg-msg { font: 400 14px/1.2 var(--font); color: var(--mute); white-space: normal; max-width: 9em; }
.ag-stage[data-kind="boggle"] .bg-word.off .bg-w, .ag-stage[data-kind="boggle"] .bg-word.bad .bg-w { color: var(--pink); }
.ag-stage[data-kind="boggle"] .bg-word.bad .bg-msg, .ag-stage[data-kind="boggle"] .bg-word.dup .bg-msg { font: 400 15px/1.2 var(--font); color: var(--pink); }
.ag-stage[data-kind="boggle"] .bg-word.dup .bg-w, .ag-stage[data-kind="boggle"] .bg-word.wait .bg-w { opacity: .55; }
.ag-stage[data-kind="boggle"] .bg-word.ok .bg-msg { font-size: 40px; color: var(--die); text-shadow: 0 0 6px #7b8cff, 0 0 18px #4a5ad8; animation: bg-pop .4s steps(3, end); }

/* ---------- the tray ---------- */
.ag-stage[data-kind="boggle"] .bg-trayw { grid-area: tray; flex: none; display: flex; justify-content: center; padding: 0 0 8px; }
.ag-stage[data-kind="boggle"] .bg-tray { position: relative; width: var(--t); height: var(--t); margin-right: 6px; border-radius: 14px; background: var(--felt);
  box-shadow: 6px 6px 0 var(--side); touch-action: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ag-stage[data-kind="boggle"] .bg-dice, .ag-stage[data-kind="boggle"] .bg-lets, .ag-stage[data-kind="boggle"] .bg-line {
  position: absolute; inset: 3.5%; width: 93%; height: 93%; display: grid; grid-template: repeat(4, 1fr) / repeat(4, 1fr); pointer-events: none; }
.ag-stage[data-kind="boggle"] .bg-die { margin: 7%; border-radius: 18%; background: var(--die); box-shadow: inset 0 calc(var(--t) * -.014) 0 var(--lip); }
.ag-stage[data-kind="boggle"] .bg-die.on { background: #000; box-shadow: inset 0 0 0 3px var(--pc); }
.ag-stage[data-kind="boggle"] .bg-line { overflow: visible; }
.ag-stage[data-kind="boggle"] .bg-line polyline { fill: none; stroke: var(--pink); stroke-width: .14; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.ag-stage[data-kind="boggle"] .bg-l { display: grid; place-items: center; padding-bottom: 4%; font-weight: 400; font-size: calc(var(--t) * .15); line-height: 1; color: var(--ink); }
.ag-stage[data-kind="boggle"] .bg-l.qu { font-size: calc(var(--t) * .11); }
.ag-stage[data-kind="boggle"] .bg-l.on { color: var(--pc); }
/* the dice roll in when the countdown ends */
.ag-stage[data-kind="boggle"] .bg-tray.roll .bg-die, .ag-stage[data-kind="boggle"] .bg-tray.roll .bg-l {
  animation: bg-roll .5s steps(5, end) both; animation-delay: calc(var(--d) * 24ms); }
@keyframes bg-roll { from { transform: rotate(-180deg) scale(.4); opacity: 0; } 40% { opacity: 1; } }
.ag-stage[data-kind="boggle"] .bg-tray.shake { animation: bg-shake .3s steps(4); }
@keyframes bg-shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }

/* ---------- your words so far ---------- */
.ag-stage[data-kind="boggle"] .bg-found { grid-area: found; flex: 1; min-height: 0; overflow: auto; padding: 8px 18px 12px; -webkit-overflow-scrolling: touch; }
.ag-stage[data-kind="boggle"] .bg-fh { font: 400 14px/1.35 var(--font); color: var(--mute); text-align: center; }
.ag-stage[data-kind="boggle"] .bg-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; margin-top: 6px; }
.ag-stage[data-kind="boggle"] .bg-fw { font-size: 24px; line-height: 1.1; }
.ag-stage[data-kind="boggle"] .bg sub { margin-left: 2px; font-size: .55em; vertical-align: baseline; color: var(--mute); }

/* ---------- time's up: both lists, then what nobody found (the result card covers the bottom, so this scrolls clear of it) ---------- */
.ag-stage[data-kind="boggle"] .is-over .bg-word, .ag-stage[data-kind="boggle"] .is-over .bg-trayw, .ag-stage[data-kind="boggle"] .is-over .bg-found { display: none; }
.ag-stage[data-kind="boggle"] .bg-res { grid-area: res; flex: 1; min-height: 0; overflow: auto; padding: 14px 16px 360px; -webkit-overflow-scrolling: touch; }
.ag-stage[data-kind="boggle"] .bg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ag-stage[data-kind="boggle"] .bg-cols.one { grid-template-columns: 1fr; }
.ag-stage[data-kind="boggle"] .bg-col h3, .ag-stage[data-kind="boggle"] .bg-missed h3 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding-bottom: 4px; margin-bottom: 6px; border-bottom: 2px solid var(--ac-line, #2a2d4a); font-weight: 400; font-size: 26px; line-height: 1; }
.ag-stage[data-kind="boggle"] .bg-col h3 span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-stage[data-kind="boggle"] .bg-col.mine h3 span { color: #7b8cff; }
.ag-stage[data-kind="boggle"] .bg-col h3 b { font-weight: 400; font-size: 34px; }
.ag-stage[data-kind="boggle"] .bg-cl { font-size: 22px; line-height: 1.25; word-spacing: .3em; }
.ag-stage[data-kind="boggle"] .bg-cl s { color: var(--pink); text-decoration-thickness: 2px; }
.ag-stage[data-kind="boggle"] .bg-cl i { font: italic 400 15px/1.3 var(--font); color: var(--mute); }
.ag-stage[data-kind="boggle"] .bg-note { margin-top: 10px !important; font: 400 14px/1.35 var(--font); color: var(--mute); }
.ag-stage[data-kind="boggle"] .bg-missed { margin-top: 18px; }
.ag-stage[data-kind="boggle"] .bg-missed h3 span { font: 400 13px/1.2 var(--font); color: var(--mute); }
.ag-stage[data-kind="boggle"] .bg-missed .bg-cl { color: var(--mute); }

/* short screens: a smaller word line */
@container bg (max-height: 600px) {
  .ag-stage[data-kind="boggle"] .bg { --t: min(calc(100cqw - 36px), calc(100cqh - 190px), 460px); }
  .ag-stage[data-kind="boggle"] .bg-word { height: 52px; }
}
/* landscape: the tray on the left, everything else beside it */
@container bg (min-aspect-ratio: 5/4) {
  .ag-stage[data-kind="boggle"] .bg { --t: min(calc(100cqh - 30px), 52cqw, 460px); display: grid; grid-template-columns: auto 1fr;
    grid-template-rows: auto auto 1fr; grid-template-areas: "tray hud" "tray word" "tray found"; column-gap: 8px; }
  .ag-stage[data-kind="boggle"] .bg-trayw { align-items: center; padding: 0 0 6px 14px; }
  .ag-stage[data-kind="boggle"] .is-over { grid-template-columns: 1fr; grid-template-areas: "hud" "res"; grid-template-rows: auto 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .ag-stage[data-kind="boggle"] .bg-tray.roll .bg-die, .ag-stage[data-kind="boggle"] .bg-tray.roll .bg-l, .ag-stage[data-kind="boggle"] .bg-tray.shake,
  .ag-stage[data-kind="boggle"] .bg-clock.low .bg-time, .ag-stage[data-kind="boggle"] .bg-word.ok .bg-msg { animation: none; }
}
