/*
 * style.css — visual design for Accessible Snake.
 *
 * WCAG notes:
 *  - all text ≥ 7:1 contrast on the page background (1.4.6)
 *  - relative units throughout, layout survives 200 % zoom (1.4.4)
 *  - visible 3px focus indicator on every interactive element (2.4.7 / 2.4.11)
 *  - touch/click targets ≥ 44×44 px (2.5.8)
 *  - respects prefers-reduced-motion (2.3.3)
 */

:root {
  --bg: #0b1220;
  --surface: #141e33;
  --surface-2: #1c2a45;
  --text: #f1f5f9;
  --text-dim: #b9c5d8;
  --accent: #4ade80;
  --accent-dark: #065f46;
  --danger: #fb923c;
  --focus: #fde047;
  --radius: 0.6rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.06rem;
  line-height: 1.55;
}

/* ---------------------------------------------------------------- helpers */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -4rem;
  z-index: 10;
  padding: 0.6rem 1rem;
  background: var(--focus);
  color: #1a1a00;
  font-weight: 700;
  border-radius: var(--radius);
  transition: top 0.15s ease-out;
}
.skip-link:focus {
  top: 0.5rem;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

header {
  background: var(--surface);
  border-bottom: 2px solid var(--surface-2);
}

.header-inner {
  max-width: 62rem;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  color: var(--accent);
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--text-dim);
}

main {
  max-width: 62rem;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem);
  gap: 1.5rem;
  align-items: start;
}

#game-region {
  min-width: 0;
}

.instructions {
  grid-column: 1 / -1;
}

@media (max-width: 52rem) {
  main {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------- language */

.lang-switch {
  display: flex;
  gap: 0.4rem;
}

.lang-switch button {
  min-height: 44px;
  padding: 0.4rem 1rem;
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--text-dim);
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}
.lang-switch button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #05230f;
  font-weight: 700;
}

/* -------------------------------------------------------------------- HUD */

.hud {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.hud p {
  margin: 0;
  padding: 0.35rem 0.9rem;
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text-dim);
}
.hud strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

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

#board {
  position: relative;
  width: 100%;
  max-width: 520px;
  border: 3px solid var(--surface-2);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0c1420;
}
#board:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

#canvas {
  display: block;
  width: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: rgba(5, 10, 20, 0.82);
  text-align: center;
  padding: 1rem;
}
.overlay[hidden] {
  display: none;
}
.overlay p {
  margin: 0;
}
#overlay-title {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--text);
}
#overlay-hint {
  color: var(--text-dim);
  font-size: 1.1rem;
}

.board-desc {
  max-width: 520px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------- buttons */

button {
  font: inherit;
}

.game-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 0.75rem 0;
}

.game-buttons button,
#dpad button {
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 1.1rem;
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--text-dim);
  border-radius: var(--radius);
  cursor: pointer;
}
.game-buttons button:hover,
#dpad button:hover {
  border-color: var(--accent);
}

.game-buttons .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05230f;
  font-weight: 700;
}

#dpad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left step right"
    ". down .";
  gap: 0.4rem;
  max-width: 520px;
  justify-content: center;
  margin-top: 0.5rem;
}
.dpad-up    { grid-area: up; }
.dpad-down  { grid-area: down; }
.dpad-left  { grid-area: left; }
.dpad-right { grid-area: right; }
.dpad-step  { grid-area: step; }

#dpad button[hidden] {
  display: none;
}

/* --------------------------------------------------------------- settings */

#settings {
  min-width: 0;
}
#settings fieldset {
  min-width: 0; /* let the fieldset shrink; long <option> text must not blow out the grid column */
  background: var(--surface);
  border: 2px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.25rem;
}
#settings legend {
  font-weight: 700;
  padding: 0 0.4rem;
}

.field {
  margin-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.field label {
  font-weight: 600;
}
.field select {
  min-height: 44px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--text-dim);
  border-radius: var(--radius);
  width: 100%;
  max-width: 100%;
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}
.field-check input {
  width: 1.4rem;
  height: 1.4rem;
  accent-color: var(--accent);
}
.field-check label {
  font-weight: 400;
}

/* ------------------------------------------------------------ instructions */

.instructions h2 {
  color: var(--accent);
  font-size: 1.25rem;
  margin: 1.5rem 0 0.5rem;
}
.instructions ul {
  margin: 0;
  padding-left: 1.4rem;
}
.instructions li {
  margin: 0.35rem 0;
  max-width: 70ch;
}
.key-list li {
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
