/* Grillé ! — styles of the client shell (owner: CLIENT).
   Contract: portrait iPhone 320-430 px wide; safe areas through env(); touch targets >= 44 px (E3); no text overflow at
   320x568, 375x667, 390x844 (E1). #app fills the window. The shell screens (.shell) sit inside the safe areas; the
   console root (.game-root) is FULL-BLEED (backgrounds reach the edges) and exposes --safe-top/right/bottom/left so the
   pilot and drone screens pad their controls themselves. Shared helpers for every screen: .stencil (French labels in a
   stencil-like style), .btn, .pic (an image over a flat fallback colour), .can-scroll (the only places that may scroll),
   the green screen (.green-screen …). */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --ink: #ece6d6;
  --ink-dim: #b9b29f;
  --bg: #111410;
  --panel: rgba(20, 24, 18, 0.88);
  --steel: #3a4136;
  --olive: #4b5a2f;
  --olive-hi: #6b7d43;
  --amber: #ffcf5a;
  --bleu: #3B82F6;
  --rouge: #DC3B2E;
  --phosphor: #7dff8a;
  --stencil: "Stencil Std", "Stencil", "Impact", "Haettenschweiler", "Arial Narrow", "Arial Black", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --touch: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; overscroll-behavior: none; }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
input { user-select: text; -webkit-user-select: text; }
canvas { display: block; touch-action: none; }
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; overflow: hidden; }

/* ---- Common pieces ---- */
.stencil { font-family: var(--stencil); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.pic { position: relative; display: block; overflow: hidden; }
.pic > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.can-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: var(--touch);
  padding: 10px 14px; border: 1px solid #1d2119; border-radius: 6px; cursor: pointer;
  background: linear-gradient(#59683a, #3c4825); color: #f3efe0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 2px 0 #151912;
  font-family: var(--stencil); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; font-size: 15px;
  text-align: center; overflow-wrap: anywhere;
}
.btn:active { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: default; transform: none; }
.btn-main { background: linear-gradient(#c79a2e, #8f6a14); color: #1b1608; border-color: #4a3708; font-size: 17px; }
.btn-small { width: auto; min-width: var(--touch); font-size: 13px; padding: 8px 14px; }
.btn-quiet { background: transparent; border-color: rgba(236, 230, 214, 0.25); box-shadow: none; color: var(--ink-dim); font-size: 13px; }

/* ---- Shell screens ---- */
.shell {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: stretch;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 16px);
  max-width: 460px; margin: 0 auto; overflow: hidden;
}
.shell[hidden], .game-root[hidden] { display: none; }
.shell > section { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.shell h1 { font-size: 26px; line-height: 1.05; }
.hint { color: var(--ink-dim); font-size: 13px; text-align: center; }

/* Home */
.home { position: relative; justify-content: flex-end; }
.home-bg { position: fixed; inset: 0; z-index: -1; background-color: #2b2f24; }
.home-bg > img { filter: brightness(0.62) saturate(0.9); }
.home-panel { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 10px; background: var(--panel); }
.home-title { font-size: clamp(40px, 15vw, 60px); color: #f6e7b8; text-shadow: 0 2px 0 #000, 0 0 18px rgba(255, 140, 40, 0.45); text-align: center; }
.home-tagline { color: var(--ink-dim); text-align: center; font-size: 14px; }
.home-message { color: #ffd2c4; background: rgba(160, 40, 20, 0.35); padding: 8px 10px; border-radius: 6px; font-size: 14px; }
.home-message[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-dim); }
.field input, .select {
  min-height: var(--touch); padding: 8px 12px; border-radius: 6px; border: 1px solid #59614c;
  background: #1c2019; color: var(--ink); font-size: 17px; /* >= 16 px: iOS does not zoom on focus */
}
.select { width: 100%; min-width: 0; font-size: 16px; -webkit-appearance: none; appearance: none; text-overflow: ellipsis;
  padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%), linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
.field-row { flex-direction: row; align-items: center; gap: 8px; }
.field-row > span { flex: none; }
.map-line { font-size: 13px; color: var(--ink-dim); text-align: center; }
.map-detail { font-size: 12px; color: var(--ink-dim); }

/* Lobby */
.lobby { align-items: stretch; }
.lobby { gap: 8px; }
.lobby-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr { background: #fff; border-radius: 6px; padding: 0; max-width: 100%; height: auto; }
.qr-help { color: var(--ink-dim); font-size: 13px; text-align: center; }
.count { font-size: 15px; color: var(--ink-dim); white-space: nowrap; }
.players { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.players li { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 10px; background: rgba(255, 255, 255, 0.05); border-radius: 6px; }
.players .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { color: var(--ink-dim); font-size: 12px; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #5b5b52; flex: none; }
.dot.on { background: #58d36b; box-shadow: 0 0 6px #58d36b; }
.row { display: flex; gap: 8px; margin-top: auto; }
.row > .btn { flex: 1; min-width: 0; }

/* Briefing */
.briefing { gap: 8px; }
.scenario { display: flex; gap: 10px; align-items: stretch; }
.scenario-pic { flex: none; width: 96px; height: 72px; border-radius: 6px; }
.scenario h1 { font-size: 20px; margin-bottom: 4px; }
.scenario p { font-size: 13px; color: var(--ink-dim); }
.scenario strong { color: var(--ink); }
.objective { font-size: 13px; padding: 8px 10px; border-left: 3px solid var(--amber); background: rgba(255, 207, 90, 0.08); }
.posts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 1; min-height: 0; }
.post {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-height: 88px; padding: 6px;
  border-radius: 8px; border: 2px solid transparent; overflow: hidden; cursor: pointer; text-align: left; background: #20251c;
}
.post-pic { position: absolute; inset: 0; }
.post-pic > img { filter: brightness(0.7); }
.post::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, rgba(0, 0, 0, 0.75)); }
.post > span:not(.post-pic) { position: relative; z-index: 1; }
.post-bleu { border-color: rgba(59, 130, 246, 0.55); }
.post-rouge { border-color: rgba(220, 59, 46, 0.55); }
.post.is-mine { border-color: var(--amber); box-shadow: 0 0 0 2px rgba(255, 207, 90, 0.35); }
.post[aria-disabled="true"] { cursor: default; }
.post.is-taken > .post-pic { opacity: 0.55; }
.post-label { font-size: 13px; line-height: 1.1; }
.post-holder { font-size: 12px; color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* End */
.end { justify-content: flex-end; }
.end-pic { position: fixed; inset: 0; z-index: -1; background-color: #2a2a26; }
.end-pic > img { filter: brightness(0.75); }
.end-panel { display: flex; flex-direction: column; gap: 8px; padding: 16px; background: var(--panel); border-radius: 10px; text-align: center; }
.end-panel h1 { font-size: clamp(28px, 10vw, 40px); }
.end-win h1 { color: #ffe08a; }
.end-loss h1 { color: #ff9c8a; }
.end-sub { font-weight: 600; }

.spectator { justify-content: center; text-align: center; gap: 12px; }
.spectator-turn { color: var(--amber); font-weight: 600; }
.post-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; text-align: left; }
.post-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; padding: 4px 10px;
  border-radius: 6px; background: rgba(255, 255, 255, 0.05); border-left: 3px solid var(--bleu); font-size: 14px; }
.post-line-rouge { border-left-color: var(--rouge); }
.post-line .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-dim); }

/* ---- Consoles ---- */
.game-root { position: absolute; inset: 0; overflow: hidden; background: #0d0f0c; }
.console-wait, .console-missing { padding: calc(var(--safe-top) + 40px) 24px; text-align: center; color: var(--ink-dim); }
.console-missing { display: flex; flex-direction: column; gap: 12px; }

/* ---- Banner and toast ---- */
.banner, .toast {
  position: fixed; left: calc(var(--safe-left) + 12px); right: calc(var(--safe-right) + 12px); z-index: 50;
  margin: 0 auto; max-width: 420px; padding: 8px 12px; border-radius: 8px; font-size: 14px; text-align: center;
  pointer-events: none; overflow-wrap: anywhere;
}
.banner { top: calc(var(--safe-top) + 6px); background: rgba(30, 60, 30, 0.92); }
.banner.is-problem { background: rgba(120, 70, 10, 0.95); }
.toast { bottom: calc(var(--safe-bottom) + 16px); background: rgba(150, 30, 20, 0.95); color: #fff; font-weight: 600; }
.banner[hidden], .toast[hidden] { display: none; }
.help-layer { position: fixed; inset: 0; z-index: 40; background: var(--bg); }
.help-layer[hidden] { display: none; }

/* ---- Green phosphor screen (src/ui/shell/green-screen.js) ---- */
.green-screen {
  position: relative; display: flex; flex-direction: column; gap: 4px; min-height: 0; height: 100%;
  padding: 8px; overflow: hidden; border-radius: 6px;
  background: #0b2a12 var(--gs-bg, none) center / cover no-repeat;
  color: var(--phosphor); font: 13px/1.3 var(--mono); text-shadow: 0 0 4px rgba(90, 255, 120, 0.55);
}
.gs-log {
  flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; /* room for .gs-count */
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y;
}
.gs-log > :first-child { margin-top: auto; } /* bottom-aligned while it fits, scrollable (not clipped) beyond (E1) */
.gs-log.has-more { -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px); mask-image: linear-gradient(to bottom, transparent 0, #000 16px); }
.gs-line { margin: 0; overflow-wrap: anywhere; }
.gs-line.is-mine { color: #c8ffcf; }
.gs-empty { opacity: 0.75; font-size: 12px; }
.gs-noise {
  position: absolute; inset: 0; pointer-events: none; mix-blend-mode: screen; opacity: 0.85;
  background: var(--gs-noise, repeating-linear-gradient(0deg, rgba(120, 255, 140, 0.18) 0 1px, transparent 1px 3px)) center / cover;
  animation: gs-flicker 0.18s steps(2) infinite;
}
.gs-noise[hidden], .gs-jam[hidden] { display: none; }
.gs-jam { position: absolute; top: 8px; left: 0; right: 0; text-align: center; font-weight: 700; letter-spacing: 0.3em; pointer-events: none; }
@keyframes gs-flicker { 0% { opacity: 0.6; transform: translateY(0); } 100% { opacity: 0.95; transform: translateY(1px); } }
.gs-form { position: relative; display: flex; gap: 4px; align-items: stretch; }
.gs-input {
  flex: 1; min-width: 0; min-height: var(--touch); padding: 6px 8px; border-radius: 4px;
  border: 1px solid rgba(125, 255, 138, 0.45); background: rgba(0, 18, 4, 0.7); color: var(--phosphor);
  font: 16px var(--mono); caret-color: var(--phosphor);
}
.gs-input::placeholder { color: rgba(125, 255, 138, 0.45); }
.gs-count { position: absolute; right: 8px; top: 6px; font-size: 10px; opacity: 0.7; pointer-events: none; }
.gs-form .gs-count { top: -14px; right: 2px; }
.gs-send, .gs-pos {
  flex: none; min-width: var(--touch); min-height: var(--touch); padding: 0 8px; border-radius: 4px; cursor: pointer;
  border: 1px solid rgba(125, 255, 138, 0.55); background: rgba(10, 50, 18, 0.85); color: var(--phosphor);
  font: 700 12px var(--mono); letter-spacing: 0.06em;
}
.gs-pos[aria-pressed="true"] { background: var(--phosphor); color: #062a0c; text-shadow: none; }
.gs-send:disabled, .gs-pos:disabled { opacity: 0.4; }
.is-jammed .gs-log { filter: blur(0.6px); opacity: 0.6; }

/* ---- Board preview console (src/ui/demo/board-preview.js) ---- */
.preview {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 8px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 8px);
}
.preview-head { font-size: 14px; text-align: center; }
.preview-board { flex: 1; min-height: 0; }
.preview-board canvas { width: 100%; height: 100%; }
.preview-screen { height: 150px; flex: none; }

@media (max-height: 600px) {
  .shell h1 { font-size: 22px; }
  .scenario-pic { width: 80px; height: 60px; }
  .post { min-height: 76px; }
  .objective { font-size: 12px; padding: 6px 8px; }
}
