/* Switch-access overlay styles.
 *
 * All selectors scope to elements injected by switch_ui.js. The
 * data-switch-mode attribute on <body> gates visibility of the scan
 * overlays (arrows, prompt, status, start screen); the "Switch
 * settings" launcher stays visible in off mode so users can turn
 * scanning on from the UI.
 *
 * The focus ring is deliberately non-colour-only: thick solid outline
 * plus a secondary dashed outline, so it reads under high-contrast and
 * colour-blind conditions.
 */

/* Overlay root sits above the heading. Always rendered so the
 * "Switch settings" button is reachable even in off mode (otherwise
 * users can't turn switch access on from the UI). Child elements
 * self-gate on the body data-switch-mode attribute. */
.switch-overlay-root {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 0;
  color: #776e65;
  font-size: 13px;
  line-height: 1.3;
}
body[data-switch-mode="off"] .switch-prompt,
body[data-switch-mode="off"] .switch-status {
  display: none;
}

/* Compact the page vertically in switch mode so the game + arrows fit
 * on one screen. Hidden: the "how to play" / provenance / credits
 * text (explains keyboard play, the one path a switch user is NOT
 * using) and the above-game New Game anchor (switch users restart via
 * the start overlay, game-over row, or settings). Shown normally when
 * switch mode is off. */
body[data-switch-mode="oneSwitch"] .game-explanation,
body[data-switch-mode="twoSwitch"] .game-explanation,
body[data-switch-mode="oneSwitch"] .above-game,
body[data-switch-mode="twoSwitch"] .above-game,
body[data-switch-mode="oneSwitch"] .container > hr,
body[data-switch-mode="twoSwitch"] .container > hr,
body[data-switch-mode="oneSwitch"] .container > p,
body[data-switch-mode="twoSwitch"] .container > p {
  display: none;
}
body[data-switch-mode="oneSwitch"] .game-container,
body[data-switch-mode="twoSwitch"] .game-container {
  margin-top: 24px;
}
body[data-switch-mode="oneSwitch"],
body[data-switch-mode="twoSwitch"] {
  margin: 24px 0;
}
body[data-switch-mode="oneSwitch"] h1.title,
body[data-switch-mode="twoSwitch"] h1.title {
  font-size: 48px;
  line-height: 1;
}

.switch-prompt {
  padding: 4px 10px;
  background: #faf8ef;
  border: 2px solid #776e65;
  border-radius: 4px;
  font-weight: bold;
}
.switch-prompt.switch-hidden { display: none; }

.switch-status {
  padding: 3px 8px;
  background: #eee4da;
  border-radius: 4px;
  color: #776e65;
}

.switch-settings-btn {
  padding: 4px 10px;
  margin-left: auto;
  background: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 4px;
  font: inherit;
  font-weight: bold;
  font-size: inherit;
  cursor: pointer;
}
.switch-settings-btn:hover { background: #9f8b77; }
.switch-settings-btn:focus { outline: 3px solid #776e65; }

/* -------- Direction arrows around the board --------
 *
 * Arrows sit just outside the game grid, overlapping the game-container
 * padding so they add minimal external height. 44px wide/tall on
 * desktop, 36px on narrow screens.
 */

.switch-arrows {
  display: none;
  position: absolute;
  top: -40px;
  left: -40px;
  right: -40px;
  bottom: -40px;
  pointer-events: none;
}
body[data-switch-mode="oneSwitch"] .switch-arrows,
body[data-switch-mode="twoSwitch"] .switch-arrows {
  display: block;
}

.switch-arrow {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eee4da;
  color: #776e65;
  border: 3px solid #bbada0;
  border-radius: 6px;
  box-sizing: border-box;
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
  pointer-events: auto;
  transition: background-color 120ms ease, color 120ms ease;
}

/* Up/down arrows match a cell's width; left/right arrows match a
 * cell's height. Looks visually tied to the grid rather than four
 * identical floating squares. Cell size on main.css is 106.25px
 * desktop, 57.5px narrow — we round to 106 / 58. */
.switch-arrow-up,
.switch-arrow-down   { width: 106px; height: 34px; left: 50%; transform: translateX(-50%); }
.switch-arrow-left,
.switch-arrow-right  { width: 34px;  height: 106px; top: 50%; transform: translateY(-50%); }
.switch-arrow-up    { top: 2px; }
.switch-arrow-down  { bottom: 2px; }
.switch-arrow-left  { left: 2px; }
.switch-arrow-right { right: 2px; }

.switch-arrow.switch-noop {
  opacity: 0.35;
  background: #cdc1b4;
}

/* Scan focus: thick solid ring + dashed outline, not colour-only. */
.switch-focus {
  outline: 6px solid #f67c5f;
  outline-offset: 2px;
  box-shadow: 0 0 0 10px rgba(246, 124, 95, 0.25);
  z-index: 2;
}
.switch-focus::after {
  content: "";
  position: absolute;
  inset: -14px;
  border: 3px dashed #776e65;
  border-radius: 12px;
  pointer-events: none;
}

/* Flash on selection — brief yellow pulse so the press→result link is
 * visible. prefers-reduced-motion collapses this to an instant state
 * change. */
.switch-flash {
  animation: switchFlash 180ms linear 1;
}
@keyframes switchFlash {
  0%   { background-color: #f2b179; }
  100% { background-color: inherit; }
}
@media (prefers-reduced-motion: reduce) {
  .switch-flash { animation: none; background-color: #f2b179; }
  .switch-arrow { transition: none; }
}

/* -------- Menu rows (start / game-over / settings) -------- */

.switch-menu-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 0;
}

.switch-menu-btn {
  position: relative;
  padding: 10px 18px;
  background: #8f7a66;
  color: #f9f6f2;
  border: 3px solid transparent;
  border-radius: 4px;
  font: inherit;
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
}
.switch-menu-btn:hover { background: #9f8b77; }

/* Game-over row only visible when switch mode is on; otherwise the
 * original Try again / Keep going anchors cover the UI. */
.switch-menu-row-gameover { display: none; margin-top: 10px; }
body[data-switch-mode="oneSwitch"] .switch-menu-row-gameover,
body[data-switch-mode="twoSwitch"] .switch-menu-row-gameover {
  display: flex;
  justify-content: center;
}
/* When the game is over but not won, hide the "Keep playing" button in
 * the switch row (it's irrelevant). Managed via data-mode. */
.switch-menu-row-gameover[data-mode="over"] .switch-menu-btn:nth-child(2) {
  /* "Keep playing" is at index 2 in markup order but we display Try
   * again then Settings for over state; the actual scan context only
   * includes the correct subset, so visually hide the extra button. */
  display: none;
}
.switch-menu-row-gameover[data-mode="won"] .switch-menu-btn:nth-child(2) {
  display: inline-block;
}

/* -------- Start overlay (switch mode only) -------- */

.switch-start-overlay {
  position: fixed;
  inset: 0;
  background: rgba(238, 228, 218, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
body[data-switch-mode="oneSwitch"] .switch-start-overlay.switch-visible,
body[data-switch-mode="twoSwitch"] .switch-start-overlay.switch-visible {
  display: flex;
}
.switch-start-overlay.switch-hidden { display: none !important; }

.switch-start-card {
  background: #faf8ef;
  border: 4px solid #bbada0;
  border-radius: 10px;
  padding: 28px 32px;
  text-align: center;
  max-width: 420px;
}
.switch-start-title { margin: 0 0 10px; color: #776e65; }
.switch-start-sub   { margin: 0 0 18px; color: #776e65; }

/* -------- Settings overlay -------- */

.switch-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(238, 228, 218, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.switch-settings-overlay.switch-hidden { display: none; }

.switch-settings-card {
  background: #faf8ef;
  border: 4px solid #bbada0;
  border-radius: 10px;
  padding: 24px 28px;
  width: min(520px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
}
.switch-settings-title { margin: 0 0 14px; color: #776e65; }

.switch-settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  margin-bottom: 6px;
  background: #eee4da;
  border: 3px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  color: #776e65;
  font-weight: bold;
  position: relative;
}
.switch-settings-value { color: #8f7a66; }

/* -------- Key-capture dialog -------- */

.switch-capture-overlay {
  position: fixed;
  inset: 0;
  background: rgba(119, 110, 101, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.switch-capture-card {
  background: #faf8ef;
  padding: 24px 28px;
  border-radius: 10px;
  border: 4px solid #bbada0;
  color: #776e65;
  font-weight: bold;
  font-size: 16px;
  max-width: 420px;
  text-align: center;
}

/* -------- Shared hidden class -------- */

.switch-hidden { display: none !important; }

/* -------- Narrow screens -------- */

@media (max-width: 520px) {
  .switch-arrows {
    top: -34px; left: -34px; right: -34px; bottom: -34px;
  }
  .switch-arrow { font-size: 20px; }
  .switch-arrow-up,
  .switch-arrow-down   { width: 58px; height: 28px; }
  .switch-arrow-left,
  .switch-arrow-right  { width: 28px; height: 58px; }
  .switch-overlay-root { font-size: 12px; }
}

/* -------- Short screens: trim heading/arrow footprint further -------- */

@media (max-height: 820px) {
  body[data-switch-mode="oneSwitch"] .game-container,
  body[data-switch-mode="twoSwitch"] .game-container {
    margin-top: 12px;
  }
}
