/* Simple Games Hub - shared look: colours, the top bar, buttons, the home page.
   Phone first. Each game adds its own stylesheet on top. */
:root {
  --bg: #11131a;
  --surface: #1a1d28;
  --surface-2: #242838;
  --line: #2f3447;
  --ink: #f3f1ea;
  --muted: #a3a9bb;
  --accent: #ffd23f;
  --accent-ink: #2b1c00;
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p, ul { margin: 0; }
button { font: inherit; color: inherit; }
button, a { touch-action: manipulation; }
[hidden] { display: none !important; }

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

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

/* ---------- top bar ---------- */
.sg-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
}
.sg-spacer { flex: 1; }
.sg-brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 0.01em; }
.sg-brand img { display: block; border-radius: 7px; }
.sg-back {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 14px 0 10px; margin-left: -10px;
  border-radius: 12px;
  color: var(--muted); text-decoration: none; font-weight: 700;
}
.sg-back:hover { color: var(--ink); background: var(--surface); }

.sg-lang { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.sg-lang button {
  min-width: 44px; min-height: 36px; padding: 0 10px;
  border: 0; border-radius: 9px; background: none;
  color: var(--muted); font-weight: 800; font-size: 13px; letter-spacing: 0.04em; cursor: pointer;
}
.sg-lang button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); }

/* ---------- buttons ---------- */
.sg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--ink);
  font-weight: 800; font-size: 15px; cursor: pointer;
  transition: transform 80ms ease, background 120ms ease;
}
.sg-btn:hover { background: #2c3145; }
.sg-btn:active { transform: scale(0.96); }
.sg-btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.sg-btn svg { width: 18px; height: 18px; flex: none; }
.sg-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
/* Lighten whatever the game's own accent is - never a fixed colour. */
.sg-btn.primary:hover { background: var(--accent); filter: brightness(1.1); }

/* ---------- fold-out notes ---------- */
.sg-details { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.sg-details summary {
  min-height: 48px; padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; cursor: pointer; list-style: none;
}
.sg-details summary::-webkit-details-marker { display: none; }
.sg-details summary::before {
  content: ""; width: 8px; height: 8px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 120ms ease;
}
.sg-details[open] summary::before { transform: rotate(45deg); }
.sg-details ul { padding: 0 16px 16px 34px; color: var(--muted); font-size: 14px; }
.sg-details li + li { margin-top: 8px; }

/* ---------- home page ---------- */
.sg-main {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.sg-hero { padding: 18px 0 6px; }
.sg-hero h1 { font-size: clamp(34px, 10vw, 46px); line-height: 1.05; font-weight: 800; letter-spacing: -0.02em; }
.sg-tag { margin-top: 10px; color: var(--muted); font-size: 17px; max-width: 30em; }
.sg-deal { list-style: none; padding: 0; margin-top: 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.sg-deal li {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px 7px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; font-weight: 700;
}
.sg-deal li::before {
  content: ""; width: 9px; height: 5px; margin-top: -3px;
  border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
}

.sg-section { margin: 30px 0 12px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.sg-other-note { margin: -4px 0 12px; color: var(--muted); font-size: 14px; }
.sg-grid { display: grid; gap: 12px; }
.sg-card {
  display: flex; align-items: center; gap: 14px;
  min-height: 92px; padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: inset 4px 0 0 var(--card-accent, var(--accent));
  color: inherit; text-decoration: none;
  transition: transform 120ms ease, background 120ms ease;
}
.sg-card:hover { background: var(--surface-2); transform: translateY(-2px); }
.sg-card:active { transform: scale(0.985); }
.sg-card img { width: 64px; height: 64px; flex: none; border-radius: 14px; display: block; }
.sg-card-text { flex: 1; min-width: 0; }
.sg-card-text b { display: block; font-size: 20px; font-weight: 800; }
.sg-card-text span { display: block; margin-top: 2px; color: var(--muted); font-size: 14px; }
.sg-card-go { flex: none; color: var(--muted); font-size: 22px; padding-right: 4px; }
.sg-more {
  display: grid; place-items: center;
  min-height: 72px; padding: 14px;
  border: 2px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); font-weight: 700; font-size: 14px; text-align: center;
}

.sg-foot { margin-top: 28px; color: var(--muted); font-size: 13px; }
.sg-foot .sg-btn { margin-top: 14px; }

@media (min-width: 720px) {
  .sg-main { max-width: 760px; }
  .sg-grid { grid-template-columns: 1fr 1fr; }
}

/* ====================================================================================
   A GAME PAGE
   <body class="sg-page-game">
     <main class="sg-game">            one column, as wide as the play area (--w)
       <div class="sg-top">            name on the left, numbers on the right
       <div class="sg-actions">        the game's buttons
       <div class="sg-stage">          the play area - the only part that eats swipes
       <p class="sg-hint">             one line on how to play
       <details class="sg-details">    "How this game plays fair"
   Everything in the column is sized from --w, so it all shrinks together on a small phone.
   Held sideways, the stage goes on the left and everything else stacks beside it.
   ==================================================================================== */
:root { --vh: 100vh; }
@supports (height: 100dvh) { :root { --vh: 100dvh; } }

.sg-page-game { overscroll-behavior: none; }

.sg-game {
  /* The room the play area may take with the top bar, name row, buttons, hint and the
     fair-play note all still on screen. A game that shows more than that around its board
     (a number pad, a tray of pieces) says how tall it is with --extra. */
  --extra: 0px;
  --room-w: calc(100vw - 32px);
  --room-h: calc(var(--vh) - 322px - var(--extra));
  /* The play area's width. This default is a square board; a game sets its own. */
  --w: clamp(240px, min(var(--room-w), var(--room-h)), 500px);
  width: var(--w);
  margin: 0 auto;
  padding: 4px 0 max(24px, env(safe-area-inset-bottom));
}

.sg-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sg-top h1 {
  font-size: clamp(22px, calc(var(--w) * 0.095), 34px);
  line-height: 1; font-weight: 800; letter-spacing: -0.02em; color: var(--accent);
  white-space: nowrap;
}
.sg-stats { display: flex; gap: clamp(5px, calc(var(--w) * 0.022), 8px); flex: none; }
.sg-stat {
  position: relative;
  min-width: clamp(48px, calc(var(--w) * 0.2), 84px);
  padding: 7px clamp(6px, calc(var(--w) * 0.026), 12px) 6px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
  text-align: center;
}
.sg-stat span {
  display: block; color: var(--muted);
  font-size: clamp(9.5px, calc(var(--w) * 0.031), 11px);
  font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap;
}
.sg-stat b {
  display: block;
  font-size: clamp(15px, calc(var(--w) * 0.056), 20px);
  line-height: 1.2; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* "+64" drifting up out of a number box: add <i class="sg-gain">+64</i> inside the .sg-stat */
.sg-gain {
  position: absolute; right: 8px; top: 2px;
  color: var(--accent); font-style: normal; font-weight: 800; font-size: 14px;
  pointer-events: none;
  animation: sg-gain 650ms ease-out forwards;
}
@keyframes sg-gain {
  from { transform: translateY(8px); opacity: 1; }
  to { transform: translateY(-20px); opacity: 0; }
}

.sg-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.sg-actions .sg-btn {
  padding: 0 clamp(9px, calc(var(--w) * 0.042), 16px);
  font-size: clamp(13px, calc(var(--w) * 0.042), 15px);
  white-space: nowrap;
}

.sg-stage { position: relative; padding: 12px 0 10px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.sg-hint { margin: 4px 0 14px; color: var(--muted); font-size: 13px; text-align: center; }

/* A panel over the play area ("You won", "No moves left", "Start over?"). Made by SG.panel(). */
.sg-overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 20px;
  border-radius: inherit;
  background: rgba(17, 19, 26, 0.9);
  text-align: center;
  animation: sg-fade 220ms ease-out;
}
.sg-overlay h2 { font-size: clamp(22px, calc(var(--w) * 0.085), 38px); line-height: 1.1; font-weight: 800; }
.sg-overlay.is-win h2 { color: var(--accent); }
.sg-overlay p { color: var(--muted); font-size: 15px; }
.sg-overlay-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }
@keyframes sg-fade { from { opacity: 0; } to { opacity: 1; } }

/* Pick one of a few: <div class="sg-seg" role="group"><button aria-pressed="true">Easy</button>... */
.sg-seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.sg-seg button {
  min-height: 38px; padding: 0 12px;
  border: 0; border-radius: 9px; background: none;
  color: var(--muted); font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.sg-seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); }

/* On / off: <label class="sg-switch"><input type="checkbox"><i></i><span>Label</span></label> */
.sg-switch { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; font-size: 14px; font-weight: 700; }
.sg-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sg-switch i {
  position: relative; flex: none; width: 42px; height: 24px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); transition: background 120ms ease;
}
.sg-switch i::after {
  content: ""; position: absolute; left: 2px; top: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); transition: transform 120ms ease, background 120ms ease;
}
.sg-switch input:checked + i { background: var(--accent); border-color: var(--accent); }
.sg-switch input:checked + i::after { transform: translateX(18px); background: var(--accent-ink); }
.sg-switch input:focus-visible + i { outline: 3px solid var(--accent); outline-offset: 2px; }

/* A short message at the bottom of the screen. Made by SG.toast(). */
.sg-toasts {
  position: fixed; left: 0; right: 0; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.sg-toast {
  max-width: min(92vw, 420px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 700; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: sg-fade 160ms ease-out;
}

/* A phone held sideways: the stage on the left, everything else beside it. */
@media (orientation: landscape) and (max-height: 560px) {
  .sg-game {
    --room-w: calc(100vw - 300px);
    --room-h: calc(var(--vh) - 84px);
    width: auto;
    display: grid;
    grid-template-columns: var(--w) minmax(200px, 250px);
    grid-template-rows: repeat(8, auto) 1fr;
    column-gap: 22px;
    justify-content: center;
    align-items: start;
    padding-top: 0;
  }
  .sg-game > * { grid-column: 2; }
  .sg-game > .sg-stage { grid-column: 1; grid-row: 1 / -1; padding: 0; }
  .sg-top { flex-direction: column; align-items: stretch; gap: 10px; }
  .sg-stats > .sg-stat { flex: 1; }
  .sg-actions .sg-btn { flex: 1 1 auto; }
  .sg-hint { margin: 12px 0; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .sg-btn, .sg-card, .sg-details summary::before, .sg-switch i, .sg-switch i::after { transition: none; }
  .sg-overlay, .sg-toast, .sg-gain { animation: none !important; }
}
