/* =========================================================================
   PLAYFIELD — SITE-WIDE SHELL & COMPONENT LIBRARY
   -------------------------------------------------------------------------
   The new global visual layer: masthead, mega menu, command palette, mobile
   navigation, footer, cookie consent and the shared buttons/chips used by the
   rebuilt landing pages.

   Loaded from Navigation::criticalStylesheets() after tokens.css and
   chrome.css. Everything new is namespaced .pf-* so it cannot collide with
   the older page styles that still power the game screens.
   ========================================================================= */

:root {
    --pf-border: 2px solid var(--pf-ink);
    --pf-drop: 0 5px 0 var(--pf-ink);
    --pf-drop-lg: 0 8px 0 var(--pf-ink);
    --pf-header-h: 80px;
    --pf-max: 1280px;
}

html[data-theme="dark"] {
    --pf-drop: 0 5px 0 rgba(0, 0, 0, 0.55);
    --pf-drop-lg: 0 8px 0 rgba(0, 0, 0, 0.55);
}

/* Static scroll lock. This used to be injected as a runtime <style>, which
   the CSP refused, so the page kept scrolling under open overlays. Keep it in
   a served stylesheet and lock both html and body for iOS/Safari. */
html.pf-scroll-locked,
body.pf-scroll-locked {
    overflow: hidden !important;
    overscroll-behavior: none !important;
}

/* Layout does not depend on JavaScript: when the new masthead is present,
   the legacy centred flex <body> must be overridden even before the inline
   body-class script runs (or when scripts are disabled entirely). */
body:has(> .pf-header) {
    display: block !important;
    align-items: stretch !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* ── Base safety rails ─────────────────────────────────────────────────── */
.pf-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;
}

.pf-wrap {
    width: 100%;
    max-width: var(--pf-max);
    margin-inline: auto;
    padding-inline: clamp(18px, 4vw, 40px);
}

.pf-mono {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.pf-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--pf-ink);
}

.pf-eyebrow__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pf-spatial);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--pf-spatial) 22%, transparent);
}

.pf-sticker {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border: 2px solid var(--pf-ink);
    border-radius: 6px;
    background: var(--pf-sun);
    color: var(--pf-word-ink); /* pinned: cream in dark drops to 1.2:1 on marigold */
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transform: rotate(-2.5deg);
    box-shadow: 2px 2px 0 var(--pf-ink);
}

/* =========================================================================
   1. BUTTONS & CHIPS
   ========================================================================= */
.pf-btn {
    --btn-bg: var(--pf-card);
    --btn-fg: var(--pf-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: 48px;
    padding: 0.72rem 1.25rem;
    border: var(--pf-border);
    border-radius: var(--radius-pill);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--pf-drop);
    transition: transform var(--dur-fast) var(--ease-spring),
                box-shadow var(--dur-fast) var(--ease-spring),
                background-color var(--dur-fast) ease;
    -webkit-tap-highlight-color: transparent;
}
.pf-btn:hover {
    color: var(--btn-fg);
    transform: translateY(-2px);
    box-shadow: var(--pf-drop-lg);
}
.pf-btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--pf-ink);
}
.pf-btn--primary {
    --btn-bg: var(--pf-pine);
    --btn-fg: #FFFDF7;
}
html[data-theme="dark"] .pf-btn--primary {
    --btn-bg: var(--pf-pine);
    --btn-fg: #0B2418;
}
.pf-btn--sun {
    --btn-bg: var(--pf-sun);
    --btn-fg: #262019;
}
.pf-btn--ink {
    --btn-bg: var(--pf-ink);
    --btn-fg: var(--pf-paper);
}
html[data-theme="dark"] .pf-btn--ink {
    --btn-bg: var(--pf-ink);
    --btn-fg: #0B2418;
}
.pf-btn--ghost {
    box-shadow: none;
    background: transparent;
}
.pf-btn--ghost:hover {
    box-shadow: none;
    transform: none;
    background: var(--pf-sun-soft);
}
.pf-btn--sm {
    min-height: 44px;
    padding: 0.45rem 0.9rem;
    font-size: 0.82rem;
    box-shadow: 0 3px 0 var(--pf-ink);
}
.pf-btn--sm:hover {
    box-shadow: 0 5px 0 var(--pf-ink);
}
.pf-btn--lg {
    min-height: 58px;
    padding: 0.95rem 1.7rem;
    font-size: 1.02rem;
}
.pf-btn__arrow {
    display: inline-block;
    transition: transform var(--dur-fast) var(--ease-out);
}
.pf-btn:hover .pf-btn__arrow {
    transform: translateX(3px);
}

.pf-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 0.8rem;
    border: 1.5px solid color-mix(in srgb, var(--pf-ink) 22%, transparent);
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--pf-ink);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    transition: border-color var(--dur), background-color var(--dur), transform var(--dur);
}
.pf-chip:hover {
    border-color: var(--pf-ink);
    background: var(--pf-sun-soft);
    color: var(--pf-ink);
    transform: translateY(-1px);
}
.pf-chip[aria-pressed="true"],
.pf-chip.is-active {
    border-color: var(--pf-ink);
    background: var(--pf-ink);
    color: var(--pf-paper);
}

/* =========================================================================
   2. MASTHEAD
   ========================================================================= */
.pf-skip {
    position: absolute;
    top: -60px;
    left: 16px;
    z-index: 10000;
    padding: 0.7rem 1rem;
    border: 2px solid var(--pf-ink);
    border-radius: 0 0 12px 12px;
    background: var(--pf-sun);
    color: var(--pf-word-ink); /* pinned: cream in dark drops to 1.2:1 on marigold */
    font-weight: 800;
    text-decoration: none;
    transition: top var(--dur) var(--ease-out);
}
.pf-skip:focus {
    top: 0;
    color: var(--pf-ink);
}

.pf-header {
    position: sticky;
    top: 0;
    z-index: 9000;
    width: 100%;
    padding: 0;
    background: var(--nav-bg);
    border-bottom: 2px solid var(--pf-ink);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
    transition: transform var(--dur) var(--ease-out);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .pf-header { background: var(--bg-0); }
}
.pf-header__inner {
    max-width: var(--pf-max);
    min-height: var(--pf-header-h);
    margin-inline: auto;
    padding: 0 clamp(16px, 3vw, 34px);
    display: flex;
    align-items: center;
    gap: clamp(12px, 2.4vw, 34px);
}

/* Brand ------------------------------------------------------------------ */
.pf-brand {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 0.65rem;
    flex: 0 0 auto;
    color: var(--pf-ink);
    text-decoration: none;
    line-height: 1;
}
.pf-brand:hover { color: var(--pf-ink); }
.pf-brand__mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 2px solid var(--pf-ink);
    border-radius: 12px;
    background: var(--pf-sun);
    box-shadow: 3px 3px 0 var(--pf-ink);
    transform: rotate(-3deg);
    transition: transform var(--dur) var(--ease-spring);
}
.pf-brand:hover .pf-brand__mark {
    transform: rotate(4deg) scale(1.04);
}
.pf-brand__mark svg {
    width: 26px;
    height: 26px;
    display: block;
}
.pf-brand__type {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.pf-brand__name {
    font-family: var(--font-display);
    font-size: 1.14rem;
    font-weight: 900;
    letter-spacing: -0.045em;
    text-transform: uppercase;
    white-space: nowrap;
}
.pf-brand__name em {
    font-style: normal;
    color: var(--pf-pine);
}
.pf-brand__tag {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--pf-ink-soft);
}

/* Primary navigation ----------------------------------------------------- */
.pf-nav {
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.6vw, 22px);
    margin-left: auto;
    min-width: 0;
}
.pf-nav__links {
    display: flex;
    align-items: center;
    gap: 2px;
}
.pf-nav__link {
    position: relative;
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 0.35rem;
    padding: 0.55rem 0.72rem;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--pf-ink);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color var(--dur), color var(--dur);
}
.pf-nav__link:hover {
    color: var(--pf-ink);
    background: var(--pf-sun-soft);
}
.pf-nav__link.is-active {
    background: var(--pf-ink);
    color: var(--pf-paper);
}
html[data-theme="dark"] .pf-nav__link.is-active {
    background: var(--pf-ink);
    color: #0B2418;
}
.pf-nav__link.is-active::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--pf-sun);
}
.pf-nav__chevron {
    width: 12px;
    height: 12px;
    transition: transform var(--dur);
}
.pf-nav__item[data-open="true"] .pf-nav__chevron {
    transform: rotate(180deg);
}

.pf-nav__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

/* Small round icon buttons */
.pf-iconbtn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    height: 40px;
    min-width: 40px;
    padding: 0 0.65rem;
    border: 1.5px solid color-mix(in srgb, var(--pf-ink) 24%, transparent);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--pf-card) 76%, transparent);
    color: var(--pf-ink);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: border-color var(--dur), background-color var(--dur), transform var(--dur);
}
.pf-iconbtn:hover {
    border-color: var(--pf-ink);
    background: var(--pf-sun-soft);
    color: var(--pf-ink);
    transform: translateY(-1px);
}
.pf-iconbtn svg {
    width: 18px;
    height: 18px;
}
.pf-iconbtn kbd {
    padding: 1px 4px;
    border: 1px solid color-mix(in srgb, var(--pf-ink) 22%, transparent);
    border-radius: 4px;
    background: color-mix(in srgb, var(--pf-ink) 6%, transparent);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--pf-ink-soft);
}

/* Theme switch: a two-position pill driven by [data-theme] ----------------- */
.pf-theme {
    width: 66px;
    height: 38px;
    padding: 3px;
    border: 1.5px solid color-mix(in srgb, var(--pf-ink) 26%, transparent);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--pf-ink) 7%, transparent);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    position: relative;
    overflow: hidden;
    flex: 0 0 auto;
}
.pf-theme:hover { border-color: var(--pf-ink); }
.pf-theme__track {
    position: absolute;
    inset: 3px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    pointer-events: none;
}
.pf-theme__track svg { width: 13px; height: 13px; color: var(--pf-ink-soft); }
.pf-theme__thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--pf-sun);
    border: 1.5px solid var(--pf-ink);
    box-shadow: 1px 2px 0 color-mix(in srgb, var(--pf-ink) 70%, transparent);
    display: grid;
    place-items: center;
    transition: transform var(--dur) var(--ease-spring), background-color var(--dur);
    z-index: 1;
}
.pf-theme__thumb svg { width: 15px; height: 15px; color: #262019; }
html[data-theme="dark"] .pf-theme__thumb {
    transform: translateX(30px);
    background: var(--pf-pine);
}
html[data-theme="dark"] .pf-theme__thumb svg { color: #0B2418; }
.pf-theme__thumb .pf-theme__moon { display: none; }
html[data-theme="dark"] .pf-theme__thumb .pf-theme__sun { display: none; }
html[data-theme="dark"] .pf-theme__thumb .pf-theme__moon { display: block; }
#theme-toggle-label {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* Account ----------------------------------------------------------------- */
.pf-account { position: relative; }
.pf-account > summary {
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 40px;
    padding: 0 0.85rem;
    border: 1.5px solid color-mix(in srgb, var(--pf-ink) 26%, transparent);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--pf-card) 76%, transparent);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color var(--dur), background-color var(--dur);
}
.pf-account > summary::-webkit-details-marker { display: none; }
.pf-account > summary:hover,
.pf-account[open] > summary {
    border-color: var(--pf-ink);
    background: var(--pf-sun-soft);
}
.pf-account__avatar {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--pf-pine);
    color: #FFFDF7;
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
}
.pf-account__panel {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    min-width: 220px;
    padding: 8px;
    border: 2px solid var(--pf-ink);
    border-radius: 16px;
    background: var(--pf-card);
    box-shadow: var(--pf-drop-lg);
    z-index: 60;
}
.pf-account__link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.58rem 0.7rem;
    border-radius: 9px;
    color: var(--pf-ink);
    font-size: 0.86rem;
    font-weight: 600;
    text-decoration: none;
    background: none;
    border: 0;
    width: 100%;
    text-align: left;
    cursor: pointer;
}
.pf-account__link:hover {
    background: var(--pf-sun-soft);
    color: var(--pf-ink);
}
.pf-account__logout { margin: 4px 0 0; padding-top: 4px; border-top: 1px solid var(--line); }
.pf-streak {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 40px;
    padding: 0 0.7rem;
    border-radius: var(--radius-pill);
    border: 1.5px solid color-mix(in srgb, var(--pf-ink) 26%, transparent);
    background: var(--pf-tomato-soft);
    color: var(--pf-ink);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
}
.pf-streak span:first-child { filter: saturate(1.2); }

/* Burger / mobile ---------------------------------------------------------- */
.pf-burger {
    display: none;
    align-items: center;
    gap: 0.5rem;
    height: 40px;
    padding: 0 0.85rem;
    border: 1.5px solid var(--pf-ink);
    border-radius: var(--radius-pill);
    background: var(--pf-card);
    color: var(--pf-ink);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
}
.pf-burger__lines {
    display: inline-flex;
    flex-direction: column;
    gap: 3px;
    width: 16px;
}
.pf-burger__lines span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transition: transform var(--dur) var(--ease-out), opacity var(--dur);
}
.pf-header[data-menu-open="true"] .pf-burger__lines span:nth-child(1) { transform: translateY(5px) rotate(45deg); }
.pf-header[data-menu-open="true"] .pf-burger__lines span:nth-child(2) { opacity: 0; }
.pf-header[data-menu-open="true"] .pf-burger__lines span:nth-child(3) { transform: translateY(-5px) rotate(-45deg); }

.pf-mobile-panel {
    display: none;
    position: fixed;
    inset: var(--pf-header-h) 0 0;
    z-index: 8900;
    background: var(--bg-0);
    border-top: 2px solid var(--pf-ink);
    overflow-y: auto;
    padding: 24px clamp(18px, 5vw, 32px) 110px;
}
.pf-header[data-menu-open="true"] ~ .pf-mobile-panel {
    display: block;
    animation: pf-panel-in 0.28s var(--ease-out) both;
}
@keyframes pf-panel-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.pf-mobile-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--pf-ink);
}
.pf-mobile-panel__title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: -0.04em;
}
.pf-mobile-panel__close {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1.5px solid var(--pf-ink);
    border-radius: 50%;
    background: var(--pf-card);
    color: var(--pf-ink);
    font-size: 1.25rem;
    cursor: pointer;
}
.pf-mobile-panel__group + .pf-mobile-panel__group { margin-top: 26px; }
.pf-mobile-panel__label {
    display: block;
    margin-bottom: 8px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--pf-ink-soft);
}
.pf-mobile-panel__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0.85rem 0.2rem;
    border-bottom: 1px solid var(--line);
    color: var(--pf-ink);
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-decoration: none;
}
.pf-mobile-panel__link small {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    color: var(--pf-ink-soft);
}
.pf-mobile-panel__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.pf-mobile-panel__tile {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem;
    border: 1.5px solid color-mix(in srgb, var(--pf-ink) 18%, transparent);
    border-radius: 12px;
    background: var(--pf-card);
    color: var(--pf-ink);
    font-size: 0.84rem;
    font-weight: 700;
    text-decoration: none;
}
.pf-mobile-panel__tile:hover { border-color: var(--pf-ink); color: var(--pf-ink); }
.pf-mobile-panel__tile span {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--pf-word);
}
.pf-mobile-panel__tile[data-family="logic"] span { background: var(--pf-logic); }
.pf-mobile-panel__tile[data-family="spatial"] span { background: var(--pf-spatial); }

/* Mobile tab bar ----------------------------------------------------------- */
.pf-tabbar {
    display: none;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 8500;
    padding: 6px;
    border: 2px solid var(--pf-ink);
    border-radius: 20px;
    background: color-mix(in srgb, var(--bg-0) 92%, transparent);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    box-shadow: var(--pf-drop);
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
}
.pf-tabbar__item {
    display: flex;
    min-width: 44px;
    border: 0;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    font-family: var(--font-body);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    padding: 5px 2px;
    border-radius: 14px;
    color: var(--pf-ink-soft);
    font-size: 0.75rem;
    font-weight: 700;
    text-decoration: none;
    line-height: 1;
}
.pf-tabbar__item svg { width: 19px; height: 19px; }
.pf-tabbar__item.is-active {
    background: var(--pf-ink);
    color: var(--pf-paper);
}
html[data-theme="dark"] .pf-tabbar__item.is-active { color: #0B2418; }
.pf-tabbar__item:hover { color: var(--pf-ink); }
.pf-tabbar__item.is-active:hover { color: var(--pf-paper); }
html[data-theme="dark"] .pf-tabbar__item.is-active:hover { color: #0B2418; }

/* =========================================================================
   3. MEGA MENU
   ========================================================================= */
.pf-nav__item { position: relative; }
.pf-mega {
    position: absolute;
    top: calc(100% + 14px);
    left: -18px;
    width: min(780px, calc(100vw - 48px));
    padding: 18px;
    border: 2px solid var(--pf-ink);
    border-radius: 24px;
    background: var(--pf-card);
    box-shadow: var(--pf-drop-lg);
    z-index: 80;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.985);
    transform-origin: top left;
    transition: opacity var(--dur), transform var(--dur) var(--ease-out), visibility var(--dur);
}
.pf-nav__item[data-open="true"] .pf-mega {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
.pf-mega__grid {
    display: grid;
    grid-template-columns: 1fr 1fr 0.95fr;
    gap: 18px;
}
.pf-mega__title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 8px;
    padding-bottom: 8px;
    border-bottom: 1.5px solid var(--line);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--pf-ink-soft);
}
.pf-mega__count {
    color: var(--pf-ink);
    background: var(--pf-sun-soft);
    border-radius: 999px;
    padding: 2px 6px;
}
.pf-mega__list {
    display: grid;
    gap: 1px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.pf-mega__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0.42rem 0.5rem;
    border-radius: 8px;
    color: var(--pf-ink);
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
}
.pf-mega__link span:last-child {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    color: var(--pf-ink-soft);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity var(--dur), transform var(--dur);
}
.pf-mega__link:hover {
    background: var(--pf-sun-soft);
    color: var(--pf-ink);
}
.pf-mega__link:hover span:last-child {
    opacity: 1;
    transform: translateX(0);
}
.pf-mega__feature {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 2px solid var(--pf-ink);
    border-radius: 16px;
    background: var(--pf-word-soft);
    color: var(--pf-ink);
    text-decoration: none;
}
.pf-mega__feature[data-family="logic"] { background: var(--pf-logic-soft); }
.pf-mega__feature[data-family="spatial"] { background: var(--pf-spatial-soft); }
.pf-mega__feature:hover { color: var(--pf-ink); }
.pf-mega__feature-art {
    display: grid;
    place-items: center;
    height: 88px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--pf-card) 72%, transparent);
    overflow: hidden;
}
.pf-mega__feature-art svg { width: 70px; height: 85px; }
.pf-mega__feature-label {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}
.pf-mega__feature-name {
    font-size: 1.05rem;
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 1.05;
}
.pf-mega__feature-cta {
    margin-top: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.76rem;
    font-weight: 800;
}
.pf-mega__all {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1.5px solid var(--line);
    color: var(--pf-ink);
    font-size: 0.8rem;
    font-weight: 800;
    text-decoration: none;
}
.pf-mega__all:hover { color: var(--pf-pine); }

/* =========================================================================
   4. COMMAND PALETTE
   ========================================================================= */
.pf-search {
    position: fixed;
    inset: 0;
    z-index: 9500;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(60px, 12vh, 140px) 18px 30px;
}
.pf-search[hidden] { display: none; }
.pf-search__backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, #070D0A 62%, transparent);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    animation: pf-fade-in var(--dur) ease both;
}
@keyframes pf-fade-in { from { opacity: 0; } to { opacity: 1; } }
.pf-search__panel {
    position: relative;
    width: min(620px, 100%);
    max-height: min(72vh, 640px);
    display: flex;
    flex-direction: column;
    border: 2px solid var(--pf-ink);
    border-radius: 22px;
    background: var(--pf-card);
    box-shadow: var(--pf-drop-lg), 0 30px 80px rgba(0, 0, 0, 0.22);
    overflow: hidden;
    animation: pf-search-in 0.24s var(--ease-spring) both;
}
@keyframes pf-search-in {
    from { opacity: 0; transform: translateY(-10px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.pf-search__head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 14px 16px;
    border-bottom: 1.5px solid var(--line);
}
.pf-search__head svg { width: 20px; height: 20px; color: var(--pf-ink-soft); flex: 0 0 auto; }
.pf-search__close {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border: 1.5px solid color-mix(in srgb, var(--pf-ink) 22%, transparent);
    border-radius: 50%;
    background: var(--pf-card);
    color: var(--pf-ink);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}
.pf-search__close:hover { background: var(--pf-sun-soft); border-color: var(--pf-ink); }
.pf-search__input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--pf-ink);
    font-family: var(--font-body);
    font-size: 1.02rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.pf-search__input:focus { outline: none; }
.pf-search__input::placeholder { color: var(--pf-ink-soft); opacity: 0.72; }
.pf-search__esc {
    flex: 0 0 auto;
    padding: 3px 7px;
    border: 1px solid color-mix(in srgb, var(--pf-ink) 20%, transparent);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--pf-ink-soft);
}
.pf-search__results {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px;
}
.pf-search__label {
    display: block;
    padding: 10px 10px 6px;
    font-family: var(--font-mono);
    font-size: 0.64rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--pf-ink-soft);
}
.pf-search__item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: var(--pf-ink);
    text-align: left;
    font-family: var(--font-body);
    cursor: pointer;
}
.pf-search__item:hover,
.pf-search__item[data-active="true"] {
    background: var(--pf-sun-soft);
}
.pf-search__swatch {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border: 1.5px solid var(--pf-ink);
    border-radius: 10px;
    background: var(--pf-word-soft);
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 700;
}
.pf-search__item[data-family="logic"] .pf-search__swatch { background: var(--pf-logic-soft); }
.pf-search__item[data-family="spatial"] .pf-search__swatch { background: var(--pf-spatial-soft); }
.pf-search__item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pf-search__item-name { font-size: 0.92rem; font-weight: 800; }
.pf-search__item-meta {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--pf-ink-soft);
}
.pf-search__item-arrow { margin-left: auto; color: var(--pf-ink-soft); }
.pf-search__empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--pf-ink-soft);
    font-size: 0.9rem;
    font-weight: 600;
}
.pf-search__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    border-top: 1.5px solid var(--line);
    font-family: var(--font-mono);
    font-size: 0.58rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--pf-ink-soft);
}
.pf-search__foot kbd {
    padding: 1px 5px;
    border: 1px solid color-mix(in srgb, var(--pf-ink) 18%, transparent);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.58rem;
}

/* =========================================================================
   5. BREADCRUMB STRIP
   ========================================================================= */
.breadcrumb-row {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: var(--pf-max);
    margin-inline: auto;
    padding: 7px clamp(16px, 3vw, 34px);
    border-top: 1px solid var(--line);
    font-size: 0.76rem;
}
.breadcrumb-trail {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    color: var(--pf-ink-soft);
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.breadcrumb-trail a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    color: var(--pf-ink-soft);
    text-decoration: none;
}
.breadcrumb-trail a:hover { color: var(--pf-pine); }
.breadcrumb-trail .crumb-separator { opacity: 0.45; }
.breadcrumb-trail span[aria-current="page"] { color: var(--pf-ink); }

/* Best-time card in the header strip */
.breadcrumb-row .best-time-card,
.breadcrumb-row .header-best-time {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--pf-card);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    white-space: nowrap;
}
.breadcrumb-row .best-time-card__label { color: var(--pf-ink-soft); }
.breadcrumb-row .best-time-card__value { color: var(--pf-ink); font-weight: 700; }

/* =========================================================================
   6. FOOTER
   ========================================================================= */
.pf-footer {
    position: relative;
    overflow: hidden;
    margin-top: clamp(40px, 7vw, 90px);
    padding: clamp(40px, 6vw, 72px) 0 22px;
    background: var(--pf-footer);
    color: #F7F2E7;
    border-top: 2px solid var(--pf-ink);
}
html[data-theme="dark"] .pf-footer { border-top-color: rgba(247, 242, 231, 0.2); }
.pf-footer a { color: inherit; text-decoration: none; }
.pf-footer__top {
    display: grid;
    grid-template-columns: 1.4fr repeat(3, minmax(0, 1fr));
    gap: clamp(24px, 4vw, 56px);
    align-items: start;
}
.pf-footer__brand .pf-brand { color: #F7F2E7; }
.pf-footer__brand .pf-brand__mark {
    border-color: #F7F2E7;
    box-shadow: 3px 3px 0 rgba(247, 242, 231, 0.35);
}
.pf-footer__blurb {
    max-width: 34ch;
    margin: 16px 0 0;
    color: rgba(247, 242, 231, 0.64);
    font-size: 0.92rem;
    line-height: 1.55;
}
.pf-footer__heading {
    margin: 4px 0 14px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: rgba(247, 242, 231, 0.72);
}
.pf-footer__list {
    display: grid;
    gap: 9px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.pf-footer__list a {
    display: inline-flex;
    align-items: center;
    min-width: 44px;
    min-height: 45px;
    padding: 2px 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: rgba(247, 242, 231, 0.85);
    transition: color var(--dur);
}
.pf-footer__list a:hover { color: var(--pf-sun); }
.pf-footer__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: clamp(32px, 5vw, 58px);
    padding-top: 18px;
    border-top: 1px solid rgba(247, 242, 231, 0.16);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: rgba(247, 242, 231, 0.66);
}
.pf-footer__social {
    display: inline-flex;
    gap: 8px;
}
.pf-footer__social a {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(247, 242, 231, 0.24);
    border-radius: 50%;
    color: rgba(247, 242, 231, 0.8);
}
.pf-footer__social a:hover {
    border-color: var(--pf-sun);
    color: var(--pf-sun);
}
.pf-footer__wordmark {
    margin: clamp(26px, 4vw, 48px) 0 -18px;
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(3.4rem, 12.6vw, 11.5rem);
    line-height: 0.78;
    letter-spacing: -0.06em;
    text-transform: uppercase;
    color: transparent;
    -webkit-text-stroke: 1.5px rgba(247, 242, 231, 0.22);
    text-align: center;
    user-select: none;
    pointer-events: none;
}

/* =========================================================================
   7. COOKIE CONSENT — restyle the existing markup
   ========================================================================= */
.cookie-modal {
    position: fixed;
    inset: auto 18px 18px auto;
    z-index: 9400;
    width: min(560px, calc(100vw - 36px));
    max-width: 560px;
    font-family: var(--font-body);
}
.cookie-modal[hidden] { display: none; }
.cookie-modal__backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: rgba(7, 13, 10, 0.28);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.cookie-modal__card {
    position: relative;
    padding: 16px 18px;
    border: 2px solid var(--pf-ink);
    border-radius: 22px;
    background: var(--pf-card);
    color: var(--pf-ink);
    box-shadow: var(--pf-drop-lg), 0 30px 70px rgba(0, 0, 0, 0.2);
    animation: pf-cookie-in 0.42s var(--ease-spring) both;
}
@keyframes pf-cookie-in {
    from { opacity: 0; transform: translateY(16px) rotate(-1deg); }
    to   { opacity: 1; transform: translateY(0) rotate(0); }
}
.cookie-modal__title {
    margin: 0 0 6px;
    font-family: var(--font-display);
    font-size: 1.12rem;
    font-weight: 900;
    letter-spacing: -0.03em;
}
.cookie-modal__text {
    margin: 0 0 10px;
    color: var(--pf-ink-soft);
    font-size: 0.8rem;
    line-height: 1.45;
}
.cookie-modal__text a { color: var(--pf-pine); font-weight: 700; }
.cookie-modal__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.cookie-modal__btn {
    min-height: 38px;
    flex: 1 1 auto;
    padding: 0.42rem 0.7rem;
    border: 1.5px solid var(--pf-ink);
    border-radius: var(--radius-pill);
    background: var(--pf-card);
    color: var(--pf-ink);
    font-family: var(--font-body);
    font-size: 0.74rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform var(--dur-fast), background-color var(--dur);
    white-space: nowrap;
}
.cookie-modal__btn:hover { background: var(--pf-sun-soft); transform: translateY(-1px); }
.cookie-modal__btn--primary {
    background: var(--pf-pine);
    color: #FFFDF7;
}
html[data-theme="dark"] .cookie-modal__btn--primary { color: #0B2418; }
.cookie-modal__btn--primary:hover { background: var(--pf-pine-deep); }
.cookie-modal__manage { margin-top: 14px; }
.cookie-modal__categories { display: grid; gap: 8px; margin-bottom: 12px; }
.cookie-modal__category {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
}
.cookie-modal__category-info { display: flex; flex-direction: column; gap: 2px; }
.cookie-modal__category-name { font-size: 0.82rem; font-weight: 800; }
.cookie-modal__category-required {
    margin-left: 4px;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--pf-spatial-soft);
    font-family: var(--font-mono);
    font-size: 0.52rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.cookie-modal__category-desc { font-size: 0.72rem; color: var(--pf-ink-soft); line-height: 1.4; }
.cookie-modal__switch {
    flex: 0 0 auto;
    padding: 4px 10px;
    border: 1.5px solid var(--pf-ink);
    border-radius: 999px;
    background: var(--pf-card);
    color: var(--pf-ink);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    cursor: pointer;
}
.cookie-modal__switch--on { background: var(--pf-spatial); color: var(--pf-spatial-ink); }
.cookie-modal__link {
    border: 0;
    background: none;
    color: var(--pf-ink-soft);
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    padding: 4px 0;
}

/* =========================================================================
   8. GENERIC LEGACY-PAGE POLISH
   Applies to the templates that have not been rebuilt individually (auth,
   legal, about, contact) so they inherit the new brand rather than looking
   like a different website behind the new header.
   ========================================================================= */
.pf-legacy-page {
    min-height: 60vh;
}

/* =========================================================================
   9. RESPONSIVE
   ========================================================================= */
@media (min-width: 961px) and (max-width: 1260px) {
    /* The desktop mega menu is 780px wide and right-aligns under the Puzzles
       trigger. Between 961 and 1260px that pushed its hidden box past the
       viewport edge and created real horizontal page scroll. Pin it to the
       header's full width inside this band instead; the fixed containing
       block is the header (backdrop-filter), so it still opens directly under
       the masthead. */
    .pf-mega {
        position: fixed;
        top: calc(var(--pf-header-h) + 2px);
        left: 16px;
        right: 16px;
        width: auto;
        max-height: calc(100vh - var(--pf-header-h) - 28px);
        overflow-y: auto;
        transform: translateY(-8px) scale(0.99);
    }
    .pf-nav__item[data-open="true"] .pf-mega {
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 1120px) {
    .pf-nav__links .pf-nav__link[data-optional="true"] { display: none; }
    .pf-brand__tag { display: none; }
    .pf-iconbtn__label { display: none; }
    .pf-iconbtn--search { width: 40px; padding: 0; }
    .pf-iconbtn--search kbd { display: none; }
}

@media (max-width: 960px) {
    :root, html[data-theme] { --pf-header-h: 70px; }
    .pf-nav__links { display: none; }
    .pf-burger { display: inline-flex; }
    .pf-nav__actions { margin-left: auto; }
    .pf-nav { gap: 8px; }
    .pf-account > summary .pf-account__name { display: none; }
    .pf-mega { display: none; }
}

@media (max-width: 767px) {
    :root, html[data-theme] { --pf-header-h: 64px; }
    .pf-search__esc { display: none; }
    .pf-search__close { width: 44px; height: 44px; }
    .pf-burger { width: 44px; padding: 0; justify-content: center; gap: 0; }
    .pf-burger > span:last-child { display: none; }
    .pf-nav__actions { gap: 6px; }
    .pf-iconbtn--search { display: inline-flex; width: 40px; padding: 0; }
    .pf-iconbtn--search .pf-iconbtn__label,
    .pf-iconbtn--search kbd { display: none; }
    .pf-brand__mark { width: 36px; height: 36px; border-radius: 10px; }
    .pf-brand__mark svg { width: 22px; height: 22px; }
    .pf-brand__name { font-size: 1rem; }
    .pf-nav__actions .pf-iconbtn--settings,
    .pf-nav__actions .pf-theme { display: none; }
    .pf-tabbar { display: grid; }
    .pf-footer__top { grid-template-columns: 1fr 1fr; }
    .pf-footer__brand { grid-column: 1 / -1; }
    .pf-footer__wordmark { font-size: clamp(3rem, 17vw, 6rem); }
    .cookie-modal {
        inset: auto 10px calc(10px + env(safe-area-inset-bottom)) 10px;
        max-width: none;
    }
    .cookie-modal__card { padding: 18px; border-radius: 18px; }
    .cookie-modal__btn { flex: 1 1 auto; }
    .breadcrumb-row { padding-block: 6px; }
}

@media (max-width: 420px) {
    .pf-brand__name { font-size: 0.92rem; }
    .pf-mobile-panel__link { padding: 0.75rem 0.2rem; }
    .pf-mobile-panel__group + .pf-mobile-panel__group { margin-top: 22px; }
}


/* Footer / account helpers added with the masthead build. */
.pf-account__logout {
    margin: 4px 0 0;
    padding-top: 4px;
    border-top: 1px solid var(--line);
}
.pf-account__logout .pf-account__link { color: var(--danger); }
.pf-header__login { white-space: nowrap; min-height: 45px; }
.pf-account--admin > summary { border-color: var(--pf-logic); }

@media (max-width: 960px) {
    .pf-header__login { display: none; }
}
@media (max-width: 767px) {
    .pf-account__name { display: none; }
    .pf-account--admin { display: none; }
}

/* No-JS fallback navigation. Hidden by default because JavaScript builds the
   interactive version; it is the only nav visible when scripting is off. */
.pf-noscript {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    padding: 10px clamp(16px, 3vw, 34px);
    border-bottom: 2px solid var(--pf-ink);
    background: var(--pf-sun);
    color: #262019;
    font-size: 0.82rem;
    font-weight: 800;
}
.pf-noscript a {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 8px;
    border-radius: 999px;
    color: #262019;
    text-decoration: underline;
    text-underline-offset: 2px;
}
/* Game pages that wrap canvas + HUD in a landmark must not change the game
   layout (the stage still sizes itself against the body flex column). */
.pf-game-main { display: contents; }

/* =========================================================================
   SETTINGS / HELP DIALOGS — Paper Arcade reskin
   -------------------------------------------------------------------------
   UIKit's dialogs were still using the old glossy iOS-style switches. These
   overrides make them read like the rest of the site (ink outlines, paper,
   hard offset shadow) and give the theme control a home in Settings too.
   ========================================================================= */
.ui-modal-backdrop .ui-modal {
    border: 2px solid var(--pf-ink) !important;
    border-radius: 22px !important;
    background: var(--pf-card) !important;
    color: var(--pf-ink) !important;
    box-shadow: 8px 8px 0 var(--pf-ink) !important;
    padding: clamp(18px, 3vw, 28px) !important;
}
.ui-modal-backdrop .ui-modal header h3,
.ui-modal-backdrop .ui-modal h3 {
    font-family: var(--font-display) !important;
    font-weight: 900 !important;
    letter-spacing: -0.04em !important;
    color: var(--pf-ink) !important;
}
.ui-modal .modal-close {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1.5px solid var(--pf-ink) !important;
    border-radius: 50%;
    background: var(--pf-card) !important;
    color: var(--pf-ink) !important;
    font-size: 1.1rem;
    line-height: 1;
}
.ui-modal .modal-close:hover { background: var(--pf-sun-soft) !important; }
.ui-settings-list { gap: 8px !important; }
.ui-settings-list li {
    border: 1.5px solid var(--line) !important;
    border-radius: 12px !important;
    background: color-mix(in srgb, var(--pf-paper) 62%, var(--pf-card)) !important;
    padding: 10px 12px !important;
    color: var(--pf-ink) !important;
}
.ui-settings-list li.ui-setting-theme {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-color: var(--pf-ink) !important;
    background: var(--pf-sun-soft) !important;
}
.ui-setting-copy { display: flex; flex-direction: column; gap: 2px; }
.ui-setting-copy strong { font-size: 0.9rem; }
.ui-setting-copy span { color: var(--pf-ink-soft); font-size: 0.76rem; line-height: 1.35; }
.ui-inline-toggle { color: var(--pf-ink) !important; font-size: 0.9rem !important; }
.ui-inline-toggle input[type='checkbox'] {
    width: 44px !important;
    height: 26px !important;
    flex-basis: 44px !important;
    border: 2px solid var(--pf-ink) !important;
    background: var(--pf-card) !important;
    box-shadow: none !important;
}
.ui-inline-toggle input[type='checkbox']::after {
    width: 18px !important;
    height: 18px !important;
    top: 2px !important;
    left: 2px !important;
    background: var(--pf-ink) !important;
}
.ui-inline-toggle input[type='checkbox']:checked {
    background: var(--pf-spatial) !important;
    border-color: var(--pf-ink) !important;
}
.ui-inline-toggle input[type='checkbox']:checked::after {
    transform: translateX(18px) !important;
    background: var(--pf-spatial-ink) !important;
}
.ui-modal .ui-button {
    min-height: 40px;
    padding: 0.5rem 1rem !important;
    border: 2px solid var(--pf-ink) !important;
    border-radius: 999px !important;
    background: var(--pf-ink) !important;
    color: var(--pf-paper) !important;
    font-family: var(--font-body) !important;
    font-weight: 800 !important;
    box-shadow: 0 3px 0 var(--pf-ink) !important;
}
.ui-modal .ui-button.secondary {
    background: var(--pf-card) !important;
    color: var(--pf-ink) !important;
}
.ui-settings-list select {
    min-height: 40px;
    border: 2px solid var(--pf-ink) !important;
    border-radius: 10px !important;
    background: var(--pf-card) !important;
    color: var(--pf-ink) !important;
    font-weight: 700;
}

/* Keep long dialogs usable on short screens: the actions stay at the bottom
   of the scrollable panel rather than falling below the viewport. */
.ui-modal-backdrop .ui-modal {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.ui-modal-backdrop .ui-modal header {
    margin-bottom: 16px !important;
    padding-bottom: 10px;
    border-bottom: 1.5px solid var(--line);
    background: transparent !important;
    border-radius: 0 !important;
}
.ui-modal .actions {
    position: sticky;
    bottom: -1px;
    padding: 10px 0 2px;
    background: var(--pf-card);
}

/* =========================================================================
   SHELL OVERRIDES THAT MUST BEAT LEGACY PAGE CSS
   -------------------------------------------------------------------------
   These used to live in an inline <style> block emitted from renderHeader().
   The body class is added before the header is parsed, so a normal stylesheet
   with a .pf-shell-body prefix has enough specificity to win without shipping
   a second, uncached style block on every request.
   ========================================================================= */
body.pf-shell-body > .breadcrumb-row {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 14px !important;
    width: 100% !important;
    max-width: var(--pf-max) !important;
    margin: 0 auto !important;
    padding: 8px clamp(16px, 3vw, 34px) !important;
    border-top: 1px solid var(--line) !important;
    font-size: 0.76rem !important;
}
body.pf-shell-body .breadcrumb-progress {
    display: grid !important;
    grid-template-columns: auto auto !important;
    align-items: center !important;
    gap: 8px !important;
    min-width: 0 !important;
    padding: 5px 10px !important;
    border: 1.5px solid var(--line) !important;
    border-radius: 10px !important;
    background: var(--pf-card) !important;
    box-shadow: none !important;
    font-family: var(--font-mono) !important;
}
body.pf-shell-body .breadcrumb-progress .progress-label {
    font-size: 0.75rem !important;
    letter-spacing: 0.08em !important;
    color: var(--pf-ink-soft) !important;
}
body.pf-shell-body .breadcrumb-progress .progress-meta {
    display: flex !important;
    align-items: baseline !important;
    gap: 8px !important;
    font-size: 0.72rem !important;
}
body.pf-shell-body .breadcrumb-progress .progress-value { font-size: 0.75rem !important; font-weight: 700 !important; color: var(--pf-ink) !important; }
body.pf-shell-body .breadcrumb-progress .progress-sub { font-size: 0.75rem !important; color: var(--pf-ink-soft) !important; }
body.pf-shell-body .breadcrumb-progress.is-hidden { display: none !important; }

@media (max-width: 767px) {
    body.pf-shell-body:not(.pf-playing):not(.pf-auth-page) { padding-bottom: 86px !important; }
    body.pf-playing .pf-tabbar,
    body.pf-auth-page .pf-tabbar { display: none !important; }
    body.pf-playing > .pf-footer,
    body.pf-auth-page > .pf-footer { padding-bottom: 36px; }
    body.pf-auth-page { padding-bottom: 0 !important; }
    body.pf-playing > .breadcrumb-row { display: none !important; }
}
@media (max-width: 720px) {
    body.pf-shell-body > .breadcrumb-row { flex-direction: row !important; align-items: center !important; }
    body.pf-shell-body .breadcrumb-progress { display: none !important; }
}

/* Back-to-library chip on game screens. It is in normal flow after the
   masthead, so it does not cover the puzzle, and it is only shown where the
   breadcrumb strip is hidden (phones). */
.pf-game-back { display: none; }
@media (max-width: 767px) {
    .pf-game-back {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        min-height: 44px;
        margin: 8px 12px 0;
        padding: 4px 10px;
        border: 1.5px solid var(--pf-ink);
        border-radius: 999px;
        background: var(--pf-card);
        color: var(--pf-ink);
        font-size: 0.78rem;
        font-weight: 800;
        text-decoration: none;
        box-shadow: 2px 2px 0 var(--pf-ink);
        width: fit-content;
    }
    .pf-game-back:hover { background: var(--pf-sun-soft); color: var(--pf-ink); }
}

/* =========================================================================
   3D GAME MOBILE HEADER
   ========================================================================= */
.pf-3d-mobile-bar { display: none; }
@media (max-width: 768px) {
    .pf-3d-mobile-bar {
        display: flex;
        align-items: center;
        gap: 9px;
        min-height: 52px;
        margin: 8px 10px 0;
        padding: 5px 10px 5px 6px;
        border: 1.5px solid var(--pf-ink);
        border-radius: 999px;
        background: var(--pf-card);
        color: var(--pf-ink);
        box-shadow: 2px 2px 0 var(--pf-ink);
    }
    .pf-3d-mobile-bar__back {
        display: inline-grid;
        place-items: center;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--pf-ink);
        color: var(--pf-paper);
        font-size: 0.9rem;
        font-weight: 800;
        text-decoration: none;
    }
    .pf-3d-mobile-bar__title {
        flex: 1 1 auto;
        margin: 0;
        overflow: hidden;
        font-family: var(--font-display);
        font-size: 1rem;
        font-weight: 900;
        letter-spacing: -0.03em;
        line-height: 1;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .pf-3d-mobile-bar__tag {
        padding: 2px 6px;
        border: 1px solid var(--pf-ink);
        border-radius: 5px;
        background: var(--pf-spatial);
        color: var(--pf-spatial-ink);
        font-family: var(--font-mono);
        font-size: 0.75rem;
        font-weight: 700;
        letter-spacing: 0.06em;
    }
    body.pf-3d-mobile .game-sidebar .game-sidebar-section.card:nth-child(1) { display: none !important; }
    body.pf-3d-mobile .game-sidebar { padding-top: 8px; }
    body.pf-3d-mobile .game-canvas-container { margin-top: 8px !important; }
}

/* Functional game/back targets are 44px; text links keep a 24px minimum. */
.pf-game-back { min-height: 44px; }
.pf-hero__3dlink { min-height: 24px; }
.ui-setting-theme .ui-button { min-height: 44px !important; }

/* =========================================================================
   2D GAME MOBILE HEADER
   ========================================================================= */
.pf-2d-mobile-bar { display: none; }
@media (max-width: 900px) {
    .pf-2d-mobile-bar {
        display: flex;
        align-items: center;
        gap: 9px;
        min-height: 52px;
        margin: 8px 12px 0;
        padding: 4px 10px 4px 5px;
        border: 1.5px solid var(--pf-ink);
        border-radius: 999px;
        background: var(--pf-card);
        color: var(--pf-ink);
        box-shadow: 2px 2px 0 var(--pf-ink);
    }
    .pf-2d-mobile-bar__back {
        display: inline-grid;
        place-items: center;
        width: 44px;
        height: 44px;
        flex: 0 0 auto;
        border-radius: 50%;
        background: var(--pf-ink);
        color: var(--pf-paper);
        font-size: 0.9rem;
        font-weight: 800;
        text-decoration: none;
    }
    .pf-2d-mobile-bar__title {
        flex: 1 1 auto;
        margin: 0;
        overflow: hidden;
        font-family: var(--font-display);
        font-size: 1rem;
        font-weight: 900;
        letter-spacing: -0.03em;
        line-height: 1;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    body.pf-2d-mobile .classic-masthead { display: none !important; }
    body.pf-2d-mobile .pf-game-back { display: none !important; }
    body.pf-2d-mobile .classic-page-wrapper { padding-top: 10px !important; }
}
@media (max-width: 900px) and (max-height: 700px) {
    .pf-2d-mobile-bar { display: none !important; }
}

/* Compact 2D title/back that lives inside the existing action row on short
   phones, so it never costs board height. */
.pf-2d-mini { display: none; }
@media (max-width: 900px) and (max-height: 700px) {
    .pf-2d-mini {
        display: flex;
        align-items: center;
        gap: 6px;
        flex: 0 0 auto;
        min-width: 0;
        margin-right: 2px;
    }
    .pf-2d-mini__back {
        display: inline-grid;
        place-items: center;
        width: 44px;
        height: 44px;
        flex: 0 0 auto;
        border-radius: 50%;
        background: var(--pf-ink);
        color: var(--pf-paper);
        font-size: 0.9rem;
        font-weight: 800;
        text-decoration: none;
    }
    .pf-2d-mini__title {
        margin: 0;
        max-width: 62px;
        overflow: hidden;
        font-family: var(--font-display);
        font-size: 0.88rem;
        font-weight: 900;
        letter-spacing: -0.03em;
        line-height: 1;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    body.pf-playing .classic-toolbar-left .classic-btn {
        padding-left: 0.3rem;
        padding-right: 0.3rem;
        font-size: 0.64rem;
        white-space: nowrap;
    }
}

/* =========================================================================
   DARK-MODE ACCENT
   -------------------------------------------------------------------------
   In light mode the serif accent sits on a solid marigold block, so pine
   text is high contrast. In dark mode the accent is mint; a solid yellow
   block behind it drops to about 1.5:1. Keep the mint text on the dark
   page and turn the marigold into a thin underline that never sits behind the
   glyphs.
   ========================================================================= */
html[data-theme="dark"] .pf-accent-serif {
    background-image: none !important;
    color: var(--pf-pine) !important;
    text-decoration: underline;
    text-decoration-color: var(--pf-sun);
    text-decoration-thickness: 3px;
    text-underline-offset: 8px;
}
.pf-footer__list a { min-height: 45px; }
.pf-footer__meta { font-size: 0.75rem !important; }
.breadcrumb-row .best-time-card,
.breadcrumb-row .header-best-time { font-size: 0.75rem; }
.breadcrumb-row .best-time-card__label { font-size: 0.75rem; }
.breadcrumb-row .best-time-card__value { font-size: 0.9rem; }
