/* Aitaroun's interface in the look of the Clipizo website (D:\A-WORK\CLIPIZO\website\DESIGN_SYSTEM.md):
   Inter, a plain black canvas, flat boxes with hairline borders, 8px controls and 12px panels, lime only for small
   highlights (the lime-tinted fill for the main action, the signature period after headings and on hovered menu
   buttons, focus rings). No glow, gradients, drop shadows (toasts excepted), all-caps labels or coloured side stripes. */
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(fonts/InterVariable-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(fonts/InterVariable-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
:root {
  color-scheme: dark;
  /* the website's palette */
  --canvas: #0c0c0c;
  --section: #101010;
  --surface: #121212;
  --panel: #181818;
  --hover: #222222;
  --border: #2a2a2a;
  --border-subtle: #242424;
  --border-hover: #383838;
  --text: #f4f4f4;
  --muted: #a8a8a8;
  --subtle: #858585;
  --accent: #bfff00;
  --tint: #2b3d12;
  --tint-hover: #34491a;
  --tint-border: #4a6619;
  --good: #a6e3a1;
  --warn: #f5cf78;
  --bad: #ff8b83;
  --radius-control: 8px;
  --radius-panel: 12px;
  --radius-tag: 4px;
  --control-h: 44px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --popover: 0 16px 36px rgb(0 0 0 / 0.35);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  /* HUD sizes */
  --top-h: 40px;
  --mm: 150px;
  --panel-h: 136px; /* two rows of 56px command buttons */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--canvas); color: var(--text); font: 400 15px/1.5 'Inter', Arial, Helvetica, sans-serif; overflow: hidden; }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
/* the visible height (100dvh): on phones a plain full-height box runs under the browser's address bar */
#app { position: fixed; top: 0; left: 0; right: 0; height: 100%; height: 100dvh; }
#gl, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { touch-action: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: var(--border-hover) transparent; }

/* ---------- controls ---------- */
button, select, input { font-family: inherit; color: var(--text); }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h); padding: 0 18px; border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--panel); font-size: 14px; font-weight: 800; line-height: 1.15; cursor: pointer; touch-action: manipulation;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease);
}
button:hover:not(:disabled) { background: var(--hover); border-color: var(--border-hover); }
button:disabled { color: var(--subtle); background: var(--section); border-color: var(--border-subtle); cursor: not-allowed; }
button.primary { background: var(--tint); border-color: var(--tint-border); }
button.primary:hover:not(:disabled) { background: var(--tint-hover); border-color: var(--tint-border); }
button.big { min-height: 48px; font-size: 15px; }
/* the website's signature: a lime period bounces in after a menu button's label on hover or keyboard focus */
:is(#menus, .modal) button:not(.x)::after {
  content: "."; display: inline-block; width: 0; margin-left: -8px; color: var(--accent); font-weight: 900; line-height: 1;
  transform: scale(0) translateY(0.2em); transform-origin: 50% 85%; pointer-events: none;
  transition: width 220ms var(--ease), margin-left 220ms var(--ease), transform 460ms cubic-bezier(0.34, 2, 0.5, 1);
}
:is(#menus, .modal) button:not(.x):not(:disabled):is(:hover, :focus-visible)::after { width: 0.3em; margin-left: -7px; transform: scale(1.35); }
select, input:not([type=range]) {
  min-height: var(--control-h); min-width: 0; max-width: 100%; padding: 0 12px; font-size: 15px;
  background: var(--section); border: 1px solid var(--border); border-radius: var(--radius-control);
}
select {
  padding-right: 34px; appearance: none; -webkit-appearance: none; cursor: pointer; text-overflow: ellipsis;
  background: var(--section) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23a8a8a8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
}
select:disabled { color: var(--muted); cursor: default; opacity: 0.75; }
option { background: var(--panel); color: var(--text); }
select:focus, input:focus { outline: none; border-color: var(--accent); }
select:focus-visible, input:focus-visible { outline: none; }
input[type=range] { width: 100%; height: 28px; margin: 0; accent-color: var(--accent); }
input::placeholder { color: var(--subtle); }

/* ---------- menus ---------- */
/* menus and modals centre their card with auto margins: unlike grid centring, a card taller than a phone held
   sideways then starts at the top and scrolls instead of being cut off at both ends */
#menus { position: absolute; inset: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 16px calc(16px + var(--safe-r)) 16px calc(16px + var(--safe-l)); background: var(--canvas); }
#menus > .card, .modal > .card { margin: auto; flex: none; }
.card { width: min(520px, 100%); background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-panel); padding: 24px; display: flex; flex-direction: column; gap: 16px; }
#skirmish, #lobby { width: min(680px, 100%); } /* a player's choices fit on one line */
h1, h2 { margin: 0; font-weight: 800; color: var(--text); overflow-wrap: anywhere; }
h1 { font-size: clamp(32px, 7vw, 48px); line-height: 1.05; }
h2 { font-size: 24px; line-height: 1.15; }
h1::after, h2::after { content: "."; color: var(--accent); } /* the website's signature period */
h3 { margin: 4px 0 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.tag, .desc { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.desc:empty { display: none; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.row > .field { flex: 1 1 140px; }
.row > .field.wide { flex-basis: 100%; }
.field input, .field select { width: 100%; color: var(--text); font-weight: 400; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.row.align-end { align-items: flex-end; } /* a button in a row of labelled fields lines up with their controls */
.row.grow > button { flex: 1 1 auto; }
.row > .field input[type=range] { height: var(--control-h); } /* level with a select beside it */
/* the main menu: name and intro, then the ways to play (side by side on a phone held sideways) */
.split, .intro, .actions { display: flex; flex-direction: column; gap: inherit; }
/* Settings, How to play and Credits: a row of links, each opening its panel underneath */
.more { display: flex; flex-wrap: wrap; gap: 0 20px; padding-top: 8px; border-top: 1px solid var(--border-subtle); }
button.link { min-height: 32px; padding: 0; border: 0; background: none; color: var(--muted); font-size: 14px; font-weight: 600; }
button.link:hover:not(:disabled), button.link[aria-expanded="true"] { background: none; color: var(--text); }
@media (pointer: coarse) { button.link { min-height: 40px; } }
.morebox { display: flex; flex-direction: column; gap: 12px; }
.help { margin: 0; padding-left: 18px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; font-size: 14px; line-height: 1.55; }
.help b { color: var(--text); font-weight: 600; }
.help a { color: var(--text); text-underline-offset: 3px; }
.help a:hover { color: var(--accent); }
.slotrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--border-subtle); }
.slotname { flex: 1 1 64px; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slotrow select { flex: 1 1 104px; min-height: 40px; padding: 0 28px 0 10px; font-size: 13px; background-position: right 10px center; }
.slotrow .x { min-height: 40px; padding: 0 14px; font-size: 14px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.code { color: var(--text); letter-spacing: 0.08em; }
#mpCodeField { flex: none; } /* Join sits right beside the code */
#mpCode { width: 128px; flex: none; text-align: center; font-size: 18px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; }
#mpCode::placeholder { font-weight: 400; }
#chatLog { max-height: 110px; overflow-y: auto; font-size: 13px; color: var(--muted); }
#chatLog:empty { display: none; }
#chatInput { width: 100%; }
.modal { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; overflow-y: auto; padding: 16px; background: rgb(0 0 0 / 0.6); }
#goTitle.win { color: var(--good); }
#goTitle.lose { color: var(--bad); }
#loading, #fatal { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--canvas); font-size: 16px; font-weight: 600; }
#loading { z-index: 45; background: rgb(12 12 12 / 0.92); }
.ldbox { width: min(320px, 100%); display: flex; flex-direction: column; gap: 12px; }
.ldbar { height: 4px; overflow: hidden; background: var(--border); border-radius: 2px; }
#loadingBar { height: 100%; width: 0; background: var(--accent); transition: width 160ms linear; }
#loadingNote { color: var(--muted); font-size: 13px; font-weight: 400; }
#loadingNote:empty { display: none; }
#fatal { z-index: 50; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; font-size: 13px; }
#hud > * { pointer-events: auto; }
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: var(--top-h); display: flex; align-items: center; gap: 16px;
  padding: 0 calc(8px + var(--safe-r)) 0 calc(12px + var(--safe-l)); background: var(--surface); border-bottom: 1px solid var(--border-subtle);
}
.stat { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat.money { color: var(--good); min-width: 72px; }
#power.low { color: var(--bad); animation: blink 1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.rank { display: flex; align-items: center; gap: 6px; color: var(--accent); }
.xpbar { width: 60px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
#xpfill { height: 100%; width: 0; background: var(--accent); }
#statusText { flex: 1; min-width: 0; text-align: center; color: var(--warn); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn { margin-left: auto; flex: none; min-height: 0; height: calc(var(--top-h) - 8px); padding: 0 10px; font-size: 16px; line-height: 1; }
.iconbtn:not([hidden]) ~ .iconbtn { margin-left: 0; } /* the first visible icon button takes the free space */
.iconbtn svg { display: block; }
@media (pointer: coarse) { .iconbtn { min-width: 44px; } }
#powers { position: absolute; top: calc(var(--top-h) + 12px); left: calc(8px + var(--safe-l)); display: flex; flex-direction: column; gap: 8px; }
.power { flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-width: 132px; min-height: 44px; padding: 6px 12px; text-align: left; background: var(--surface); }
.power b { font-size: 13px; font-weight: 700; }
.power small { color: var(--muted); font-size: 12px; font-weight: 400; }
.power.ready { background: var(--tint); border-color: var(--tint-border); }
.power.ready small { color: var(--accent); }
#toasts { position: absolute; top: calc(var(--top-h) + 12px); left: 50%; transform: translateX(-50%); width: min(560px, calc(100vw - 32px)); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { max-width: 100%; padding: 8px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-control); box-shadow: var(--popover); text-align: center; font-weight: 600; transition: opacity 0.8s; }
.toast.good { color: var(--good); }
.toast.bad { color: var(--bad); }
.toast.fade { opacity: 0; }
#modebar {
  position: absolute; top: calc(var(--top-h) + 12px); left: 50%; transform: translateX(-50%); z-index: 2; max-width: calc(100vw - 20px);
  display: flex; gap: 8px; align-items: center; padding: 6px 6px 6px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-panel); box-shadow: var(--popover);
}
#modeText { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#modebar button { min-height: 36px; padding: 0 12px; flex: none; }
#modeOk { background: var(--tint); border-color: var(--tint-border); }
#bottom {
  position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--panel-h) + 8px + var(--safe-b)); display: flex; align-items: flex-end; gap: 8px;
  padding: 0 calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) calc(8px + var(--safe-l)); pointer-events: none;
}
#bottom > * { pointer-events: auto; }
#mmwrap { width: var(--mm); height: var(--mm); flex: none; overflow: hidden; background: #000; border: 1px solid var(--border); border-radius: var(--radius-control); }
#minimap { width: 100%; height: 100%; display: block; touch-action: none; }
#panel { flex: 1; min-width: 0; height: var(--panel-h); display: flex; gap: 12px; padding: 8px; background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-panel); }
#selinfo { width: 210px; flex: none; min-width: 0; overflow: hidden; display: flex; flex-direction: column; gap: 4px; }
.hint { color: var(--muted); font-size: 13px; }
.selname { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vet { color: var(--accent); }
.owner { font-size: 12px; font-weight: 600; }
.status { color: var(--muted); font-size: 12px; }
.hp { position: relative; height: 14px; flex: none; overflow: hidden; background: var(--section); border: 1px solid var(--border); border-radius: var(--radius-tag); }
.hp > div { height: 100%; }
.hp span { position: absolute; inset: 0; color: var(--canvas); font-size: 10px; font-weight: 700; line-height: 12px; text-align: center; }
.queue, .chips { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; overflow-y: auto; }
.qchip, .chip { min-height: 24px; padding: 0 8px; border-radius: var(--radius-tag); font-size: 12px; font-weight: 600; }
#card { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); grid-auto-rows: 56px; gap: 6px; align-content: start; overflow-y: auto; }
.cmd { position: relative; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-height: 0; padding: 4px 10px; overflow: hidden; text-align: left; }
.cmd .lbl { max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 13px; font-weight: 700; line-height: 1.15; }
.cmd .lbl u { text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 2px; }
.cmd .sub { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.2; }
.cmd .badge { position: absolute; top: 4px; right: 6px; color: var(--accent); font-size: 12px; font-weight: 800; }
.cmd .prog { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--accent); }
.cmd.poor .sub { color: var(--bad); }
.cmd.util { background: var(--section); }
.cmd.danger { color: var(--bad); }
#quick { position: absolute; right: calc(8px + var(--safe-r)); bottom: calc(var(--panel-h) + 16px + var(--safe-b)); display: flex; gap: 6px; }
#quick button { min-height: 36px; padding: 0 12px; font-size: 13px; background: var(--surface); }
@media (pointer: coarse) { #quick button { min-height: 44px; } }
#rotate { display: none; }

/* phones held sideways: little height */
@media (max-height: 520px) {
  :root { --top-h: 34px; --mm: 104px; --panel-h: 104px; }
  html, body { font-size: 14px; }
  #topbar { gap: 12px; }
  .stat { font-size: 13px; }
  .xpbar { width: 40px; }
  .power { min-width: 0; min-height: 36px; padding: 4px 10px; }
  .power b { font-size: 12px; }
  #selinfo { width: 150px; }
  #card { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); grid-auto-rows: 40px; gap: 5px; }
  .cmd { padding: 3px 8px; gap: 1px; }
  .cmd .lbl { -webkit-line-clamp: 1; font-size: 12px; }
  .cmd .sub { font-size: 11px; }
  #panel.empty { visibility: hidden; }
}
/* narrow screens: the command card gets the selection box's room, so a dozer's buttons fit in two rows */
@media (max-width: 820px) {
  #selinfo { display: none; }
}
@media (max-width: 700px) {
  #statusText { display: none; }
}
@media (max-width: 600px) {
  html, body { font-size: 14px; }
}
/* phones: a smaller title, controls and spacing, so a menu fits on one screen */
@media (max-width: 600px), (max-height: 520px) {
  :root { --control-h: 40px; }
  .card { padding: 16px; gap: 12px; }
  h1 { font-size: 30px; }
  h2 { font-size: 20px; }
  .tag, .desc, .help { font-size: 13px; }
  button { padding: 0 14px; }
  button.big { min-height: 44px; font-size: 14px; }
  .row { gap: 8px; }
  #chatLog { max-height: 72px; }
}
/* narrow screens: a player's row shows the name first and the choices on a second line */
@media (max-width: 600px) {
  .slotrow { row-gap: 4px; }
  .slotrow::after { content: ''; flex-basis: 100%; order: 1; }
  .slotrow select { order: 2; flex: 2 1 0; padding: 0 24px 0 8px; background-position: right 8px center; }
  .slotrow select.f { flex-grow: 3; } /* faction names are the longest */
  .slotrow select.d { order: 0; flex: 0 1 104px; } /* an AI's difficulty stays beside its name */
}
/* phones held sideways: wider cards, the main menu's name and buttons side by side, and each setup screen's
   Start button on the title line (with the lobby's map), so it shows without scrolling */
@media (max-height: 520px) and (min-width: 560px) {
  #menus { padding-top: 10px; padding-bottom: 10px; }
  #menus > .card, .modal > .card { width: min(720px, 100%); }
  .card { padding: 12px 18px; gap: 10px; }
  h1 { font-size: 26px; }
  #mainMenu .split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 24px; align-items: end; }
  .intro, .actions { gap: 10px; }
  #skirmish, #multiplayer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  #lobby { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; }
  #skirmish > *, #multiplayer > *, #lobby > * { grid-column: 1 / -1; }
  #skirmish > h2, #multiplayer > h2, #lobby > h2 { grid-column: 1; grid-row: 1; }
  #skirmish > .row.end, #multiplayer > .row.end { grid-column: 2; grid-row: 1; }
  #lobby > .maprow { grid-column: 2; grid-row: 1; }
  #lobby > .row.end { grid-column: 3; grid-row: 1; }
  #lobby .maprow .field { flex-direction: row; align-items: center; gap: 8px; }
  .row > .field { flex-basis: 96px; }
  .row > .field.wide { flex: 2 1 180px; } /* there's room for it beside the others, with the bigger share */
  .slotrow { padding: 4px 0; }
  .slotrow select, .slotrow .x { min-height: 36px; }
}
@media (orientation: portrait) and (max-width: 600px) {
  #hud:not([hidden]) ~ #rotate { display: grid; position: absolute; inset: 0; z-index: 40; place-items: center; padding: 24px; background: var(--canvas); font-size: 17px; font-weight: 600; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::after { transition: none !important; animation: none !important; }
}
