/* Jigglygames core: tokens, reset, type, shared chrome. See DESIGN.md. */

:root {
  color-scheme: light;
  --ground: #E9ECF3;
  --surface: #FFFFFF;
  --surface-hover: #E4E8F5;
  --ink: #1D2333;
  --ink-2: #5B6478;
  --line: #CFD4E0;
  --brand: #2851E3;
  --brand-ink: #1B3AA8;
  --brand-hover: #3D63F5;
  --on-brand: #FFFFFF;
  --pill: rgba(29,35,51,.07);
  --backdrop: rgba(29,35,51,.45);
  --walnut: #7A4A22;
  --walnut-dark: #5A3416;
  --walnut-light: #A06A38;
  --brass: #E3A93B;
  --charcoal: #2B2E35;
  --signal: #FF3A2D;
  --lit-glow: #FFB199;
  --field: #173B2A;
  --bone: #EFE9DC;
  --ok: #1F9D55;

  --font-display: 'Titan One', 'Arial Black', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;

  --radius-pill: 999px;
  --radius-toy: 28px;
  --shadow-lift: 0 1px 0 rgba(255,255,255,.6) inset, 0 6px 14px -6px rgba(29,35,51,.35);

  --measure: 65ch;
  --gutter: clamp(16px, 4vw, 40px);
}

/* Dark chrome. The toys keep their materials; only the table changes.
   The media block follows the system unless the toggle chose light;
   the attribute block is the toggle choosing dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --ground: #14161C;
  --surface: #1F232C;
  --surface-hover: #2E3442;
  --ink: #E8EAF0;
  --ink-2: #9AA3B5;
  --line: #343A47;
  --brand: #6C8CFF;
  --brand-ink: #3E5BC9;
  --brand-hover: #82A0FF;
  --on-brand: #14161C;
  --pill: rgba(232,234,240,.08);
  --backdrop: rgba(0,0,0,.6);
  --ok: #3FBF78;
  color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #14161C;
  --surface: #1F232C;
  --surface-hover: #2E3442;
  --ink: #E8EAF0;
  --ink-2: #9AA3B5;
  --line: #343A47;
  --brand: #6C8CFF;
  --brand-ink: #3E5BC9;
  --brand-hover: #82A0FF;
  --on-brand: #14161C;
  --pill: rgba(232,234,240,.08);
  --backdrop: rgba(0,0,0,.6);
  --ok: #3FBF78;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
@media (min-width: 640px) { body { font-size: 17px; } }

img, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
a { color: var(--brand); }
p { max-width: var(--measure); margin: 0 0 1em; }
h1, h2, h3 { margin: 0; line-height: 1.1; }

:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 3px;
  border-radius: 6px;
}

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

/* ---- Layout ---- */
.wrap {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding-inline: var(--gutter);
}

/* ---- Site header (injected by ui.js) ---- */
.site-header {
  padding-block: 18px 6px;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.wordmark {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
  display: inline-flex;
  line-height: 1;
}
.wordmark span {
  display: inline-block;
  transform: rotate(var(--tilt, 0deg)) translateY(var(--dip, 0));
  transition: transform .18s cubic-bezier(.34,1.56,.64,1);
}
.wordmark span:nth-child(odd)  { --tilt: -5deg; --dip: 2px; }
.wordmark span:nth-child(even) { --tilt: 5deg;  --dip: -2px; }
.wordmark span:nth-child(3n)   { --tilt: -2deg; --dip: 0px; }
.wordmark:hover span { animation: jiggle .5s ease-in-out infinite alternate; }
.wordmark span:nth-child(even) { animation-delay: -.25s; }
@keyframes jiggle {
  from { transform: rotate(-5deg) translateY(1px); }
  to   { transform: rotate(5deg) translateY(-2px); }
}

.header-actions { display: flex; gap: 10px; }

/* ---- Buttons: everything pressable looks pressable ---- */
.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 15px;
  background: var(--surface);
  color: var(--ink);
  box-shadow:
    0 1px 0 rgba(255,255,255,.7) inset,
    0 3px 0 var(--line),
    0 8px 16px -8px rgba(29,35,51,.4);
  transform: translateY(0);
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease;
  text-decoration: none;
}
.btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255,255,255,.7) inset,
    0 4px 0 var(--line),
    0 12px 20px -8px rgba(29,35,51,.5);
}
.btn:active, .btn[aria-pressed="true"] {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 0 0 var(--line), 0 2px 6px -4px rgba(29,35,51,.4);
}
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
  box-shadow:
    0 1px 0 rgba(255,255,255,.25) inset,
    0 3px 0 var(--brand-ink),
    0 8px 16px -8px rgba(40,81,227,.6);
}
.btn-primary:hover {
  background: var(--brand-hover);
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255,255,255,.25) inset,
    0 4px 0 var(--brand-ink),
    0 12px 20px -8px rgba(40,81,227,.7);
}
.btn-primary:active { box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 0 0 var(--brand-ink); }
.btn-icon { padding: 0; width: 44px; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-icon.btn-sm { width: 36px; padding: 0; }
.btn-icon svg { width: 18px; height: 18px; fill: currentColor; }

/* ---- Mode switch: two pressable tabs, the chosen one filled ---- */
.modes {
  display: inline-flex;
  gap: 6px;
  padding: 5px;
  background: var(--pill);
  border-radius: var(--radius-pill);
  margin: 18px 0 8px;
}
.modes .btn { min-height: 38px; box-shadow: none; background: transparent; color: var(--ink-2); font-weight: 600; }
.modes .btn:hover { color: var(--ink); background: var(--surface-hover); }
.modes .btn[aria-selected="true"] {
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: 0 2px 8px -2px rgba(40,81,227,.5);
}
.modes .btn[aria-selected="true"]:hover { background: var(--brand-hover); color: var(--on-brand); }

/* ---- Modal ---- */
.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(92vw, 440px);
  width: 100%;
}
.modal::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.modal-panel {
  background: var(--surface);
  border-radius: 24px;
  padding: 28px 28px 24px;
  box-shadow: 0 30px 60px -20px rgba(29,35,51,.5);
}
.modal h2 {
  font-family: var(--font-display);
  font-size: 28px;
  margin-bottom: 8px;
}
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.modal[open] .modal-panel { animation: pop .22s cubic-bezier(.34,1.56,.64,1); }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Stats grid ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0 4px;
}
.stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1;
}
.stat span { font-size: 13px; color: var(--ink-2); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--ground);
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: transform .2s ease, opacity .2s ease;
  z-index: 50;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---- Motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .wordmark span { transform: none; }
}

.stats-note { color: var(--ink-2); margin: 0; }
