/* styles.css — page shell + responsive canvas wrapper.
   Gameplay visuals are drawn on the canvas; this file styles the surrounding
   shell and scales the fixed 768x576 stage down on small screens (spec Camera:
   preserve aspect ratio, no scrolling, no logical-grid change). */

:root {
  /* Spec palette direction (Visual Direction). */
  --concrete: #4a4a50;
  --concrete-dark: #34343a;
  --asphalt: #232327;
  --asphalt-deep: #161618;
  --deli-red: #e0473f;
  --taxi-yellow: #f2c33d;
  --sanitation-green: #3a9d63;
  --bakery-tan: #e0c08c;
  --hazard: #ff6a00;
  --ink: #f5f2ea;
  --ink-dim: #c4c0b6;

  --canvas-w: 768px;
  --canvas-h: 576px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* Grubby asphalt backdrop. */
  background: radial-gradient(ellipse at 50% 0%, var(--asphalt) 0%, var(--asphalt-deep) 100%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  /* No pull-to-refresh / rubber-banding while playing on touch. */
  overscroll-behavior: none;
}

.game-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  min-height: 100%;
}

.game-title {
  margin: 4px 0;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--taxi-yellow);
  text-shadow: 2px 2px 0 #000, 0 0 14px rgba(242, 195, 61, 0.25);
}

/* The stage is the fixed-aspect box that holds the canvas + overlay.
   max-width keeps it within the viewport; aspect-ratio preserves 4:3. */
.stage {
  position: relative;
  width: var(--canvas-w);
  max-width: 100%;
  aspect-ratio: 768 / 576;
  background: var(--asphalt-deep);
  /* Concrete frame with a taxi-yellow under-glow. */
  border: 3px solid var(--concrete);
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* Crisp, faux-pixel-art rendering (spec Visual Direction). */
  image-rendering: pixelated;
  background: var(--asphalt);
  /* Swipes on the board drive the player — don't let the browser scroll/zoom. */
  touch-action: none;
}

/* On-screen pause button (mainly for touch; harmless on desktop). */
.pause-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  cursor: pointer;
  z-index: 5;
  touch-action: manipulation;
}
.pause-btn:hover { background: rgba(0, 0, 0, 0.65); }
.pause-btn:focus-visible { outline: 3px solid var(--taxi-yellow); outline-offset: 2px; }

/* Transient banner over the board (e.g. the black-belt bestowal). */
.toast {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translate(-50%, -8px);
  max-width: 92%;
  padding: 8px 16px;
  font-weight: 700;
  font-size: clamp(0.8rem, 2.4vw, 1.05rem);
  text-align: center;
  color: #101013;
  background: var(--taxi-yellow);
  border: 2px solid #101013;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 6;
}
.toast--show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Overlay sits on top of the canvas for menus / intros / end screens. */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none; /* enabled by the UI layer when a menu is active */
}

/* Overlay becomes interactive when a menu is active. */
.overlay--active {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.55);
}

/* Menu / overlay panel — a concrete card. */
.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 34px;
  max-width: 90%;
  background: linear-gradient(180deg, var(--concrete-dark) 0%, #26262b 100%);
  border: 2px solid #000;
  border-top: 3px solid var(--taxi-yellow);
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

.panel__heading {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: var(--taxi-yellow);
  text-shadow: 2px 2px 0 #000;
}

.panel__sub {
  margin: 0;
  color: var(--bakery-tan);
}

.panel__footer {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: stretch;
}

.menu__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 18px;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.08s ease, border-color 0.08s ease;
  touch-action: manipulation; /* no 300ms tap delay on mobile */
}

.menu__item:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Keyboard-selected item: clearly highlighted (spec Accessibility: visible focus). */
.menu__item.is-selected {
  background: rgba(242, 195, 61, 0.18);
  border-color: var(--taxi-yellow);
}

/* Native focus ring kept visible for keyboard users. */
.menu__item:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.menu__hint {
  font-size: 0.78rem;
  color: #cfcabf;
}

.hud {
  width: var(--canvas-w);
  max-width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hud__group {
  display: flex;
  gap: 16px;
  align-items: baseline;
}

.hud__item--score { color: var(--taxi-yellow); }
.hud__item--bonus { color: var(--hazard); }
.hud__item--belt { color: #6fb0ff; font-weight: 700; }
.hud__item--streak { color: #ff9d3d; font-weight: 700; }
.hud__item--lives { color: var(--deli-red); letter-spacing: 1px; }
.hud__item--level { color: var(--bakery-tan); }
.hud__item--bread { color: var(--ink-dim); }
.hud__item--char {
  color: var(--sanitation-green);
  text-transform: capitalize;
  border: 1px solid var(--sanitation-green);
  border-radius: 4px;
  padding: 0 6px;
}

/* Reduced-motion: drop the few menu transitions (spec Accessibility nice-to-have). */
@media (prefers-reduced-motion: reduce) {
  .menu__item { transition: none; }
}

/* Small screens: fit the whole game (title + board + HUD) in the viewport without
   page scrolling, and lean on the dynamic viewport height for mobile browser bars. */
@media (max-width: 820px), (max-height: 720px) {
  .game-shell {
    gap: 8px;
    padding: 8px;
    min-height: 100dvh;
    justify-content: center;
  }
  /* Fit the board to whichever is tighter — width or height — so it never
     overflows (handles portrait AND landscape phones without page scroll). */
  .stage {
    width: min(var(--canvas-w), 100%, calc((100dvh - 96px) * 4 / 3));
  }
  .game-title {
    font-size: 1.3rem;
  }
  .hud {
    font-size: 0.82rem;
  }
  .hud__group {
    gap: 10px;
  }
  .panel__heading { font-size: 1.3rem; }
  .panel { padding: 16px 20px; }
}
