/* PHNXgames shared shell — one look for every game (modelled on 2048).
 * Loaded by every static game from /shell.css AFTER its own style.css, so the
 * tokens and components here win. A game page is:
 *
 *   <body class="g-body">            banner.js inserts the top bar first
 *     <div class="g-app">            fills the rest of the screen, never scrolls
 *       <header class="g-header">    title left, meta right
 *       <nav class="g-tabs">         optional segmented tabs
 *       <div class="g-chips">        2-3 stat chips
 *       <main class="g-stage">       the board: takes every remaining pixel
 *       <div class="g-actions">      one row of buttons
 *       <section class="g-panel">    non-play tabs render here (scrolls inside)
 *
 * Dark mode: html[data-theme="dark"] (set by banner.js from the OS).
 */

:root {
  --tangelo: #EE7526; --mustard: #FBD652; --vermilion: #D74820; --plum: #77161C;
  --rich-black: #000000; --cream: #F5EEE5; --beige: #EFEDE9; --off-white: #F5F5F5; --pastel-grey: #5C5C5C;

  --bg: #FFFFFF; --bg-elev: var(--off-white); --panel: var(--off-white); --panel-2: #FFFFFF;
  --border: var(--plum); --fg: var(--pastel-grey); --fg-strong: var(--rich-black);
  --fg-muted: #8A8A8A; --fg-faint: #BFBFBF;
  --accent: var(--tangelo); --accent-hover: var(--vermilion); --highlight: var(--mustard);
  --radius: 12px; --radius-sm: 8px; --gap: 10px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --cream: #222222; --beige: #1a1a1a; --off-white: #111111;
  --bg: #000000; --bg-elev: #111111; --panel: #111111; --panel-2: #1a1a1a;
  --border: #5a2a30; --fg: #C9C6BE; --fg-strong: #F5F5F5; --fg-muted: #A8A59C; --fg-faint: #6B6961;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* ---- full-height, no-scroll page ---- */
html, body.g-body { height: 100%; }
body.g-body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(1100px 500px at 20% -150px, rgba(238, 117, 38, 0.07) 0%, transparent 60%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
@supports (height: 100dvh) { html, body.g-body { height: 100dvh; } }
.g-app {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.g-app > * { flex: 0 0 auto; }
.g-hidden { display: none !important; }

/* ---- header ---- */
.g-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.g-title { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; color: var(--fg-strong); }
.g-title .accent { color: var(--accent); }
.g-meta {
  color: var(--fg-faint); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- segmented tabs (2048 style) ---- */
.g-tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; scrollbar-width: none;
}
.g-tabs::-webkit-scrollbar { display: none; }
.g-tab {
  flex: 1 0 auto; background: transparent; color: var(--fg-muted); border: none; border-radius: var(--radius-sm);
  padding: 8px 12px; font: 600 13px var(--font); cursor: pointer; white-space: nowrap;
}
.g-tab.active { background: var(--accent); color: #FFFFFF; }

/* ---- stat chips (2048 score cards) ---- */
.g-chips { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.g-chip {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 10px; min-width: 0;
}
.g-chip .label { display: block; color: var(--fg-faint); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.g-chip .value {
  display: block; color: var(--fg-strong); font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.g-chip .value.accent { color: var(--accent); }

/* ---- difficulty / mode segmented row ---- */
.g-seg { display: flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.g-seg > button { flex: 1; background: transparent; border: none; border-radius: var(--radius-sm); padding: 7px 8px; font: 600 13px var(--font); color: var(--fg-muted); cursor: pointer; }
.g-seg > button.active { background: var(--accent); color: #fff; }

/* ---- mode / difficulty / New game toolbar (2048 style) ---- */
.g-toolbar { display: flex; gap: 6px; }
.g-toolbar select {
  flex: 1 1 0; min-width: 0; padding: 9px 28px 9px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23EE7526'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--fg-strong); font: 600 14px var(--font); -webkit-appearance: none; appearance: none; cursor: pointer;
}
.g-toolbar .btn { flex: 0 0 auto; white-space: nowrap; }
.g-overlay .btn { margin-top: 8px; }

/* ---- the board: every remaining pixel, square-ish, never overflows ---- */
.g-stage {
  flex: 1 1 auto !important;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}
.g-board-box {
  /* --ratio = board width / height; fits inside the stage by its tighter side */
  --ratio: 1;
  width: min(100cqw, calc(100cqh * var(--ratio)));
  height: min(100cqh, calc(100cqw / var(--ratio)));
  position: relative;
}

/* ---- buttons ---- */
.btn {
  background: var(--panel-2); color: var(--fg-strong); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; font: 600 14px var(--font); cursor: pointer; -webkit-appearance: none; appearance: none;
}
.btn:active { transform: translateY(1px); }
.btn.active, .btn-primary, .btn.primary { background: var(--accent); border-color: transparent; color: #FFFFFF; }
.btn-ghost { background: transparent; color: var(--fg-muted); }
.btn:disabled { opacity: .45; cursor: default; }
.g-actions { display: flex; gap: 8px; }
.g-actions > .btn { flex: 1 1 0; min-width: 0; padding-left: 6px; padding-right: 6px; }

/* ---- overlay on top of the board ---- */
.g-overlay {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); border-radius: var(--radius); text-align: center; z-index: 5;
}
.g-overlay.show { display: flex; }
.g-overlay h2 { margin: 0; color: var(--accent); font-size: 26px; }
.g-overlay p { margin: 0; color: var(--fg); }

/* ---- panels for non-play tabs: scroll INSIDE, the page never scrolls ---- */
.g-panel {
  flex: 1 1 auto !important; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.g-panel h2 { margin: 0 0 10px; font-size: 17px; color: var(--fg-strong); }
.g-panel .muted { color: var(--fg-muted); font-size: 13px; }
.g-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.g-list li {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px;
}
.g-list li.me { border-color: var(--accent); }
.g-list .rank { color: var(--fg-faint); font-weight: 700; }
.g-list .who { color: var(--fg-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-list .val { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.g-statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.g-panel input {
  width: 100%; box-sizing: border-box; padding: 10px 12px; margin: 4px 0 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel-2); color: var(--fg-strong); font: 16px var(--font);
}

/* short phones (SE): tighten everything so the board keeps its space */
@media (max-height: 700px) {
  .g-app { gap: 7px; padding-top: 8px; }
  .g-title { font-size: 22px; }
  .g-chip { padding: 4px 8px; }
  .g-chip .value { font-size: 15px; }
  .btn { padding: 8px 10px; font-size: 13px; }
  .g-tab, .g-seg > button { padding: 6px 8px; }
  .g-toolbar select { padding-top: 7px; padding-bottom: 7px; font-size: 13px; }
}
