/* Game screens: Tic Tac Toe extras, Trailblades, Orbit Rumble, Moat & Mortar. Loaded after ui.css. */

/* ---------- Tic Tac Toe extras ---------- */

.game-actions { display: flex; gap: 10px; }
.game-actions > * { flex: 1; }

.timer {
  height: 10px;
  margin-top: -6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.timer-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #84cc16);
  transform-origin: left;
}
.timer.low .timer-fill { background: linear-gradient(90deg, #ef4444, #f97316); animation: blink 0.5s steps(2) infinite; }
@keyframes blink {
  50% { opacity: 0.6; }
}

.board.thump { animation: thump 0.18s ease-out; }
@keyframes thump {
  40% { transform: scale(0.985); }
}
.board.shake { animation: shake 0.35s ease-in-out; }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Move numbers: shown once a round ends, and during a replay. */
.cell { position: relative; }
.board.numbered .cell[data-move]::after {
  content: attr(data-move);
  position: absolute;
  top: 4px;
  left: 5px;
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  text-shadow: none;
  animation: pop 0.2s ease-out backwards;
}
.board[data-size="5"].numbered .cell[data-move]::after { top: 2px; left: 2px; font-size: 0.625rem; min-width: 15px; }

/* ---------- Game screens: shared HUD, stage and overlay ---------- */

.quest { gap: 12px; }

.hud-bar {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1.2fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 16px;
  background: var(--surface);
  outline: 1px solid var(--line);
  outline-offset: -1px;
}
.hud-stat { display: flex; flex-direction: column; align-items: flex-start; }
.hud-label { font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.hud-stat strong { font-family: "Fredoka", system-ui, sans-serif; font-size: 1.35rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.hud-stat strong.bump { animation: bump 0.45s ease-out; display: inline-block; }
.hud-btn {
  --ledge: color-mix(in srgb, var(--accent), #000 35%);
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.875rem;
  font-weight: 700;
}

.stage { position: relative; }
.stage canvas {
  display: block;
  width: 100%;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--line), 0 10px 24px -10px rgb(0 0 0 / 0.4);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 20px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface), transparent 10%);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}
.overlay.pop-in { animation: screen-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
.overlay-title { margin: 0; font-family: "Fredoka", system-ui, sans-serif; font-size: 2.25rem; font-weight: 700; }
.overlay-text { margin: 0 0 8px; color: var(--muted); line-height: 1.5; }
.overlay-text b { color: var(--text); }
.new-best { color: #f59e0b !important; }
.overlay .play-btn { min-width: 200px; }

/* High scores: stat tiles */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  outline: 1px solid var(--line);
  outline-offset: -1px;
}
.big-stat strong { font-family: "Fredoka", system-ui, sans-serif; font-size: 1.75rem; }

/* ---------- Trailblades ---------- */

.class-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-bottom: 6px; }
.class-card {
  --ledge: color-mix(in srgb, var(--line), #000 25%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  outline: 2px solid var(--line);
  outline-offset: -2px;
  font-family: "Fredoka", system-ui, sans-serif;
}
.class-card[aria-pressed="true"] {
  --ledge: color-mix(in srgb, var(--accent), #000 35%);
  background: var(--accent);
  color: var(--on-accent);
  outline-color: transparent;
}
.class-icon { font-size: 1.75rem; transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.6, 1); }
.class-card[aria-pressed="true"] .class-icon { transform: scale(1.15) rotate(-6deg); }
.class-name { font-weight: 700; }
.class-hp { font-size: 0.75rem; font-weight: 600; opacity: 0.85; }
.class-desc { font-family: system-ui, sans-serif; font-size: 0.6875rem; line-height: 1.3; opacity: 0.8; }

.loadout { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gear-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  outline: 1px solid var(--line);
  outline-offset: -1px;
  text-align: left;
  transition: transform 0.1s;
}
.gear-slot:active { transform: scale(0.96); }
.gear-slot .swatch { width: 40px; padding: 4px; }
.gear-text { display: flex; flex-direction: column; min-width: 0; font-size: 0.8125rem; }
.gear-swatch {
  font-size: 1.25rem;
  background: color-mix(in srgb, var(--gear), transparent 70%) !important;
  border-color: var(--gear) !important;
}

.label .link.inline { font-size: 0.75rem; text-transform: none; letter-spacing: 0; }

.quest-hud { grid-template-columns: 1fr 1.4fr auto; }

.pad { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 8px; }
.pad-group { display: flex; gap: 10px; align-items: center; }
.act-btn {
  --ledge: color-mix(in srgb, var(--bg-btn), #000 40%);
  --bg-btn: var(--accent);
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--bg-btn);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  text-shadow: 0 2px 0 rgb(0 0 0 / 0.25);
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.act-btn.move { --bg-btn: #64748b; border-radius: 16px; width: 64px; }
.act-btn.attack { --bg-btn: #dc2626; width: 70px; height: 70px; font-size: 1.6rem; }
.act-btn.jump { --bg-btn: #2563eb; }
.act-btn.run { --bg-btn: #0d9488; width: 52px; height: 52px; font-size: 1.2rem; }
.act-btn.special { --bg-btn: #9333ea; width: 52px; height: 52px; font-size: 1.15rem; }
/* Held from the keyboard or a finger: stays pressed down. */
.act-btn.held {
  transform: translateY(var(--depth)) scale(0.97, 0.94);
  box-shadow: 0 0 0 var(--ledge), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  filter: brightness(1.1);
}

@media (prefers-reduced-motion: reduce) {
}

/* Trailblades: pause sits in the top bar; the canvas draws HP, coins and round itself. */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-right .hud-btn { width: 36px; height: 36px; border-radius: 10px; }
.quest .stage canvas { border-radius: 18px; box-shadow: 0 0 0 3px var(--line), 0 14px 30px -12px rgb(0 0 0 / 0.5); }
.keys-hint { font-size: 0.8125rem; }
/* Touch pads only where there's a touchscreen; keyboards get the hint instead. */
@media (hover: hover) and (pointer: fine) {
  .quest .pad { opacity: 0.9; }
}
@media (hover: none) {
  .keys-hint { display: none; }
}

/* Narrow phones: six action buttons must fit in one row without sideways scrolling. */
@media (max-width: 430px) {
  .pad { gap: 6px; }
  .pad-group { gap: 6px; }
  .act-btn { width: 50px; height: 50px; font-size: 1.15rem; }
  .act-btn.move { width: 50px; }
  .act-btn.attack { width: 58px; height: 58px; font-size: 1.35rem; }
  .act-btn.run, .act-btn.special { width: 42px; height: 42px; font-size: 1rem; }
}

/* ---------- Orbit Rumble ---------- */
.ship-svg { width: 34px; height: 34px; filter: drop-shadow(0 2px 2px rgb(0 0 0 / 0.3)); transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.6, 1); }
.ship-card[aria-pressed="true"] .ship-svg { transform: scale(1.15) rotate(-8deg); }
.ship-cards { grid-template-columns: repeat(4, 1fr); }
.ship-cards .class-desc { display: none; }
.rp-icon .ship-svg { width: 24px; height: 24px; vertical-align: middle; }
.class-icon .ship-svg { width: 30px; height: 30px; }
.duel-dpad { display: grid; grid-template-columns: repeat(3, auto); grid-template-areas: ". up ." "left down right"; gap: 6px; }
.duel-dpad [data-dctl="up"] { grid-area: up; }
.duel-dpad [data-dctl="left"] { grid-area: left; }
.duel-dpad [data-dctl="down"] { grid-area: down; }
.duel-dpad [data-dctl="right"] { grid-area: right; }
.duel .act-btn.attack { --bg-btn: #f59e0b; }

/* ---------- Moat & Mortar ---------- */
body[data-screen="td"] main { width: min(100% - 24px, (100dvh - 340px) * 1.6, 1100px); }

.map-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-bottom: 6px; }
.map-card {
  --ledge: color-mix(in srgb, var(--map), #000 40%);
  --depth: 6px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 92px;
  padding: 12px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(160deg, var(--map), color-mix(in srgb, var(--map), #000 25%));
  color: #fff;
  text-align: left;
  font-family: "Fredoka", system-ui, sans-serif;
  box-shadow: 0 var(--depth) 0 var(--ledge);
  transition: transform 0.12s cubic-bezier(0.3, 1.6, 0.6, 1), box-shadow 0.12s;
}
.map-card:hover { transform: translateY(-2px); box-shadow: 0 calc(var(--depth) + 2px) 0 var(--ledge); }
.map-card:active { transform: translateY(var(--depth)); box-shadow: 0 0 0 var(--ledge); }
.map-card[aria-pressed="true"] { outline: 3px solid #fde047; outline-offset: 2px; }
.map-meadow { --map: #16a34a; }
.map-canyon { --map: #d97706; }
.map-frozen { --map: #0284c7; }
.map-lava { --map: #b91c1c; }
.map-name { font-size: 1.1rem; font-weight: 700; }
.map-meta { font-family: system-ui, sans-serif; font-size: 0.75rem; opacity: 0.9; }
.map-stars { margin-top: auto; color: #fde047; font-weight: 700; letter-spacing: 0.05em; }

.td-toolbar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; padding-bottom: 6px; }
.tower-btn {
  --ledge: color-mix(in srgb, var(--tc), #000 40%);
  --depth: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 2px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  outline: 2px solid color-mix(in srgb, var(--tc), transparent 40%);
  outline-offset: -2px;
  font-family: "Fredoka", system-ui, sans-serif;
  box-shadow: 0 var(--depth) 0 var(--ledge);
  transition: transform 0.1s cubic-bezier(0.3, 1.6, 0.6, 1), box-shadow 0.1s, opacity 0.15s;
}
.tower-btn:active { transform: translateY(var(--depth)); box-shadow: 0 0 0 var(--ledge); }
.tower-btn[aria-pressed="true"] { background: var(--tc); color: #fff; transform: translateY(3px); box-shadow: 0 2px 0 var(--ledge); }
.tower-btn[data-poor] { opacity: 0.45; }
.tower-icon { font-size: 1.3rem; }
.tower-name { font-size: 0.75rem; font-weight: 600; }
.tower-cost { font-size: 0.75rem; font-weight: 700; color: #ca8a04; }
.tower-btn[aria-pressed="true"] .tower-cost { color: #fef08a; }

.td-selected {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--surface);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  animation: rise-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.td-selected strong { flex: 1 1 100%; text-align: left; font-family: "Fredoka", system-ui, sans-serif; }
.td-selected button { padding: 8px 12px; font-size: 0.875rem; }
.td-controls { display: flex; gap: 10px; }
.td-controls .play-btn { flex: 1; padding: 12px; font-size: 1.15rem; }
.td-controls .play-btn:disabled { opacity: 0.5; filter: grayscale(0.4); }
#td-speed { min-width: 70px; font-size: 1.15rem; }

@media (max-width: 430px) {
  .td-toolbar { grid-template-columns: repeat(3, 1fr); }
}

/* Tic Tac Toe: hint, undo and the ghost preview of your next piece */
.ttt-tools { display: flex; gap: 10px; margin-top: -4px; }
.ttt-tools > * { flex: 1; }
.ttt-tools button:disabled { opacity: 0.45; box-shadow: none; transform: translateY(4px); }
@media (hover: hover) {
  .cell:not(:disabled):empty:hover::before {
    content: var(--ghost);
    color: var(--x);
    opacity: 0.28;
  }
  .board.ghost-o .cell:not(:disabled):empty:hover::before { color: var(--o); }
}
.cell.hint { animation: hint-glow 1.2s ease-in-out 2; }
@keyframes hint-glow {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 0 5px #facc15; background: color-mix(in srgb, var(--surface), #facc15 25%); }
}

/* Moat & Mortar: stats of the selected tower */
.td-stats { display: block; font-family: system-ui, sans-serif; font-size: 0.8125rem; font-weight: 500; color: var(--muted); }
.td-next { color: #16a34a; font-weight: 600; }
