/* ===== CSS Variables (Summer/Default Theme) ===== */
:root {
    /* Surfaces */
    --surface-primary: #121212;
    --surface-card: #1E1E1E;
    --surface-card-elevated: #2A2A2A;
    --surface-board-overlay: rgba(30, 30, 30, 0.73);

    /* Accents */
    --accent-primary: #1976D2;
    --accent-secondary: #2A2A2A;
    --accent-success: #43A047;
    --accent-danger: #E53935;
    --accent-warning: #FFC107;
    --accent-info: #1976D2;

    /* Text */
    --text-primary: #FFFFFF;
    --text-secondary: #BEBEBE;
    --text-disabled: #666666;

    /* Dividers */
    --divider: #333333;

    /* Players */
    --player-one: #4AA8D8;
    --player-two: #E91E63;

    /* Board */
    --board-start: #4CAF50;
    --board-mid: #388E3C;
    --board-end: #2E7D32;
    --board-grid: #A5D6A7;

    /* Buttons */
    --btn-primary: #5ed3fd;
    --btn-primary-end: #40c1fd;
    --btn-utility-bg: #2A2A2A;
    --btn-utility-border: #444444;

    /* Legacy mappings for existing CSS that references old variable names */
    --primary: var(--accent-warning);
    --primary-dark: var(--accent-danger);
    --secondary: var(--surface-card);
    --cream: var(--surface-primary);
    --amber-light: var(--accent-warning);
    --amber: var(--accent-warning);
    --surface: var(--surface-card);
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.5);
    --radius: 12px;
    --radius-lg: 20px;
    --blue: var(--player-one);
    --blue-light: #64B5F6;
    --orange: var(--player-two);
    --orange-light: #F48FB1;
    --text-light: var(--text-disabled);
    --board-dark: var(--board-end);
    --board-light: var(--board-start);
}

/* ===== Seasonal Themes ===== */
/* Summer is default (:root) — no [data-theme] needed */

[data-theme="spring"] {
    --surface-primary: #0D1A0D;
    --surface-card: #1A2E1A;
    --surface-card-elevated: #2A3E2A;
    --surface-board-overlay: rgba(26, 46, 26, 0.73);
    --accent-primary: #C2185B;
    --accent-secondary: #1A2E1A;
    --board-start: #81C784;
    --board-mid: #4CAF50;
    --board-end: #388E3C;
    --board-grid: #A5D6A7;
    --btn-primary: #C2185B;
    --btn-primary-end: #E91E63;
    --btn-utility-bg: #1A2E1A;
    --btn-utility-border: #2A3E2A;
    --divider: #2A3E2A;
}

[data-theme="fall"] {
    --surface-primary: #1A1208;
    --surface-card: #2A1E10;
    --surface-card-elevated: #3A2E1A;
    --surface-board-overlay: rgba(42, 30, 16, 0.73);
    --accent-primary: #dd61fd;
    --accent-secondary: #2A1E10;
    --accent-warning: #FF8F00;
    --board-start: #8D6E43;
    --board-mid: #6B4F30;
    --board-end: #5A3D22;
    --board-grid: #BCAAA4;
    --btn-primary: #dd61fd;
    --btn-primary-end: #c243fd;
    --btn-utility-bg: #2A1E10;
    --btn-utility-border: #3A2E1A;
    --divider: #3A2E1A;
}

[data-theme="winter"] {
    --surface-primary: #0A1A2A;
    --surface-card: #1A2A3A;
    --surface-card-elevated: #2A3A4A;
    --surface-board-overlay: rgba(26, 42, 58, 0.73);
    --accent-primary: #dd61fd;
    --accent-secondary: #1A2A3A;
    --board-start: #90CAF9;
    --board-mid: #42A5F5;
    --board-end: #1565C0;
    --board-grid: #BBDEFB;
    --btn-primary: #dd61fd;
    --btn-primary-end: #c243fd;
    --btn-utility-bg: #1A2A3A;
    --btn-utility-border: #2A3A4A;
    --divider: #2A3A4A;
}

[data-theme="stadium"] {
    --surface-primary: #0D1E0D;
    --surface-card: #0D1E0D;
    --surface-card-elevated: #1A2E1A;
    --surface-board-overlay: rgba(13, 30, 13, 0.73);
    --accent-primary: #bdf406;
    --accent-secondary: #0D1E0D;
    --board-start: #2E7D32;
    --board-mid: #1B5E20;
    --board-end: #0D3B0F;
    --board-grid: #4CAF50;
    --btn-primary: #bdf406;
    --btn-primary-end: #88e006;
    --btn-utility-bg: #0D1E0D;
    --btn-utility-border: #1A2E1A;
    --divider: #1A2E1A;
}

/* Piece Skins */
[data-skin="neon"] .cell-piece,
[data-skin="neon"] .tray-piece {
    filter: drop-shadow(0 0 6px rgba(0,255,255,0.6)) brightness(1.2) saturate(1.5);
}

[data-skin="vintage"] .cell-piece,
[data-skin="vintage"] .tray-piece {
    filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.3)) sepia(0.4) saturate(0.8) brightness(0.95);
}

/* High Contrast Mode */
[data-contrast="high"] {
    --surface-primary: #000000;
    --surface-card: #111111;
    --surface-card-elevated: #222222;
    --text-primary: #FFFFFF;
    --text-secondary: #E0E0E0;
    --text-disabled: #BDBDBD;
    --player-one: #64B5F6;
    --player-two: #F48FB1;
    --board-grid: #666666;
    --divider: #666666;
    --shadow: rgba(255, 255, 255, 0.1);
    /* Legacy overrides */
    --surface: #000000;
    --blue: #64B5F6;
    --orange: #F48FB1;
    --text-light: #BDBDBD;
}

[data-contrast="high"] .board-cell {
    border: 1px solid #666;
}

[data-contrast="high"] .board-cell.legal-target {
    border-color: #FFD600;
    background: rgba(255,214,0,0.25);
}

[data-contrast="high"] .board-cell.selected-cell {
    border-color: #64B5F6;
    background: rgba(100,181,246,0.25);
}

[data-contrast="high"] .cell-piece {
    filter: drop-shadow(0 0 2px white) contrast(1.2);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--surface-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ===== Loading Screen ===== */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
}

.loading-screen h1 {
    font-family: 'Fredoka One', cursive;
    font-size: 2.5rem;
    color: var(--primary);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--amber-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== App Container ===== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Menu Page ===== */
.menu-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    gap: 2rem;
}

.menu-header {
    text-align: center;
}

.game-title {
    font-family: 'Fredoka One', cursive;
    font-size: 3.5rem;
    color: var(--primary);
    text-shadow: 2px 2px 4px var(--shadow);
    margin-bottom: 0.25rem;
}

.game-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 320px;
}

/* ===== Buttons ===== */
.btn, .menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-family: 'Open Sans', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 80ms cubic-bezier(0.33, 0, 0.67, 1), box-shadow 0.2s ease;
    box-shadow: 0 2px 8px var(--shadow);
    text-decoration: none;
}

.btn:hover, .menu-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--shadow-strong);
}

.btn:active, .menu-btn:active {
    transform: scale(0.95);
}

.menu-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn, .menu-btn.primary {
    background: linear-gradient(135deg, var(--btn-primary), var(--btn-primary-end));
    color: #FFFFFF;
}

/* Hero button — matches MAUI HeroButtonStyle */
.btn-hero, .menu-btn.hero {
    min-height: 80px;
    font-size: 20px;
    border-radius: 24px;
    padding: 20px 40px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Utility button — matches MAUI UtilityButtonStyle */
.btn-utility, .menu-btn.secondary, .menu-btn.outline {
    background: var(--btn-utility-bg);
    color: var(--text-primary);
    border: 1px solid var(--btn-utility-border);
    border-radius: 14px;
    min-height: 52px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Danger button — matches MAUI DangerButtonStyle */
.btn-danger {
    background: var(--accent-danger);
    color: #FFFFFF;
    border: none;
    border-radius: 14px;
    min-height: 48px;
}

.menu-btn.accent {
    background: linear-gradient(135deg, var(--accent-success), #2E7D32);
    color: #FFFFFF;
}

.menu-btn.outline:hover {
    background: var(--surface-card-elevated);
}

.btn-icon {
    font-size: 1.3rem;
}

/* ===== App Store Section ===== */
.app-download-section {
    text-align: center;
    margin-top: 1rem;
}

.app-download-section h3 {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.store-links {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.store-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--text-primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    min-width: 140px;
}

.store-badge:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-strong);
    background: var(--surface-card-elevated);
    color: var(--text-primary);
}

.store-icon {
    font-size: 1.5rem;
}

.store-info {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.store-label {
    font-size: 0.6rem;
    opacity: 0.8;
    text-transform: uppercase;
}

.store-name {
    font-size: 0.85rem;
    font-weight: 600;
}

/* ===== Page Content ===== */
.page-content {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem;
}

.page-content h1 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary);
    margin-bottom: 1.5rem;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.5rem 0;
    margin-bottom: 1rem;
    font-weight: 600;
    transition: color 0.2s;
}

.back-btn:hover {
    color: var(--primary);
}

/* ===== How to Play ===== */
.rules-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.rule-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 2px 8px var(--shadow);
}

.rule-card h2 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary-dark);
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
}

.rule-card p {
    line-height: 1.6;
    color: var(--text-secondary);
}

.rule-card ul {
    padding-left: 1.25rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.blue-text { color: var(--blue); font-weight: 600; }
.orange-text { color: var(--orange); font-weight: 600; }

.piece-demo, .nomnom-demo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--surface-card-elevated);
    border-radius: 8px;
}

.demo-piece.small { width: 40px; height: 40px; }
.demo-piece.medium { width: 55px; height: 55px; }
.demo-piece.large { width: 70px; height: 70px; }

.nomnom-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.arrow {
    font-size: 1.5rem;
    color: var(--text-light);
}

/* ===== Help Icon Button ===== */
.help-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.help-icon-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 0 12px rgba(255,143,0,0.5);
}

/* ===== How to Play Modal ===== */
.howtoplay-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.howtoplay-modal {
    background: var(--surface-card);
    border-radius: 20px;
    border: 1px solid var(--divider);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.howtoplay-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--divider);
}
.howtoplay-modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text-primary);
}
.howtoplay-close-btn {
    background: none;
    border: none;
    color: var(--text-disabled);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
}
.howtoplay-close-btn:hover { color: var(--text-primary); background: var(--surface-card-elevated); }
.howtoplay-modal-tabs {
    display: flex;
    justify-content: center;
    padding: 0.75rem 1rem 0;
    gap: 0;
}
.howtoplay-modal-tabs button {
    padding: 8px 20px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
}
.howtoplay-modal-tabs button:first-child { border-radius: 10px 0 0 10px; }
.howtoplay-modal-tabs button:last-child { border-radius: 0 10px 10px 0; }
.howtoplay-modal-tabs .tab-active { background: var(--accent-warning); }
.howtoplay-modal-tabs .tab-inactive { background: var(--accent-secondary); }
.howtoplay-modal-body {
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.howtoplay-modal-body .rule-card {
    background: var(--surface-card-elevated);
    border-radius: 12px;
    padding: 1rem;
}
.howtoplay-modal-body h3 {
    color: var(--orange-light);
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
}
.howtoplay-modal-body h4 {
    color: var(--orange-light);
    margin: 1rem 0 0.4rem;
    font-size: 0.9rem;
}
.tips-card ul { margin: 0.25rem 0 0.5rem 1rem; }
.tips-card li { margin-bottom: 0.4rem; line-height: 1.5; }

/* ===== Settings ===== */
.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.setting-group {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: 0 2px 8px var(--shadow);
}

.setting-group > label {
    display: block;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.setting-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 2px solid var(--amber-light);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--cream);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.setting-input:focus {
    outline: none;
    border-color: var(--primary);
}

.toggle-label {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0 !important;
    cursor: default;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--divider);
    border-radius: 28px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* Theme selector */
.theme-selector {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.theme-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: border-color 0.2s ease, transform 0.15s ease;
}

.theme-btn:hover { transform: scale(1.05); }
.theme-btn.selected { border-color: var(--primary); }

.theme-preview {
    width: 40px;
    height: 28px;
    border-radius: 6px;
    display: block;
}

.theme-preview.classic {
    background: linear-gradient(135deg, #8D6E43, #5A3D22);
}

.theme-preview.ocean {
    background: linear-gradient(135deg, #336B99, #1A3A5C);
}

.theme-preview.dark {
    background: linear-gradient(135deg, var(--accent-secondary), var(--surface-primary));
}

.skin-preview {
    font-size: 1.5rem;
    display: block;
    line-height: 1.2;
}

/* ===== Game Page ===== */
.game-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.game-setup {
    max-width: 400px;
    width: 100%;
    padding: 2rem;
}

.game-setup h1 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary);
    margin-bottom: 1.5rem;
}

.setup-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ===== Difficulty Selector ===== */
.difficulty-selector {
    display: flex;
    gap: 0.5rem;
}

.diff-btn {
    flex: 1;
    padding: 0.625rem;
    border: 2px solid var(--amber-light);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s;
    color: var(--text-primary);
}

.diff-btn:hover {
    border-color: var(--primary);
}

.diff-btn.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ===== Game Active ===== */
.game-active {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
}

.game-header {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 1rem;
}

.turn-indicator {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 2px 6px var(--shadow);
}

.turn-indicator.thinking {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.turn-color {
    font-size: 1.5rem;
    line-height: 1;
}

.turn-color.blue { color: var(--blue); }
.turn-color.orange { color: var(--orange); }

/* ===== Game Board ===== */
.game-board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

/* Move log */
.move-log {
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 1px 4px var(--shadow);
    font-size: 0.8rem;
}

.move-log summary {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 600;
    user-select: none;
}

.move-list {
    max-height: 150px;
    overflow-y: auto;
    padding: 0 0.75rem 0.5rem 2rem;
    margin: 0;
    list-style-type: decimal;
}

.move-entry {
    padding: 1px 0;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.move-entry.blue { color: var(--blue); }
.move-entry.orange { color: var(--orange); }

/* Player panels */
.player-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
    width: 100%;
    opacity: 0.55;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.player-panel.active {
    opacity: 1;
    border-color: var(--primary);
    box-shadow: 0 4px 16px var(--shadow-strong);
}

.player-label {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.3px;
}

.orange-text { color: var(--orange); }
.blue-text { color: var(--blue); }

/* Piece tray - horizontal row of piece stacks */
.piece-tray {
    width: 100%;
    overflow: hidden;
}

.piece-group {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 12px;
    padding: 4px 0;
}

/* Each size group stacks pieces with overlap */
.piece-stack {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.piece-stack.small  { }
.piece-stack.medium { }
.piece-stack.large  { }

/* Tray pieces - sized to match MAUI app */
.tray-piece {
    display: block;
    object-fit: contain;
    cursor: pointer;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3));
    transition: transform 0.15s ease, filter 0.15s ease;
    flex-shrink: 0;
}

/* Overlap: each piece after the first shifts left */
.piece-stack .tray-piece + .tray-piece {
    margin-left: -22px;
}

.piece-stack.medium .tray-piece + .tray-piece {
    margin-left: -30px;
}

.piece-stack.large .tray-piece + .tray-piece {
    margin-left: -40px;
}

/* Tray piece sizes */
.tray-piece.small  { width: 36px;  height: 36px; }
.tray-piece.medium { width: 50px;  height: 50px; }
.tray-piece.large  { width: 64px;  height: 64px; }
.tray-piece.extralarge { width: 72px; height: 72px; }

.tray-piece:hover {
    transform: scale(1.12);
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.4));
    z-index: 2;
}

.tray-piece.selected {
    transform: scale(1.2) translateY(-4px);
    filter: drop-shadow(0 0 10px var(--primary)) brightness(1.1);
    z-index: 3;
    animation: selection-pulse 1s ease-in-out infinite;
}

.player-panel.top .tray-piece.selected {
    animation-name: selection-pulse-p2;
}

@keyframes selection-pulse {
    0%, 100% {
        transform: scale(1.1) translateY(-4px);
        filter: drop-shadow(0 0 8px var(--player-one)) brightness(1.1);
    }
    50% {
        transform: scale(1.3) translateY(-4px);
        filter: drop-shadow(0 0 15px var(--player-one)) brightness(1.1);
    }
}

@keyframes selection-pulse-p2 {
    0%, 100% {
        transform: scale(1.1) translateY(-4px);
        filter: drop-shadow(0 0 8px var(--player-two)) brightness(1.1);
    }
    50% {
        transform: scale(1.3) translateY(-4px);
        filter: drop-shadow(0 0 15px var(--player-two)) brightness(1.1);
    }
}

/* Board frame - wood-grain surround */
.board-frame {
    position: relative;
    width: 100%;
    max-width: 360px;
    padding: 10px;
    background: linear-gradient(145deg, var(--board-light), var(--board-mid), var(--board-dark));
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px var(--shadow-strong), inset 0 1px 3px rgba(255,255,255,0.15);
}

/* Board grid */
.board-grid {
    display: grid;
    grid-template-columns: repeat(var(--board-size), 1fr);
    gap: 6px;
    aspect-ratio: 1;
}

/* Cells */
.board-cell {
    background: var(--board-grid);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    aspect-ratio: 1;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.08);
    border: 2px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
    overflow: hidden;
    position: relative;
}

.board-cell:hover {
    filter: brightness(1.2);
}

.board-cell:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: -3px;
}

.board-cell.legal-target {
    background: rgba(255,245,157,0.7);
    border-color: var(--amber);
    animation: cellPulse 1.5s ease-in-out infinite;
}

.board-cell.selected-cell {
    border-color: var(--player-one);
    background: rgba(74,168,216,0.15);
    box-shadow: inset 0 0 12px rgba(74,168,216,0.4);
}

@keyframes cellPulse {
    0%, 100% { box-shadow: inset 0 0 6px rgba(255,193,7,0.3); }
    50% { box-shadow: inset 0 0 14px rgba(255,193,7,0.6); }
}

/* Pieces on board - percentages of cell size */
.cell-piece {
    display: block;
    object-fit: contain;
    filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.3));
    animation: pieceDrop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell-piece.movable {
    cursor: grab;
    transition: filter 0.15s ease;
}

.cell-piece.movable:hover {
    filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.3)) brightness(1.15);
}

.cell-piece.small  { width: 45%; height: 45%; }
.cell-piece.medium { width: 70%; height: 70%; }
.cell-piece.large  { width: 92%; height: 92%; }
.cell-piece.extralarge { width: 98%; height: 98%; }

@keyframes pieceDrop {
    from { transform: scale(0.4); opacity: 0.4; }
    to   { transform: scale(1);   opacity: 1; }
}

/* NomNom wobble — capture/eat animation */
@keyframes nom-nom {
    0%   { transform: scale(1) rotate(0deg); }
    35%  { transform: scale(1.25) rotate(-6deg); }
    65%  { transform: scale(0.95) rotate(4deg); }
    100% { transform: scale(1) rotate(0deg); }
}
.cell-nom-nom {
    animation: nom-nom 340ms cubic-bezier(0.33, 1, 0.67, 1);
}

/* Shake — illegal move feedback */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-10px); }
    80% { transform: translateX(10px); }
}
.cell-shake {
    animation: shake 250ms linear;
}

/* Win bounce — staggered per winning cell */
@keyframes win-bounce {
    0%   { transform: translateY(0); }
    50%  { transform: translateY(-15px); }
    100% { transform: translateY(0); }
}
.cell-win-bounce {
    animation: win-bounce 240ms cubic-bezier(0.33, 1, 0.67, 1) 3;
}
.cell-win-bounce.stagger-1 { animation-delay: 0ms; }
.cell-win-bounce.stagger-2 { animation-delay: 60ms; }
.cell-win-bounce.stagger-3 { animation-delay: 120ms; }
.cell-win-bounce.stagger-4 { animation-delay: 180ms; }

/* Win glow — gold pulse on winning cells */
@keyframes win-glow {
    0%, 100% { box-shadow: 0 0 8px rgba(255, 214, 0, 0.6); border-color: #FFD600; }
    50%      { box-shadow: 0 0 20px rgba(255, 214, 0, 1.0); }
}
.cell-win-glow {
    animation: win-glow 800ms ease-in-out 5;
    border: 3px solid #FFD600;
    background-color: rgba(255, 214, 0, 0.2);
}

/* Draw vignette — warm radial overlay for draw state */
@keyframes vignette-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.7; }
}
.draw-vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center,
        rgba(255, 183, 77, 0.4) 0%,
        rgba(255, 143, 0, 0.2) 50%,
        transparent 80%);
    animation: vignette-pulse 2400ms ease-in-out infinite;
    pointer-events: none;
    z-index: 5;
}

/* Turn glow — pulse on active player panel */
@keyframes turn-glow {
    0%, 100% { border-color: transparent; box-shadow: none; }
    50%      { border-color: var(--active-player-color); box-shadow: 0 0 12px var(--active-player-color); }
}
.player-panel.active-turn {
    animation: turn-glow 1300ms ease-in-out infinite;
}
.player-panel.active-turn.p1 { --active-player-color: var(--player-one); }
.player-panel.active-turn.p2 { --active-player-color: var(--player-two); }

/* Menu stagger entry */
@keyframes stagger-in {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
.stagger-item {
    animation: stagger-in 200ms cubic-bezier(0.33, 1, 0.67, 1) both;
}
.stagger-item:nth-child(1) { animation-delay: 0ms; }
.stagger-item:nth-child(2) { animation-delay: 80ms; }
.stagger-item:nth-child(3) { animation-delay: 160ms; }
.stagger-item:nth-child(4) { animation-delay: 240ms; }
.stagger-item:nth-child(5) { animation-delay: 320ms; }
.stagger-item:nth-child(6) { animation-delay: 400ms; }
.stagger-item:nth-child(7) { animation-delay: 480ms; }
.stagger-item:nth-child(8) { animation-delay: 560ms; }

/* ===== Game Over Overlay ===== */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: banner-enter 500ms cubic-bezier(0.33, 1, 0.67, 1) forwards;
}

@keyframes banner-enter {
    0%   { opacity: 0; transform: scale(0.5); }
    70%  { opacity: 1; transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1.0); }
}

/* Win/loss emoji bounce */
.win-icon {
    display: inline-block;
    animation: emoji-bounce 380ms cubic-bezier(0.33, 1, 0.67, 1);
    animation-delay: 200ms;
    animation-fill-mode: both;
}

@keyframes emoji-bounce {
    0%   { transform: scale(0.6) rotate(-12deg); }
    58%  { transform: scale(1.4) rotate(8deg); }
    100% { transform: scale(1.0) rotate(0deg); }
}

.game-over-card {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    max-width: 320px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.game-over-card h2 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary-dark);
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.game-over-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.undo-bar {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
}

.menu-btn.small {
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
    border: 1px solid var(--amber);
    color: var(--amber);
    border-radius: var(--radius);
    transition: background 0.2s ease, transform 0.15s ease;
}

.menu-btn.small:hover {
    background: rgba(255,193,7,0.12);
    transform: scale(1.04);
}

.hint-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,245,157,0.15);
    border: 1px solid var(--amber);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.hint-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.hint-dismiss {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    line-height: 1;
    flex-shrink: 0;
}

.hint-dismiss:hover {
    color: var(--text);
}

/* ===== Online Specific ===== */
.online-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.divider-text {
    text-align: center;
    color: var(--text-light);
    font-size: 0.85rem;
}

.join-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.code-input {
    text-align: center;
    font-size: 1.3rem !important;
    letter-spacing: 4px;
    font-weight: 600;
}

.waiting-room {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    gap: 1.5rem;
    padding: 2rem;
}

.waiting-room h1 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary);
}

.game-code-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.code-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.game-code {
    font-family: 'Fredoka One', cursive;
    font-size: 3rem;
    color: var(--primary);
    letter-spacing: 8px;
    background: var(--surface);
    padding: 0.5rem 2rem;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px var(--shadow);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--amber-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.waiting-text {
    color: var(--text-light);
}

.error-message {
    color: var(--accent-danger);
    background: rgba(229, 57, 53, 0.15);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
}

.status-message {
    color: var(--text-secondary);
    background: var(--cream);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
    margin-top: 0.5rem;
}

/* ===== Blazor Error UI ===== */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ===== Typography Scale (matches MAUI Styles.xaml) ===== */
.display-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--text-primary);
}

.heading-large {
    font-size: 22px;
    font-family: 'Open Sans', sans-serif;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

.heading-small {
    font-size: 18px;
    font-family: 'Open Sans', sans-serif;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-primary);
}

.body-large {
    font-size: 16px;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-primary);
}

.body-medium {
    font-size: 14px;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-primary);
}

.body-small {
    font-size: 12px;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}

.label-micro {
    font-size: 10px;
    font-family: 'Open Sans', sans-serif;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    color: var(--text-primary);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .game-title {
        font-size: 2.5rem;
    }

    .board-frame {
        max-width: 300px;
    }

    .tray-piece.small  { width: 28px; height: 28px; }
    .tray-piece.medium { width: 40px; height: 40px; }
    .tray-piece.large  { width: 52px; height: 52px; }
    .tray-piece.extralarge { width: 58px; height: 58px; }

    .piece-stack .tray-piece + .tray-piece { margin-left: -18px; }
    .piece-stack.medium .tray-piece + .tray-piece { margin-left: -24px; }
    .piece-stack.large .tray-piece + .tray-piece { margin-left: -34px; }

    .store-links {
        flex-direction: column;
        align-items: center;
    }

    .store-badge {
        width: 200px;
    }

    .game-code {
        font-size: 2rem;
        letter-spacing: 4px;
    }
}

@media (min-width: 768px) {
    .menu-page {
        padding: 3rem;
    }

    .game-title {
        font-size: 4rem;
    }

    .board-frame {
        max-width: 420px;
    }

    .tray-piece.small  { width: 40px; height: 40px; }
    .tray-piece.medium { width: 55px; height: 55px; }
    .tray-piece.large  { width: 70px; height: 70px; }
    .tray-piece.extralarge { width: 80px; height: 80px; }
}

/* ===== Confetti ===== */
.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: all;
    overflow: hidden;
    z-index: 1000;
}

.confetti-piece {
    position: absolute;
    top: -10px;
    border-radius: 2px;
    animation: confettiFall var(--fall-duration, 2s) cubic-bezier(0.55, 0, 1, 0.45) forwards;
    animation-delay: var(--fall-delay, 0s);
    opacity: 0;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-20px) rotate(var(--start-rot, 0deg));
        opacity: 1;
    }
    60% {
        opacity: 1;
    }
    100% {
        transform: translateY(calc(100vh + 30px)) rotate(var(--end-rot, 360deg));
        opacity: 0.3;
    }
}

/* ===== Match History ===== */
.history-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 3rem 0;
}

.empty-history {
    text-align: center;
    padding: 3rem 0;
    color: var(--text-secondary);
}

.empty-history p {
    margin-bottom: 0.5rem;
}

.hint-text {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 1.5rem !important;
}

/* ===== Stats Page ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: 0 2px 8px var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-card.win { border-left: 4px solid var(--accent-success); }
.stat-card.loss { border-left: 4px solid var(--accent-danger); }
.stat-card.draw { border-left: 4px solid var(--amber); }

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: 'Fredoka One', cursive;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-details, .stats-breakdown {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px var(--shadow);
}

.stats-breakdown h2 {
    font-size: 1rem;
    color: var(--primary-dark);
    margin-bottom: 0.75rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--divider);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.stat-row:last-child { border-bottom: none; }

.stat-highlight {
    font-weight: 600;
    color: var(--text-primary);
}

.win-text { color: var(--accent-success); }
.loss-text { color: var(--accent-danger); }

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.history-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: 0 2px 8px var(--shadow);
    border-left: 4px solid var(--text-light);
}

.history-card.win {
    border-left-color: var(--accent-success);
}

.history-card.loss {
    border-left-color: var(--accent-danger);
}

.history-card.draw {
    border-left-color: var(--amber);
}

.match-result {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.result-badge {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    color: white;
}

.result-badge.win { background: var(--accent-success); }
.result-badge.loss { background: var(--accent-danger); }
.result-badge.draw { background: var(--amber); color: var(--text-primary); }

.match-type-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.match-type-badge.local { background: rgba(74,168,216,0.15); color: var(--player-one); }
.match-type-badge.online { background: rgba(67,160,71,0.15); color: var(--accent-success); }

.match-date {
    font-size: 0.8rem;
    color: var(--text-light);
}

.match-players {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
}

.player-blue { color: var(--blue); }
.player-orange { color: var(--orange); }

.vs {
    font-size: 0.75rem;
    color: var(--text-light);
    font-weight: 400;
}

.match-details {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-light);
}

/* ===== Leaderboard ===== */
.leaderboard-table {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
    overflow: hidden;
}

.lb-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.lb-row {
    display: flex;
    align-items: center;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--divider);
    transition: background 0.15s;
}

.lb-row:last-child {
    border-bottom: none;
}

.lb-row:hover {
    background: var(--cream);
}

.lb-me {
    background: var(--surface-card-elevated);
    font-weight: 600;
}

.lb-rank {
    width: 2.5rem;
    text-align: center;
    flex-shrink: 0;
}

.lb-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0.5rem;
}

.lb-stat {
    width: 2.5rem;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.lb-stat-wide {
    width: 3.5rem;
    text-align: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 0.85rem;
}

.win-stat { color: var(--accent-success); }
.loss-stat { color: var(--accent-danger); }
.draw-stat { color: var(--amber); }

/* ===== Piece Placement Animation ===== */
.cell-piece {
    animation: pieceDrop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.board-cell.legal-target .cell-piece {
    animation: none;
}

/* ===== Tray Piece Pickup Animation ===== */
.tray-piece {
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tray-piece:active {
    transform: scale(0.85);
}

/* ===== Game Save Indicator ===== */
.save-indicator {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-light);
    padding: 0.25rem 0.5rem;
}

.save-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-success);
    animation: savePulse 1s ease-out;
}

@keyframes savePulse {
    0% { transform: scale(1.5); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

/* Global animation suppression when user disables animations */
[data-animations="off"] * {
    animation-duration: 0s !important;
    animation-delay: 0s !important;
    transition-duration: 0s !important;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0s !important;
        transition-duration: 0s !important;
    }
}

/* Theme selector grid */
.theme-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.theme-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border-radius: 12px;
    border: 2px solid var(--divider);
    background: var(--surface-card);
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.15s ease;
    width: 110px;
}

.theme-card:hover {
    transform: scale(1.05);
}

.theme-card:active {
    transform: scale(0.95);
}

.theme-card.active {
    border-color: var(--accent-primary);
}

.theme-preview {
    width: 90px;
    height: 60px;
    border-radius: 8px;
}

.theme-name {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
}

.theme-active {
    font-size: 10px;
    color: var(--accent-success);
}

.piece-preview {
    width: 60px;
    height: 60px;
    object-fit: contain;
}

/* Font Awesome icon utilities */
.btn i.fa-solid, .btn i.fa-brands,
.menu-btn i.fa-solid, .menu-btn i.fa-brands {
  font-size: 1.1em;
}

.icon-sm { font-size: 0.85em; }
.icon-lg { font-size: 1.3em; }
.icon-xl { font-size: 1.6em; }

/* Medal colors for leaderboard */
.medal-gold { color: #FFD700; }
.medal-silver { color: #C0C0C0; }
.medal-bronze { color: #CD7F32; }
