/* Play page. Builds on site.css tokens and the .board/.cell look from the home-page replay. */

[hidden] { display: none !important; }

.play {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 0.25rem 16px 3rem; /* 16px keeps the board clear of iOS edge swipes */
}

.play-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 0 0.5rem;
  min-height: 52px;
}
.play-head h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--step-2);
  line-height: 1.1;
  margin: 0;
}
.play .btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0.65rem 1.1rem;
  font-size: var(--step-0);
  cursor: pointer;
  line-height: 1.2;
}
.play .btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.play .btn:disabled:hover { background: var(--robot); color: #fff; }
.play .btn.quiet:disabled:hover { background: var(--panel); color: var(--chalk); }

.loading { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- level select ---------- */

#select-view { padding-inline: 0; }
.mode-tabs {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 1rem;
}
/* Small wooden sign boards. */
.mode-tabs a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 80px;
  padding: 0 1rem;
  border: 2px solid var(--outline);
  border-radius: 8px;
  background:
    repeating-linear-gradient(180deg, transparent 0 9px, color-mix(in srgb, var(--outline) 14%, transparent) 9px 10px),
    var(--sign);
  box-shadow: 0 2px 0 var(--outline);
  color: var(--panel);
  font-family: var(--font-display);
  font-weight: 800;
  text-decoration: none;
}
.mode-tabs a:hover { color: #fff; background-color: var(--sign-deep); }
.mode-tabs a[aria-current="page"] { background-color: var(--sign-deep); color: #fff; box-shadow: inset 0 -5px 0 var(--gold), 0 2px 0 var(--outline); }
.daily-note { padding: 1rem; background: var(--panel); border: 2px solid var(--outline); border-radius: 14px; display: grid; gap: 0.75rem; justify-items: start; max-width: 44ch; }
.daily-note p { margin: 0; }
.select-intro {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}
.select-summary { margin: 0; color: var(--muted); max-width: 36ch; }
.group-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--step-1);
  color: var(--chalk);
  margin: 1.75rem 0 0.6rem;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px 10px;
  max-width: 520px;
}
.level-grid:has(.next) { padding-top: 26px; } /* room for the gnome peeking over the next level */
/* Cream stepping stones. */
.level-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 64px;
  padding: 6px 2px;
  background: var(--panel);
  color: var(--chalk);
  border: 2px solid var(--outline);
  border-radius: 18px 20px 18px 20px / 20px 18px 20px 18px;
  box-shadow: 0 3px 0 var(--outline);
  font: inherit;
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.level-btn .num { font-family: var(--font-display); font-weight: 800; font-size: var(--step-1); line-height: 1; }
.level-btn:hover { background: #fff; }
.level-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--outline); }
.level-btn.next { box-shadow: 0 0 0 3px var(--page), 0 0 0 6px var(--robot), 0 3px 0 6px var(--robot); }
.level-btn.next:active { transform: none; }
/* A third of the stone's height of gnome looks over its top edge. */
.level-btn .peek {
  position: absolute;
  left: 50%;
  top: -27px;
  width: 40px;
  height: 31px;
  transform: translateX(-50%);
  overflow: hidden;
  pointer-events: none;
}
.level-btn .peek .gnome-sprite { display: block; width: 40px; height: 40px; }
.level-btn .peek .gnome-sprite svg { display: block; width: 100%; height: 100%; }
.level-stars { display: flex; gap: 1px; height: 16px; align-items: center; }
.star { width: 15px; height: 15px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linejoin: round; }
.star.on { fill: var(--gold); stroke: var(--outline); stroke-width: 1.8; }

/* ---------- game layout ---------- */

.game {
  --board-size: min(calc(100vw - 32px), 560px); /* JS refines this to fit the window height too */
  display: grid;
  --game-gap: 10px;
  gap: var(--game-gap);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "stats" "board" "villain" "side";
}
.stats { grid-area: stats; }
.play-board { grid-area: board; }
.side { grid-area: side; }

@media (min-width: 880px) {
  .game {
    grid-template-columns: var(--board-size) minmax(260px, 300px);
    grid-template-areas: "board stats" "board side" "villain side";
    grid-template-rows: auto auto 1fr; /* the spare height goes to the last row, so the toad stays under the board */
    justify-content: center;
    --game-gap: 12px;
    gap: var(--game-gap) 36px;
    padding-top: 0.25rem;
  }
  /* Only the game screen centres its heading over the board; the level select keeps it flush with the tabs. */
  .play:has(#game-view:not([hidden])) .play-head { max-width: calc(var(--board-size, 560px) + 336px); margin-inline: auto; }
}
/* Short laptop windows: trim the page chrome so the board gets the height. */
@media (min-width: 880px) and (max-height: 760px) {
  .site-header { padding-block: 0.5rem; }
  .play-head { min-height: 44px; padding-bottom: 0.25rem; }
  .play-head h1 { font-size: var(--step-1); }
  .play { padding-bottom: 1rem; }
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding-inline: 0;
}
@media (min-width: 880px) { .stats { grid-template-columns: 1fr; gap: 6px; } }
.stat {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  background: var(--panel);
  border: 2px solid var(--outline);
  border-radius: 10px;
  line-height: 1.2;
  min-width: 0;
}
@media (min-width: 880px) { .stat { flex-direction: row; justify-content: space-between; align-items: baseline; padding: 6px 12px; } }
.stat-label { font-size: 0.8125rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.stat strong { font-family: var(--font-display); font-weight: 800; font-size: var(--step-1); font-variant-numeric: tabular-nums; }
.stat.refused { animation: refuse 320ms ease; border-color: var(--refuse); }
@keyframes refuse { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- board ---------- */

.play-board {
  --refuse: #d6402a; /* only for "you can't do that" */
  gap: var(--gap, 3px);
  width: var(--board-size);
  height: var(--board-size);
  margin-inline: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;
}
.play-board .cell {
  appearance: none;
  display: grid;
  place-items: center;
  padding: 0;
  min-width: 0;
  color: var(--teleporter-ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(0.75rem, 3.4vw, 1.1rem);
  cursor: inherit;
  touch-action: none;
}
.play-board.locked { cursor: default; }
.play-board .cell:focus-visible {
  outline: 3px solid var(--outline);
  outline-offset: -3px;
  z-index: 2;
}
.play-board .cell.teleporter.linked {
  box-shadow: 0 0 0 3px var(--teleporter), 0 0 0 5px var(--outline), 0 0 16px var(--teleporter);
  z-index: 1;
}

/* The line under your finger. Timber with an outline: a wall can go here. Red: it can't. */
.line-hint {
  position: absolute;
  z-index: 3;
  border-radius: 4px;
  pointer-events: none;
  box-sizing: border-box;
}
.line-hint[hidden] { display: none; }
.line-hint.ok { background: color-mix(in srgb, var(--wall) 55%, transparent); border: 2px solid var(--outline); }
.line-hint.no { background: color-mix(in srgb, var(--refuse) 55%, transparent); border: 2px solid var(--outline); box-shadow: 0 0 0 2px var(--refuse); }
.line-hint.hover { opacity: 0.55; box-shadow: none; }
.line-hint.pulse { animation: hint-pulse 380ms ease 2; }
@keyframes hint-pulse { 50% { transform: scale(1.25, 1.25); } }

/* Teal line joining a teleporter pair (held on press, flashed in the replay). */
.tele-link {
  position: absolute;
  z-index: 1;
  height: 4px;
  transform-origin: 0 50%;
  border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--teleporter) 0 8px, transparent 8px 14px);
  box-shadow: 0 0 0 1.5px var(--outline), 0 0 10px var(--teleporter);
  pointer-events: none;
}
.tele-link.jump { animation: link-in 220ms ease-out; height: 5px; background: var(--teleporter); }
@keyframes link-in { from { opacity: 0; } }

.play-board .robot { z-index: 4; transition: transform 240ms cubic-bezier(.4,.1,.3,1), opacity 110ms ease; }

/* ---------- side panel ---------- */

.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding-inline: 0; }
.hint {
  margin: 0;
  min-height: 2.9em; /* two lines, so the buttons don't jump */
  font-size: var(--step--1);
  color: var(--muted);
  line-height: 1.45;
  max-width: 44ch;
  border-left: 3px solid transparent;
  padding-left: 8px;
}
.hint.refused { color: var(--chalk); border-left-color: var(--refuse); background: color-mix(in srgb, var(--refuse) 14%, transparent); animation: hint-flash 900ms ease; }
@keyframes hint-flash { 0% { background: color-mix(in srgb, var(--refuse) 32%, transparent); } }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.controls #go { grid-column: 1 / -1; }
.hint-cost { grid-column: 1 / -1; margin: -4px 0 0; font-size: 0.8125rem; color: var(--muted); line-height: 1.3; }
.hint-panel {
  background: var(--panel);
  border: 2px solid var(--outline);
  border-left: 6px solid var(--gold);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}
.hint-panel p { margin: 0; font-size: var(--step--1); line-height: 1.45; }
.hint-panel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint-panel-actions .btn { width: 100%; }
.result .hint-used { color: var(--chalk); font-size: var(--step--1); }
.controls[hidden], .result[hidden], .hint-panel[hidden] { display: none; }
.controls .btn { width: 100%; }

.result {
  background: var(--panel);
  border: 2px solid var(--outline);
  border-radius: 14px;
  padding: 16px;
  display: grid;
  gap: 10px;
}
.result h2 { font-family: var(--font-display); font-size: var(--step-2); font-weight: 800; margin: 0; line-height: 1.15; }
.result p { margin: 0; }
.result .result-text { color: var(--chalk); }
.result .par { color: var(--muted); font-size: var(--step--1); }
.result .par strong { color: var(--chalk); font-family: var(--font-display); font-size: var(--step-0); margin-right: 0.35rem; }
.result .result-head { display: flex; align-items: center; gap: 12px; }
.result .result-head .picture { flex: none; width: 72px; height: 72px; position: relative; }
.result .result-head .picture .gnome-sprite { display: block; width: 72px; height: 72px; }
.result .result-head .picture .gnome-sprite svg { display: block; width: 100%; height: 100%; }
.result .result-head .picture.house { border: 2px solid var(--outline); border-radius: 12px; background: center / 100% 100% no-repeat url(../sprites/tile-house.svg); }
.result .result-head .titles { display: grid; gap: 6px; min-width: 0; }
.result-stars { display: flex; gap: 4px; }
.result-stars .star { width: 32px; height: 32px; }
.result-stars .star:not(.on) { stroke: var(--muted); }
.result-stars .star.on { animation: pop 380ms cubic-bezier(.3,1.5,.5,1) backwards; }
.result-stars .star.on:nth-child(2) { animation-delay: 120ms; }
.result-stars .star.on:nth-child(3) { animation-delay: 240ms; }
@keyframes pop { from { transform: scale(0.2) rotate(-25deg); opacity: 0; } }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.result[data-result="lose"] .result-actions { grid-template-columns: 1fr; }
.result-actions .btn { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .play-board .robot { transition: none; }
  .stat.refused, .hint.refused, .line-hint.pulse, .tele-link.jump, .result-stars .star.on { animation: none; }
  .level-btn { transition: none; }
}

/* ---------- lab ---------- */

.lab-note {
  margin: 0 0 0.75rem;
  padding: 10px 12px;
  max-width: 52ch;
  color: var(--chalk);
  background: var(--panel);
  border: 2px solid var(--outline);
  border-left: 6px solid var(--wall);
  border-radius: 10px;
  font-size: var(--step--1);
  line-height: 1.45;
}
.lab-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.mode-tabs a { min-width: 80px; }
