/**
 * Cupcake 2048 - Canonical Full Surface Styles
 * 
 * Implements a premium, cohesive, and modern design for the main play surface.
 * Visual Language: Glassmorphism, Sophisticated HSL Palettes, Clear Hierarchy.
 */

:root {
    /* -- Curated Premium Palette (Mode Aware) -- */
    --c-brand: #8c2f39;
    --c-brand-light: #a63d4a;
    --c-brand-dark: #6a1f27;
    
    /* Dark Mode Defaults (Baseline) */
    --surface: 240 10% 4%;
    --surface-elevated: 240 10% 8%;
    --surface-glass: 240 10% 8% / 0.7;
    --surface-border: 240 10% 15%;
    
    --text-primary: 0 0% 98%;
    --text-secondary: 240 5% 70%;
    --text-muted: 240 5% 50%;
    
    --glass-blur: blur(12px);
    --premium-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    --premium-border: 1px solid rgba(255, 255, 255, 0.08);

    /* Spacing System */
    --p-page: 2rem;
    --p-card: 1.5rem;
    --radius-premium: 18px;
    --anim-smooth: 400ms cubic-bezier(0.23, 1, 0.32, 1);
}

[data-theme="light"] {
    --surface: 0 0% 98%;
    --surface-elevated: 0 0% 100%;
    --surface-glass: 0 0% 100% / 0.75;
    --surface-border: 0 0% 90%;
    
    --text-primary: 240 10% 15%;
    --text-secondary: 240 5% 40%;
    --text-muted: 240 5% 60%;
    
    --premium-shadow: 0 15px 40px rgba(140, 47, 57, 0.08);
    --premium-border: 1px solid rgba(0, 0, 0, 0.05);
}

/* 0. Core UI Components */
.premium-link {
    color: #8c2f39;
    font-weight: 800;
    text-decoration: none;
    position: relative;
    transition: var(--anim-smooth);
}

.premium-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: #8c2f39;
    transition: var(--anim-smooth);
}

.premium-link:hover::after {
    width: 100%;
}

.badge {
    display: inline-flex;
    padding: 2px 10px;
    font-size: 0.6rem;
    font-weight: 900;
    border-radius: 100px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.active-badge {
    background: hsla(var(--surface-border) / 0.5);
    color: hsl(var(--text-secondary));
    border: 1px solid hsla(var(--surface-border) / 0.5);
}

/* 0. Vendor Reset & Body Normalization */
body {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    background-image: none !important;
    background-color: hsl(var(--surface));
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

/* 1. Global Shell & Surface */
.cupcake2048-full-wrapper {
    background-color: hsl(var(--surface));
    color: hsl(var(--text-primary));
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
    min-height: 100vh;
    padding-bottom: 4rem;
}

/* 2. Structural Containment */
.canonical-app-shell {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--p-page);
}

.layout-split {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 3rem;
    align-items: start;
    padding: 4rem 0;
}

.game-column {
    grid-column: span 8;
    display: flex;
    flex-direction: column;
}

.sidebar-column {
    grid-column: span 4;
}

@media screen and (max-width: 1100px) {
    .gap-3rem { gap: 2rem; }
}

@media screen and (max-width: 960px) {
    .layout-split {
        grid-template-columns: 1fr;
        padding-top: 2rem;
        gap: 2rem;
    }
    .game-column,
    .sidebar-column {
        grid-column: span 1;
    }
}

/* 3. Hero Console & Logic Header */
.hero-console {
    margin-bottom: 3.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.controls-row {
    display: flex;
    align-items: flex-end;
    gap: 2rem;
    flex-wrap: wrap;
}

.page-title {
    margin: 0 0 0.75rem 0;
    font-size: 4rem;
    font-weight: 900;
    letter-spacing: -0.04em;
    background: linear-gradient(135deg, hsl(var(--text-primary)), var(--c-brand));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
}

.hero-intro {
    font-size: 1.2rem;
    color: hsl(var(--text-secondary));
    margin: 0;
    max-width: 650px;
    line-height: 1.6;
}

/* 4. Refined Mode Switcher */
.mode-switcher {
    display: inline-flex;
    background: hsla(var(--surface-border) / 0.3);
    backdrop-filter: var(--glass-blur);
    border: var(--premium-border);
    padding: 6px;
    border-radius: 100px;
    gap: 4px;
    box-shadow: var(--premium-shadow);
}

.mode-tab {
    background: transparent;
    border: none;
    color: hsl(var(--text-secondary));
    padding: 10px 24px;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    border-radius: 100px;
    transition: var(--anim-smooth);
}

.mode-tab:hover {
    color: hsl(var(--text-primary));
}

.mode-tab.active {
    background: var(--c-brand);
    color: #fff;
    box-shadow: 0 4px 15px rgba(140, 47, 57, 0.3);
}

/* 5. Mode Meta HUD */
.mode-status-bar {
    margin-top: 1.5rem;
    padding: 1.25rem 1.5rem;
    background: hsla(var(--surface-glass));
    backdrop-filter: var(--glass-blur);
    border: var(--premium-border);
    border-radius: var(--radius-premium);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    box-shadow: var(--premium-shadow);
    max-width: 500px;
}

/* Mode status lives beside mode pills on the canonical surface.
   Avoid unintended vertical offsets when the two controls share a row. */
.controls-row .mode-status-bar {
    margin-top: 0;
}

.active-mode-label {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--c-brand);
}

.status-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.daily-badge {
    background: var(--c-brand);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 900;
}

.mode-microcopy {
    font-size: 0.95rem;
    color: hsl(var(--text-secondary));
    margin: 0;
}

/* 6. Premium Timer & Scores Group */
.scores-container-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 2rem 0;
}

/* Prevent double-spacing: score modules already sit inside .scores-container-group. */
.cupcake2048-full-wrapper .scores-container-group .scores-container {
    margin-bottom: 0;
}

.cupcake-timer {
    background: hsla(var(--surface-glass));
    backdrop-filter: var(--glass-blur);
    border: var(--premium-border);
    border-radius: var(--radius-premium);
    padding: 1rem 1.5rem;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--premium-shadow);
}

/* Suppress Legacy HUD in Full Mode */
.game-container .scores-container,
.game-container .cupcake-timer-label {
    display: none !important;
}

.cupcake-timer .timer-display {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--c-brand);
    font-family: var(--font-primary);
    line-height: 1;
}

.cupcake-timer .timer-label {
    font-size: 0.65rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--c-brand);
    margin-bottom: 4px;
    opacity: 0.8;
}

/* EP09: Global Leaderboard V3 (Premium Refresh) */
.leaderboard-v2-container {
    background: hsla(var(--surface-glass));
    backdrop-filter: var(--glass-blur);
    border: var(--premium-border);
    border-radius: var(--radius-premium);
    overflow: hidden;
    box-shadow: var(--premium-shadow);
    margin-top: 3rem;
}

.leaderboard-mount {
    min-height: 200px;
    position: relative;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: hsl(var(--text-muted));
    padding: 1.25rem 1.5rem;
    border-bottom: 2px solid hsla(var(--surface-border) / 0.5);
    background: hsla(var(--surface-border) / 0.2);
}

/* Numeric Column Alignment */
.leaderboard-table th.col-score,
.leaderboard-table th.col-kcal {
    text-align: right;
}

.leaderboard-row {
    transition: var(--anim-smooth);
}

.leaderboard-row:hover {
    background: hsla(var(--surface-border) / 0.3);
}

.leaderboard-row td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid hsla(var(--surface-border) / 0.5);
    font-size: 0.95rem;
    color: hsl(var(--text-primary));
}

.col-rank { width: 60px; text-align: center; }
.col-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.col-score { width: 100px; text-align: right; font-weight: 800; color: var(--c-brand) !important; }
.col-kcal { width: 110px; text-align: right; color: hsl(var(--text-secondary)); }
.col-kcal .unit { font-size: 0.7rem; color: hsl(var(--text-muted)); text-transform: uppercase; letter-spacing: 0.05em; }

/* 8. Premium Overlays & Messaging */
.game-container .game-message {
    background: hsla(var(--surface) / 0.72);
    backdrop-filter: var(--glass-blur);
    border-radius: var(--radius-premium);
    border: none;
    box-shadow: none;
    padding: 1.25rem;
    z-index: 100;
    text-align: left;
    align-items: center;
    justify-content: center;
}

.game-container .game-message.energy-gated {
    background: hsla(var(--surface-glass));
}

.game-container .game-message.game-won,
.game-container .game-message.game-over,
.game-container .game-message.is-visible {
    display: flex;
}

.game-container .game-message p {
    color: hsl(var(--text-primary));
    margin: 0;
    margin-top: 0;
    height: auto;
    line-height: 1.4;
    font-size: 1rem;
    font-weight: 600;
}

.game-container .game-message .lower {
    margin-top: 0;
}

@keyframes fade-in {
    0% { opacity: 0; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}

/* TICKET-PREMIUM-003: Premium end-of-run hierarchy (summary → publish → actions) */
.game-container .game-message.platform-overlay .overlay-shell {
    width: min(460px, 100%);
    max-height: calc(100% - 2.5rem);
    overflow: auto;
    background: hsla(var(--surface-glass));
    border-radius: var(--radius-premium);
    border: var(--premium-border);
    box-shadow: var(--premium-shadow);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.game-container .game-message.platform-overlay .overlay-summary {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.game-container .game-message.platform-overlay .summary-title {
    font-size: 1.6rem;
    font-weight: 900;
    margin: 0;
    letter-spacing: -0.02em;
    color: hsl(var(--text-primary));
}

.game-container .game-message.platform-overlay .summary-sub {
    font-size: 1rem;
    font-weight: 600;
    color: hsl(var(--text-secondary));
    margin: 0;
}

.game-container .game-message.platform-overlay .result-summary-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0.75rem 0 0;
    padding: 0.9rem;
    background: hsla(var(--surface-border) / 0.18);
    border-radius: 14px;
    border: 1px solid hsla(var(--surface-border) / 0.4);
}

.game-container .game-message.platform-overlay .summary-stat {
    align-items: flex-start;
}

.game-container .game-message.platform-overlay .stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: hsl(var(--text-muted));
    font-weight: 800;
}

.game-container .game-message.platform-overlay .stat-value {
    font-size: 1.05rem;
    font-weight: 900;
    color: hsl(var(--text-primary));
}

.game-container .game-message.platform-overlay .overlay-publish {
    padding-top: 0.25rem;
}

.game-container .game-message.platform-overlay .overlay-actions.lower {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin-top: 0.25rem;
}

/* Legacy theme/vendor overrides: prevent cramped/overlapping overlay typography and button rules. */
#cupcake2048-canonical-surface .game-container .game-message.platform-overlay p {
    margin: 0;
    margin-top: 0;
    height: auto;
    line-height: 1.4;
    font-size: 1rem;
}

#cupcake2048-canonical-surface .game-container .game-message.platform-overlay .lower {
    margin-top: 0;
}

#cupcake2048-canonical-surface .game-container .game-message.platform-overlay a {
    height: auto;
    margin-left: 0;
    line-height: normal;
}

@media (max-width: 520px) {
    .game-container .game-message.platform-overlay .overlay-shell {
        padding: 1.25rem;
    }
    .game-container .game-message.platform-overlay .result-summary-panel {
        grid-template-columns: 1fr;
    }
    .game-container .game-message.platform-overlay .overlay-actions.lower {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Rank Badges */
.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #f0f0f0;
    font-size: 0.8rem;
    font-weight: 800;
}

.rank-1 { background: #ffd700; color: #856404; }
.rank-2 { background: #c0c0c0; color: #383d41; }
.rank-3 { background: #cd7f32; color: #ffffff; }

/* Loading State & Shimmer */
.leaderboard-loading {
    padding: 10px 20px;
}

.skeleton-row {
    height: 40px;
    margin: 10px 0;
    background: #f6f7f8;
    background: linear-gradient(to right, #f6f7f8 0%, #edeef1 20%, #f6f7f8 40%, #f6f7f8 100%);
    background-size: 800px 104px;
    animation: shimmer 1.5s infinite linear;
    border-radius: 4px;
}

@keyframes shimmer {
    0% { background-position: -468px 0; }
    100% { background-position: 468px 0; }
}

/* Messaging States */
.leaderboard-empty, .leaderboard-error {
    padding: 40px 20px;
    text-align: center;
}

.empty-msg {
    color: #666;
    margin-bottom: 15px;
    font-style: italic;
}

/* Leaderboard Submission Flow (Overlay) */
.game-container .game-message .leaderboard-submit-box {
    background: hsla(var(--surface-elevated));
    border: 1px solid hsla(var(--surface-border) / 0.8);
    border-radius: 14px;
    padding: 1rem;
    margin: 0;
    text-align: left;
}

.submit-header {
    margin-bottom: 12px;
}

.submit-title {
    font-weight: 800;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--c-brand);
    letter-spacing: 0.05em;
}

.submit-body {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.submit-body.offline-state {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.offline-desc {
    margin: 0 0 4px 0;
    font-size: 0.85rem;
    color: #776e65;
    line-height: 1.4;
}

#leaderboard-name-input {
    flex-grow: 1;
    min-height: var(--btn-h, 44px);
    border: 1px solid hsla(var(--surface-border) / 0.7);
    padding: 0.75rem 0.9rem;
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 650;
    background: hsla(var(--surface-border) / 0.12);
    color: hsl(var(--text-primary));
    outline: none;
    transition: all 0.2s ease;
}

#leaderboard-name-input:focus {
    border-color: hsla(var(--surface-border) / 1);
    background: hsla(var(--surface-elevated));
    box-shadow: 0 0 0 3px rgba(140, 47, 57, 0.16);
}

.submit-feedback {
    margin-top: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.4;
}

.submit-feedback.error {
    color: #8c2f39;
    background: rgba(140, 47, 57, 0.05);
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 3px solid #8c2f39;
}

button:disabled, .button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #ccc;
    color: #fff;
    border-color: #ccc;
}

.submit-success-msg {
    color: #28a745;
    font-weight: 800;
    font-size: 1rem;
    text-align: center;
    width: 100%;
}

.submit-success-msg.is-flagged {
    color: #fd7e14;
}

.check-icon {
    font-size: 1.2rem;
    margin-right: 5px;
}

/* Row Highlighting (EP09-008) */
.leaderboard-row.is-highlighted {
    background: #fff9e6 !important;
    border-left: 4px solid #ffd700;
}

.your-rank-tag {
    background: #ffd700;
    color: #856404;
    font-size: 0.65rem;
    font-weight: 900;
    padding: 1px 4px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

/* Status Containers (Empty/Error) */
.leaderboard-status-container {
    padding: 60px 40px;
    text-align: center;
    background: rgba(140, 47, 57, 0.03);
    border-radius: var(--radius-lg);
    border: 2px dashed rgba(140, 47, 57, 0.15);
    margin: 20px 0;
}

.leaderboard-status-container.error-state {
    background: rgba(204, 0, 0, 0.03);
    border-color: rgba(204, 0, 0, 0.15);
}

.status-icon {
    font-size: 3rem;
    margin-bottom: 20px;
    opacity: 0.9;
    filter: drop-shadow(0 4px 12px rgba(140, 47, 57, 0.2));
}

.status-title {
    margin: 0 0 12px 0;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--color-brand, #8c2f39);
    letter-spacing: -0.02em;
}

.status-desc {
    color: #776e65;
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 25px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.leaderboard-status-container .button {
    /* Inherit the canonical button family; keep container-specific spacing only. */
    margin-top: 0.25rem;
}

.leaderboard-status-container .primary-button {
    /* Keep variant compatibility for existing markup. */
}

.leaderboard-status-container .primary-button:hover {
    /* Hover handled by the canonical button system. */
}

.leaderboard-status-container .retry-btn {
    /* Utility styling handled by the canonical button system. */
}

.leaderboard-status-container .retry-btn:hover {
    /* Hover handled by the canonical button system. */
}

.leaderboard-footer {
    padding: 12px;
    text-align: center;
    background: #fdfdfd;
    border-top: 1px solid #f5f5f5;
    font-size: 0.75rem;
    color: #bbb;
    text-transform: uppercase;
    font-weight: 700;
}

/* 6. Result Summary Overlay (EP08) */
.game-message .summary-title {
    font-size: var(--font-size-2xl);
    font-weight: 900;
    margin: 0 0 var(--space-sm);
    color: var(--color-text);
}

.result-summary-panel {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    margin: var(--space-md) 0 var(--space-lg);
    padding: var(--space-md);
    background: rgba(var(--color-brand-rgb), 0.05);
    border-radius: var(--radius-md);
    border: 1px dashed var(--color-border);
}

.summary-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    color: var(--color-text-muted);
    font-weight: 700;
}

.stat-value {
    font-size: var(--font-size-lg);
    font-weight: 800;
    color: var(--color-brand);
}

/* 3. HUD & Scoring Modules (Refreshed TICKET-RUNTIME-UI-004) */
.scores-container {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-3);
    margin-bottom: var(--spacing-6);
    flex-wrap: wrap;
}

.score-container, .best-container,
.score-points, .best-points,
.cupcake-timer {
    position: relative;
    background: var(--color-surface-elevated) !important;
    border: 1px solid var(--color-border);
    padding: var(--spacing-6) var(--spacing-5) var(--spacing-2);
    border-radius: var(--radius-lg);
    min-width: 140px;
    height: 5.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    box-shadow: var(--shadow-sm);
    font-size: var(--font-size-lg);
    font-weight: 800;
    color: var(--color-text-primary);
    text-align: center;
    box-sizing: border-box;
    transition: transform var(--motion-duration-fast) var(--motion-ease-standard);
    float: none !important; /* Killer for vendor drift */
    width: auto !important; /* Killer for vendor drift */
}

/* Unified Labels Styling */
.score-container::before, 
.best-container::before,
.score-points::before,
.best-points::before,
.cupcake-timer::before {
    content: "";
    position: absolute;
    top: var(--spacing-2);
    left: 0;
    width: 100%;
    text-align: center;
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-secondary);
    line-height: 1;
}

/* Unified Labels (Shortened for mobile clearance) */
.score-container::before { content: "Cupcake Rank"; }
.best-container::before  { content: "All-Time Best"; }
.score-points::before     { content: "Kcal Score"; }
.best-points::before      { content: "Kcal Best"; }
.cupcake-timer::before    { content: "Time Left"; }

/* Vendor Label Suppression (Hardened) */
.score-container:after, .best-container:after,
.score-points:after, .best-points:after {
    content: none !important;
}

/* Score Addition Animation */
.score-container .score-addition,
.cupcake-timer .score-addition {
    position: absolute;
    top: -20px;
    right: 0;
    font-size: var(--font-size-xl);
    font-weight: 900;
    color: var(--color-brand);
    animation: addition-slide-fade 600ms ease-out both;
    z-index: 100;
}

@keyframes addition-slide-fade {
    0% { transform: translateY(0); opacity: 0; }
    30% { opacity: 1; }
    100% { transform: translateY(-40px); opacity: 0; }
}

.secondary-scores {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-top: var(--spacing-1);
}

/* 3. Global Header Rhythm (Theme Integration) */
header.site-header {
    margin-bottom: 0 !important; /* Tighten gap to game area */
    border-bottom: 1px solid var(--color-border);
}

/* 4. Feature Scaffolds (Sidebar Widgets) */
.sidebar-widget, .feature-scaffold {
    background: hsla(var(--surface-glass));
    backdrop-filter: var(--glass-blur);
    border: var(--premium-border);
    box-shadow: var(--premium-shadow);
    border-radius: var(--radius-premium);
    margin-bottom: 2rem;
    overflow: hidden;
    transition: var(--anim-smooth);
}

.sidebar-widget:last-child {
    margin-bottom: 0;
}

/* Light-mode rhythm: slightly tighter card stack without increasing visual noise. */
[data-theme="light"] .cupcake2048-full-wrapper .sidebar-widget,
[data-theme="light"] .cupcake2048-full-wrapper .feature-scaffold {
    margin-bottom: 1.5rem;
}

[data-theme="light"] .cupcake2048-full-wrapper .widget-head {
    padding: 0.875rem 1.1rem;
}

[data-theme="light"] .cupcake2048-full-wrapper .widget-body {
    padding: 1.1rem;
}

.sidebar-widget:hover, .feature-scaffold:hover {
    transform: translateY(-4px);
    border-color: hsla(var(--surface-border) / 0.8);
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.widget-head {
    background: hsla(var(--surface-border) / 0.3);
    border-bottom: 1px solid hsla(var(--surface-border) / 0.5);
    padding: 1rem 1.25rem;
}

.widget-title {
    font-weight: 800;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--c-brand);
}

.widget-body {
    padding: 1.25rem;
}

/* Baking Energy & Lives States */
.lives-display {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.hearts-row {
    font-size: 2rem;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
}

.heart-unit {
    transition: all 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.heart-unit.empty {
    opacity: 0.15;
    filter: grayscale(100%) brightness(0.5);
    transform: scale(0.8);
}

.heart-unit.filled {
    filter: drop-shadow(0 4px 10px rgba(140, 47, 57, 0.4));
}

.lives-status-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.status-meta {
    font-size: 0.78rem;
    color: hsl(var(--text-muted));
    line-height: 1.3;
}

.status-label {
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--text-muted));
}

.status-value {
    font-size: 1.15rem;
    font-weight: 800;
    color: hsl(var(--text-primary));
}

.status-max { color: var(--c-brand); }
.status-regen { color: hsl(var(--text-secondary)); font-variant-numeric: tabular-nums; }

.feature-desc {
    color: hsl(var(--text-secondary));
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 1rem;
}

.regen-progress-bar {
    background: hsla(var(--surface-border) / 0.2);
    height: 10px;
    border-radius: 100px;
    overflow: hidden;
    position: relative;
    border: 1px solid hsla(var(--surface-border) / 0.3);
}

.regen-fill {
    height: 100%;
    background: linear-gradient(to right, var(--c-brand), var(--c-brand-light));
    transition: width 1s linear;
    border-radius: 100px;
}

/* Energy degraded / failure panel (product-grade, restrained) */
.lives-error-state {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.lives-error-state .status-icon {
    font-size: 1.1rem;
    line-height: 1;
    color: hsl(var(--text-muted));
}

.lives-failure-head {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.lives-failure-meta {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.lives-failure-meta .status-label {
    font-size: 0.7rem;
}

.lives-failure-meta .status-value {
    font-size: 0.95rem;
}

.lives-error-state .error-msg {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 800;
    color: hsl(var(--text-primary));
}

.lives-error-state .error-sub {
    margin: 0;
    font-size: 0.85rem;
    color: hsl(var(--text-secondary));
    line-height: 1.5;
}

.lives-failure-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.retry-btn-sm {
    min-width: 0;
    /* Normalized by the canonical button system (see Premium Buttons section). */
}

[data-theme="light"] .cupcake2048-full-wrapper .lives-error-state .status-icon {
    color: rgba(15, 23, 42, 0.55);
}

[data-theme="light"] .cupcake2048-full-wrapper .lives-error-state .error-sub {
    color: rgba(15, 23, 42, 0.75);
}

/* 5. Mobile HUD Optimization */
@media screen and (max-width: 600px) {
    .scores-container-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        gap: var(--spacing-2);
    }
    
    .cupcake-timer {
        grid-column: span 2;
        margin-bottom: var(--spacing-2);
    }
    
    .scores-container {
        min-width: 0;
        padding: var(--spacing-2);
    }
    
    .score-container::before, .best-container::before {
        display: block;
        margin-bottom: 2px;
    }
}

/* ----- (Stale duplicate Hearts & Energy rules removed in UI-REFRESH-002.
   Canonical rules are in the glassmorphism section above, ~L813–L885.) ----- */

.error-msg {
    color: #cc0000;
    font-size: 0.8rem;
    font-weight: 700;
}

/* 6. Progress Bars (Placeholders) */
.progress-bar-placeholder {
    height: 6px;
    background: var(--color-surface);
    border-radius: var(--radius-full);
    margin-top: var(--spacing-2);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--color-brand);
    border-radius: var(--radius-full);
}

/* 7. Game Board Enhancements */
.game-container {
    background: var(--c2048-board-bg, var(--color-surface-elevated));
    border: 4px solid var(--c2048-board-border, var(--color-border));
    border-radius: var(--radius-xl);
    box-shadow: var(--c2048-board-shadow, var(--shadow-lg));
    width: var(--board-size-desktop);
    height: var(--board-size-desktop);
    padding: var(--grid-gap-desktop);
    margin: var(--spacing-6) 0; /* Reduced from 8 */
    background-clip: padding-box;
}

.game-controls {
    margin-top: var(--spacing-6);
}

.cupcake2048-full-wrapper .grid-container {
    background: transparent;
}

.grid-cell {
    /* Dark-mode baseline (matches prior canonical tuning) */
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
}

/* Light Mode: Empty cell contrast + grid readability */
[data-theme="light"] .cupcake2048-full-wrapper .grid-cell {
    background: var(--c2048-cell-bg, rgba(15, 23, 42, 0.06));
    box-shadow: inset 0 0 0 1px var(--c2048-cell-border, rgba(15, 23, 42, 0.08));
}

/* Tile-to-board separation + movement stability (shared renderer) */
.cupcake2048-full-wrapper .tile {
    will-change: transform;
}

.cupcake2048-full-wrapper .tile .tile-inner {
    background: var(--c2048-tile-underlay, rgba(255, 255, 255, 0.06)) !important;
    overflow: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

[data-theme="light"] .cupcake2048-full-wrapper .tile .tile-inner {
    box-shadow: var(--c2048-tile-shadow, 0 12px 22px rgba(15, 23, 42, 0.18));
    outline: 1px solid var(--c2048-tile-outline, rgba(255, 255, 255, 0.55));
    outline-offset: -1px;
}

.cupcake2048-full-wrapper .tile .tile-inner img {
    display: block;
    background-color: transparent;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* 8. Overlays & CTAs */
.cupcake2048-full-wrapper .game-message {
    background: var(--color-surface-overlay);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
}

.button.primary-button {
    background: var(--color-brand);
    color: var(--color-text-inverse);
    padding: var(--spacing-3) var(--spacing-6);
    font-weight: 800;
    font-size: var(--font-size-base);
    border-radius: var(--radius-md);
    text-decoration: none;
    display: inline-block;
    transition: background var(--motion-duration-fast);
}

.button.primary-button:hover {
    background: var(--color-brand-muted);
}

/* 9. Meta Zone (Leaderboards / Achievements) */
.meta-zone {
    padding: var(--spacing-16) 0;
    border-top: 1px solid var(--color-border);
    background: linear-gradient(to bottom, var(--color-surface), rgba(0,0,0,0.05));
}

.leaderboard-v2-container {
    max-width: 800px;
    margin: 0 auto;
}

.tabs-header {
    display: flex;
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-6);
    border-bottom: 2px solid var(--color-border);
}

.tab-button {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: var(--spacing-3) var(--spacing-6);
    font-size: var(--font-size-lg);
    font-weight: 800;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--motion-duration-fast);
    padding-bottom: 12px;
    margin-bottom: -2px;
}

.tab-button:hover:not(:disabled) {
    color: var(--color-brand);
}

.tab-button.active {
    color: var(--color-brand);
    border-bottom-color: var(--color-brand);
}

.tab-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.leaderboard-dynamic-panel {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: var(--spacing-8);
    border: 1px solid var(--color-border);
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-6);
    padding-bottom: var(--spacing-4);
    border-bottom: 1px solid var(--color-border-light, #eee);
}

.leaderboard-mode-label {
    font-size: var(--font-size-xl);
    font-weight: 900;
    color: var(--color-text);
}

.scope-toggle {
    display: inline-flex;
    background: rgba(140, 47, 57, 0.05);
    border-radius: var(--radius-md);
    padding: 3px;
}

.scope-btn {
    background: transparent;
    border: none;
    padding: 6px 14px;
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--motion-duration-fast);
}

.scope-btn:hover {
    color: var(--color-brand);
}

.scope-btn.active {
    background: var(--color-surface);
    color: var(--color-brand);
    box-shadow: var(--shadow-sm);
}

.section-head {
    margin-bottom: var(--spacing-8);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-title {
    font-size: var(--font-size-xl);
    font-weight: 800;
}

/* 9.1 Placeholder Aesthetics (The "Intentional Future" Look) */
.leaderboard-placeholder {
    background: var(--color-surface-elevated);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--spacing-12) var(--spacing-6);
    margin-bottom: var(--spacing-12);
}

.placeholder-hero {
    max-width: 60ch;
    margin: 0 auto;
    text-align: center;
}

.placeholder-title {
    font-size: var(--font-size-xl);
    margin-bottom: var(--spacing-4);
    color: var(--color-text-primary);
}

.placeholder-desc {
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: var(--spacing-6);
}

.future-date-badge {
    display: inline-block;
    padding: var(--spacing-2) var(--spacing-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 900;
    letter-spacing: 0.1em;
    color: var(--color-brand);
}

/* 9.2 Achievement Gallery */
.achievement-gallery-placeholder {
    padding: var(--spacing-12) 0;
}

.placeholder-grid-empty {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--spacing-4);
    margin-top: var(--spacing-8);
}

.grid-item-locked {
    aspect-ratio: 1;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-3xl);
    color: var(--color-border);
    position: relative;
    overflow: hidden;
}

.grid-item-locked::after {
    content: "LOCKED";
    position: absolute;
    bottom: var(--spacing-2);
    font-size: 8px;
    font-weight: 900;
    letter-spacing: 0.1em;
    opacity: 0.5;
}

/* 10. Narrative Site Content Rhythm */
.narrative-zone {
    padding: var(--spacing-16) 0;
    background: var(--color-surface);
}

.content-narrow {
    max-width: 72ch;
    margin: 0 auto;
    line-height: 1.8;
    color: var(--color-text-secondary);
}

/* 11. Footer Integration & Page End */
#cupcake2048-canonical-surface {
    padding-bottom: 0;
}

.site-footer {
    border-top: 1px solid var(--color-border);
    margin-top: 0;
}

/* 12. Baking Summary Dashboard (EP11) */
.ritual-summary-widget {
    background: linear-gradient(135deg, var(--color-surface) 0%, rgba(200, 150, 255, 0.05) 100%);
}

.summary-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: var(--spacing-2) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.summary-row .row-label {
    color: var(--color-text-secondary);
}

.summary-row .row-value {
    font-weight: 700;
}

.summary-row .row-value.critical {
    color: #ff4d4d;
}

.summary-row .row-value.warning {
    color: hsl(var(--text-secondary));
    font-weight: 800;
}

.guidance-box {
    margin-top: var(--spacing-2);
    padding: var(--spacing-3);
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--color-brand);
}

.guidance-text {
    font-size: 12px;
    line-height: 1.5;
    margin-bottom: var(--spacing-2);
    color: var(--color-text-secondary) !important;
}

.guidance-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 2px 6px;
    background: var(--color-brand);
    color: white;
    border-radius: 4px;
}

.recent-insight {
    margin-top: var(--spacing-2);
    font-size: 11px;
    opacity: 0.7;
    font-style: italic;
}

.summary-skeleton {
    color: hsl(var(--text-secondary));
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Light-mode mastery panel should not inherit dark, muddy blocks. */
[data-theme="light"] .cupcake2048-full-wrapper .guidance-box {
    background: rgba(15, 23, 42, 0.04);
    border-left-color: var(--color-brand);
}

[data-theme="light"] .cupcake2048-full-wrapper .summary-row {
    border-bottom-color: rgba(15, 23, 42, 0.06);
}

/* 14. Platform Overlays (EP11) */
.game-message.energy-gated {
    background: rgba(40, 0, 0, 0.95) !important;
}

.game-message.service-unavailable {
    background: rgba(30, 20, 60, 0.95) !important;
}

.game-message.platform-overlay.energy-gated .summary-title,
.game-message.platform-overlay.service-unavailable .summary-title,
.game-message.platform-overlay.game-loading .summary-title {
    color: #ffffff;
    letter-spacing: 0.05em;
    font-size: 28px;
}

/* 9. Premium Buttons & Interaction */
.cupcake2048-full-wrapper {
    --btn-h: 44px;
    --btn-h-sm: 38px;
    --btn-radius: 999px;
    --btn-pad-x: 1.25rem;
    --btn-pad-y: 0.75rem;
    --btn-font-size: 0.95rem;
    --btn-font-weight: 850;
    --btn-letter-spacing: 0.01em;
    --btn-shadow: 0 10px 26px rgba(15, 23, 42, 0.16);
    --btn-shadow-primary: 0 14px 34px rgba(140, 47, 57, 0.28);
    --btn-ring: 0 0 0 3px rgba(140, 47, 57, 0.22);
}

.cupcake2048-full-wrapper .button,
.cupcake2048-full-wrapper button.button,
.cupcake2048-full-wrapper a.button,
.cupcake2048-full-wrapper .restart-button,
.cupcake2048-full-wrapper .retry-button,
.cupcake2048-full-wrapper .keep-playing-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--btn-h);
    padding: var(--btn-pad-y) var(--btn-pad-x);
    border-radius: var(--btn-radius);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    line-height: 1;
    letter-spacing: var(--btn-letter-spacing);
    text-transform: none;
    cursor: pointer;
    transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
    border: 1px solid hsla(var(--surface-border) / 0.6);
    text-decoration: none;
    outline: none;
    white-space: nowrap;
    text-align: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    background: hsla(var(--surface-border) / 0.14);
    color: hsl(var(--text-primary));
    box-shadow: var(--btn-shadow);
}

.cupcake2048-full-wrapper .button:hover,
.cupcake2048-full-wrapper .restart-button:hover,
.cupcake2048-full-wrapper .retry-button:hover,
.cupcake2048-full-wrapper .keep-playing-button:hover {
    transform: translateY(-1px);
    background: hsla(var(--surface-border) / 0.2);
}

.cupcake2048-full-wrapper .button:active,
.cupcake2048-full-wrapper .restart-button:active,
.cupcake2048-full-wrapper .retry-button:active,
.cupcake2048-full-wrapper .keep-playing-button:active {
    transform: translateY(0);
}

.cupcake2048-full-wrapper .button:focus-visible,
.cupcake2048-full-wrapper .restart-button:focus-visible,
.cupcake2048-full-wrapper .retry-button:focus-visible,
.cupcake2048-full-wrapper .keep-playing-button:focus-visible {
    box-shadow: var(--btn-shadow), var(--btn-ring);
}

.cupcake2048-full-wrapper .primary-button {
    background: var(--c-brand) !important;
    color: #fff !important;
    border-color: transparent;
    box-shadow: var(--btn-shadow-primary);
}

.cupcake2048-full-wrapper .primary-button:hover {
    background: var(--c-brand-light) !important;
}

.cupcake2048-full-wrapper .secondary-button {
    background: hsla(var(--surface-border) / 0.12);
    border-color: hsla(var(--surface-border) / 0.7);
    box-shadow: var(--btn-shadow);
}

.cupcake2048-full-wrapper .tertiary-button {
    background: transparent;
    border-color: hsla(var(--surface-border) / 0.55);
    box-shadow: none;
}

/* Guarantee overlay buttons override legacy theme/vendor anchor rules. */
#cupcake2048-canonical-surface .game-container .game-message.platform-overlay a.button {
    background: hsla(var(--surface-border) / 0.14);
    border: 1px solid hsla(var(--surface-border) / 0.6);
    box-shadow: var(--btn-shadow);
}

#cupcake2048-canonical-surface .game-container .game-message.platform-overlay a.button.primary-button {
    background: var(--c-brand) !important;
    color: #fff !important;
    border-color: transparent;
    box-shadow: var(--btn-shadow-primary);
}

#cupcake2048-canonical-surface .game-container .game-message.platform-overlay a.button.secondary-button {
    background: hsla(var(--surface-border) / 0.12);
    border-color: hsla(var(--surface-border) / 0.7);
    box-shadow: var(--btn-shadow);
}

#cupcake2048-canonical-surface .game-container .game-message.platform-overlay a.button.tertiary-button {
    background: transparent;
    border-color: hsla(var(--surface-border) / 0.55);
    box-shadow: none;
}

.cupcake2048-full-wrapper .utility-button,
.cupcake2048-full-wrapper .retry-btn,
.cupcake2048-full-wrapper .retry-btn-sm {
    min-height: var(--btn-h-sm);
    padding: 0.55rem 0.95rem;
    font-size: 0.85rem;
    font-weight: 850;
    border-color: hsla(var(--surface-border) / 0.65);
    background: hsla(var(--surface-border) / 0.08);
    box-shadow: none;
}

.cupcake2048-full-wrapper .button:disabled,
.cupcake2048-full-wrapper button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.game-controls {
    margin-top: 3rem;
    display: flex;
    justify-content: center;
}

/* --------------------------------------------------------------------------
 * Light-Mode Canonical Polish: spacing, alignment, rhythm (UI-SPACING-001)
 * Scope: canonical surface only, avoid dark-mode regressions.
 * -------------------------------------------------------------------------- */

[data-theme="light"] .cupcake2048-full-wrapper .hero-console {
    gap: 1.5rem;
    margin-bottom: 3rem;
}

[data-theme="light"] .cupcake2048-full-wrapper .controls-row {
    align-items: center;
    gap: 1.25rem;
}

[data-theme="light"] .cupcake2048-full-wrapper .mode-switcher {
    background: rgba(15, 23, 42, 0.03);
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    padding: 4px;
    gap: 4px;
}

[data-theme="light"] .cupcake2048-full-wrapper .mode-tab {
    padding: 10px 18px;
    min-height: 40px;
    line-height: 1;
    letter-spacing: 0.06em;
    font-size: 0.8rem;
}

[data-theme="light"] .cupcake2048-full-wrapper .mode-status-bar {
    padding: 1rem 1.25rem;
    gap: 0.5rem;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

[data-theme="light"] .cupcake2048-full-wrapper .active-mode-label {
    font-size: 1.15rem;
}

[data-theme="light"] .cupcake2048-full-wrapper .scores-container-group {
    margin: 1.5rem 0 1.25rem;
    gap: 0.75rem;
}

[data-theme="light"] .cupcake2048-full-wrapper .score-container,
[data-theme="light"] .cupcake2048-full-wrapper .best-container,
[data-theme="light"] .cupcake2048-full-wrapper .score-points,
[data-theme="light"] .cupcake2048-full-wrapper .best-points,
[data-theme="light"] .cupcake2048-full-wrapper .cupcake-timer {
    padding: var(--spacing-5) var(--spacing-4) var(--spacing-2);
    height: 4.85rem;
    min-width: 132px;
}

/* Keep New Game anchored to the board without feeling detached/floating. */
[data-theme="light"] .cupcake2048-full-wrapper .game-container {
    margin-bottom: var(--spacing-4);
}

.cupcake2048-full-wrapper .game-controls {
    margin-top: var(--spacing-4);
}

[data-theme="light"] .cupcake2048-full-wrapper .restart-button {
    padding: 12px 28px;
    min-width: 160px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

/* Mobile: when controls wrap, restore intentional separation between clusters. */
@media screen and (max-width: 600px) {
    .cupcake2048-full-wrapper .controls-row {
        align-items: stretch;
        gap: 1rem;
    }

    .cupcake2048-full-wrapper .mode-status-bar {
        width: 100%;
        max-width: none;
        margin-top: 0.75rem;
    }
}

/* 10. Board Scaling & Responsive Grid */
@media screen and (max-width: 600px) {
    .game-container {
        width: calc(100vw - 40px);
        max-width: 450px;
        aspect-ratio: 1/1;
        margin: 0 auto;
        padding: 5px;
        box-sizing: border-box;
    }

    .grid-container {
        width: 100%;
        height: 100%;
    }
    
    .page-title {
        font-size: 2.25rem;
    }
    
    .hero-intro {
        font-size: 0.95rem;
    }
    
    .restart-button {
        padding: 10px 24px;
        font-size: 0.85rem;
        white-space: normal;
        min-width: 120px;
    }
}
