/* ==========================================================================
   Moonhowl — base design system (CSS worker)
   Moonlit folk-tale village. Themes are game-driven via body[data-theme].
   Logical properties only (RTL-safe). No external fonts (CSP style-src 'self').
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
/* Registered so the sky gradient itself can transition between themes */
@property --sky-top { syntax: "<color>"; inherits: true; initial-value: #050818; }
@property --sky { syntax: "<color>"; inherits: true; initial-value: #0b1130; }
@property --horizon { syntax: "<color>"; inherits: true; initial-value: #18224f; }

:root {
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial,
    "Noto Sans Devanagari", "Nirmala UI", "Mangal", "Noto Sans Bengali", "Vrinda",
    "Noto Naskh Arabic", "Noto Sans Arabic", "Segoe UI Arabic", "Geeza Pro", "Tahoma",
    "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L",
    P052, "Hoefler Text", Georgia, "Noto Serif", "Noto Serif Devanagari", "Noto Serif Bengali",
    "Noto Naskh Arabic", "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;

  /* fluid type scale (360px → 1200px) */
  --fs-xs: clamp(0.75rem, 0.72rem + 0.12vw, 0.8125rem);
  --fs-sm: clamp(0.84rem, 0.8rem + 0.18vw, 0.9375rem);
  --fs-md: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --fs-lg: clamp(1.15rem, 1.05rem + 0.45vw, 1.375rem);
  --fs-xl: clamp(1.4rem, 1.2rem + 1vw, 1.875rem);
  --fs-2xl: clamp(1.8rem, 1.3rem + 2.4vw, 2.85rem);
  --fs-narr: clamp(1.85rem, 1.1rem + 4.6vw, 3.75rem);

  --lh: 1.6;
  --track: 0.02em;          /* letter-spacing for display text; 0 for joined scripts */
  --track-caps: 0.08em;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --r-pill: 999px;

  --gap: 1rem;
  --tap: 44px;
  --ease: cubic-bezier(0.22, 0.8, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
  --theme-dur: 600ms;

  --orb-size: clamp(46px, 9vw, 96px);
}

/* Night (default) */
:root,
body,
body[data-theme="night"],
.theme-night {
  --sky-top: #050818;
  --sky: #0b1130;
  --horizon: #19235a;
  --text: #e9edfb;
  --text-soft: #c5cdec;
  --muted: #a3aed6;
  --title: #f5f1e4;
  --title-glow: rgba(196, 214, 255, 0.35);

  --surface: rgba(19, 27, 62, 0.74);
  --surface-2: rgba(33, 45, 96, 0.55);
  --surface-solid: #131b3d;
  --surface-bar: rgba(8, 12, 34, 0.72);
  --input-bg: rgba(5, 9, 28, 0.6);
  --line: rgba(160, 182, 255, 0.2);
  --line-strong: rgba(160, 182, 255, 0.38);
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.7), 0 2px 6px -2px rgba(0, 0, 0, 0.5);

  --accent: #8fb8ff;
  --accent-2: #b9d2ff;
  --on-accent: #0a1030;
  --accent-ink: #a5c6ff;
  --accent-soft: rgba(143, 184, 255, 0.17);
  --glow: rgba(143, 184, 255, 0.45);
  --focus: #ffd98a;
  --track-off: rgba(160, 182, 255, 0.28);

  --wolves: #e5484d;
  --danger: #cc3340;
  --wolves-ink: #ff9196;
  --village: #2fae84;
  --village-ink: #73e2b8;
  --neutral: #9b6cf0;
  --neutral-ink: #cbb0ff;

  --night-o: 1;
  --day-o: 0;
  --orb: #e4e9fb;
  --orb-glow: 0 0 40px 10px rgba(200, 216, 255, 0.35), 0 0 120px 40px rgba(120, 150, 255, 0.18);
  --orb-y: calc(env(safe-area-inset-top, 0px) + 14px);
  --hills: #04071a;
  --scroll: rgba(160, 182, 255, 0.35);
  --backdrop: rgba(3, 5, 18, 0.7);
  color-scheme: dark;
}

body[data-theme="day"],
.theme-day {
  --sky-top: #fbf0d8;
  --sky: #f4e2bd;
  --horizon: #ebcf9c;
  --text: #2a1c0c;
  --text-soft: #4a3520;
  --muted: #69502f;
  --title: #3a220d;
  --title-glow: rgba(255, 214, 140, 0.55);

  --surface: rgba(255, 251, 240, 0.84);
  --surface-2: rgba(250, 236, 206, 0.8);
  --surface-solid: #fffaf0;
  --surface-bar: rgba(255, 247, 228, 0.8);
  --input-bg: rgba(255, 255, 250, 0.85);
  --line: rgba(110, 72, 28, 0.22);
  --line-strong: rgba(110, 72, 28, 0.42);
  --shadow: 0 10px 28px -14px rgba(120, 72, 20, 0.45), 0 2px 6px -2px rgba(120, 72, 20, 0.2);

  --accent: #a24c09;
  --accent-2: #b3570c;
  --on-accent: #fffaf0;
  --accent-ink: #8f4208;
  --accent-soft: rgba(194, 98, 15, 0.14);
  --glow: rgba(230, 150, 40, 0.45);
  --focus: #1d4ed8;
  --track-off: rgba(110, 72, 28, 0.3);

  --wolves: #b4232f;
  --danger: #a51f2b;
  --wolves-ink: #9c1c27;
  --village: #2b7a58;
  --village-ink: #1d6145;
  --neutral: #7445c9;
  --neutral-ink: #5e34a6;

  --night-o: 0;
  --day-o: 1;
  --orb: #ffd77a;
  --orb-glow: 0 0 50px 18px rgba(255, 200, 90, 0.55), 0 0 160px 70px rgba(255, 180, 70, 0.25);
  --orb-y: calc(env(safe-area-inset-top, 0px) + 6px);
  --hills: #dcc290;
  --scroll: rgba(110, 72, 28, 0.35);
  --backdrop: rgba(60, 36, 10, 0.45);
  color-scheme: light;
}

body[data-theme="dusk"],
.theme-dusk {
  --sky-top: #1a1236;
  --sky: #3a2155;
  --horizon: #8e4468;
  --text: #f8edf5;
  --text-soft: #e6d2e4;
  --muted: #d4bcd6;
  --title: #ffe8d4;
  --title-glow: rgba(255, 170, 150, 0.4);

  --surface: rgba(52, 30, 76, 0.74);
  --surface-2: rgba(84, 46, 104, 0.55);
  --surface-solid: #36204f;
  --surface-bar: rgba(34, 18, 52, 0.72);
  --input-bg: rgba(24, 10, 38, 0.55);
  --line: rgba(255, 190, 220, 0.2);
  --line-strong: rgba(255, 190, 220, 0.4);
  --shadow: 0 10px 30px -12px rgba(10, 0, 20, 0.7), 0 2px 6px -2px rgba(10, 0, 20, 0.5);

  --accent: #ffa9bf;
  --accent-2: #ffc9a8;
  --on-accent: #2a0d22;
  --accent-ink: #ffbacb;
  --accent-soft: rgba(255, 169, 191, 0.17);
  --glow: rgba(255, 150, 175, 0.45);
  --focus: #ffe38f;
  --track-off: rgba(255, 190, 220, 0.3);

  --wolves: #f05a6a;
  --danger: #d0364a;
  --wolves-ink: #ffa5ae;
  --village: #3fbf95;
  --village-ink: #8ae9c5;
  --neutral: #b083ff;
  --neutral-ink: #ddc8ff;

  --night-o: 0.4;
  --day-o: 0;
  --orb: #ffae7e;
  --orb-glow: 0 0 46px 16px rgba(255, 140, 110, 0.5), 0 0 150px 60px rgba(255, 110, 140, 0.25);
  --orb-y: calc(100vh - 13vh);
  --hills: #1a0e2c;
  --scroll: rgba(255, 190, 220, 0.35);
  --backdrop: rgba(18, 6, 30, 0.7);
  color-scheme: dark;
}

/* Joined / stacked scripts: no letter-spacing, roomier lines */
:root:lang(ar), :root:lang(ur), :root:lang(hi), :root:lang(bn), :root:lang(zh) {
  --track: 0;
  --track-caps: 0;
}
:root:lang(ar), :root:lang(ur), :root:lang(hi), :root:lang(bn) { --lh: 1.75; }
:root:lang(ur) { --lh: 1.9; }

/* --------------------------------------------------------------------------
   2. Reset & base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll) transparent;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: var(--r-pill); }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: var(--lh);
  color: var(--text);
  background-color: var(--sky);
  background-image: linear-gradient(180deg, var(--sky-top) 0%, var(--sky) 50%, var(--horizon) 100%);
  background-attachment: fixed;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color var(--theme-dur) ease, color var(--theme-dur) ease,
    --sky-top var(--theme-dur) ease, --sky var(--theme-dur) ease, --horizon var(--theme-dur) ease;
}

:where(h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ul, ol) { margin: 0; }
:where(p + p) { margin-block-start: 0.75em; }
:where(ul, ol) { padding-inline-start: 1.25rem; }
:where(h1, h2, h3, h4) {
  font-family: var(--font-display);
  line-height: 1.25;
  color: var(--title);
  text-wrap: balance;
}
:where(img, svg, video, canvas) { display: block; max-width: 100%; }
:where(button, input, select, textarea) { font: inherit; color: inherit; letter-spacing: inherit; }
:where(button) { cursor: pointer; }
:where(a) {
  color: var(--accent-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
:where(a:hover) { text-decoration-thickness: 2px; }
hr { border: 0; block-size: 1px; background: var(--line); margin-block: 1rem; }
[hidden] { display: none !important; }

::selection { background: var(--accent); color: var(--on-accent); }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* --------------------------------------------------------------------------
   3. Sky: night layer, day layer, moon/sun orb, hills silhouette
   -------------------------------------------------------------------------- */
body::before,
body::after,
.app::before,
.app::after {
  content: "";
  position: fixed;
  pointer-events: none;
}

/* Night sky + starfield */
body::before {
  inset: 0;
  z-index: -4;
  opacity: var(--night-o);
  transition: opacity var(--theme-dur) ease;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255, 255, 255, 0.9), transparent 60%),
    radial-gradient(1.5px 1.5px at 72% 9%, rgba(255, 255, 255, 0.95), transparent 60%),
    radial-gradient(1px 1px at 38% 42%, rgba(220, 230, 255, 0.8), transparent 60%),
    radial-gradient(2px 2px at 88% 33%, rgba(255, 255, 255, 0.85), transparent 60%),
    radial-gradient(1px 1px at 55% 26%, rgba(200, 215, 255, 0.75), transparent 60%),
    radial-gradient(1px 1px at 22% 61%, rgba(255, 255, 255, 0.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 64% 57%, rgba(230, 236, 255, 0.7), transparent 60%),
    radial-gradient(1px 1px at 93% 71%, rgba(255, 255, 255, 0.5), transparent 60%),
    radial-gradient(ellipse 70% 40% at 50% 100%, rgba(70, 100, 200, 0.28), transparent 70%),
    radial-gradient(ellipse 120% 60% at 30% 0%, rgba(40, 60, 140, 0.35), transparent 70%);
  background-size:
    230px 230px, 310px 310px, 190px 190px, 420px 420px, 270px 270px, 350px 350px, 240px 240px,
    380px 380px, 100% 100%, 100% 100%;
  background-repeat: repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
    no-repeat, no-repeat;
}

/* Day sky: warm sunlight, parchment haze */
body::after {
  inset: 0;
  z-index: -3;
  opacity: var(--day-o);
  transition: opacity var(--theme-dur) ease;
  background-image:
    radial-gradient(ellipse 80% 55% at 85% 0%, rgba(255, 214, 130, 0.65), transparent 70%),
    radial-gradient(ellipse 90% 50% at 10% 100%, rgba(232, 160, 90, 0.28), transparent 70%),
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.4), transparent 40%);
}

/* Moon (night) → low rose sun (dusk) → golden sun (day) */
.app::before {
  z-index: -2;
  inline-size: var(--orb-size);
  block-size: var(--orb-size);
  inset-block-start: var(--orb-y);
  inset-inline-end: clamp(12px, 5vw, 96px);
  border-radius: 50%;
  background-color: var(--orb);
  background-image:
    radial-gradient(circle at 34% 32%, rgba(255, 255, 255, 0.75), transparent 46%),
    radial-gradient(circle at 64% 60%, rgba(0, 0, 30, 0.07) 0 12%, transparent 13%),
    radial-gradient(circle at 40% 70%, rgba(0, 0, 30, 0.06) 0 8%, transparent 9%),
    radial-gradient(circle at 72% 34%, rgba(0, 0, 30, 0.05) 0 7%, transparent 8%);
  box-shadow: var(--orb-glow);
  transition: background-color var(--theme-dur) ease, box-shadow var(--theme-dur) ease,
    inset-block-start 1200ms var(--ease);
  animation: mh-orb 6s ease-in-out infinite alternate;
}

/* Rolling hills and a pine treeline, painted with a mask so the colour can transition */
.app::after {
  z-index: -1;
  inset-inline: 0;
  inset-block-end: 0;
  block-size: clamp(90px, 17vh, 190px);
  background-color: var(--hills);
  transition: background-color var(--theme-dur) ease;
  opacity: 0.92;
  --hill-mask:
    linear-gradient(#000, #000),
    radial-gradient(ellipse 38% 60% at 16% 100%, #000 98%, transparent 100%),
    radial-gradient(ellipse 30% 46% at 58% 100%, #000 98%, transparent 100%),
    radial-gradient(ellipse 34% 55% at 93% 100%, #000 98%, transparent 100%),
    conic-gradient(from 165deg at 50% 0%, #000 30deg, transparent 0),
    conic-gradient(from 164deg at 50% 0%, #000 32deg, transparent 0),
    conic-gradient(from 166deg at 50% 0%, #000 28deg, transparent 0);
  -webkit-mask-image: var(--hill-mask);
  mask-image: var(--hill-mask);
  -webkit-mask-size: 100% 31%, 100% 100%, 100% 100%, 100% 100%, 34px 62px, 23px 40px, 47px 78px;
  mask-size: 100% 31%, 100% 100%, 100% 100%, 100% 100%, 34px 62px, 23px 40px, 47px 78px;
  -webkit-mask-position: 0 100%, 0 0, 0 0, 0 0, left 0 bottom 30%, left 11px bottom 42%, left 20px bottom 20%;
  mask-position: 0 100%, 0 0, 0 0, 0 0, left 0 bottom 30%, left 11px bottom 42%, left 20px bottom 20%;
  -webkit-mask-repeat: no-repeat, no-repeat, no-repeat, no-repeat, repeat-x, repeat-x, repeat-x;
  mask-repeat: no-repeat, no-repeat, no-repeat, no-repeat, repeat-x, repeat-x, repeat-x;
}

/* Theme preview wrappers (styleguide): same tokens on a section */
.theme-night,
.theme-day,
.theme-dusk {
  color: var(--text);
  background-color: var(--sky);
  font-family: var(--font-body);
  line-height: var(--lh);
}
.theme-night,
.theme-day,
.theme-dusk {
  background-image: linear-gradient(180deg, var(--sky-top) 0%, var(--sky) 50%, var(--horizon) 100%);
}
.theme-night {
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255, 255, 255, 0.9), transparent 60%),
    radial-gradient(1.5px 1.5px at 72% 9%, rgba(255, 255, 255, 0.95), transparent 60%),
    radial-gradient(1px 1px at 38% 42%, rgba(220, 230, 255, 0.8), transparent 60%),
    radial-gradient(2px 2px at 88% 33%, rgba(255, 255, 255, 0.85), transparent 60%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky) 50%, var(--horizon) 100%);
  background-size: 230px 230px, 310px 310px, 190px 190px, 420px 420px, 100% 100%;
}

/* --------------------------------------------------------------------------
   4. Layout
   -------------------------------------------------------------------------- */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-block-size: 56px;
  padding-block: calc(0.4rem + env(safe-area-inset-top, 0px)) 0.4rem;
  padding-inline: max(1rem, calc((100% - 760px) / 2 + 1rem), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  background: var(--surface-bar);
  border-block-end: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  transition: background-color var(--theme-dur) ease, border-color var(--theme-dur) ease;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-block-size: var(--tap);
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: var(--track);
  color: var(--title);
  text-decoration: none;
  text-shadow: 0 0 18px var(--title-glow);
  white-space: nowrap;
}
a.brand:hover { text-decoration: none; }

.container {
  inline-size: 100%;
  max-inline-size: 760px;
  margin-inline: auto;
  padding-inline: max(1rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  padding-block: 1.25rem calc(2.5rem + env(safe-area-inset-bottom, 0px));
  flex: 1 0 auto;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  animation: mh-rise 420ms var(--ease) both;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.stack > * { margin-block: 0; }

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}
.row > .input { flex: 1 1 10rem; min-inline-size: 0; inline-size: auto; }

.spacer { flex: 1 1 auto; }

.center { text-align: center; justify-content: center; align-items: center; margin-inline: auto; }
.stack.center { align-items: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: var(--gap);
}

/* --------------------------------------------------------------------------
   5. Text
   -------------------------------------------------------------------------- */
.title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: var(--track);
  color: var(--title);
  text-shadow: 0 0 24px var(--title-glow);
  text-wrap: balance;
  margin: 0;
}
.subtitle {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-soft);
  text-wrap: balance;
  margin: 0;
}
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.big { font-size: var(--fs-xl); line-height: 1.35; }

.narration {
  font-family: var(--font-display);
  font-size: var(--fs-narr);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: var(--track);
  text-align: center;
  text-wrap: balance;
  color: var(--title);
  text-shadow: 0 0 30px var(--title-glow), 0 2px 12px rgba(0, 0, 0, 0.25);
  max-inline-size: 20ch;
  margin-inline: auto;
  padding-block: clamp(1.5rem, 6vh, 4rem);
  overflow-wrap: anywhere;
  animation: mh-fade 900ms var(--ease) both;
}

/* --------------------------------------------------------------------------
   6. Surfaces
   -------------------------------------------------------------------------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: clamp(1rem, 0.8rem + 1.2vw, 1.5rem);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background-color var(--theme-dur) ease, border-color var(--theme-dur) ease,
    box-shadow var(--theme-dur) ease;
}
.card.glow {
  border-color: var(--line-strong);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-soft), 0 0 36px -6px var(--glow);
  animation: mh-glow 5s ease-in-out infinite alternate;
}

.panel {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 0.9rem 1rem;
  transition: background-color var(--theme-dur) ease, border-color var(--theme-dur) ease;
}

.banner {
  --b: var(--accent);
  --b-ink: var(--accent-ink);
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--b) 35%, transparent);
  border-inline-start: 4px solid var(--b);
  background-color: var(--surface);
  background-image: linear-gradient(color-mix(in srgb, var(--b) 14%, transparent), color-mix(in srgb, var(--b) 14%, transparent));
  color: var(--text);
  animation: mh-fade 300ms var(--ease) both;
}
.banner.danger { --b: var(--wolves); --b-ink: var(--wolves-ink); }
.banner.success { --b: var(--village); --b-ink: var(--village-ink); }
.banner.info { --b: var(--accent); --b-ink: var(--accent-ink); }
.banner strong, .banner b { color: var(--b-ink); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.12rem 0.6rem;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--team-ink);
  background: color-mix(in srgb, var(--team) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--team) 45%, transparent);
}
:where(.badge, .role-card, .role-option) { --team: var(--accent); --team-ink: var(--accent-ink); }
.badge.wolves, [data-team="wolves"] { --team: var(--wolves); --team-ink: var(--wolves-ink); }
.badge.village, [data-team="village"] { --team: var(--village); --team-ink: var(--village-ink); }
.badge.neutral, [data-team="neutral"] { --team: var(--neutral); --team-ink: var(--neutral-ink); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-block-size: 2.25rem;
  padding: 0.25rem 0.8rem;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
button.chip { min-block-size: var(--tap); }
button.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip.is-active, button.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* --------------------------------------------------------------------------
   7. Controls
   -------------------------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-line: var(--line-strong);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-block-size: 48px;
  min-inline-size: var(--tap);
  padding: 0.6rem 1.15rem;
  border: 1px solid var(--btn-line);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 650;
  font-size: var(--fs-md);
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease,
    box-shadow 200ms ease, transform 120ms var(--ease), filter 180ms ease;
}
.btn:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: var(--r-md); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  filter: saturate(0.4);
}

.btn.primary {
  --btn-fg: var(--on-accent);
  --btn-line: transparent;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  background-color: var(--accent);
  box-shadow: 0 6px 18px -8px var(--glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn.primary:hover { filter: brightness(1.06); box-shadow: 0 8px 26px -8px var(--glow), 0 0 0 3px var(--accent-soft); }

.btn.ghost {
  --btn-bg: transparent;
  --btn-line: transparent;
  --btn-fg: var(--text-soft);
}
.btn.ghost:hover { --btn-bg: var(--accent-soft); --btn-fg: var(--text); box-shadow: none; border-color: transparent; }

.btn.danger {
  --btn-bg: var(--danger);
  --btn-fg: #fff;
  --btn-line: transparent;
  box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--wolves) 70%, transparent);
}
.btn.danger:hover { filter: brightness(1.08); box-shadow: 0 0 0 3px color-mix(in srgb, var(--wolves) 30%, transparent); }

.btn.block { display: flex; inline-size: 100%; }
.btn.big {
  min-block-size: 58px;
  padding: 0.85rem 1.5rem;
  font-size: var(--fs-lg);
  border-radius: var(--r-lg);
}
.btn.icon {
  inline-size: var(--tap);
  block-size: var(--tap);
  min-block-size: var(--tap);
  padding: 0;
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
}
.btn.icon.big { inline-size: 56px; block-size: 56px; font-size: 1.5rem; }

.input {
  display: block;
  inline-size: 100%;
  min-block-size: 48px;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--input-bg);
  color: var(--text);
  font-size: max(16px, var(--fs-md)); /* avoids iOS zoom */
  line-height: 1.4;
  transition: border-color 180ms ease, box-shadow 180ms ease, background-color var(--theme-dur) ease;
}
.input::placeholder { color: var(--muted); opacity: 0.85; }
.input:hover { border-color: var(--accent); }
.input:focus-visible, .input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}
.input:disabled { opacity: 0.55; cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--wolves); }
textarea.input { min-block-size: 6rem; resize: vertical; }

select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-inline-end: 2.5rem;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 1.15rem center, right 0.8rem center;
  background-size: 0.36rem 0.36rem, 0.36rem 0.36rem;
  background-repeat: no-repeat;
}
[dir="rtl"] select.input { background-position: left 0.8rem center, left 1.15rem center; }
select.input option { background: var(--surface-solid); color: var(--text); }

.field {
  display: grid;
  gap: 0.35rem;
}
.field > label, .field > .field-label, .field > span:first-child {
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--text-soft);
}
.field small, .field .small { color: var(--muted); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-block-size: var(--tap);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  inline-size: 3.1rem;
  block-size: 1.8rem;
  margin: 0;
  border-radius: var(--r-pill);
  background: var(--track-off);
  border: 1px solid var(--line-strong);
  cursor: pointer;
  transition: background-color 220ms ease, border-color 220ms ease;
}
.toggle input[type="checkbox"]::before {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 3px;
  inline-size: 1.35rem;
  block-size: 1.35rem;
  margin-block-start: -0.675rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: inset-inline-start 240ms var(--ease-spring);
}
.toggle input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle input[type="checkbox"]:checked::before { inset-inline-start: calc(100% - 1.35rem - 3px); }
.toggle input[type="checkbox"]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.toggle input[type="checkbox"]:disabled { opacity: 0.5; cursor: not-allowed; }
.toggle:has(input:disabled) { cursor: not-allowed; opacity: 0.7; }

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--input-bg);
}
.stepper > button {
  display: inline-grid;
  place-items: center;
  inline-size: var(--tap);
  block-size: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
  transition: background-color 160ms ease, transform 120ms var(--ease);
}
.stepper > button:hover { background: var(--accent-soft); }
.stepper > button:active { transform: scale(0.9); }
.stepper > button:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.stepper > :not(button) {
  min-inline-size: 2.4ch;
  padding-inline: 0.25rem;
  text-align: center;
  font-weight: 700;
  font-size: var(--fs-lg);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   8. Players
   -------------------------------------------------------------------------- */
.players {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr));
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.player {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.3rem;
  inline-size: 100%;
  min-block-size: var(--tap);
  padding: 0.8rem 0.45rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  text-align: center;
  font: inherit;
  box-shadow: var(--shadow);
  transition: transform 180ms var(--ease), border-color 180ms ease, box-shadow 220ms ease,
    background-color var(--theme-dur) ease, opacity 300ms ease, filter 300ms ease;
}
button.player { cursor: pointer; }
button.player:hover { border-color: var(--line-strong); transform: translateY(-1px); }
button.player:active { transform: scale(0.96); }

.player-avatar {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: 3.2rem;
  block-size: 3.2rem;
  border-radius: 50%;
  font-size: 1.85rem;
  line-height: 1;
  background: radial-gradient(circle at 35% 30%, var(--accent-soft), transparent 70%), var(--surface-2);
  border: 1px solid var(--line);
}
.player-name {
  max-inline-size: 100%;
  font-weight: 650;
  font-size: var(--fs-sm);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-meta {
  max-inline-size: 100%;
  font-size: var(--fs-xs);
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.player-votes {
  position: absolute;
  inset-block-start: -0.45rem;
  inset-inline-end: -0.35rem;
  display: inline-grid;
  place-items: center;
  min-inline-size: 1.7rem;
  block-size: 1.7rem;
  padding-inline: 0.4rem;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--sky), 0 4px 10px -2px rgba(0, 0, 0, 0.45);
  animation: mh-pop 260ms var(--ease-spring) both;
}
.player-votes:empty { display: none; }

.player.is-me {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  background-image: linear-gradient(180deg, var(--accent-soft), transparent 70%);
}
.player.is-me .player-name { color: var(--accent-ink); }

.player.is-host::before {
  content: "\1F451";
  position: absolute;
  inset-block-start: -0.55rem;
  inset-inline-start: 0.3rem;
  font-size: 1.15rem;
  line-height: 1;
  transform: rotate(-14deg);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}
[dir="rtl"] .player.is-host::before { transform: rotate(14deg); }

.player.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent), 0 0 26px 2px var(--glow);
  transform: translateY(-2px);
}
.player.is-selected .player-avatar { border-color: var(--accent); }

.player.is-dead {
  filter: grayscale(1);
  opacity: 0.55;
  border-style: dashed;
  box-shadow: none;
  background: transparent;
}
.player.is-dead .player-avatar { opacity: 0.7; }
.player.is-dead .player-avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, transparent 46%, var(--muted) 47% 53%, transparent 54%);
}
.player.is-dead .player-name {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  color: var(--muted);
}

.player.is-offline { opacity: 0.6; }
.player.is-offline .player-avatar::before {
  content: "";
  position: absolute;
  inset-block-end: 0;
  inset-inline-end: 0;
  inline-size: 0.8rem;
  block-size: 0.8rem;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 2px var(--surface-solid);
}

.player.is-disabled,
.player:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.player.is-dead.is-disabled { opacity: 0.4; }

/* --------------------------------------------------------------------------
   9. Roles
   -------------------------------------------------------------------------- */
.role-card {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 0.5rem;
  max-inline-size: 26rem;
  inline-size: 100%;
  margin-inline: auto;
  padding: clamp(1.5rem, 1rem + 3vw, 2.25rem) clamp(1.1rem, 0.8rem + 2vw, 1.75rem);
  text-align: center;
  color: var(--text);
  border: 2px solid color-mix(in srgb, var(--team) 60%, transparent);
  border-radius: var(--r-xl);
  background-color: var(--surface-solid);
  background-image:
    radial-gradient(ellipse 90% 55% at 50% 0%, color-mix(in srgb, var(--team) 30%, transparent), transparent 70%),
    linear-gradient(180deg, transparent, color-mix(in srgb, var(--team) 10%, transparent));
  box-shadow: var(--shadow), 0 0 44px -10px color-mix(in srgb, var(--team) 70%, transparent);
  transform-origin: 50% 60%;
  animation: mh-flip 760ms var(--ease) both;
  isolation: isolate;
}
/* folk-card inner frame */
.role-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  z-index: -1;
  border: 1px dashed color-mix(in srgb, var(--team) 45%, transparent);
  border-radius: calc(var(--r-xl) - 7px);
  pointer-events: none;
}
.role-icon {
  font-size: clamp(4rem, 3rem + 10vw, 6.5rem);
  line-height: 1.1;
  filter: drop-shadow(0 6px 18px color-mix(in srgb, var(--team) 65%, transparent));
  animation: mh-float 4.5s ease-in-out 800ms infinite alternate;
}
.role-name {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: var(--track);
  color: var(--title);
  text-shadow: 0 0 22px color-mix(in srgb, var(--team) 55%, transparent);
}
.role-team {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.75rem;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--team-ink);
  background: color-mix(in srgb, var(--team) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--team) 45%, transparent);
}
.role-desc {
  max-inline-size: 34ch;
  margin: 0.35rem 0 0;
  color: var(--text-soft);
  font-size: var(--fs-md);
  line-height: var(--lh);
  text-wrap: pretty;
}

.role-card.compact {
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  justify-items: start;
  align-items: center;
  column-gap: 0.85rem;
  row-gap: 0.15rem;
  max-inline-size: none;
  padding: 0.75rem 1rem;
  text-align: start;
  border-width: 1.5px;
  border-radius: var(--r-lg);
  background-image: linear-gradient(100deg, color-mix(in srgb, var(--team) 20%, transparent), color-mix(in srgb, var(--team) 6%, transparent) 70%);
  box-shadow: var(--shadow);
  animation: mh-fade 320ms var(--ease) both;
}
.role-card.compact::before { display: none; }
.role-card.compact .role-icon {
  grid-row: 1 / span 2;
  font-size: 2.4rem;
  animation: none;
}
.role-card.compact .role-name { font-size: var(--fs-lg); align-self: end; }
.role-card.compact .role-team { align-self: start; }

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.75rem), 1fr));
  gap: 0.6rem;
}

.role-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-block-size: var(--tap);
  padding: 0.75rem 0.5rem;
  border: 2px solid color-mix(in srgb, var(--team) 28%, var(--line));
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  text-align: center;
  font: inherit;
  transition: border-color 180ms ease, background-color 180ms ease, box-shadow 220ms ease,
    transform 140ms var(--ease);
}
button.role-option, .role-option[role="button"] { cursor: pointer; }
.role-option:hover { border-color: color-mix(in srgb, var(--team) 60%, transparent); }
button.role-option:active { transform: scale(0.97); }
.role-option .role-icon { font-size: 2.1rem; line-height: 1.15; animation: none; filter: grayscale(0.55); opacity: 0.85; transition: filter 200ms ease, opacity 200ms ease; }
.role-option .role-name { font-size: var(--fs-md); text-shadow: none; }
.role-option .role-team { font-size: 0.68rem; }
.role-option.is-active,
.role-option[aria-pressed="true"] {
  border-color: var(--team);
  background-color: var(--surface);
  background-image: linear-gradient(180deg, color-mix(in srgb, var(--team) 24%, transparent), color-mix(in srgb, var(--team) 8%, transparent));
  box-shadow: 0 0 0 1px var(--team), 0 0 22px -6px color-mix(in srgb, var(--team) 80%, transparent);
}
.role-option.is-active .role-icon,
.role-option[aria-pressed="true"] .role-icon { filter: none; opacity: 1; }
.role-option:disabled, .role-option.is-disabled { opacity: 0.5; cursor: not-allowed; }
.role-option .stepper { margin-block-start: 0.2rem; }

/* --------------------------------------------------------------------------
   10. Misc
   -------------------------------------------------------------------------- */
.timer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-inline-size: 4.5rem;
  min-block-size: 2.4rem;
  padding: 0.25rem 0.9rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--title);
  font-family: var(--font-num);
  font-size: var(--fs-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  direction: ltr;   /* keep m:ss order in RTL */
  unicode-bidi: isolate;
  transition: color 300ms ease, border-color 300ms ease, background-color 300ms ease;
}
.timer.low {
  color: var(--wolves-ink);
  border-color: var(--wolves);
  background: color-mix(in srgb, var(--wolves) 16%, var(--surface-solid));
  animation: mh-pulse 1s ease-in-out infinite;
}

.phase-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background-color: var(--surface);
  background-image: linear-gradient(100deg, var(--accent-soft), transparent 60%);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
[dir="rtl"] .phase-header { background-image: linear-gradient(260deg, var(--accent-soft), transparent 60%); }
.phase-header > :first-child { flex: 1 1 auto; min-inline-size: 0; }
.phase-header :where(h1, h2, h3, .title, .subtitle) { margin: 0; font-size: var(--fs-xl); }
.phase-header .timer { margin-inline-start: auto; }

.chat {
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1 1 auto;
  min-block-size: 8rem;
  max-block-size: min(50vh, 24rem);
  padding: 0.85rem;
  margin: 0;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.chat-msg {
  align-self: flex-start;
  max-inline-size: 85%;
  padding: 0.45rem 0.8rem;
  border-radius: var(--r-md);
  border-end-start-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
  animation: mh-pop 220ms var(--ease) both;
}
.chat-msg :where(strong, b, .chat-name) {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--accent-ink);
}
.chat-msg.is-mine {
  align-self: flex-end;
  border-radius: var(--r-md);
  border-end-end-radius: 4px;
  background: color-mix(in srgb, var(--accent) 22%, var(--surface-solid));
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
.chat-msg.is-system {
  align-self: center;
  max-inline-size: 100%;
  padding: 0.2rem 0.6rem;
  background: transparent;
  border: 0;
  border-radius: var(--r-pill);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-style: italic;
  text-align: center;
}
.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem;
  border-block-start: 1px solid var(--line);
  background: var(--surface-bar);
}
.chat-form .input { flex: 1 1 auto; min-inline-size: 0; inline-size: auto; }
.chat-form .btn { flex: none; }

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-block-size: var(--tap);
  padding: 0.4rem 1rem;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-soft);
  font-weight: 650;
  font-size: var(--fs-sm);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 200ms ease, color 200ms ease;
}
.tab:hover { color: var(--text); background: var(--accent-soft); }
.tab.is-active, .tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 4px 14px -6px var(--glow);
}
.tab:focus-visible { outline-offset: -3px; border-radius: var(--r-pill); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px))
    max(1rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: mh-fade 200ms ease both;
}
.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  inline-size: min(100%, 30rem);
  max-block-size: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: clamp(1.1rem, 0.9rem + 1.5vw, 1.75rem);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--accent-soft);
  animation: mh-modal 320ms var(--ease-spring) both;
}

.toast {
  position: fixed;
  z-index: 100;
  inset-inline: 1rem;
  inset-block-end: calc(1rem + env(safe-area-inset-bottom, 0px));
  margin-inline: auto;
  inline-size: fit-content;
  max-inline-size: min(calc(100% - 2rem), 28rem);
  padding: 0.75rem 1.15rem;
  border-radius: var(--r-md);
  background: var(--title);
  color: var(--sky);
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 14px 36px -10px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  animation: mh-toast 300ms var(--ease-spring) both;
  pointer-events: none;
}

.list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-block-size: 52px;
  padding: 0.65rem 1rem;
  color: var(--text);
  text-decoration: none;
}
.list-item + .list-item { border-block-start: 1px solid var(--line); }
a.list-item:hover, button.list-item:hover { background: var(--accent-soft); }
button.list-item {
  inline-size: 100%;
  border: 0;
  background: transparent;
  text-align: start;
}

.stat {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.15rem;
  padding: 1rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  text-align: center;
}
.stat-value {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--muted);
}

.avatar-pick {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.25rem, 1fr));
  gap: 0.5rem;
}
.avatar-pick > button,
.avatar-pick > .avatar-option {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-block-size: var(--tap);
  min-inline-size: var(--tap);
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: 1.65rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms var(--ease), border-color 160ms ease, background-color 160ms ease, box-shadow 200ms ease;
}
.avatar-pick > button:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.avatar-pick > button:active { transform: scale(0.92); }
.avatar-pick > .is-active,
.avatar-pick > [aria-pressed="true"],
.avatar-pick > [aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft), 0 0 18px -4px var(--glow);
  transform: scale(1.04);
}

.hidden { display: none !important; }

/* Visually hidden but available to screen readers (helper) */
.sr-only {
  position: absolute !important;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   11. Wide screens
   -------------------------------------------------------------------------- */
@media (min-width: 600px) {
  .players { grid-template-columns: repeat(auto-fill, minmax(7.25rem, 1fr)); gap: 0.75rem; }
  .player-avatar { inline-size: 3.6rem; block-size: 3.6rem; font-size: 2.1rem; }
}
@media (min-width: 900px) {
  :root { --gap: 1.25rem; }
  .container { padding-block: 2rem 3.5rem; }
  .card { padding: 1.75rem; }
  .players { grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); gap: 0.9rem; }
  .modal { inline-size: min(100%, 34rem); }
}

/* --------------------------------------------------------------------------
   12. Motion
   -------------------------------------------------------------------------- */
@keyframes mh-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes mh-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes mh-pop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: none; }
}
@keyframes mh-flip {
  0% { opacity: 0; transform: perspective(1000px) rotateY(-95deg) scale(0.9); }
  55% { opacity: 1; }
  80% { transform: perspective(1000px) rotateY(6deg) scale(1.01); }
  100% { opacity: 1; transform: perspective(1000px) rotateY(0) scale(1); }
}
@keyframes mh-float {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}
@keyframes mh-orb {
  from { filter: brightness(1); scale: 1; }
  to { filter: brightness(1.12); scale: 1.04; }
}
@keyframes mh-glow {
  from { box-shadow: var(--shadow), 0 0 0 1px var(--accent-soft), 0 0 28px -8px var(--glow); }
  to { box-shadow: var(--shadow), 0 0 0 1px var(--accent-soft), 0 0 46px -4px var(--glow); }
}
@keyframes mh-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 color-mix(in srgb, var(--wolves) 50%, transparent); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 8px transparent; }
}
@keyframes mh-modal {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes mh-toast {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .btn, .input, .card, .player, .role-card, .role-option, .tab { border: 1px solid CanvasText; }
  .player.is-selected, .role-option.is-active, .tab.is-active { outline: 3px solid Highlight; }
  .toggle input[type="checkbox"] { border: 1px solid CanvasText; }
}
