:root[data-theme="dark"] {
    --bg-dark: #090d16;
    --bg-card: rgba(18, 26, 43, 0.75);
    --bg-input: rgba(15, 23, 42, 0.85);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(99, 102, 241, 0.4);
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent-cat: #ec4899;
    --accent-dog: #3b82f6;
    --accent-win: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    /* Dark Mode Embossed Mechanical 3D Board & Tiles */
    --grid-bg: #0b1120;
    --grid-border-tl: rgba(0, 0, 0, 0.8);
    --grid-border-br: rgba(255, 255, 255, 0.12);
    --cell-bg: linear-gradient(145deg, #1e293b 0%, #151f32 100%);
    --cell-bevel-tl: rgba(255, 255, 255, 0.22);
    --cell-bevel-br: rgba(0, 0, 0, 0.65);
    --cell-hover: linear-gradient(145deg, #25334d 0%, #1a263c 100%);
    --cell-taken-bg: #0a0f1d;
    --cell-taken-border: rgba(255, 255, 255, 0.07);
    --cell-taken-inset: inset 2px 2px 5px rgba(0, 0, 0, 0.7);
    --shadow: rgba(0, 0, 0, 0.4);
}

:root[data-theme="light"] {
    --bg-dark: #e2e8f0;
    --bg-card: rgba(255, 255, 255, 0.95);
    --bg-input: rgba(241, 245, 249, 0.95);
    --border-glass: rgba(0, 0, 0, 0.12);
    --border-highlight: rgba(79, 70, 229, 0.5);
    
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --accent-cat: #f43f5e;
    --accent-dog: #3b82f6;
    --accent-win: #059669;
    --accent-warning: #d97706;
    --accent-danger: #dc2626;

    --text-main: #0f172a;
    --text-muted: #475569;
    
    /* Modern Polished Retro Minesweeper 3D Board & Tiles */
    --grid-bg: #cbd5e1;
    --grid-border-tl: #94a3b8;
    --grid-border-br: #ffffff;
    --cell-bg: linear-gradient(145deg, #f8fafc 0%, #e2e8f0 100%);
    --cell-bevel-tl: #ffffff;
    --cell-bevel-br: #94a3b8;
    --cell-hover: linear-gradient(145deg, #ffffff 0%, #ecf0f5 100%);
    --cell-taken-bg: #cbd5e1;
    --cell-taken-border: #94a3b8;
    --cell-taken-inset: inset 2px 2px 4px rgba(0, 0, 0, 0.15);
    --shadow: rgba(0, 0, 0, 0.1);
}

:root {
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(236, 72, 153, 0.1) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: var(--font-sans);
    min-height: 100vh;
    padding: 1rem;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 1440px;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

/* Glassmorphism Card */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px 0 var(--shadow);
    padding: 1rem;
}

/* Header Bar */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.brand-logo {
    font-size: 1.8rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
}

.brand-title {
    font-size: 1.3rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge-tag {
    font-size: 0.7rem;
    background: linear-gradient(135deg, var(--primary), var(--accent-cat));
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
}

.brand-subtitle {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.icon-select, .icon-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.icon-btn:hover, .icon-select:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}

.help-btn {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(236, 72, 153, 0.2));
    border-color: var(--border-highlight);
    font-weight: 600;
}

/* Status Badge Top Right Format :8004 */
.status-badge {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.status-idle { background: rgba(16, 185, 129, 0.12); color: var(--accent-win); border: 1px solid rgba(16, 185, 129, 0.3); }
.status-thinking { background: rgba(99, 102, 241, 0.15); color: var(--primary); border: 1px solid var(--border-highlight); }
.status-paused { background: rgba(245, 158, 11, 0.15); color: var(--accent-warning); border: 1px solid rgba(245, 158, 11, 0.3); }
.status-error { background: rgba(239, 68, 68, 0.15); color: var(--accent-danger); border: 1px solid rgba(239, 68, 68, 0.3); }

/* Layout Grid */
.workbench-layout {
    display: grid;
    grid-template-columns: 310px 1fr 310px;
    gap: 0.8rem;
    align-items: start;
}

@media (max-width: 1023px) {
    .workbench-layout {
        grid-template-columns: 1fr;
    }
}

/* Control Panel */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    font-size: 0.85rem;
}

.section-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.6rem;
    color: var(--text-main);
}

.panel-section {
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.6rem;
}
.panel-section:last-child { border-bottom: none; }

.player-config-card {
    background: var(--bg-input);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 0.7rem;
    margin-bottom: 0.6rem;
}

.player-card-title {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.cat-title { color: var(--accent-cat); }
.dog-title { color: var(--accent-dog); }

.inline-control-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.flex-1 { flex: 1; }

.hint-icon-btn {
    padding: 0.35rem 0.6rem;
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.4);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
}

.form-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.custom-select, .custom-input {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s ease;
}
.custom-select:focus, .custom-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.slider-val {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 600;
}

.slider-val.depth-tier-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.12rem 0.42rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}
.depth-tier-badge.tier-green {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.4);
}
.depth-tier-badge.tier-indigo {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.4);
}
.depth-tier-badge.tier-rose {
    background: rgba(236, 72, 153, 0.15);
    color: #ec4899;
    border: 1px solid rgba(236, 72, 153, 0.4);
}
.depth-tier-badge.tier-red {
    background: rgba(239, 68, 68, 0.18);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.5);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.35);
}

.custom-slider {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
    transition: accent-color 0.15s ease;
}

/* Switch */
.checkbox-group { margin-top: 0.2rem; }
.switch-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.8rem;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.3rem;
}

.btn {
    padding: 0.65rem 0.8rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.5);
}
.btn-secondary {
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
}
.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Game Area Layout */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    position: relative;
}

/* Unified Header Bar */
.unified-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 52px;
    box-sizing: border-box;
    background: var(--bg-input);
    padding: 0.35rem 0.8rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
    gap: 0.4rem;
}

.btn-header-action {
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.btn-header-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.5);
}

.player-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid transparent;
}
.player-card.active { border-color: var(--primary); }
.cat-card.active { border-color: var(--accent-cat); background: rgba(236, 72, 153, 0.15); }
.dog-card.active { border-color: var(--accent-dog); background: rgba(59, 130, 246, 0.15); }

.avatar { font-size: 1.2rem; }
.player-name { font-weight: 600; font-size: 0.85rem; }

.score-badge {
    font-size: 1.1rem;
    font-family: var(--font-mono);
    font-weight: 700;
    background: rgba(0, 0, 0, 0.25);
    padding: 0.1rem 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-glass);
}

.unified-turn-pill {
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-glass);
    white-space: nowrap;
}

/* Pie Rule Prompt Banner (Floating HUD Overlay - Zero Layout Shift) */
.pie-rule-banner {
    position: absolute;
    top: 66px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 9999px;
    padding: 0.4rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    z-index: 60;
    animation: popIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
}
[data-theme="light"] .pie-rule-banner {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(99, 102, 241, 0.3);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.2);
}
.pie-banner-text {
    font-size: 0.82rem;
    color: var(--text-main);
}
.pie-btn-row {
    display: flex;
    gap: 0.4rem;
}
.btn-pie-swap {
    background: linear-gradient(135deg, var(--accent-dog), var(--primary));
    color: #fff;
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 9999px;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-pie-keep {
    background: var(--bg-input);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-pie-swap:hover, .btn-pie-keep:hover {
    transform: scale(1.04);
}

/* Board Wrapper & Grid */
.board-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    overflow-x: auto;
    padding: 0.2rem;
}

.grid-container {
    display: grid;
    gap: 3px;
    background: var(--grid-bg);
    padding: 6px;
    border-radius: 8px;
    border-top: 3px solid var(--grid-border-tl);
    border-left: 3px solid var(--grid-border-tl);
    border-right: 3px solid var(--grid-border-br);
    border-bottom: 3px solid var(--grid-border-br);
    box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.15);
}

@media (min-width: 1024px) {
    .grid-15x3 {
        grid-template-columns: repeat(3, min(60px, calc((72vh - 120px) / 15)));
    }
    .grid-12x4 {
        grid-template-columns: repeat(4, min(60px, calc((72vh - 120px) / 15)));
    }
    .cell {
        height: min(60px, calc((72vh - 120px) / 15));
        aspect-ratio: 1 / 1;
        width: 100%;
        font-size: min(1.5rem, calc((72vh - 120px) / 22));
    }
}

@media (max-width: 1023px) {
    .grid-15x3 { grid-template-columns: repeat(3, minmax(48px, 80px)); }
    .grid-12x4 { grid-template-columns: repeat(4, minmax(48px, 80px)); }
    .cell { aspect-ratio: 1; font-size: 1.5rem; }
}

.cell {
    background: var(--cell-bg);
    border-top: 2.5px solid var(--cell-bevel-tl);
    border-left: 2.5px solid var(--cell-bevel-tl);
    border-right: 2.5px solid var(--cell-bevel-br);
    border-bottom: 2.5px solid var(--cell-bevel-br);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.cell:hover:not(.taken) {
    background: var(--cell-hover);
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}
.cell:active:not(.taken) {
    border-top: 2.5px solid var(--cell-bevel-br);
    border-left: 2.5px solid var(--cell-bevel-br);
    border-right: 2.5px solid var(--cell-bevel-tl);
    border-bottom: 2.5px solid var(--cell-bevel-tl);
    transform: translateY(1px);
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.2);
}
.cell.taken {
    cursor: default;
    background: var(--cell-taken-bg);
    border: 1.5px solid var(--cell-taken-border);
    box-shadow: var(--cell-taken-inset);
    transform: none;
}
.cell.taken.cat, .cell.taken.dog {
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15));
}

.cell.last-move {
    outline: 2px solid var(--accent-warning);
    outline-offset: -2px;
}

.cell.winning-cell {
    background: rgba(16, 185, 129, 0.45) !important;
    border-color: var(--accent-win) !important;
    animation: winPulse 0.8s infinite alternate;
}

@keyframes winPulse {
    from { transform: scale(1); }
    to { transform: scale(1.06); }
}

/* Log Panel */
.log-panel {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.metrics-row { display: flex; gap: 0.4rem; }
.metric-box {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-glass);
    padding: 0.4rem;
    border-radius: var(--radius-md);
    text-align: center;
}
.metric-label { font-size: 0.7rem; color: var(--text-muted); }
.metric-value { font-family: var(--font-mono); font-weight: 600; font-size: 0.85rem; color: var(--primary); }

.log-container {
    background: var(--bg-input);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 0.6rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    height: min(420px, calc(75vh - 100px));
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.log-entry {
    line-height: 1.35;
    padding-bottom: 0.25rem;
    border-bottom: 1px dotted var(--border-glass);
}
.log-entry.sys { color: var(--text-muted); }
.log-entry.move { color: var(--text-main); }
.log-entry.win { color: var(--accent-win); font-weight: bold; }
.log-entry.fallback { color: var(--accent-warning); }

/* Modal Dialog */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 1rem;
}

.modal-content {
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border: 1px solid var(--border-highlight);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.5rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.6rem;
    color: var(--text-muted);
    cursor: pointer;
}
.close-btn:hover { color: var(--accent-cat); }

.modal-body {
    font-size: 0.9rem;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}
.modal-body h3 { font-size: 1rem; color: var(--primary); margin-top: 0.4rem; }
.modal-body ul { padding-left: 1.2rem; }
.modal-body p  { color: var(--text-muted); font-size: 0.88rem; }
.modal-body a  { color: var(--primary); text-decoration: underline; }

/* ─────────────────────────────────────────────────────────────────
   MOBILE TOGGLE BUTTONS
   Hidden on desktop; shown on mobile to collapse/expand panels
   ───────────────────────────────────────────────────────────────── */
.mobile-toggle-btn {
    display: none; /* hidden on desktop */
}

/* ─────────────────────────────────────────────────────────────────
   DESKTOP: collapsible wrappers always open, toggle buttons hidden
   ───────────────────────────────────────────────────────────────── */
@media (min-width: 1024px) {
    #config-collapsible { display: block !important; }
    #log-collapsible    { display: block !important; }
    .mobile-toggle-btn  { display: none !important; }
}

/* ─────────────────────────────────────────────────────────────────
   TABLET / MOBILE ≤ 1023px
   ───────────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {

    /* --- Layout: Board always first --- */
    .workbench-layout {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    .game-area     { order: 1; padding: 0.6rem; }
    .control-panel { order: 2; }
    .log-panel     { order: 3; }

    /* --- Mobile toggle buttons --- */
    .mobile-toggle-btn {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        background: var(--bg-input);
        border: 1px solid var(--border-glass);
        color: var(--text-main);
        padding: 0.65rem 1rem;
        border-radius: var(--radius-md);
        font-family: var(--font-sans);
        font-size: 0.9rem;
        font-weight: 600;
        cursor: pointer;
        transition: border-color 0.2s;
        margin-bottom: 0.3rem;
    }
    .mobile-toggle-btn:hover { border-color: var(--primary); }
    .mobile-toggle-btn.open  { border-color: var(--primary); background: rgba(99,102,241,0.1); }

    /* Log toggle: smaller, inline in header row */
    .mobile-toggle-log {
        width: auto;
        flex: 1;
        margin-bottom: 0;
        font-size: 0.8rem;
        padding: 0.4rem 0.7rem;
    }

    /* --- Collapsible panels: hidden by default on mobile --- */
    #config-collapsible { display: none; }
    #log-collapsible    { display: none; }
    #config-collapsible.open { display: block; }
    #log-collapsible.open    { display: block; }

    /* --- Log header row --- */
    .log-header-row {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    .log-header-row h2 { flex: none; margin-bottom: 0; }

    /* --- Compact log --- */
    .log-container { height: 200px; }
}

/* Mobile-only elements hidden on desktop */
.mobile-rules-preset-select { display: none; }
.floating-side-dock { display: none; }
.mobile-only-sheet-close { display: none; }
.sheet-backdrop { display: none; }
.victory-popup-overlay { display: none; }

/* ─────────────────────────────────────────────────────────────────
   SMARTPHONE ≤ 768px — Dedicated Mobile Gaming UX (Console-Style HUD)
   ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

    html, body {
        height: 100vh !important;
        max-height: 100vh !important;
        overflow: hidden !important;
        overscroll-behavior: none !important;
        padding: 0.25rem !important;
    }

    .app-container {
        height: 100vh !important;
        max-height: 100vh !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .workbench-layout {
        flex: 1 !important;
        height: calc(100vh - 56px) !important;
        max-height: calc(100vh - 56px) !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .game-area {
        flex: 1 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 0.35rem !important;
    }

    /* Hide in-flow settings and log below the board on mobile */
    .control-panel:not(.open-as-sheet),
    .log-panel:not(.open-as-sheet) {
        display: none !important;
    }

    /* Compact App Header: zero overflow, perfectly fitting title + icons */
    .app-header {
        padding: 0.3rem 0.5rem;
        margin-bottom: 0.35rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .header-brand {
        display: flex;
        align-items: center;
        gap: 0.35rem;
        cursor: pointer;
        user-select: none;
    }
    .brand-subtitle { display: none; }
    .brand-logo     { font-size: 1.15rem; padding: 0.1rem 0.25rem; border-radius: 6px; }
    .brand-title    {
        font-size: 0.95rem;
        display: flex;
        align-items: center;
        gap: 0.3rem;
        margin: 0;
        white-space: nowrap;
    }
    
    /* Version Tag: Hidden by default on mobile, revealed on tap with smooth fade-in */
    .badge-tag {
        font-size: 0.62rem;
        padding: 0.1rem 0.32rem;
        display: none;
        opacity: 0;
        transition: opacity 0.25s ease, transform 0.25s ease;
    }
    .badge-tag.show-version {
        display: inline-block !important;
        opacity: 1 !important;
        animation: fadeInVersion 0.25s ease-out;
    }
    @keyframes fadeInVersion {
        from { opacity: 0; transform: scale(0.85) translateY(-2px); }
        to { opacity: 1; transform: scale(1) translateY(0); }
    }

    #i18n-btn-help  { display: none; }   /* keep ❓ emoji icon */
    .status-badge   { display: none; }   /* status shown in turn pill */
    .header-actions {
        display: flex;
        align-items: center;
        gap: 0.25rem;
    }
    
    /* Unified Symmetrical 34px Glass Button Pack */
    .icon-select.lang-select,
    .icon-btn {
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
        max-width: 34px !important;
        min-height: 34px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1rem !important;
        border-radius: var(--radius-sm) !important;
        box-sizing: border-box !important;
    }
    .icon-select.lang-select {
        text-align: center !important;
        text-align-last: center !important;
        appearance: none !important;
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        background-image: none !important;
        cursor: pointer !important;
    }

    /* 1-Row Responsive Match Scoreboard (Zero 2nd Row) */
    .unified-header-bar {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 0.25rem 0.4rem !important;
        gap: 0.4rem !important;
        margin-bottom: 0.35rem !important;
        border-radius: var(--radius-md);
    }
    
    /* Hide 2nd row items inside top header bar on mobile */
    .unified-header-bar #btn-main-action,
    .unified-header-bar #turn-banner,
    .unified-header-bar .mobile-rules-preset-select {
        display: none !important;
    }

    /* Symmetrical Face-Off Score Cards (50/50) */
    .player-card.cat-card,
    #player-cat-card,
    .player-card.dog-card,
    #player-dog-card {
        flex: 1 1 calc(50% - 0.2rem) !important;
        height: 36px !important;
        padding: 0.25rem 0.5rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        box-sizing: border-box !important;
        border: 1.5px solid var(--border-glass) !important;
        transition: border-color 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease !important;
    }

    /* Active Turn: Glowing Emerald Green Frame on active player */
    .player-card.active-turn {
        border: 2px solid #10b981 !important;
        box-shadow: 0 0 16px rgba(16, 185, 129, 0.45) !important;
        opacity: 1 !important;
        background: rgba(16, 185, 129, 0.08) !important;
    }
    .player-card:not(.active-turn) {
        opacity: 0.7 !important;
        border-color: var(--border-glass) !important;
        box-shadow: none !important;
    }

    .player-info {
        gap: 0.25rem;
    }
    .player-name {
        font-size: 0.76rem;
    }
    .player-wins,
    .score-badge {
        min-width: 20px;
        height: 20px;
        font-size: 0.75rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Full-Screen No-Scroll Game Board: Rock-Solid Static JS Computed Pixels */
    .board-wrapper {
        padding: 0.1rem;
        position: relative !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        flex: 1 !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    /* Floating Side Dock: Aligned Strictly to the Left with Breathing Space to Board */
    .floating-side-dock {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.4rem !important;
        position: absolute !important;
        left: 0.35rem !important;
        top: 1.2rem !important;
        z-index: 20 !important;
        width: auto !important;
        align-items: flex-start !important;
    }

    /* Floating Action Button (Start / Pause / Next Round) */
    .floating-btn-action {
        background: linear-gradient(135deg, #6366f1, #4f46e5);
        color: white;
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: var(--radius-md);
        padding: 0.35rem 0.45rem;
        font-size: 0.76rem;
        font-weight: 700;
        width: 82px;
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
        cursor: pointer;
        text-align: center;
        line-height: 1.15;
        transition: all 0.2s ease;
    }
    .floating-btn-action.btn-action-next {
        background: linear-gradient(135deg, #10b981, #059669);
        box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
    }
    .floating-btn-action.btn-action-pause {
        background: var(--bg-card);
        border-color: var(--border-glass);
        color: var(--text-main);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    /* Floating Preset Selector */
    .floating-preset-select {
        display: inline-flex !important;
        background: var(--bg-card);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 1px solid var(--border-glass);
        color: var(--text-main);
        border-radius: var(--radius-md);
        padding: 0.3rem 0.35rem;
        font-size: 0.74rem;
        font-weight: 600;
        width: 82px;
        height: 34px;
        text-align: center;
        text-align-last: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
        cursor: pointer;
    }

    /* Floating Square Tools Row: Settings & Log (Identical Size & Shape) */
    .floating-square-row {
        display: flex !important;
        gap: 0.35rem !important;
        width: 82px !important;
        justify-content: space-between !important;
    }

    .floating-square-btn {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        background: var(--bg-card) !important;
        backdrop-filter: blur(12px) !important;
        -webkit-backdrop-filter: blur(12px) !important;
        border: 1px solid var(--border-glass) !important;
        color: var(--text-main) !important;
        border-radius: var(--radius-md) !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1.15rem !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12) !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        padding: 0 !important;
    }
    .floating-square-btn:active {
        transform: scale(0.92) !important;
    }

    /* Tap-to-Dismiss Victory Popup Overlay */
    .victory-popup-overlay {
        position: fixed !important;
        inset: 0 !important;
        background: rgba(0, 0, 0, 0.55) !important;
        backdrop-filter: blur(6px) !important;
        -webkit-backdrop-filter: blur(6px) !important;
        z-index: 1100 !important;
        display: none;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        animation: fadeIn 0.2s ease-out;
    }
    .victory-popup-overlay.show-popup {
        display: flex !important;
    }
    .victory-popup-card {
        background: var(--bg-card) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border: 1px solid var(--border-glass) !important;
        border-radius: var(--radius-lg) !important;
        padding: 1.5rem 2rem !important;
        text-align: center !important;
        box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4) !important;
        animation: scaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
        max-width: 85vw !important;
    }
    @keyframes scaleUp {
        from { transform: scale(0.85); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
    }
    .victory-popup-emoji {
        font-size: 2.8rem;
        margin-bottom: 0.4rem;
    }
    .victory-popup-title {
        font-size: 1.25rem;
        font-weight: 800;
        color: var(--text-main);
        margin-bottom: 0.35rem;
    }
    .victory-popup-sub {
        font-size: 0.78rem;
        color: var(--text-muted);
    }

    /* Mobile Bottom Sheet Drawer for Settings & Log */
    .sheet-backdrop {
        position: fixed !important;
        inset: 0 !important;
        background: rgba(0, 0, 0, 0.5) !important;
        backdrop-filter: blur(4px) !important;
        -webkit-backdrop-filter: blur(4px) !important;
        z-index: 998 !important;
        animation: fadeIn 0.2s ease-out;
    }

    .control-panel.open-as-sheet,
    .log-panel.open-as-sheet {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-height: 82vh !important;
        border-radius: 20px 20px 0 0 !important;
        background: var(--bg-card) !important;
        backdrop-filter: blur(24px) !important;
        -webkit-backdrop-filter: blur(24px) !important;
        border: 1px solid var(--border-glass) !important;
        border-bottom: none !important;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35) !important;
        z-index: 999 !important;
        overflow-y: auto !important;
        animation: slideUpSheet 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
        display: block !important;
        padding: 1.2rem 1rem !important;
    }
    .control-panel.open-as-sheet #config-collapsible,
    .log-panel.open-as-sheet #log-collapsible {
        display: block !important;
    }
    @keyframes slideUpSheet {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .mobile-only-sheet-close {
        display: inline-flex !important;
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        border: 1px solid var(--border-glass);
        background: var(--bg-input);
        color: var(--text-main);
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 0.9rem;
        z-index: 10;
    }

    .grid-container {
        padding: 5px;
        gap: 2.5px;
    }

    .grid-15x3 {
        grid-template-columns: repeat(3, var(--board-cell-size, 38px)) !important;
    }
    .grid-12x4 {
        grid-template-columns: repeat(4, var(--board-cell-size, 38px)) !important;
    }
    .cell {
        aspect-ratio: 1 / 1;
        width: 100%;
        height: auto;
        font-size: clamp(1.1rem, 5.5vw, 1.65rem);
    }

    /* Pie Rule Banner on Mobile */
    .pie-rule-banner {
        top: 60px;
        width: calc(100% - 1.2rem);
        max-width: 360px;
        padding: 0.4rem 0.65rem;
        font-size: 0.78rem;
        gap: 0.4rem;
        flex-wrap: wrap;
        justify-content: center;
    }
    .pie-banner-text {
        font-size: 0.75rem;
        text-align: center;
    }
    .pie-btn-row {
        gap: 0.3rem;
    }

    /* Modal fits phone */
    .modal-content { max-height: 92vh; width: 94vw; padding: 1.1rem; }
    .modal-body    { font-size: 0.85rem; }
}

/* ─────────────────────────────────────────────────────────────────
   v1.2.0: Rules Box, 3D Bone Walls, Coin-Flip, & Quick-Start Chips
   ───────────────────────────────────────────────────────────────── */
.rules-card {
    background: rgba(99, 102, 241, 0.04);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    margin-bottom: 0.8rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.rules-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border-glass);
}
.rules-card-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.02em;
}
.rules-header-controls {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.rules-preset-select {
    font-size: 0.72rem;
    padding: 0.18rem 0.35rem;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    max-width: 105px;
}
.btn-reset-card {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 0.18rem 0.45rem;
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    transition: all 0.15s ease;
}
.btn-reset-card:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    transform: scale(1.03);
}

/* 3D Stylized Bone Walls */
.grid-container {
    position: relative;
}
.bone-wall-h, .bone-wall-v {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    border-radius: 4px;
    background: linear-gradient(135deg, #fefce8 0%, #fef08a 50%, #fde047 100%);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35), inset 0 1px 1px #ffffff;
    border: 1px solid #ca8a04;
}
[data-theme="dark"] .bone-wall-h, [data-theme="dark"] .bone-wall-v {
    background: linear-gradient(135deg, #fef9c3 0%, #fef08a 60%, #eab308 100%);
    box-shadow: 0 0 8px rgba(254, 240, 138, 0.4), inset 0 1px 1px #ffffff;
    border: 1px solid #a16207;
}

.bone-wall-h {
    height: 6px;
    transform: translateY(-50%);
}
.bone-wall-h::before, .bone-wall-h::after {
    content: '';
    position: absolute;
    top: -2px;
    width: 6px;
    height: 10px;
    background: inherit;
    border: inherit;
    border-radius: 50%;
    box-shadow: inherit;
}
.bone-wall-h::before { left: -3px; }
.bone-wall-h::after { right: -3px; }

.bone-wall-v {
    width: 6px;
    transform: translateX(-50%);
}
.bone-wall-v::before, .bone-wall-v::after {
    content: '';
    position: absolute;
    left: -2px;
    width: 10px;
    height: 6px;
    background: inherit;
    border: inherit;
    border-radius: 50%;
    box-shadow: inherit;
}
.bone-wall-v::before { top: -3px; }
.bone-wall-v::after { bottom: -3px; }

/* Interactive Edge Slots for Human Wall Placement */
.wall-slot-h, .wall-slot-v {
    position: absolute;
    z-index: 25;
    cursor: pointer;
    background: transparent;
    transition: all 0.15s ease;
}
.wall-slot-h {
    height: 18px;
    transform: translateY(-50%);
}
.wall-slot-v {
    width: 18px;
    transform: translateX(-50%);
}
.wall-slot-h:hover, .wall-slot-v:hover {
    background: rgba(234, 179, 8, 0.45);
    box-shadow: 0 0 12px rgba(254, 240, 138, 0.85), inset 0 0 6px rgba(255, 255, 255, 0.6);
    border-radius: 4px;
}
.wall-slot-h:hover::after, .wall-slot-v:hover::after {
    content: '🦴';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.9rem;
    pointer-events: none;
    animation: pulseBone 0.8s infinite alternate ease-in-out;
}
@keyframes pulseBone {
    from { transform: translate(-50%, -50%) scale(0.9); opacity: 0.8; }
    to { transform: translate(-50%, -50%) scale(1.2); opacity: 1; filter: drop-shadow(0 0 4px #fef08a); }
}

/* Two-Cell Tap Selection for Wall Placement */
.cell.wall-selected {
    box-shadow: 0 0 0 3px #eab308, inset 0 0 12px rgba(234, 179, 8, 0.5) !important;
    transform: scale(1.04);
}
.cell.wall-adjacent-target {
    animation: targetPulse 1.2s infinite alternate ease-in-out;
    cursor: pointer;
}
@keyframes targetPulse {
    from { box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.4); }
    to { box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.85), inset 0 0 8px rgba(234, 179, 8, 0.35); }
}

/* 3D Coin-Flip on Swap */
.cell.swapped {
    animation: coinFlipSwap 0.45s ease-in-out;
}
@keyframes coinFlipSwap {
    0% { transform: rotateY(0deg) scale(1); }
    50% { transform: rotateY(90deg) scale(1.15); filter: brightness(1.5); }
    100% { transform: rotateY(0deg) scale(1); }
}

/* Attention Pulse on Start Button */
.attention-pulse {
    animation: attentionPulse 1.2s ease-in-out;
}
@keyframes attentionPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7); }
    50% { transform: scale(1.04); box-shadow: 0 0 18px 6px rgba(99, 102, 241, 0.85); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* Floating Toast Chip for Swap */
.swap-toast-chip {
    position: absolute;
    top: 75px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    z-index: 100;
    pointer-events: none;
    animation: toastFloat 1.2s ease-out forwards;
}
@keyframes toastFloat {
    0% { opacity: 0; transform: translate(-50%, -10px); }
    15% { opacity: 1; transform: translate(-50%, 0); }
    80% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -10px); }
}

/* Quick-Start Tile Prompt Chip */
.quick-start-chip {
    position: absolute;
    z-index: 50;
    transform: translate(-50%, -120%);
    pointer-events: auto;
    animation: popIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-quick-start {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.4rem 0.8rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.45);
    white-space: nowrap;
    transition: all 0.15s ease;
}
.btn-quick-start:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.6);
}
@keyframes popIn {
    from { opacity: 0; transform: translate(-50%, -90%) scale(0.7); }
    to { opacity: 1; transform: translate(-50%, -120%) scale(1); }
}

/* Confirmation Modal Box */
.confirm-modal-box {
    max-width: 520px;
}
.confirm-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1.2rem;
    justify-content: flex-end;
}
.confirm-btn-row .btn {
    font-size: 0.8rem;
    padding: 0.45rem 0.75rem;
}
