/* Wasted Space — shared styles for the site shell and every game.

   Breakpoints (the site-wide layout rule):
     Mobile   < 600px
     Tablet   600–899px
     Desktop  900–1279px
     Wide     1280px+
   Content is constrained to a 1200px container; backgrounds always fill the
   full width.

   The shell (homepage, menu) is white in light mode and neutral dark in dark
   mode. Game pages use body.game plus their own --game-* colors, which stay
   the same in dark mode. */

:root {
  --ws-bg: #FFFFFF;
  --ws-surface: #F4F5F7;
  --ws-surface-hover: #E9EBEF;
  --ws-text: #16181D;
  --ws-muted: #5F6673;
  --ws-border: #E2E4E9;
  --ws-accent: #1565FF;
  --ws-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 18px rgba(16, 24, 40, 0.08);
  --ws-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ws-emoji-font: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', 'Segoe UI Symbol', sans-serif;
  --ws-container: 1200px;
  --ws-gutter: 16px;

  /* Game defaults; each game overrides these on its body class. */
  --game-bg: #1565FF;
  --game-deep: #0B3BA8;       /* button shadow, rims */
  --game-accent: #1565FF;     /* big numbers and links on white cards */
  --game-yellow: #FFD23F;
  --game-ink: #FFFFFF;         /* text and icons on the game background */
  --game-ink-rgb: 255, 255, 255;
  /* Optional per game: --game-on-white (text on white buttons; default
     --game-bg) and --game-focus (focus ring; default --game-yellow). */
  --card-text: #0B1F4D;
  --card-muted: #5B6B8C;
  --card-line: #E6EEFF;
  --good: #0E7A3E;
  --bad: #B3261E;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ws-bg: #15171C;
    --ws-surface: #1F2229;
    --ws-surface-hover: #292D36;
    --ws-text: #ECEEF2;
    --ws-muted: #9BA2AE;
    --ws-border: #2C3039;
    --ws-accent: #6C9DFF;
    --ws-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 22px rgba(0, 0, 0, 0.35);
  }
}

@media (min-width: 900px) {
  :root { --ws-gutter: 32px; }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body.ws-shell,
body.game {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--ws-font);
  line-height: 1.4;
  overflow-x: hidden;
}

body.ws-shell {
  background: var(--ws-bg);
  color: var(--ws-text);
  color-scheme: light dark;
}

body.game {
  background: var(--game-bg);
  color: var(--game-ink);
  color-scheme: light;
}

a { color: inherit; }

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

/* Focus stays visible for keyboard users at every size. */
body.game :focus-visible { outline: 3px solid var(--game-focus, var(--game-yellow)); outline-offset: 3px; }
body.game .card :focus-visible { outline-color: var(--card-text); }
body.ws-shell :focus-visible,
.ws-menu :focus-visible { outline: 3px solid var(--ws-accent); outline-offset: 2px; }

/* ── Header ────────────────────────────────────────────── */

.ws-header {
  position: relative;
  z-index: 100;
  font-family: var(--ws-font);
}

.ws-header-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(44px, 1fr) minmax(0, auto) minmax(44px, 1fr);
  align-items: center;
  gap: 8px;
  max-width: calc(var(--ws-container) + 2 * var(--ws-gutter));
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) max(var(--ws-gutter), env(safe-area-inset-right)) 8px max(var(--ws-gutter), env(safe-area-inset-left));
}

.ws-header--shell {
  border-bottom: 1px solid var(--ws-border);
  background: var(--ws-bg);
  color: var(--ws-text);
}

.ws-header--game { color: var(--game-ink); }

.ws-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-left: -6px;
}

.ws-site-link {
  display: none;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  opacity: 0.85;
}

@media (min-width: 600px) {
  .ws-site-link { display: inline; }
}

.ws-title {
  margin: 0;
  min-width: 0;
  text-align: center;
  font-size: clamp(22px, 6.4vw, 30px);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-header--shell .ws-title { font-size: 24px; font-weight: 800; }

.ws-title a { color: inherit; text-decoration: none; }

.ws-actions { display: flex; justify-content: flex-end; margin-right: -6px; }

.ws-menu-btn,
.ws-menu-close,
.sound-toggle {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ws-menu-btn svg,
.ws-menu-close svg { width: 26px; height: 26px; }

.ws-header--game .ws-menu-btn,
.sound-toggle { background: rgba(var(--game-ink-rgb), 0.14); }

.sound-toggle svg { display: block; width: 24px; height: 24px; }
.sound-toggle .icon-sound-on { display: none; }
.sound-toggle.is-on .icon-sound-on { display: block; }
.sound-toggle.is-on .icon-sound-off { display: none; }

/* ── Menu: drawer on phones and tablets, dropdown on desktop ─ */

.ws-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms;
}

.ws-menu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 110;
  width: min(320px, 86vw);
  padding: max(10px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  background: var(--ws-bg);
  color: var(--ws-text);
  font-family: var(--ws-font);
  text-align: left;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  transform: translateX(-105%);
  visibility: hidden;
  transition: transform 220ms ease, visibility 220ms;
}

/* On open, visibility flips instantly (so the close button can take focus);
   on close it waits for the slide-out to finish. */
.ws-menu-open .ws-overlay { opacity: 1; visibility: visible; transition: opacity 200ms ease, visibility 0s; }
.ws-menu-open .ws-menu { transform: none; visibility: visible; transition: transform 220ms ease, visibility 0s; }

@media (max-width: 899px) {
  .ws-menu-open { overflow: hidden; }
}

.ws-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 10px 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--ws-border);
}

.ws-menu-brand {
  color: inherit;
  font-size: 20px;
  font-weight: 800;
  text-decoration: none;
}

.ws-menu-list,
.ws-menu-sub { margin: 0; padding: 0; list-style: none; }

.ws-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  color: inherit;
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.ws-menu-item[aria-current="page"],
.ws-menu-item.is-active { background: var(--ws-surface); }

.ws-menu-icon {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.ws-menu-icon--home {
  display: grid;
  place-items: center;
  background: var(--ws-surface);
}

.ws-menu-icon--home svg { width: 20px; height: 20px; fill: var(--ws-muted); }

.ws-menu-sub { margin: 2px 0 6px 54px; }

.ws-menu-sub a {
  display: block;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--ws-muted);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}

.ws-menu-sub a[aria-current="page"] { color: var(--ws-text); background: var(--ws-surface); }

@media (min-width: 900px) {
  .ws-overlay { background: transparent; }

  .ws-menu {
    position: absolute;
    top: calc(100% - 2px);
    bottom: auto;
    left: max(calc(var(--ws-gutter) - 6px), env(safe-area-inset-left));
    width: 560px;
    max-height: calc(100vh - 90px);
    padding: 12px;
    border: 1px solid var(--ws-border);
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    transform: translateY(-8px);
    opacity: 0;
    transition: transform 160ms ease, opacity 160ms ease, visibility 160ms;
  }

  .ws-menu-open .ws-menu {
    transform: none;
    opacity: 1;
    transition: transform 160ms ease, opacity 160ms ease, visibility 0s;
  }

  .ws-menu-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 8px;
    align-items: start;
  }

  .ws-menu-all { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .ws-menu, .ws-overlay { transition: none !important; }
}

/* ── Homepage ──────────────────────────────────────────── */

.ws-home {
  width: 100%;
  max-width: calc(var(--ws-container) + 2 * var(--ws-gutter));
  margin: 0 auto;
  padding: 20px var(--ws-gutter) 24px;
}

.ws-intro {
  margin: 0 0 20px;
  color: var(--ws-muted);
  font-size: 16px;
  text-align: center;
}

.ws-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 600px)  { .ws-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; } }
@media (min-width: 900px)  { .ws-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; } }
@media (min-width: 1280px) { .ws-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

/* Square buttons: icon centered, name below. */
.ws-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  aspect-ratio: 1;
  padding: 12px;
  border: 1px solid var(--ws-border);
  border-radius: 20px;
  background: var(--ws-surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--ws-shadow);
  -webkit-tap-highlight-color: transparent;
}

.ws-tile:active { transform: scale(0.98); }

.ws-tile img {
  display: block;
  width: 58%;
  min-width: 48px;
  height: auto;
  aspect-ratio: 1;
  border-radius: 22%;
}

@media (min-width: 900px) { .ws-tile img { min-width: 64px; } }

.ws-tile-name {
  font-size: clamp(14px, 4vw, 18px);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.ws-footer {
  margin-top: auto;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  color: var(--ws-muted);
  font-size: 13px;
  text-align: center;
}

/* ── Game pages: play column ───────────────────────────── */

.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* Desktop: center the game in the space below the header when the page is
   shorter than the window. */
@media (min-width: 900px) {
  .play { flex: 1 0 auto; justify-content: center; padding: 16px 0 24px; }
}

.big-button {
  position: relative;
  min-width: 220px;
  padding: 18px 48px;
  border: 0;
  border-radius: 999px;
  background: #FFFFFF;
  color: var(--game-on-white, var(--game-bg));
  font: 800 26px/1 var(--ws-font);
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--game-deep), 0 10px 24px rgba(0, 0, 0, 0.22);
  transition: transform 80ms ease, box-shadow 80ms ease, opacity 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.big-button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--game-deep), 0 4px 12px rgba(0, 0, 0, 0.22);
}

.big-button:disabled { opacity: 0.6; cursor: default; }

.play-message {
  min-height: 1.4em;
  margin: 16px 16px 0;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
}

.play-link {
  margin-top: 10px;
  padding: 8px 14px;
  font-size: 16px;
  font-weight: 600;
  color: rgba(var(--game-ink-rgb), 0.9);
}

.site-footer {
  margin-top: auto;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 13px;
  color: rgba(var(--game-ink-rgb), 0.78);
}

.pop { animation: ws-pop 420ms cubic-bezier(0.2, 0.9, 0.3, 1.4); }

@keyframes ws-pop {
  0%   { transform: scale(0.3); opacity: 0; }
  60%  { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); }
}

/* Keyboard hints: only on devices with a mouse. */
.kbd {
  display: none;
  margin-left: 10px;
  padding: 2px 6px;
  border: 1px solid currentColor;
  border-radius: 6px;
  font: 600 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  vertical-align: middle;
  opacity: 0.55;
}

@media (hover: hover) and (pointer: fine) {
  .kbd { display: inline-block; }
}

/* ── Stats pages: shared card grid ─────────────────────── */

.stats {
  width: 100%;
  max-width: calc(var(--ws-container) + 2 * var(--ws-gutter));
  margin: 0 auto;
  padding: 4px var(--ws-gutter) 8px;
}

.back-link {
  display: inline-block;
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 600;
}

.range-bar { margin: 0 0 16px; }

/* Desktop: the range selector stays pinned while the page scrolls. */
@media (min-width: 900px) {
  .range-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 calc(-1 * var(--ws-gutter)) 16px;
    padding: 10px var(--ws-gutter);
    background: var(--game-bg);
  }
  .range { max-width: 480px; }
}

.range {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(var(--game-ink-rgb), 0.16);
}

.range button {
  flex: 1;
  padding: 10px 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--game-ink);
  font: 700 15px/1 var(--ws-font);
  cursor: pointer;
}

.range button[aria-pressed="true"] {
  background: #FFFFFF;
  color: var(--game-on-white, var(--game-bg));
}

.stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

@media (min-width: 900px)  { .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; } }
@media (min-width: 1280px) { .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card--wide { grid-column: 1 / -1; }

.card {
  min-width: 0;
  margin: 0;
  padding: 18px;
  border-radius: 16px;
  background: #FFFFFF;
  color: var(--card-text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.card h2 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 800;
}

.card .scope {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--card-muted);
}

.card p { margin: 0; }
.card a { color: var(--game-accent); }

.big-number {
  font-size: 48px;
  font-weight: 900;
  line-height: 1.1;
  color: var(--game-accent);
  font-variant-numeric: tabular-nums;
}

.emoji { font-family: var(--ws-emoji-font); }

.emoji-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 34px;
  line-height: 1.1;
}

.detail { font-size: 14px; color: var(--card-muted); }
.emoji-row + .detail, .big-number + .detail { margin-top: 6px; }
.detail + .detail { margin-top: 6px; }

.verdict { font-size: 18px; font-weight: 700; }
.verdict.is-fair { color: var(--good); }
.verdict.is-uneven { color: var(--bad); }

.chart { min-height: 200px; margin: 0 -6px; }

.table-wrap { overflow-x: auto; margin: 12px -4px 0; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.table th, .table td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid var(--card-line);
}

.table th:first-child, .table td:first-child { text-align: left; }
.table th { font-size: 12px; font-weight: 700; color: var(--card-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.table td.emoji { font-size: 22px; }
.table .pos { color: var(--good); }
.table .neg { color: var(--bad); }

.facts { margin: 0; padding: 0; list-style: none; }
.facts li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--card-line); }
.facts li:last-child { border-bottom: 0; }
.facts .fact-label { font-weight: 600; }
.facts .fact-value { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.facts .fact-value small { display: block; color: var(--card-muted); font-size: 12px; }

.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 28px;
  line-height: 1.2;
}

.empty { padding: 40px 18px; text-align: center; }
.empty p { font-size: 20px; font-weight: 700; }
.empty a { display: inline-block; margin-top: 14px; font-weight: 700; }

.notice { font-size: 15px; color: var(--card-muted); }
.error-card { color: var(--bad); font-weight: 600; }

/* ── Desktop niceties: hover states, only with a mouse ─── */

@media (hover: hover) and (pointer: fine) {
  .ws-header--shell .ws-menu-btn:hover,
  .ws-menu-close:hover,
  .ws-menu-item:hover { background: var(--ws-surface-hover); }
  .ws-menu-sub a:hover { background: var(--ws-surface-hover); color: var(--ws-text); }
  .ws-header--game .ws-menu-btn:hover,
  .sound-toggle:hover { background: rgba(var(--game-ink-rgb), 0.24); }
  .ws-site-link:hover { opacity: 1; text-decoration: underline; }

  .ws-tile { transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease; }
  .ws-tile:hover { background: var(--ws-surface-hover); transform: translateY(-3px); }

  .big-button:hover:not(:disabled) { filter: brightness(1.04); transform: translateY(-1px); }
  .range button:hover:not([aria-pressed="true"]) { background: rgba(var(--game-ink-rgb), 0.14); }
  .play-link:hover, .back-link:hover { color: var(--game-ink); }

  .card { transition: transform 120ms ease, box-shadow 120ms ease; }
  .card:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2); }
}

@media (prefers-reduced-motion: reduce) {
  .pop { animation-duration: 1ms; }
  .big-button, .card, .ws-tile { transition: none !important; }
}
