/* Base tokens, world token sets, shell layout and shared components.
   Every color in the app comes from these tokens; never hard-code colors elsewhere.
   The look is a Saturday-morning cartoon: bright saturated sea colors, a navy ink outline,
   sticker-like panels and bouncy motion. Light is "sunny shallows", dark is "night dive".
   Storybook extras (--sb-*) and the sticker components live in storybook.css. */

:root {
  --font-display: 'Fredoka', 'Nunito', ui-rounded, system-ui, sans-serif;
  --font-body: 'Nunito', ui-rounded, system-ui, sans-serif;
  --font-mono: 'Atkinson Hyperlegible Mono', ui-monospace, monospace;
  --radius: 18px;
  --radius-sm: 12px;
  --radius-lg: 26px;
  --gap: 16px;
  --maxw: 1080px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --bg: #dff6fb;
  --surface: #ffffff;
  --surface-2: #effafd;
  --ink: #14213d;
  --ink-muted: #475677;
  --border: #b9e3ee;
  --accent: #00789a;
  --accent-2: #d93a6e;
  --accent-ink: #ffffff;
  --good: #14823b;
  --bad: #d1283a;
  --warn: #a96500;
  --pending: #61739a;
  --shadow: 0 3px 0 rgb(20 33 61 / 0.12), 0 8px 22px rgb(20 33 61 / 0.1);

  /* Finger zones for the on-screen keyboard: pinky, ring, middle, index. */
  --finger-1: #ffd6e4;
  --finger-2: #ffeeb3;
  --finger-3: #c9f5d6;
  --finger-4: #c8ecff;
  --finger-thumb: #e7e3ff;

  /* Cartoon shell: the header band, the page tint and the four world colors (stickers, emblems, duotones). */
  --snow: #ffffff;
  --shell-bg: var(--sb-sea);
  --shell-ink: var(--sb-outline);
  --page-tint: 38%;
  --wt-deep: var(--sb-sea);   --wt-deep-lo: #0d5c8c;
  --wt-baker: var(--sb-orange); --wt-baker-lo: #9a3d0e;
  --wt-gothic: var(--sb-grape); --wt-gothic-lo: #4a2aa8;
  --wt-wonder: var(--sb-pink);  --wt-wonder-lo: #a3195f;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0b1736;
    --surface: #13234d;
    --surface-2: #1a2d5e;
    --ink: #f2f7ff;
    --ink-muted: #aab9de;
    --border: #2b4282;
    --accent: #3fe0f5;
    --accent-2: #ff86b8;
    --accent-ink: #0b1736;
    --good: #5ef28c;
    --bad: #ff6b81;
    --warn: #ffcf5c;
    --pending: #8a9acb;
    --shadow: 0 3px 0 rgb(0 0 0 / 0.35), 0 8px 22px rgb(0 0 0 / 0.35);
    --finger-1: #5a2944;
    --finger-2: #5a4a1e;
    --finger-3: #1f5236;
    --finger-4: #1d4466;
    --finger-thumb: #34306a;
    --shell-bg: var(--sb-panel);
    --shell-ink: var(--ink);
    --page-tint: 22%;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1736;
  --surface: #13234d;
  --surface-2: #1a2d5e;
  --ink: #f2f7ff;
  --ink-muted: #aab9de;
  --border: #2b4282;
  --accent: #3fe0f5;
  --accent-2: #ff86b8;
  --accent-ink: #0b1736;
  --good: #5ef28c;
  --bad: #ff6b81;
  --warn: #ffcf5c;
  --pending: #8a9acb;
  --shadow: 0 3px 0 rgb(0 0 0 / 0.35), 0 8px 22px rgb(0 0 0 / 0.35);
  --finger-1: #5a2944;
  --finger-2: #5a4a1e;
  --finger-3: #1f5236;
  --finger-4: #1d4466;
  --finger-thumb: #34306a;
  --shell-bg: var(--sb-panel);
  --shell-ink: var(--ink);
  --page-tint: 22%;
  color-scheme: dark;
}

/* ---------- World token sets (light) ---------- */

body[data-world="deep"] {
  --bg: #dff6fb; --surface: #ffffff; --surface-2: #effafd; --ink: #14213d; --ink-muted: #475677;
  --border: #b9e3ee; --accent: #00789a; --accent-2: #d93a6e; --accent-ink: #ffffff; --pending: #61739a;
}
body[data-world="baker"] {
  --bg: #fff3dc; --surface: #ffffff; --surface-2: #fff8ea; --ink: #2a1e14; --ink-muted: #6a5543;
  --border: #f1d9ad; --accent: #a5481b; --accent-2: #19747a; --accent-ink: #ffffff; --pending: #7a6552;
}
body[data-world="gothic"] {
  --bg: #efe9ff; --surface: #ffffff; --surface-2: #f6f2ff; --ink: #1d1433; --ink-muted: #5b4d7a;
  --border: #d9cdf6; --accent: #7a2fd0; --accent-2: #2f8a3c; --accent-ink: #ffffff; --pending: #6e6290;
}
body[data-world="wonder"] {
  --bg: #ffe9f3; --surface: #ffffff; --surface-2: #fff4f9; --ink: #2b1630; --ink-muted: #6c4c72;
  --border: #f7cde2; --accent: #c22a7a; --accent-2: #1d7f5f; --accent-ink: #ffffff; --pending: #7c5f82;
}

/* ---------- World token sets (dark) ---------- */

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] body[data-world="deep"] {
    --bg: #0b1736; --surface: #13234d; --surface-2: #1a2d5e; --ink: #f2f7ff; --ink-muted: #aab9de;
    --border: #2b4282; --accent: #3fe0f5; --accent-2: #ff86b8; --accent-ink: #0b1736; --pending: #8a9acb;
  }
  :root[data-theme="auto"] body[data-world="baker"] {
    --bg: #1f160f; --surface: #2c2016; --surface-2: #3a2b1e; --ink: #fff3e0; --ink-muted: #d6bd9c;
    --border: #5a4128; --accent: #ffb054; --accent-2: #5fd6cf; --accent-ink: #1f160f; --pending: #a88f72;
  }
  :root[data-theme="auto"] body[data-world="gothic"] {
    --bg: #150f2a; --surface: #20173d; --surface-2: #2a1f4f; --ink: #f1ebff; --ink-muted: #b8a9e0;
    --border: #3f2f75; --accent: #c39bff; --accent-2: #8af08f; --accent-ink: #150f2a; --pending: #8f80bb;
  }
  :root[data-theme="auto"] body[data-world="wonder"] {
    --bg: #23102a; --surface: #31183a; --surface-2: #3e2049; --ink: #fff0f8; --ink-muted: #e0b4cf;
    --border: #5e2f6c; --accent: #ff8ac6; --accent-2: #6ff2c0; --accent-ink: #23102a; --pending: #b089a8;
  }
}
:root[data-theme="dark"] body[data-world="deep"] {
  --bg: #0b1736; --surface: #13234d; --surface-2: #1a2d5e; --ink: #f2f7ff; --ink-muted: #aab9de;
  --border: #2b4282; --accent: #3fe0f5; --accent-2: #ff86b8; --accent-ink: #0b1736; --pending: #8a9acb;
}
:root[data-theme="dark"] body[data-world="baker"] {
  --bg: #1f160f; --surface: #2c2016; --surface-2: #3a2b1e; --ink: #fff3e0; --ink-muted: #d6bd9c;
  --border: #5a4128; --accent: #ffb054; --accent-2: #5fd6cf; --accent-ink: #1f160f; --pending: #a88f72;
}
:root[data-theme="dark"] body[data-world="gothic"] {
  --bg: #150f2a; --surface: #20173d; --surface-2: #2a1f4f; --ink: #f1ebff; --ink-muted: #b8a9e0;
  --border: #3f2f75; --accent: #c39bff; --accent-2: #8af08f; --accent-ink: #150f2a; --pending: #8f80bb;
}
:root[data-theme="dark"] body[data-world="wonder"] {
  --bg: #23102a; --surface: #31183a; --surface-2: #3e2049; --ink: #fff0f8; --ink-muted: #e0b4cf;
  --border: #5e2f6c; --accent: #ff8ac6; --accent-2: #6ff2c0; --accent-ink: #23102a; --pending: #b089a8;
}

/* ---------- Base ---------- */

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.5;
  font-variant-numeric: lining-nums;
  transition: background-color 0.4s ease, color 0.4s ease;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 0.4em;
}
h1 { font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700; }
h2 { font-size: clamp(1.5rem, 3.5vw, 2.1rem); }
h3 { font-size: 1.3rem; }
p { margin: 0 0 0.8em; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }

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

.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* The page behind every screen: the sunny-shallows sky, or a world-tinted wash. The story screens and the
   title get the plain sky from storybook.css. */
body:has(> main:not([data-screen="campaign"]):not([data-screen="voyage"]):not([data-screen="title"]))::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--sb-page);
  pointer-events: none;
}
body[data-world]:has(> main:not([data-screen="campaign"]):not([data-screen="voyage"]):not([data-screen="title"]))::before {
  background: linear-gradient(180deg, color-mix(in srgb, var(--wt) var(--page-tint), var(--bg)) 0%, var(--bg) 52%);
}

/* The world a screen is in sets its sticker colors. */
body[data-world="deep"], .wt-deep { --wt: var(--wt-deep); --wt-lo: var(--wt-deep-lo); }
body[data-world="baker"], .wt-baker { --wt: var(--wt-baker); --wt-lo: var(--wt-baker-lo); }
body[data-world="gothic"], .wt-gothic { --wt: var(--wt-gothic); --wt-lo: var(--wt-gothic-lo); }
body[data-world="wonder"], .wt-wonder { --wt: var(--wt-wonder); --wt-lo: var(--wt-wonder-lo); }
body { --wt: var(--sb-sea); --wt-lo: var(--wt-deep-lo); }

/* ---------- Shell: the header band ---------- */

.shell-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  padding: 10px 20px 12px;
  background: var(--shell-bg);
  color: var(--shell-ink);
  border-bottom: var(--sb-outline-w) solid var(--sb-outline);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--sb-outline) 22%, transparent);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--sb-sun);
  text-decoration: none;
  white-space: nowrap;
  flex: none;
}
.brand-mark { width: 48px; height: 32px; overflow: visible; transition: transform 0.3s var(--ease-spring); }
.brand:hover .brand-mark { transform: rotate(-6deg) translateY(-2px); }
.brand-mark path, .brand-mark circle { stroke: var(--sb-outline); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.bm-hull { fill: var(--sb-sun); }
.bm-fin { fill: var(--sb-orange); }
.bm-top { fill: none; }
.bm-shine { fill: none; stroke: var(--snow) !important; stroke-width: 2.6 !important; opacity: 0.85; }
.bm-port { fill: var(--sb-sky); stroke-width: 2 !important; }
.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  line-height: 1;
  letter-spacing: 0.01em;
  paint-order: stroke fill;
  -webkit-text-stroke: 5px var(--sb-outline);
  text-shadow: 0 2px 0 var(--sb-outline);
}

/* The 20,000-words meter: a sticker progress bar with a glossy fill and the count written on it. */
.word-progress { flex: 1 1 200px; min-width: 150px; max-width: 460px; }
.word-bar {
  --progress: 0;
  position: relative;
  display: grid;
  place-items: center;
  height: 36px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-card);
  box-shadow: 0 3px 0 var(--sb-outline);
  overflow: hidden;
}
.word-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: calc(var(--progress) * 100%);
  border-right: calc(min(1, var(--progress) * 400) * 3px) solid var(--sb-outline);
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.55) 0 34%, transparent 34% 100%),
    linear-gradient(180deg, var(--sb-primary) 0 70%, var(--sb-primary-lo) 100%);
  transition: width 0.7s var(--ease-out);
}
.word-progress-label {
  position: relative;
  padding: 3px 12px 4px;
  border: 2px solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-card);
  color: var(--sb-card-ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.word-progress-label strong { font-weight: 700; }

.shell-nav { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.shell-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 6px 14px;
  border: var(--sb-outline-w) solid transparent;
  border-radius: 999px;
  color: var(--shell-ink);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1;
  transition: background-color 0.15s, transform 0.15s var(--ease-spring);
}
.shell-nav a:hover { background: color-mix(in srgb, var(--snow) 38%, transparent); transform: translateY(-1px); }
.shell-nav a[aria-current="page"] {
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  border-color: var(--sb-outline);
  box-shadow: 0 3px 0 var(--sb-outline);
}
.nav-icon, .icon-btn svg {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 50%;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--sb-outline);
  transition: transform 0.15s var(--ease-spring), box-shadow 0.15s ease;
}
.icon-btn:hover { transform: translateY(-1px) rotate(-6deg); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--sb-outline); }
.icon-btn .mute-off { display: none; }
.icon-btn[aria-pressed="true"] { background: var(--sb-pink); color: var(--sb-outline); }
.icon-btn[aria-pressed="true"] .mute-on { display: none; }
.icon-btn[aria-pressed="true"] .mute-off { display: block; }
#theme-btn svg { display: none; }
#theme-btn[data-mode="light"] .theme-light, #theme-btn[data-mode="dark"] .theme-dark, #theme-btn[data-mode="auto"] .theme-auto { display: block; }
.shell-header :focus-visible { outline-color: var(--sb-outline); outline-offset: 2px; }
:root[data-theme="dark"] .shell-header :focus-visible { outline-color: var(--accent); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .shell-header :focus-visible { outline-color: var(--accent); } }

#screen {
  display: block;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 16px 72px;
  outline: none;
}

/* ---------- Shared components ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 20px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.1;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 3px 0 var(--sb-outline);
  transition: transform 0.15s var(--ease-spring), box-shadow 0.15s ease, filter 0.15s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.04); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--sb-outline); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; filter: none; }
.btn-primary {
  background: var(--sb-primary);
  color: var(--sb-primary-ink);
  box-shadow: inset 0 -4px 0 var(--sb-primary-lo), inset 0 3px 0 var(--sb-primary-hi), var(--sb-pop);
}
.btn-primary:active { box-shadow: inset 0 -2px 0 var(--sb-primary-lo), inset 0 2px 0 var(--sb-primary-hi), 0 1px 0 var(--sb-outline); }
.btn-ghost { background: transparent; box-shadow: none; border-color: color-mix(in srgb, var(--sb-outline) 35%, transparent); }
.btn-ghost:active { box-shadow: none; }
.btn-sm { min-height: 40px; padding: 4px 14px; font-size: 0.95rem; border-width: 2px; box-shadow: 0 2px 0 var(--sb-outline); }
.btn-lg { min-height: 56px; padding: 12px 28px; font-size: 1.2rem; }
.btn .sb-icon { width: 1.2em; height: 1.2em; }

.card {
  background: var(--surface);
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--sb-pop);
}

.stack > * + * { margin-top: var(--gap); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.muted { color: var(--ink-muted); }

/* The little label above a heading: a sticker pill, sentence case. */
.eyebrow {
  display: inline-block;
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  color: var(--ink-muted);
}
.eyebrow.is-pill {
  padding: 3px 14px;
  border: 2px solid var(--sb-outline);
  border-radius: 999px;
  background: color-mix(in srgb, var(--wt) 30%, var(--sb-chip));
  color: var(--sb-chip-ink);
}

/* Page heads: a round sticker badge beside the title. */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.page-head h1 { margin: 0; }
.page-head .eyebrow { margin: 0; }
.page-badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 56px;
  height: 56px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 50%;
  background: var(--wt);
  color: var(--sb-outline);
  box-shadow: var(--sb-pop);
  transform: rotate(-5deg);
}
.page-badge svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }

/* Stat tiles: a sticker with a small label above a big rounded number. */
.stats-row { display: flex; flex-wrap: wrap; gap: 12px; }
.stat {
  flex: 1 1 130px;
  background: var(--sb-card);
  color: var(--sb-card-ink);
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius-sm);
  padding: 10px 14px 12px;
  box-shadow: var(--sb-pop);
}
.stat-label { font-family: var(--font-body); font-weight: 700; font-size: 0.9rem; color: var(--sb-card-muted); }
.stat-value { font-family: var(--font-display); font-weight: 700; font-size: 1.8rem; line-height: 1.2; font-variant-numeric: tabular-nums; }

.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 2px dashed var(--border); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row label { cursor: pointer; }
.toggle-row strong { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; }

/* Big toggle switch (a checkbox with class "switch"). */
input[type="checkbox"].switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 68px;
  height: 40px;
  margin: 0;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 3px 0 color-mix(in srgb, var(--sb-outline) 18%, transparent);
  cursor: pointer;
  transition: background-color 0.2s;
}
input[type="checkbox"].switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
  border: 3px solid var(--sb-outline);
  border-radius: 50%;
  background: var(--snow);
  box-shadow: 0 2px 0 var(--sb-outline);
  transition: transform 0.25s var(--ease-spring), background-color 0.2s;
}
input[type="checkbox"].switch:checked { background: var(--sb-kelp); }
input[type="checkbox"].switch:checked::after { transform: translateX(28px); background: var(--sb-primary); }
input[type="checkbox"].switch:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 999px; }

/* Form controls themed with tokens (native selects look off-theme in dark mode). */
select {
  min-height: 44px;
  padding: 6px 14px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  box-shadow: 0 3px 0 var(--sb-outline);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

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

/* ---------- Title screen: see css/title.css ---------- */

/* a world as a sticker card with its emblem */
.world-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 18px 20px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius);
  background: var(--sb-card);
  color: var(--sb-card-ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
  box-shadow: inset 0 8px 0 var(--wt), var(--sb-pop);
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease;
}
.world-card:hover { transform: translateY(-4px) rotate(-1deg); }
.world-card:active { transform: translateY(2px); }
.world-card .emblem { margin: 8px 0 6px; }
.world-card h3 { margin: 0; font-size: 1.45rem; }
.world-card p { margin: 0; }
.world-card .wc-tag { color: var(--sb-card-muted); font-size: 1rem; line-height: 1.35; }
.world-card .wc-by { margin-top: 8px; font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; color: var(--sb-card-ink); }

/* a world's round emblem sticker */
.emblem {
  display: grid;
  place-items: center;
  flex: none;
  width: 64px;
  height: 64px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 50%;
  background: var(--wt);
  box-shadow: var(--sb-pop);
  transform: rotate(-6deg);
}
.emblem svg { width: 78%; height: 78%; overflow: visible; }
.emblem svg * { stroke: var(--sb-outline); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; fill: none; }
.emblem .em-a { fill: var(--snow); }
.emblem .em-b { fill: var(--sb-sun); }
.emblem .em-c { fill: var(--wt-lo); }
.emblem .em-n { stroke: none; }
/* Emblems never sit still: the badge rocks and squashes a little, the picture inside bobs on its own beat.
   Each world keeps a different phase so a row of them never moves in step. `rotate`/`scale`/`translate`
   stack on the badge's resting tilt (its transform). */
.emblem { animation: emblem-idle 3.6s ease-in-out infinite; animation-delay: var(--em-d, 0s); }
.emblem svg { animation: emblem-bob 2.6s ease-in-out infinite; animation-delay: var(--em-d, 0s); }
.emblem.wt-baker { --em-d: -0.9s; }
.emblem.wt-gothic { --em-d: -1.8s; }
.emblem.wt-wonder { --em-d: -2.7s; }
@keyframes emblem-idle {
  0%, 100% { rotate: 0deg; scale: 1; }
  25% { rotate: 6deg; scale: 1.04 0.97; }
  50% { rotate: 0deg; scale: 1; }
  75% { rotate: -5deg; scale: 0.97 1.04; }
}
@keyframes emblem-bob {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  50% { translate: 0 -2px; rotate: -4deg; }
}
@keyframes emblem-wiggle {
  0%, 100% { rotate: 0deg; scale: 1; }
  25% { rotate: -12deg; scale: 1.1; }
  75% { rotate: 12deg; scale: 1.1; }
}
.lib-shelf:hover .emblem, .lib-shelf:focus-within .emblem, .world-intro:hover .emblem {
  animation: emblem-wiggle 0.7s ease-in-out infinite;
}
html.reduced-motion .emblem, html.reduced-motion .emblem svg { animation: none; }

@media (max-width: 640px) {
  .world-card { display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center; padding: 18px 16px 16px; }
  .world-card .emblem { grid-row: 1 / span 3; margin: 6px 0 0; }
}
@media (max-width: 760px) {
  .shell-header { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px 10px; position: relative; }
  .brand { order: 1; flex: 1 1 auto; min-width: 0; }
  .brand-mark { width: 40px; height: 27px; }
  .brand-text { font-size: 1.2rem; overflow: hidden; text-overflow: ellipsis; }
  #mute-btn, #theme-btn { order: 2; }
  .word-progress { order: 3; flex: 1 1 100px; min-width: 0; max-width: none; }
  .shell-nav { order: 4; margin-left: 0; gap: 4px; flex: none; }
  .shell-nav a { width: 40px; min-height: 40px; padding: 0; }
  .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .word-unit { display: none; }
}
@media (max-width: 400px) {
  .brand-text { font-size: 1.1rem; }
  .word-progress-label { font-size: 0.9rem; padding: 2px 9px 3px; }
}
@media (max-width: 640px) {
  body { font-size: 17px; }
  #screen { padding-top: 18px; }
}
