/* ==========================================================================
   Friendoku design system (fd-*)
   Documented in /design.md. Loaded after style.css, so these rules win over
   legacy styles. Build new UI from these classes; avoid inline styles.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   Base colour/space/type/radius tokens live in style.css :root and are
   overridden for dark mode on body.dark-mode. These add the fd-* layer.
   Declared on :root AND body: var() references resolve where declared, so
   redeclaring on body makes these follow body.dark-mode's colours.
   -------------------------------------------------------------------------- */
:root,
body {
    --fd-page-width: 560px;

    --fd-surface: var(--menu-bg);
    --fd-surface-alt: var(--color-bg-alt);
    --fd-line: var(--color-border);
    --fd-ink: var(--text-color);
    --fd-ink-muted: var(--color-text-muted);

    --fd-gradient-brand: linear-gradient(120deg, var(--color-primary), var(--color-info) 60%, var(--color-success));
    --fd-gradient-cta: linear-gradient(135deg, var(--color-primary), #6366f1);
    --fd-gradient-gold: linear-gradient(120deg, #f59e0b, #f97316 50%, #ec4899);
    --fd-gold: #f5b301;

    --fd-radius-card: var(--radius-xl);
    --fd-radius-control: var(--radius-full);
    --fd-shadow-card: var(--shadow-md);
    --fd-shadow-pop: 0 3px 0 rgba(15, 23, 42, 0.18);

    --fd-ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --------------------------------------------------------------------------
   2. Layout
   -------------------------------------------------------------------------- */
.fd-page {
    width: 100%;
    max-width: var(--fd-page-width);
    box-sizing: border-box;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    min-width: 0;
}

.fd-page > * { min-width: 0; }

/* PageLayout's back button: same width as the page column, centred under it. */
.page-layout > .page-back-button {
    align-self: center;
    width: min(var(--fd-page-width), calc(100% - 2 * var(--space-md)));
    max-width: none;
    margin: var(--space-lg) auto;
    float: none;
}

/* The game board pieces (info bar, grid, controls) share this width. */
.game-area {
    width: min(90vw, var(--grid-max-width));
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

/* Light/dark toggle: fixed top-left, mirroring the menu button top-right,
   so neither overlaps the centred logo on phones. */
button.theme-toggle {
    position: fixed;
    top: var(--space-md);
    left: var(--space-md);
    z-index: var(--z-hamburger);
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--fd-radius-control);
    background: var(--fd-surface);
    color: var(--fd-ink);
    border: 1px solid var(--fd-line);
    box-shadow: var(--shadow-sm);
}

/* Menu toggle: fixed top-right, the same round button as the theme toggle.
   It sits above the drawer (z-hamburger > z-sidebar) and turns into a close (✕). */
button.fd-menu-toggle {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    z-index: var(--z-hamburger);
    width: 40px;
    height: 40px;
    padding: 0;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--fd-radius-control);
    background: var(--fd-surface);
    color: var(--fd-ink);
    border: 1px solid var(--fd-line);
    box-shadow: var(--shadow-sm);
    transition: transform 200ms var(--fd-ease-bounce), color var(--transition-fast);
}

button.fd-menu-toggle:hover { color: var(--color-primary); transform: scale(1.06); }
button.fd-menu-toggle.is-open svg { animation: fd-menu-spin 260ms var(--fd-ease-bounce); }

@keyframes fd-menu-spin {
    from { rotate: -90deg; scale: 0.6; }
    to { rotate: 0deg; scale: 1; }
}

@media (prefers-reduced-motion: reduce) {
    button.fd-menu-toggle.is-open svg { animation: none; }
}

/* Drawer layout: a padded column with even gaps; the footer sits at the bottom.
   Top padding leaves room for the menu toggle. */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    height: 100vh;
    height: 100dvh;
    padding: calc(var(--space-md) + 52px) var(--space-lg) calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
}

.sidebar > a:first-child { align-self: center; }

.sidebar .fd-actions--stack { gap: 10px; }

.sidebar hr {
    margin: 0;
    border: none;
    border-top: 1px solid var(--fd-line);
}

.sidebar .fd-drawer-foot {
    margin-top: auto;
    padding-top: var(--space-lg);
    border-top: 1px solid var(--fd-line);
}

@media (max-width: 560px) {
    .sidebar {
        gap: var(--space-xl);
        padding-left: var(--space-xl);
        padding-right: var(--space-xl);
    }

    .sidebar .fd-actions--stack { gap: 12px; }
    .sidebar .fd-btn { min-height: 48px; }
}

button.theme-toggle:hover {
    color: var(--color-primary);
    transform: rotate(-15deg);
}

/* --------------------------------------------------------------------------
   3. Buttons
   <button class="fd-btn fd-btn--primary"> · also works on <a>/<Link>.
   Variants: --primary (gradient CTA), --secondary (quiet), --danger, --ghost.
   Size: --sm. Layout: --block (full width).
   -------------------------------------------------------------------------- */
.fd-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    min-height: 44px;
    box-sizing: border-box;
    border: 1px solid transparent;
    border-radius: var(--fd-radius-control);
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: transform 160ms var(--fd-ease-bounce), box-shadow var(--transition-fast),
        background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.fd-btn:hover:not(:disabled) { transform: translateY(-2px); }
.fd-btn:active:not(:disabled) { transform: translateY(1px); }

.fd-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.fd-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.fd-btn--primary {
    background: var(--fd-gradient-cta);
    color: #fff;
    box-shadow: var(--fd-shadow-pop);
}

.fd-btn--primary:hover:not(:disabled) { box-shadow: 0 5px 0 rgba(15, 23, 42, 0.18); color: #fff; }
.fd-btn--primary:active:not(:disabled) { box-shadow: 0 1px 0 rgba(15, 23, 42, 0.18); }

.fd-btn--secondary {
    background: var(--fd-surface-alt);
    color: var(--fd-ink);
    border-color: var(--fd-line);
}

.fd-btn--secondary:hover:not(:disabled) { border-color: var(--color-primary); color: var(--fd-ink); }

.fd-btn--danger {
    background: var(--color-danger);
    color: #fff;
    box-shadow: var(--fd-shadow-pop);
}

.fd-btn--danger:hover:not(:disabled) { background: var(--color-danger-hover); color: #fff; }

.fd-btn--ghost {
    background: transparent;
    color: var(--fd-ink-muted);
}

.fd-btn--ghost:hover:not(:disabled) { color: var(--fd-ink); background: var(--fd-surface-alt); }

.fd-btn--gold {
    background: var(--fd-gradient-gold);
    color: #fff;
    box-shadow: var(--fd-shadow-pop);
}

.fd-btn--gold:hover:not(:disabled) { color: #fff; box-shadow: 0 5px 0 rgba(15, 23, 42, 0.18); }

/* Square icon-only button; pair with --ghost/--sm and an aria-label. */
.fd-btn--icon {
    width: 44px;
    padding: 0;
}

.fd-btn--sm.fd-btn--icon { width: 34px; }

.fd-btn--sm {
    min-height: 34px;
    padding: 4px var(--space-md);
    font-size: var(--font-size-sm);
}

.fd-btn--block { width: 100%; }

.fd-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

/* Stacked, equal-width buttons (landing page menu) */
.fd-actions.fd-actions--stack {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    margin: 0;
    width: 100%;
}

.fd-actions--stack .fd-btn { width: 100%; }

/* --------------------------------------------------------------------------
   4. Surfaces: hero + card
   -------------------------------------------------------------------------- */
.fd-hero {
    background: var(--fd-surface);
    border: 1px solid var(--fd-line);
    border-radius: var(--fd-radius-card);
    box-shadow: var(--fd-shadow-card);
    overflow: hidden;
}

/* Gradient strip with floating sudoku digits (<HeroBanner />). */
.fd-banner {
    height: 112px;
    background: var(--fd-gradient-brand);
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    align-items: center;
    padding: 0 var(--space-md);
    overflow: hidden;
    user-select: none;
}

.is-gold .fd-banner { background: var(--fd-gradient-gold); }

.fd-banner span {
    font-family: var(--font-family-mono);
    font-size: 1.75rem;
    color: rgba(255, 255, 255, 0.28);
    text-align: center;
    animation: fd-float 6s ease-in-out infinite;
}

.fd-banner span:nth-child(odd) { animation-delay: -3s; transform: translateY(-14px); }
.fd-banner span:nth-child(3n) { animation-duration: 8s; }

.fd-hero-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0 var(--space-lg) var(--space-lg);
}

/* Round avatar overlapping the banner. Use .fd-emblem for an emoji instead of an image. */
.fd-avatar {
    width: 120px;
    height: 120px;
    margin-top: -60px;
    box-sizing: border-box;
    border-radius: var(--radius-full);
    object-fit: cover;
    background: var(--fd-surface);
    border: 5px solid var(--fd-surface);
    box-shadow: var(--shadow-lg);
    transition: transform 300ms var(--fd-ease-bounce);
}

.fd-avatar:hover { transform: rotate(-6deg) scale(1.05); }

.fd-emblem {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.25rem;
    background: var(--fd-surface-alt);
}

.fd-name {
    margin: var(--space-sm) 0 0;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--fd-ink);
    overflow-wrap: anywhere;
}

.fd-tagline {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-xs) var(--space-md);
    margin-top: var(--space-sm);
    font-size: var(--font-size-sm);
    color: var(--fd-ink-muted);
}

.fd-vibe {
    font-weight: 600;
    color: var(--fd-ink);
}

/* Streak status under a profile name; warms up as the streak grows */
.fd-streak-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: var(--space-md);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--fd-line);
    background: var(--fd-surface-alt);
    color: var(--fd-ink);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.fd-streak-pill.is-warm {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.45);
}

.fd-streak-pill.is-hot {
    background: rgba(249, 115, 22, 0.16);
    border-color: rgba(249, 115, 22, 0.55);
}

.fd-streak-pill.is-legend {
    background: var(--fd-gradient-gold);
    border-color: transparent;
    color: #fff;
    box-shadow: var(--fd-shadow-pop);
}

.fd-streak-pill.is-rest { color: var(--fd-ink-muted); font-weight: 600; }

.fd-supporter-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: var(--space-xs);
    padding: 2px 12px;
    border-radius: var(--radius-full);
    background: var(--fd-gradient-gold);
    color: #fff;
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-decoration: none;
}

.fd-card {
    background: var(--fd-surface);
    border: 1px solid var(--fd-line);
    border-radius: var(--fd-radius-card);
    padding: var(--space-lg);
    box-sizing: border-box;
}

.fd-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-xs) var(--space-sm);
    margin-bottom: var(--space-md);
}

.fd-card-head h2,
.fd-card-head h3 {
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--fd-ink);
}

.fd-card-head--center {
    justify-content: center;
    text-align: center;
}

.fd-card-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

/* --------------------------------------------------------------------------
   5. Text
   -------------------------------------------------------------------------- */
.fd-muted {
    font-size: var(--font-size-sm);
    color: var(--fd-ink-muted);
}

.fd-lead {
    margin: 0 0 var(--space-md);
    color: var(--fd-ink-muted);
    line-height: 1.6;
}

/* Long-form copy (privacy, terms, help, changelog). Put inside .fd-card. */
.fd-prose {
    color: var(--fd-ink);
    line-height: 1.65;
    overflow-wrap: anywhere;
}

.fd-prose > :first-child { margin-top: 0; }
.fd-prose > :last-child { margin-bottom: 0; }

.fd-prose h2 {
    margin: var(--space-lg) 0 var(--space-sm);
    font-size: var(--font-size-lg);
    font-weight: 700;
}

.fd-prose h3 {
    margin: var(--space-md) 0 var(--space-xs);
    font-size: var(--font-size-base);
    font-weight: 700;
}

.fd-prose p { margin: 0 0 var(--space-md); }

.fd-prose ul,
.fd-prose ol {
    margin: 0 0 var(--space-md);
    padding-left: 1.4em;
}

.fd-prose li { margin-bottom: var(--space-xs); }

.fd-prose a {
    color: var(--color-primary);
    font-weight: 600;
}

.fd-prose code {
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    background: var(--fd-surface-alt);
    font-size: 0.9em;
}

/* --------------------------------------------------------------------------
   6. Lists, tabs, chips
   -------------------------------------------------------------------------- */
/* Divided rows with an emoji/icon on the left. */
.fd-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fd-list > li {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md) 0;
}

.fd-list > li + li { border-top: 1px solid var(--fd-line); }
.fd-list > li:first-child { padding-top: 0; }
.fd-list > li:last-child { padding-bottom: 0; }

.fd-list-icon {
    font-size: 1.5rem;
    line-height: 1.2;
    flex-shrink: 0;
}

.fd-list-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.fd-list-body strong { color: var(--fd-ink); }

.fd-list-aside {
    flex-shrink: 0;
    align-self: center;
}

/* Tappable navigation rows */
.fd-links {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.fd-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    color: var(--fd-ink);
    text-decoration: none;
    font-weight: 500;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.fd-link:hover {
    background: var(--fd-surface-alt);
    transform: translateX(3px);
}

.fd-link--danger { color: var(--color-danger); }

/* Underline tabs */
.fd-tabs {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    margin-bottom: var(--space-sm);
    border-bottom: 1px solid var(--fd-line);
}

button.fd-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    margin-bottom: -1px;
    padding: var(--space-sm) var(--space-xs);
    color: var(--fd-ink-muted);
    font-weight: 600;
}

button.fd-tab:hover { color: var(--fd-ink); }

button.fd-tab.is-active {
    color: var(--fd-ink);
    border-bottom-color: var(--color-primary);
}

/* Small rounded label. Variants: --danger, --success, --gold, --muted */
.fd-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 20px;
    height: 20px;
    padding: 0 8px;
    box-sizing: border-box;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    color: #fff;
    font-size: var(--font-size-xs);
    font-weight: 600;
    white-space: nowrap;
}

.fd-pill--danger { background: var(--color-danger); }
.fd-pill--success { background: var(--color-success); }
.fd-pill--gold { background: var(--fd-gradient-gold); }
.fd-pill--muted { background: var(--fd-surface-alt); color: var(--fd-ink-muted); border: 1px solid var(--fd-line); }

/* --------------------------------------------------------------------------
   7. Data display
   -------------------------------------------------------------------------- */
.fd-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
}

.fd-stats.fd-stats--fit { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

.fd-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-md) var(--space-sm);
    background: var(--fd-surface);
    border: 1px solid var(--fd-line);
    border-radius: var(--radius-lg);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.fd-stat--inset { background: var(--fd-surface-alt); }

.fd-stat:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.fd-stat:hover .fd-stat-emoji { animation: fd-bounce 500ms ease; }

.fd-stat-emoji { font-size: 1.5rem; line-height: 1.2; }

.fd-stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--fd-ink);
    font-variant-numeric: tabular-nums;
}

.fd-stat-label {
    font-size: var(--font-size-xs);
    color: var(--fd-ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: center;
}

/* 28-day activity grid (profile) */
.fd-activity {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    max-width: 320px;
}

.fd-day {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    background: var(--fd-surface-alt);
    border: 1px solid var(--fd-line);
}

.fd-day.is-solved {
    background: linear-gradient(135deg, var(--color-primary), var(--color-info));
    border-color: transparent;
}

.fd-day.is-today {
    outline: 2px solid var(--color-warning);
    outline-offset: 1px;
}

/* Achievement badges */
.fd-badges {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: var(--space-sm);
}

.fd-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-md) var(--space-xs);
    border-radius: var(--radius-lg);
    background: var(--fd-surface-alt);
    text-align: center;
    cursor: default;
    transition: transform 200ms var(--fd-ease-bounce);
}

.fd-badge:hover { transform: rotate(-3deg) scale(1.06); }

.fd-badge-icon { font-size: 2rem; line-height: 1; }

.fd-badge-name {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--fd-ink);
    line-height: 1.3;
}

/* Avatar grid (friends) */
.fd-friends {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: var(--space-md) var(--space-sm);
}

.fd-friend {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    min-width: 0;
    text-decoration: none;
    color: var(--fd-ink-muted);
    font-size: var(--font-size-xs);
}

.fd-friend img {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    object-fit: cover;
    border: 2px solid var(--fd-line);
    transition: transform var(--transition-base), border-color var(--transition-base);
}

.fd-friend:hover img {
    transform: scale(1.1);
    border-color: var(--color-primary);
}

.fd-friend span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Ranked player rows (leaderboards, archive) */
.fd-rank-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fd-rank-list li + li { border-top: 1px solid var(--fd-line); }

.fd-rank-row {
    display: grid;
    grid-template-columns: 2rem 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-xs);
    text-decoration: none;
    color: var(--fd-ink);
}

.fd-rank-row:hover .fd-rank-name { color: var(--color-primary); }

.fd-rank-row.is-me {
    box-shadow: inset 3px 0 0 var(--color-primary);
    padding-left: var(--space-sm);
}

.fd-rank-row.is-me .fd-rank-name { font-weight: 700; }

.fd-rank-pos {
    text-align: center;
    font-weight: 700;
    font-size: var(--font-size-sm);
    color: var(--fd-ink-muted);
}

.is-podium .fd-rank-pos { font-size: 1.35rem; }

/* Supporters: drifting orange stars behind their row (support orange, see --fd-gradient-gold) */
.fd-rank-row.is-supporter {
    position: relative;
    isolation: isolate;
    border-radius: var(--radius-lg);
    background:
        linear-gradient(90deg, rgba(249, 115, 22, 0.16), rgba(245, 158, 11, 0.08) 60%, rgba(236, 72, 153, 0.10)),
        url('/static/supporter-stars.svg') 0 0 / 128px 60px repeat;
    animation: fd-stars-drift 24s linear infinite;
}

.fd-rank-row.is-supporter .fd-rank-name {
    color: var(--fd-ink);
    text-shadow: 0 0 10px rgba(249, 115, 22, 0.55), 0 0 18px rgba(245, 158, 11, 0.35);
    animation: none;
}

.fd-rank-row.is-supporter .fd-rank-avatar { box-shadow: 0 0 0 2px #f97316; }

/* Keep text readable over the stars */
.fd-rank-row.is-supporter .fd-rank-who,
.fd-rank-row.is-supporter .fd-rank-score {
    padding: 0 4px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--fd-surface) 60%, transparent);
}

@keyframes fd-stars-drift {
    from { background-position: 0 0, 0 0; }
    to { background-position: 0 0, 128px 60px; }
}

.fd-rank-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.fd-rank-who {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.fd-rank-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color var(--transition-fast);
}

.fd-rank-meta {
    display: flex;
    gap: var(--space-sm);
    font-size: var(--font-size-xs);
    color: var(--fd-ink-muted);
}

/* Right side of a rank row: [flawless | errors] [hints] time.
   Rows sort by errors first, then time (see server.py LEADERBOARD_ORDER). */
.fd-rank-score {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
}

.fd-rank-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.fd-rank-flawless { box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-success) 25%, transparent); }

/* Narrow phones: just the ✨ (the title still says "Flawless") */
@media (max-width: 400px) {
    .fd-rank-flawless-label { display: none; }
}

/* Person row: avatar, name + meta, optional aside. Like .fd-rank-row without a rank column. */
.fd-person-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-xs);
    text-decoration: none;
    color: var(--fd-ink);
}

a.fd-person-row:hover .fd-rank-name { color: var(--color-primary); }

.fd-leaderboard {
    width: 100%;
    min-width: 0;
}

/* Friends still to play: avatar grid that never widens its card */
.fd-nudge { margin-top: var(--space-lg); }

.fd-nudge-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-xs) var(--space-sm);
    margin-bottom: var(--space-sm);
}

.fd-nudge-head h3 {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: 700;
    color: var(--fd-ink);
}

.fd-nudge-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: var(--space-sm);
}

.fd-nudge-list li { min-width: 0; }

button.fd-nudge-friend {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 0;
    background: none;
    border: none;
    color: var(--fd-ink-muted);
    font-size: var(--font-size-xs);
}

button.fd-nudge-friend:disabled { opacity: 0.55; }

.fd-nudge-avatar {
    position: relative;
    display: block;
}

.fd-nudge-avatar img {
    display: block;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    object-fit: cover;
    transition: transform var(--transition-fast);
}

button.fd-nudge-friend:hover:not(:disabled) .fd-nudge-avatar img { transform: scale(1.08); }

.fd-nudge-badge {
    position: absolute;
    right: -4px;
    bottom: -2px;
    font-size: 0.85rem;
    line-height: 1;
}

.fd-nudge-name {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

/* --------------------------------------------------------------------------
   8. Forms
   -------------------------------------------------------------------------- */
.fd-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.fd-form .fd-card-foot { margin-top: 0; }

.fd-field label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--fd-ink);
}

.fd-field input,
.fd-field textarea,
.fd-field select,
.fd-input {
    width: 100%;
    box-sizing: border-box;
    padding: var(--space-sm) var(--space-md);
    min-height: 44px;
    border: 2px solid var(--fd-line);
    border-radius: var(--radius-lg);
    background: var(--color-bg);
    color: var(--fd-ink);
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.fd-field textarea { resize: vertical; }

.fd-field input:focus,
.fd-field textarea:focus,
.fd-field select:focus,
.fd-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.fd-field input:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.fd-hint {
    margin-top: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--fd-ink-muted);
}

/* One-time code */
/* Input + button side by side (invite link + copy) */
.fd-inline-field {
    display: flex;
    gap: var(--space-sm);
}

.fd-inline-field .fd-input { flex: 1; min-width: 0; }
.fd-inline-field .fd-btn { flex-shrink: 0; }

/* Search input with a leading icon */
.fd-search-input {
    position: relative;
}

.fd-search-input .fd-input { padding-left: 2.5rem; }

.fd-search-input svg {
    position: absolute;
    left: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--fd-ink-muted);
    pointer-events: none;
}

.fd-field input.fd-otp-input {
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5em;
    font-size: var(--font-size-2xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Label + description on the left, switch on the right */
.fd-switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    background: var(--fd-surface-alt);
    cursor: pointer;
}

.fd-switch-row > span {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.fd-switch-title {
    font-weight: 600;
    color: var(--fd-ink);
}

.fd-switch {
    appearance: none;
    flex-shrink: 0;
    width: 48px;
    height: 28px;
    margin: 0;
    border-radius: var(--radius-full);
    background: var(--fd-line);
    position: relative;
    cursor: pointer;
    transition: background var(--transition-base);
}

.fd-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform 220ms var(--fd-ease-bounce);
}

.fd-switch:checked { background: var(--color-primary); }
.fd-switch:checked::after { transform: translateX(20px); }

.fd-switch:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.fd-range {
    flex: 1;
    min-width: 0;
    accent-color: var(--color-primary);
}

.fd-volume {
    flex-direction: column;
    align-items: stretch;
    cursor: default;
}

.fd-volume-control {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--fd-ink-muted);
}

.fd-volume-value {
    min-width: 3ch;
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--fd-ink);
}

/* Star rating (feedback) */
.fd-stars {
    display: flex;
    justify-content: center;
    gap: var(--space-xs);
}

button.fd-star {
    padding: 2px;
    background: none;
    border: none;
    color: var(--fd-gold);
    transition: transform 160ms var(--fd-ease-bounce);
}

button.fd-star:hover { transform: scale(1.18); }

/* --------------------------------------------------------------------------
   9. Feedback: messages, empty states, spinner
   -------------------------------------------------------------------------- */
.fd-message {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    border: 1px solid var(--fd-line);
    background: var(--fd-surface-alt);
    color: var(--fd-ink);
    font-size: var(--font-size-sm);
}

.fd-message--success {
    background: var(--color-success-light);
    border-color: var(--color-success);
    color: #065f46;
}

.fd-message--error {
    background: var(--color-danger-light);
    border-color: var(--color-danger);
    color: #991b1b;
}

body.dark-mode .fd-message--success { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
body.dark-mode .fd-message--error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

.fd-empty {
    text-align: center;
    padding: var(--space-md);
    color: var(--fd-ink-muted);
}

.fd-empty p { margin: 0 0 var(--space-md); }

.fd-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------------------------
   10. Modal
   <div class="fd-modal-backdrop"><div class="fd-modal" role="dialog">…
   -------------------------------------------------------------------------- */
.fd-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    animation: fd-fade-in 160ms ease-out;
}

.fd-modal {
    position: relative;
    width: 100%;
    max-width: var(--fd-page-width);
    max-height: calc(100vh - 2 * var(--space-md));
    overflow-y: auto;
    box-sizing: border-box;
    background: var(--fd-surface);
    color: var(--fd-ink);
    border: 1px solid var(--fd-line);
    border-radius: var(--fd-radius-card);
    box-shadow: var(--shadow-xl);
    padding: var(--space-lg);
    animation: fd-pop-in 260ms var(--fd-ease-bounce);
}

.fd-modal--sm { max-width: 420px; }

.fd-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.fd-modal-head h2 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 700;
}

button.fd-modal-close {
    width: 36px;
    height: 36px;
    padding: 0;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--fd-surface-alt);
    color: var(--fd-ink-muted);
    border: none;
}

button.fd-modal-close:hover { color: var(--fd-ink); transform: rotate(90deg); }

/* --------------------------------------------------------------------------
   11. Page patterns
   -------------------------------------------------------------------------- */
/* Landing: result + countdown above the menu */
.fd-landing-note {
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--fd-ink-muted);
}

.fd-landing-note p { margin: 0; }

.fd-landing-result {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--fd-ink);
    font-variant-numeric: tabular-nums;
}

/* Inline search results under the search box */
.fd-search-results {
    margin-top: var(--space-md);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--fd-line);
}

.fd-search-results-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xs);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--fd-ink);
}

/* Friends: profile QR code. White background on purpose so it stays scannable in dark mode. */
.fd-qr {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    text-align: center;
}

.fd-qr img {
    display: block;
    width: 160px;
    max-width: 100%;
    height: auto;
    padding: var(--space-xs);
    border-radius: var(--radius-lg);
    border: 1px solid var(--fd-line);
    background: #fff;
}

/* Completion modal: unlocked rewards */
.fd-rewards {
    margin-top: var(--space-lg);
    text-align: center;
}

.fd-rewards h3 {
    margin: 0 0 var(--space-sm);
    font-size: var(--font-size-base);
    font-weight: 700;
    color: var(--fd-ink);
}

.fd-reward-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-md);
}

.fd-reward {
    width: 96px;
    height: 96px;
    object-fit: contain;
    animation: fd-reward-pop 500ms var(--fd-ease-bounce) both;
}
.fd-modal .fd-stats { margin-bottom: var(--space-lg); }

/* Profile edit: clickable avatar + avatar picker */
button.fd-avatar-edit {
    position: relative;
    display: inline-block;
    margin-top: -60px;
    padding: 0;
    background: none;
    border: none;
    border-radius: var(--radius-full);
}

button.fd-avatar-edit .fd-avatar {
    display: block;
    margin-top: 0;
}

button.fd-avatar-edit:hover .fd-avatar { transform: rotate(-6deg) scale(1.05); }

.fd-avatar-edit-badge {
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--fd-gradient-cta);
    color: #fff;
    border: 3px solid var(--fd-surface);
    box-shadow: var(--shadow-md);
}

.fd-avatar-pack + .fd-avatar-pack {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--fd-line);
}

.fd-avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: var(--space-sm);
}

button.fd-avatar-option {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: none;
    border: 3px solid transparent;
    border-radius: var(--radius-full);
    aspect-ratio: 1;
    transition: transform 160ms var(--fd-ease-bounce), border-color var(--transition-fast);
}

button.fd-avatar-option img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
    object-fit: cover;
}

button.fd-avatar-option:hover { transform: scale(1.08); border-color: var(--fd-line); }
button.fd-avatar-option.is-active { border-color: var(--color-primary); }

/* Logout */
.fd-logout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    box-sizing: border-box;
    background: var(--color-bg-page);
}

.fd-logout .fd-page {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    transition: opacity 400ms ease, transform 400ms ease;
}

.fd-logout.is-animating .fd-page {
    opacity: 1;
    transform: none;
}

.fd-logout.is-complete .fd-page {
    opacity: 0;
    transform: translateY(-12px);
    transition-duration: 250ms;
}

.fd-logout .fd-emblem { animation: fd-wave 1.2s ease-in-out 200ms 2; }

.fd-logout-bar {
    width: 100%;
    max-width: 220px;
    height: 6px;
    margin-top: var(--space-lg);
    border-radius: var(--radius-full);
    background: var(--fd-surface-alt);
    overflow: hidden;
}

.fd-logout-bar span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--color-primary), var(--color-info));
}

.fd-logout.is-animating .fd-logout-bar span {
    width: 100%;
    transition: width 1.5s ease-in-out;
}

/* --------------------------------------------------------------------------
   11b. Sidebar drawer
   The drawer itself is positioned by legacy .sidebar rules in style.css; these
   undo its more specific `.sidebar button` / `.sidebar svg` rules for fd-btn.
   -------------------------------------------------------------------------- */
.sidebar .fd-btn {
    display: inline-flex;
    width: 100%;
    margin: 0;
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--fd-radius-control);
}

.sidebar .fd-btn--secondary { background: var(--fd-surface-alt); color: var(--fd-ink); border: 1px solid var(--fd-line); }
.sidebar .fd-btn--primary { background: var(--fd-gradient-cta); color: #fff; border: 1px solid transparent; }
.sidebar .fd-btn--ghost { background: transparent; color: var(--fd-ink-muted); border: 1px solid transparent; }
.sidebar .fd-btn--ghost:hover:not(:disabled) { background: var(--fd-surface-alt); color: var(--fd-ink); }

.sidebar .fd-btn svg { position: static; }

.fd-drawer-foot {
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--fd-ink-muted);
}

.fd-drawer-foot p { margin: var(--space-xs) 0; }

.fd-drawer-foot nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-xs) var(--space-md);
}

.fd-drawer-foot a {
    color: var(--fd-ink-muted);
    text-decoration: none;
}

.fd-drawer-foot a:hover { color: var(--fd-ink); text-decoration: underline; }
.sidebar .fd-btn--gold { background: var(--fd-gradient-gold); color: #fff; border: 1px solid transparent; }

/* --------------------------------------------------------------------------
   11c. Dense views: wide page, tables, toolbar, pagination, toasts
   Used by the admin dashboard; available anywhere data needs a table.
   -------------------------------------------------------------------------- */
.fd-page.fd-page--wide { max-width: 1100px; }

.fd-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;
}

.fd-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: var(--font-size-xs);
    color: var(--fd-ink-muted);
}

/* Tabs that scroll sideways instead of wrapping on small screens */
.fd-tabs--scroll {
    justify-content: flex-start;
    gap: var(--space-md);
    overflow-x: auto;
    scrollbar-width: none;
}

.fd-tabs--scroll .fd-tab { white-space: nowrap; flex-shrink: 0; }

/* Prominent segmented tabs: a raised bar of pills, active one filled.
   Use for top-level sections of a tool (admin). Add --sticky to keep it in view. */
.fd-tabs.fd-tabs--pills {
    justify-content: flex-start;
    gap: var(--space-xs);
    margin: 0;
    padding: 6px;
    border: 1px solid var(--fd-line);
    border-radius: var(--fd-radius-control);
    background: var(--fd-surface);
    box-shadow: var(--fd-shadow-card);
    overflow-x: auto;
    scrollbar-width: none;
}

.fd-tabs--pills::-webkit-scrollbar { display: none; }

.fd-tabs--pills button.fd-tab {
    flex: 1 0 auto;
    margin: 0;
    padding: var(--space-sm) var(--space-lg);
    min-height: 48px;
    border: none;
    border-radius: var(--fd-radius-control);
    font-size: var(--font-size-base);
    font-weight: 700;
    white-space: nowrap;
    color: var(--fd-ink-muted);
    transition: background var(--transition-fast), color var(--transition-fast), transform 160ms var(--fd-ease-bounce);
}

.fd-tabs--pills button.fd-tab:hover:not(.is-active) {
    background: var(--fd-surface-alt);
    color: var(--fd-ink);
}

.fd-tabs--pills button.fd-tab.is-active {
    background: var(--fd-gradient-cta);
    color: #fff;
    box-shadow: var(--fd-shadow-pop);
    transform: translateY(-1px);
}

.fd-tabs--pills button.fd-tab:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.fd-tabs--sticky {
    position: sticky;
    /* sits below the fixed corner buttons (16px + 40px + gap) */
    top: 64px;
    z-index: 5;
}

@media (max-width: 560px) {
    .fd-tabs--pills button.fd-tab {
        padding: var(--space-sm) var(--space-md);
        font-size: var(--font-size-sm);
    }
}

.fd-admin-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    min-width: 0;
}

/* Data table: wrap in .fd-table-wrap so wide tables scroll inside their card */
.fd-table-wrap {
    width: 100%;
    overflow-x: auto;
    transition: opacity var(--transition-fast);
}

.fd-table-wrap.is-loading { opacity: 0.55; }

.fd-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
    color: var(--fd-ink);
}

.fd-table th,
.fd-table td {
    padding: var(--space-sm);
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--fd-line);
}

.fd-table thead th {
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--fd-ink-muted);
    white-space: nowrap;
}

.fd-table tbody th { font-weight: 600; }
.fd-table tbody tr:last-child > * { border-bottom: none; }
.fd-table tbody tr:hover > * { background: var(--fd-surface-alt); }

.fd-table .is-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.fd-table .is-actions {
    text-align: right;
    white-space: nowrap;
}

.fd-table td.fd-empty { text-align: center; }

/* Player cell: avatar + name/email */
.fd-user-cell {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 220px;
    color: var(--fd-ink);
    text-decoration: none;
}

.fd-user-cell img {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    object-fit: cover;
    flex-shrink: 0;
}

.fd-user-cell-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.fd-user-cell-name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.fd-user-cell:hover .fd-user-cell-name { color: var(--color-primary); }

/* Search / filter row above a table */
.fd-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.fd-toolbar--end {
    justify-content: flex-end;
    margin: var(--space-md) 0 0;
}

.fd-toolbar-grow { flex: 1 1 240px; }
.fd-toolbar-select { width: auto; flex: 0 1 200px; }

.fd-field--inline {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.fd-field--inline label { margin: 0; white-space: nowrap; }
.fd-field--inline input { width: 96px; }

.fd-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-md);
}

.fd-check {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: 44px;
    padding: 0 var(--space-md);
    border-radius: var(--fd-radius-control);
    border: 1px solid var(--fd-line);
    background: var(--fd-surface-alt);
    color: var(--fd-ink);
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.fd-check input { accent-color: var(--color-primary); width: 16px; height: 16px; }
.fd-check:has(input:checked) { border-color: var(--color-primary); }

.fd-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    margin-top: var(--space-md);
}

/* Row of compact actions (list asides) */
.fd-row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-xs);
}

@media (max-width: 560px) {
    .fd-pack-row { flex-wrap: wrap; }
    .fd-pack-row .fd-row-actions {
        width: 100%;
        justify-content: flex-start;
        padding-left: calc(1.5rem + var(--space-md));
    }
}

/* Ghost button that turns red on hover: for delete icons in dense rows */
.fd-btn--danger-ghost:hover:not(:disabled) {
    color: var(--color-danger);
    background: var(--color-danger-light);
}

body.dark-mode .fd-btn--danger-ghost:hover:not(:disabled) { background: rgba(239, 68, 68, 0.15); }

.fd-danger-zone { border-color: var(--color-danger); }

/* Expandable list rows (admin packs) */
.fd-list > li.fd-pack { display: block; }

.fd-pack-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
}

.fd-pack-items { margin-top: var(--space-md); }

/* Image thumbnails with caption and optional remove button */
.fd-thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: var(--space-sm);
}

.fd-thumb {
    position: relative;
    margin: 0;
    padding: var(--space-xs);
    border-radius: var(--radius-lg);
    background: var(--fd-surface-alt);
    text-align: center;
    min-width: 0;
}

.fd-thumb img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
}

.fd-thumb figcaption {
    margin-top: 4px;
    font-size: var(--font-size-xs);
    color: var(--fd-ink-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

button.fd-thumb-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    border: none;
    background: var(--fd-surface);
    color: var(--fd-ink-muted);
    box-shadow: var(--shadow-sm);
    opacity: 0;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}

.fd-thumb:hover button.fd-thumb-remove,
button.fd-thumb-remove:focus-visible { opacity: 1; }

button.fd-thumb-remove:hover { color: var(--color-danger); }

@media (hover: none) {
    button.fd-thumb-remove { opacity: 1; }
}

/* Tiny read-only sudoku preview */
.fd-mini-grid {
    display: grid;
    grid-template-columns: repeat(9, 12px);
    grid-auto-rows: 12px;
    gap: 1px;
    width: max-content;
    padding: 1px;
    background: var(--fd-line);
    border-radius: 3px;
}

.fd-mini-grid span {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--fd-surface);
    font-size: 8px;
    line-height: 1;
    color: var(--fd-ink-muted);
}

.fd-mini-grid span.is-given { color: var(--fd-ink); font-weight: 700; }
.fd-mini-grid span:nth-child(9n + 4),
.fd-mini-grid span:nth-child(9n + 7) { margin-left: 1px; }
.fd-mini-grid span:nth-child(n + 28):nth-child(-n + 36),
.fd-mini-grid span:nth-child(n + 55):nth-child(-n + 63) { margin-top: 1px; }

/* Toasts (<ToastProvider>): non-blocking notifications, bottom centre */
.fd-toasts {
    position: fixed;
    left: 50%;
    bottom: var(--space-lg);
    transform: translateX(-50%);
    z-index: calc(var(--z-modal) + 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    width: min(92vw, 440px);
    pointer-events: none;
}

.fd-toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    box-sizing: border-box;
    padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    border: 1px solid var(--fd-line);
    background: var(--fd-surface);
    color: var(--fd-ink);
    box-shadow: var(--shadow-xl);
    font-size: var(--font-size-sm);
    pointer-events: auto;
    animation: fd-pop-in 260ms var(--fd-ease-bounce);
}

.fd-toast--success { border-left: 4px solid var(--color-success); }
.fd-toast--error { border-left: 4px solid var(--color-danger); }
.fd-toast--info { border-left: 4px solid var(--color-primary); }

.fd-toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }

button.fd-toast-close {
    width: 30px;
    height: 30px;
    padding: 0;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--fd-ink-muted);
}

button.fd-toast-close:hover { background: var(--fd-surface-alt); color: var(--fd-ink); }

.fd-stat .fd-hint { margin-top: 0; }

/* --------------------------------------------------------------------------
   11d. Game feel (see /fun.md): staggered entrances and celebrations.
   Elements set their order with style={{ '--i': index }}.
   -------------------------------------------------------------------------- */
.fd-highlights {
    list-style: none;
    margin: 0 0 var(--space-lg);
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.fd-highlight {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    background: var(--fd-surface-alt);
    font-weight: 600;
    color: var(--fd-ink);
    animation: fd-pop-in 420ms var(--fd-ease-bounce) both;
    animation-delay: calc(var(--i, 0) * 140ms + 250ms);
}

.fd-highlight-icon { font-size: 1.35rem; line-height: 1; }

.fd-highlight.is-special {
    background: var(--fd-gradient-gold);
    color: #fff;
    box-shadow: var(--fd-shadow-pop);
}

.fd-highlight.is-special .fd-highlight-icon { animation: fd-bounce 700ms ease 2; animation-delay: calc(var(--i, 0) * 140ms + 500ms); }

/* Leaderboard rows rise in one after another */
.fd-rank-list > li {
    animation: fd-rise 380ms ease-out both;
    animation-delay: calc(min(var(--i, 0), 12) * 45ms);
}

.fd-rank-row.is-me { animation: fd-me-glow 1.6s ease-out 600ms 1; }

@keyframes fd-rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@keyframes fd-me-glow {
    0% { background-color: transparent; }
    30% { background-color: var(--color-primary-light); }
    100% { background-color: transparent; }
}

/* Profile: the activity grid fills in day by day; badges pop in */
.fd-day {
    animation: fd-day-in 300ms ease-out both;
    animation-delay: calc(var(--i, 0) * 18ms);
}

@keyframes fd-day-in {
    from { opacity: 0; transform: scale(0.6); }
    to { opacity: 1; transform: none; }
}

.fd-badge {
    animation: fd-pop-in 380ms var(--fd-ease-bounce) both;
    animation-delay: calc(min(var(--i, 0), 16) * 50ms);
}

/* Small tag inside a button ("Start Thursday's puzzle  [Hard]") */
.fd-btn-meta {
    padding: 1px 8px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.22);
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.fd-btn--secondary .fd-btn-meta { background: var(--fd-surface); }

/* Evening "streak is waiting" line on the landing page */
.fd-landing-note.fd-streak-risk {
    margin: 0;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    background: rgba(249, 115, 22, 0.12);
    border: 1px solid rgba(249, 115, 22, 0.4);
    color: var(--fd-ink);
    font-weight: 600;
    animation: fd-pop-in 420ms var(--fd-ease-bounce) both;
}

/* Weekly recap card */
.fd-recap-week {
    list-style: none;
    margin: 0 0 var(--space-md);
    padding: 0;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--space-xs);
}

.fd-recap-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.fd-recap-dot {
    width: 100%;
    max-width: 44px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--fd-surface-alt);
    border: 1px solid var(--fd-line);
    color: #fff;
    font-weight: 800;
}

.fd-recap-day.is-solved .fd-recap-dot {
    background: linear-gradient(135deg, var(--color-primary), var(--color-info));
    border-color: transparent;
    animation: fd-day-in 320ms var(--fd-ease-bounce) both;
    animation-delay: calc(var(--i, 0) * 70ms + 150ms);
}

.fd-recap-label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--fd-ink-muted);
}

/* Hot streaks flicker */
.fd-streak-pill.is-hot > span:first-child,
.fd-streak-pill.is-legend > span:first-child {
    display: inline-block;
    animation: fd-flicker 1.8s ease-in-out infinite;
    transform-origin: 50% 90%;
}

@keyframes fd-flicker {
    0%, 100% { transform: rotate(-4deg) scale(1); }
    25% { transform: rotate(3deg) scale(1.08); }
    50% { transform: rotate(-2deg) scale(0.96); }
    75% { transform: rotate(4deg) scale(1.05); }
}

@media (prefers-reduced-motion: reduce) {
    .fd-highlight,
    .fd-highlight.is-special .fd-highlight-icon,
    .fd-rank-list > li,
    .fd-rank-row.is-me,
    .fd-day,
    .fd-badge,
    .fd-streak-pill.is-hot > span:first-child,
    .fd-streak-pill.is-legend > span:first-child,
    .fd-landing-note.fd-streak-risk,
    .fd-recap-day.is-solved .fd-recap-dot { animation: none; }
}

/* --------------------------------------------------------------------------
   11e. Logo: the "nine cells" wordmark (components/Logo.jsx).
   Sizes are in em: set font-size on .fd-logo. Each tile's resting pose uses
   `transform`; the hover wiggle uses `translate` so it stacks on top of the pose.
   -------------------------------------------------------------------------- */
.fd-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.32em;
    padding: 0.35em 0.2em 0.45em;
    font-family: var(--font-family-base);
    font-weight: 900;
    line-height: 1;
    user-select: none;
    vertical-align: middle;
}

.fd-logo--header { font-size: clamp(18px, 5.2vw, 34px); }
.fd-logo--drawer { font-size: 17px; }

.fd-logo-box {
    display: inline-flex;
    gap: 0.105em;
}

.fd-logo-slot { display: inline-block; }

.fd-logo-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.32em;
    height: 1.47em;
    border-radius: 0.32em;
    background: var(--c);
    color: #fff;
    box-shadow: 0 0.13em 0 var(--s);
    transform: rotate(var(--r)) translateY(var(--y));
    transition: translate 160ms var(--fd-ease-bounce);
}

/* A little wiggle on hover, so the logo always feels alive */
a:hover > .fd-logo .fd-logo-tile,
.fd-logo:hover .fd-logo-tile {
    animation: fd-logo-wave 520ms ease-in-out both;
    animation-delay: calc(var(--i, 0) * 40ms);
}

@keyframes fd-logo-wave {
    0%, 100% { translate: 0 0; }
    40% { translate: 0 -0.3em; }
}

@media (prefers-reduced-motion: reduce) {
    .fd-logo .fd-logo-tile,
    a:hover > .fd-logo .fd-logo-tile { animation: none !important; }
}

/* --------------------------------------------------------------------------
   12. Motion
   -------------------------------------------------------------------------- */
@keyframes fd-float {
    0%, 100% { translate: 0 6px; }
    50% { translate: 0 -6px; }
}

@keyframes fd-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    40% { transform: translateY(-6px) scale(1.15); }
}

@keyframes fd-wave {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(14deg); }
    75% { transform: rotate(-10deg); }
}

@keyframes fd-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fd-pop-in {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to { opacity: 1; transform: none; }
}

@keyframes fd-reward-pop {
    from { opacity: 0; transform: scale(0.4) rotate(-12deg); }
    to { opacity: 1; transform: scale(1) rotate(0); }
}

@media (prefers-reduced-motion: reduce) {
    .fd-banner span,
    .fd-stat:hover .fd-stat-emoji,
    .fd-logout .fd-emblem,
    .fd-modal,
    .fd-modal-backdrop,
    .fd-reward,
    .fd-toast,
    .fd-rank-row.is-supporter { animation: none; }

    .fd-btn:hover:not(:disabled),
    .fd-btn:active:not(:disabled),
    .fd-avatar:hover,
    .fd-badge:hover,
    .fd-stat:hover,
    .fd-link:hover,
    button.theme-toggle:hover,
    button.fd-menu-toggle:hover,
    .fd-tabs--pills button.fd-tab.is-active,
    button.fd-modal-close:hover,
    button.fd-avatar-option:hover,
    button.fd-avatar-edit:hover .fd-avatar { transform: none; }
}

/* --------------------------------------------------------------------------
   13. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 560px) {
    .fd-stats { grid-template-columns: repeat(2, 1fr); }
    .fd-card,
    .fd-modal { padding: var(--space-md); }
    .fd-banner { height: 92px; }
    .fd-activity { max-width: none; }
    .fd-rank-row { grid-template-columns: 1.75rem 34px minmax(0, 1fr) auto; }
    .fd-rank-avatar { width: 34px; height: 34px; }
}
