:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --green-dark: #0d3f29;
  --green: #1d8f4e;
  --green-light: #59d47d;
  --cream: #f6ffe9;
  --panel: rgba(5, 35, 22, .88);
}

.rotate-notice { display: none; }
.desktop-help { display: none; }

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--cream);
  background:
    radial-gradient(circle at 15% 10%, rgba(104, 220, 126, .25), transparent 28rem),
    linear-gradient(145deg, #062719, #176b3a 55%, #0b3824);
  overscroll-behavior: none;
}

button, a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.game-shell {
  width: min(1100px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-header, .scoreboard {
  display: grid;
  align-items: center;
}

.game-header { grid-template-columns: 1fr auto 1fr; }

.game-header h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 2rem);
  letter-spacing: .02em;
}

.home-link {
  justify-self: start;
  color: white;
  text-decoration: none;
  font-weight: 750;
}

.icon-button {
  justify-self: end;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 50%;
  color: white;
  background: rgba(0,0,0,.22);
  cursor: pointer;
}

.scoreboard {
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 14px;
  background: rgba(0,0,0,.18);
}

.scoreboard div { display: flex; align-items: baseline; gap: 8px; }
.scoreboard span { font-size: .78rem; opacity: .82; text-transform: uppercase; letter-spacing: .08em; }
.scoreboard strong { font-size: 1.45rem; }

#pauseButton {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  color: #092719;
  background: #dfffb7;
  font-weight: 800;
  cursor: pointer;
}

#pauseButton:disabled { opacity: .45; cursor: default; }

.game-area {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  max-height: calc(100dvh - 250px);
  margin: auto;
  border: clamp(4px, 1vw, 10px) solid rgba(255,255,255,.92);
  border-radius: 18px;
  overflow: hidden;
  background: #07120b;
  box-shadow: 0 16px 45px rgba(0,0,0,.34);
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px),
    #061109;
  background-size: 20px 20px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 15, 8, .62);
  backdrop-filter: blur(3px);
}

.overlay.hidden { display: none; }

.overlay-card {
  width: min(480px, 92%);
  padding: clamp(18px, 4vw, 34px);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 22px;
  text-align: center;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0,0,0,.38);
}

.overlay-card h2 { margin: 4px 0 10px; font-size: clamp(1.5rem, 5vw, 2.5rem); }
.overlay-card p { margin: 0 0 18px; line-height: 1.45; }
.overlay-card .eyebrow { margin-bottom: 2px; color: #9aefa9; font-size: .78rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }

.start-button {
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  color: #07321d;
  background: linear-gradient(#baff80, #63db67);
  box-shadow: 0 6px 0 #25843e;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
}

.start-button:active { transform: translateY(3px); box-shadow: 0 3px 0 #25843e; }

.controls {
  width: 194px;
  height: 130px;
  margin: 0 auto;
  display: grid;
  grid-template: repeat(2, 58px) / repeat(3, 58px);
  gap: 8px;
  grid-template-areas: ". up ." "left down right";
}

.control {
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 16px;
  color: white;
  background: linear-gradient(rgba(255,255,255,.18), rgba(0,0,0,.18));
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
  font-size: 1.35rem;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.control:active, .control.active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); background-color: var(--green); }
.up { grid-area: up; }
.left { grid-area: left; }
.down { grid-area: down; }
.right { grid-area: right; }

.help { margin: 0; text-align: center; font-size: .82rem; opacity: .76; }

@media (min-width: 850px) and (min-height: 720px) {
  .game-shell { gap: 14px; }
  .controls { width: 230px; height: 156px; grid-template: repeat(2, 70px) / repeat(3, 70px); gap: 10px; }
}

@media (orientation: landscape) and (max-height: 650px) {
  .game-shell { display: grid; grid-template-columns: minmax(0, 1fr) 165px; grid-template-rows: auto auto 1fr; gap: 6px 12px; }
  .game-header, .scoreboard, .game-area { grid-column: 1; }
  .game-header { grid-row: 1; }
  .scoreboard { grid-row: 2; }
  .game-area { grid-row: 3; max-height: calc(100dvh - 118px); }
  .game-area { width: min(100%, calc((100dvh - 118px) * 5 / 3)); justify-self: center; }
  .controls { grid-column: 2; grid-row: 1 / 4; align-self: center; width: 165px; height: 110px; grid-template: repeat(2, 50px) / repeat(3, 50px); gap: 5px; }
  .control { border-radius: 13px; }
  .help { display: none; }
}

@media (max-width: 500px) and (orientation: portrait) {
  .game-area { max-height: none; }
  .overlay-card { padding: 16px; }
  .overlay-card p:not(.eyebrow) { font-size: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}

/* Le panneau participe à la hauteur : son texte ne peut plus être rogné. */
.game-area {
  display: grid;
  aspect-ratio: auto;
  max-height: none;
  margin: 0 auto;
}
#gameCanvas {
  grid-area: 1 / 1;
  aspect-ratio: 5 / 3;
  height: auto;
  align-self: center;
}
.overlay {
  position: relative;
  inset: auto;
  grid-area: 1 / 1;
  align-self: stretch;
}
.overlay-card { width: min(480px, 100%); }

@media (max-width: 600px) and (orientation: portrait) {
  .game-shell { padding-left: 3px; padding-right: 3px; gap: 12px; }
  .game-header, .scoreboard { margin-left: 5px; margin-right: 5px; }
  .game-area { width: 100%; border-width: 3px; border-radius: 14px; }
  .overlay { padding: 8px; }
  .overlay-card { padding: 18px 12px; border-radius: 14px; }
  .overlay-card h2 { font-size: 1.65rem; }
  .overlay-card p:not(.eyebrow) { font-size: 1rem; }
  .controls { margin-top: 8px; flex-shrink: 0; }
  .help { padding: 0 10px 10px; }
}

@media (orientation: landscape) and (max-height: 650px) and (any-pointer: coarse) {
  .game-shell { display: none; }
  .rotate-notice {
    display: grid;
    place-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    text-align: center;
  }
  .rotate-notice div { max-width: 540px; }
  .rotate-notice span { font-size: 3rem; }
  .rotate-notice h2 { margin: 8px 0; font-size: clamp(1.2rem, 4vw, 1.8rem); }
  .rotate-notice p { margin: 8px 0; }
}

/* Réglages PC uniquement : aucune modification du portrait tactile. */
@media (hover: hover) and (pointer: fine) {
  .game-shell { display: flex; flex-direction: column; gap: 10px; }
  .controls, .help { display: none; }
  .desktop-help { display: block; }
  .game-area {
    width: min(100%, var(--desktop-board-width, 850px));
    max-height: none;
    flex: none;
    margin: 0 auto;
    border-width: 6px;
  }
  .game-area .overlay {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    align-items: safe center;
    padding: 10px;
  }
  .overlay-card { padding: 18px; }
  .overlay-card h2 { font-size: 1.8rem; }
}
