:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #10b981;
  --accent-dark: #047857;
  --danger: #ef4444;
  --danger-dark: #b91c1c;
  --head: #34d399;
  --body: #10b981;
  --food: #ef4444;
  --grid: #334155;
  --max-grid: 400px;
}

* { box-sizing: border-box; }

html {
  scrollbar-width: none;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

h1, h2 { margin: 0; }
p { margin: 0; }

/* ---------- HUD ---------- */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--grid);
}

.hud h1 {
  font-size: 1.5rem;
  letter-spacing: 0.05em;
}

.hud-values {
  display: flex;
  gap: 1.5rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.hud-values span {
  color: var(--text);
}

.hud-actions {
  display: flex;
  gap: 0.5rem;
}

button {
  cursor: pointer;
  border: 1px solid var(--grid);
  background: var(--panel);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9375rem;
  font-weight: 600;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

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

button:hover:not(:disabled) { background: #334155; }
button:active:not(:disabled) { background: #475569; }
button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Arena ---------- */
.arena {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  min-height: 0;
  overflow: hidden;
}

#status-live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
  white-space: nowrap;
}

.state-panel {
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 12px;
  color: var(--text);
}

.state-panel p { font-size: 1.125rem; }

#loading { display: flex; }

.hidden { display: none !important; }

/* ---------- Canvas ---------- */
#canvas-wrap {
  position: relative;
  display: inline-block;
}

#game-canvas {
  display: block;
  background: #0b1120;
  border: 2px solid var(--grid);
  border-radius: 8px;
  max-width: 100%;
  height: auto;
  touch-action: none;
}

#canvas-wrap {
  max-width: var(--max-grid);
}

#canvas-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(11, 17, 32, 0.9);
  color: var(--danger);
  padding: 1rem;
  border-radius: 8px;
  border: 2px solid var(--danger);
}

/* ---------- Overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 17, 32, 0.55);
  backdrop-filter: blur(4px);
}

/* L'overlay n'est visible que lorsque son état l'autorise (voir main.js). */
.overlay[aria-hidden="true"] {
  display: none;
}

.overlay-card {
  text-align: center;
  padding: 2rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 12px;
  min-width: 260px;
}

.overlay-card h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.overlay-card p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.overlay-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.overlay-actions button { min-width: 110px; }

/* ---------- D-pad ---------- */
.dpad {
  display: grid;
  grid-template-areas:
    " . up ."
    "left down right";
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 12px;
  max-width: 220px;
}

.dpad button {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#dpad-up { grid-area: up; }
#dpad-left { grid-area: left; }
#dpad-down { grid-area: down; }
#dpad-right { grid-area: right; }

/* ---------- Footer ---------- */
.help {
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-top: 1px solid var(--grid);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.help kbd {
  background: #334155;
  color: var(--text);
  padding: 0.125rem 0.35rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.875rem;
  margin: 0 0.125rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .hud { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .hud-values { justify-content: center; }
  .hud-actions { justify-content: center; width: 100%; }
  .hud-actions button { flex: 1; }
  #game-canvas { max-width: 100%; }
  #canvas-wrap { max-width: 100%; }
}

@media (min-width: 769px) {
  #dpad { display: none; }
}

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

/* ---------- sr-only ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
  white-space: nowrap;
}
