/* Shared look for every NordgrenLabs game: tokens, ambient backdrop, glass, buttons, menu, sheets, segmented control. */
:root {
  color-scheme: light dark;
  --canvas: #f2f2f7; --solid: #fff; --ink: #1d1d1f; --ink2: #6e6e73;
  --accent: #0071e3; --danger: #d70015; --good: #1d7a33; --primary: #0071e3;
  --glass: rgba(255, 255, 255, .58); --glass-strong: rgba(255, 255, 255, .8);
  --edge: rgba(255, 255, 255, .75); --hair: rgba(60, 60, 67, .14); --fill: rgba(120, 120, 128, .13);
  --thumb: #fff;
  /* Dice invert against the theme: white dice on the light glass were about 1.1:1. */
  --die: linear-gradient(145deg, #48484a, #1c1c1e); --die-edge: rgba(255, 255, 255, .14); --pip: #fff;
  --glass-menu: rgba(250, 250, 252, .92);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 12px 40px rgba(0, 0, 0, .08);
  --text: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --num: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  /* Spring with stiffness 400, damping 30 (mass 1), sampled into linear(). */
  --spring: linear(0, .068, .22, .398, .569, .715, .829, .912, .967, 1.002, 1.02, 1.027, 1.028, 1.025, 1.02, 1.015, 1.011, 1.007, 1.004, 1.002, 1, 1, 1);
  --spring-dur: .45s;
}
:root[data-theme="light"] { color-scheme: light; }
/* data-theme is set before paint by the inline script in each page's <head>; the media query covers pages without it. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #000; --solid: #1c1c1e; --ink: #f5f5f7; --ink2: #a1a1a6;
  --accent: #2997ff; --danger: #ff453a; --good: #30d158; --primary: #0a84ff;
  --glass: rgba(44, 44, 46, .55); --glass-strong: rgba(72, 72, 74, .6);
  --edge: rgba(255, 255, 255, .13); --hair: rgba(255, 255, 255, .1); --fill: rgba(120, 120, 128, .26);
  --thumb: #636366;
  --die: linear-gradient(145deg, #fff, #e6e6eb); --die-edge: rgba(0, 0, 0, .07); --pip: #1d1d1f;
  --glass-menu: rgba(20, 20, 22, .9);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 40px rgba(0, 0, 0, .5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --canvas: #000; --solid: #1c1c1e; --ink: #f5f5f7; --ink2: #a1a1a6;
    --accent: #2997ff; --danger: #ff453a; --good: #30d158; --primary: #0a84ff;
    --glass: rgba(44, 44, 46, .55); --glass-strong: rgba(72, 72, 74, .6);
    --edge: rgba(255, 255, 255, .13); --hair: rgba(255, 255, 255, .1); --fill: rgba(120, 120, 128, .26);
    --thumb: #636366;
    --die: linear-gradient(145deg, #fff, #e6e6eb); --die-edge: rgba(0, 0, 0, .07); --pip: #1d1d1f;
    --glass-menu: rgba(20, 20, 22, .9);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 40px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* iOS otherwise enlarges text when the phone turns to landscape. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--ink);
  font: 17px/1.4 var(--text); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Ambient backdrop: soft colour for the glass to bend. A page adds .live to warm it. */
body::before, body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  transition: opacity .9s ease;
}
body::before {
  background:
    radial-gradient(60vmax 50vmax at 0% 0%, rgba(0, 113, 227, .30), transparent 60%),
    radial-gradient(50vmax 45vmax at 100% 18%, rgba(175, 82, 222, .20), transparent 60%),
    radial-gradient(60vmax 50vmax at 70% 100%, rgba(48, 176, 199, .24), transparent 60%);
}
body::after {
  opacity: 0;
  background:
    radial-gradient(60vmax 50vmax at 0% 0%, rgba(255, 59, 48, .32), transparent 60%),
    radial-gradient(50vmax 45vmax at 100% 18%, rgba(255, 149, 0, .26), transparent 60%),
    radial-gradient(60vmax 50vmax at 70% 100%, rgba(255, 45, 85, .22), transparent 60%);
}
body.live::before { opacity: 0; }
body.live::after { opacity: 1; }

.app { max-width: 440px; min-height: 100dvh; margin: 0 auto; display: flex; flex-direction: column;
  padding: 0 max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
h1 { margin: 8px 0 4px; font: 700 40px/1.1 var(--num); letter-spacing: -.02em; }
h2 { margin: 0; font-size: 17px; font-weight: 600; }
.lede { margin: 0 0 24px; color: var(--ink2); }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(28px) saturate(180%); backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--edge); border-radius: 26px;
  box-shadow: var(--shadow), inset 0 1px 0 var(--edge);
}
@media (prefers-reduced-transparency: reduce) {
  .glass { background: var(--solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

button, input { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; transition: transform .12s ease, opacity .2s; }
/* Fast taps on keys and buttons must not zoom the page or select their labels. */
button, .menu .item { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:active:not(:disabled) { transform: scale(.96); }
button:disabled { opacity: .35; cursor: default; }
.btn { min-height: 44px; padding: 0 18px; border-radius: 999px; background: var(--fill); font-weight: 600; }
.btn.primary { width: 100%; min-height: 54px; background: var(--primary); color: #fff; font-size: 18px; }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

a.tile { display: block; padding: 20px; color: var(--ink); }
a.tile strong { display: block; font: 700 24px var(--num); }
a.tile span { color: var(--ink2); }
/* Account control filled by NL.account(); not(hidden) so the hidden attribute still wins. */
.account:not([hidden]) { display: grid; gap: 10px; }
.account p { margin: 0; color: var(--ink2); font-size: 15px; }

/* Menu: one glass circle fixed top right. Opened, its items slide down from behind it into a spaced column, each with a label chip.
   It floats over the score and standings, so its glass is near solid to stay readable. */
.menu { --glass: var(--glass-menu); position: fixed; z-index: 20; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 48px; height: 48px; }
.menu-trigger, .menu .item { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); }
.menu-trigger { position: relative; z-index: 1; }
.menu svg { width: 22px; height: 22px; }
.menu-trigger svg { grid-area: 1 / 1; transition: opacity .3s ease-in-out, transform .3s ease-in-out; }
.menu-trigger .x { opacity: 0; transform: rotate(-180deg) scale(0); }
.menu.open .menu-trigger .bars { opacity: 0; transform: rotate(180deg) scale(0); }
.menu.open .menu-trigger .x { opacity: 1; transform: none; }
.menu .item { position: absolute; top: 0; right: 0; opacity: 0; visibility: hidden;
  transition: transform .3s cubic-bezier(.4, 0, .2, 1), opacity .3s cubic-bezier(.4, 0, .2, 1), visibility 0s .3s; }
.menu.open .item { transform: translateY(calc(var(--i) * 58px)); opacity: 1; visibility: visible; transition-delay: 0s; }
.menu .item span { position: absolute; top: 50%; right: calc(100% + 8px); translate: 8px -50%; padding: 6px 12px; border-radius: 999px;
  font-size: 15px; font-weight: 600; white-space: nowrap; transition: translate .3s cubic-bezier(.4, 0, .2, 1); }
.menu.open .item span { translate: 0 -50%; }
.menu .item:disabled svg, .menu .item:disabled span { opacity: .35; }

/* Sheets: a native <dialog> opened with showModal(); the inner div carries the padding so a click on the dialog itself is a backdrop click. */
dialog.sheet { width: min(100% - 24px, 408px); max-width: none; margin: auto auto max(12px, env(safe-area-inset-bottom)); padding: 0; color: var(--ink);
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom))); overflow: auto; overscroll-behavior: contain; }
dialog.sheet > div { padding: 22px 18px 18px; display: grid; gap: 10px; }
dialog.sheet h2 { font-size: 20px; }
dialog.sheet h3 { margin: 10px 0 0; font-size: 15px; font-weight: 600; color: var(--ink2); }
dialog.sheet p { margin: 0 0 6px; color: var(--ink2); font-size: 15px; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .3); }
dialog.sheet[open] { animation: sheet-in var(--spring-dur) var(--spring); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

/* Segmented control: a role=group of <button aria-pressed>; NL.segmented() sets --n and --i so the thumb springs to the chosen one. */
.segmented { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--fill); border-radius: 12px; padding: 3px; }
.segmented::before { content: ""; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / var(--n, 2)); transform: translateX(calc(100% * var(--i, 0)));
  border-radius: 9px; background: var(--thumb); box-shadow: 0 1px 4px rgba(0, 0, 0, .14); transition: transform var(--spring-dur) var(--spring); }
.segmented button { position: relative; min-height: 44px; padding: 0 6px; font-size: 15px; font-weight: 600; border-radius: 9px; }
.segmented button:active { transform: none; }

/* Sun/moon icon showing the resolved theme: rays draw out, the disc shrinks, the moon grows in. */
.theme-icon { flex: none; color: var(--ink2); }
.theme-icon line { stroke-dasharray: 1; stroke-dashoffset: 0; transition: stroke-dashoffset .7s ease-in-out, opacity .7s ease-in-out; }
.theme-icon circle, .theme-icon path { transform-box: view-box; transform-origin: 12px 12px; transition: transform .7s ease-in-out, opacity .7s ease-in-out; }
.theme-icon path { transform: scale(0); opacity: 0; }
:root[data-theme="dark"] .theme-icon line { stroke-dashoffset: 1; opacity: 0; }
:root[data-theme="dark"] .theme-icon circle { transform: scale(0); }
:root[data-theme="dark"] .theme-icon path { transform: scale(1); opacity: 1; }

@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation: none !important; transition: none !important; } }
