:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #141928;
    --bg-panel: rgba(20, 25, 40, 0.95);
    --border-subtle: rgba(100, 120, 150, 0.3);
    --text-primary: #eee;
    --text-secondary: #a0b0c0;
    --text-muted: #607080;
    --accent-gold: #f0d080;
    --color-blue: #3498db;
    --color-red: #e74c3c;
    --color-green: #2ecc71;
    --card-push: #2196f3;
    --card-pull: #9c27b0;
    --card-drill: #ff9800;
    --card-magnet: #00bcd4;
    --card-explosion: #f44336;
    --card-swap: #e91e63;
    --card-charge: #ff5722;
    --card-quake: #795548;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    height: 100vh; height: 100dvh;
}

/* ========== TITLE SCREEN ========== */
#title-screen {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(-45deg, #0a0e1a, #1a1a3e, #0e2a1a, #1a0a2e);
    background-size: 400% 400%;
    animation: titleBg 12s ease infinite;
    padding: 20px;
}
@media (prefers-reduced-motion: reduce) {
    #title-screen { animation: none; }
    .title-logo, .title-subtitle { animation: none !important; }
    .mob-turn-pill.human-turn { animation: none !important; }
    .mob-score-pill.active { animation: none !important; }
    .mob-combo { animation: none !important; }
    .confetti-particle { animation-duration: 0.01ms !important; }
    .orbit-piece { animation: none !important; }
}
#title-screen.hidden { display: none; }
#title-orbit { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.orbit-piece {
    position: absolute;
    border-radius: 3px;
    opacity: 0.1;
    animation: orbitFloat linear infinite;
    will-change: transform;
}
@keyframes orbitFloat {
    0%   { transform: translateY(0px)   rotate(0deg); }
    25%  { transform: translateY(-18px) rotate(90deg); }
    50%  { transform: translateY(0px)   rotate(180deg); }
    75%  { transform: translateY(18px)  rotate(270deg); }
    100% { transform: translateY(0px)   rotate(360deg); }
}
@keyframes titleBg {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.title-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 540px;
    width: 100%;
}


.title-logo {
    font-size: 3.5rem;
    font-weight: 800;
    text-align: center;
    background: linear-gradient(135deg, #3498db, #9b59b6, #2ecc71);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(52, 152, 219, 0.3);
    margin-bottom: 8px;
}

.title-subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 16px;
}

.config-card, .auth-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    width: 100%;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.config-card h3 {
    color: var(--text-primary);
    font-size: 1.1rem;
    margin-bottom: 16px;
    text-align: center;
    font-weight: 600;
}

.player-config, .game-config {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.game-config {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.primary-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.btn-large {
    padding: 16px 32px;
    font-size: 1.1rem;
    font-weight: 600;
    min-width: 180px;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.btn-large:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.secondary-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

@media (max-width: 768px) {
    .title-container {
        gap: 20px;
        padding: 0 16px;
    }
    
    .title-logo {
        font-size: 2.8rem;
    }
    
    .primary-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .btn-large {
        min-width: 200px;
    }
    
    .secondary-actions {
        grid-template-columns: repeat(2, 1fr);
    }
}
.title-logo {
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 900; text-transform: uppercase; letter-spacing: 4px;
    background: linear-gradient(135deg, var(--color-blue), var(--accent-gold), var(--color-green));
    background-size: 200% 200%;
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: titleShine 3s ease infinite;
    text-align: center; margin-bottom: 8px;
}
@keyframes titleShine {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
.title-subtitle {
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    color: var(--text-secondary); letter-spacing: 6px;
    text-transform: uppercase; margin-bottom: 48px;
}

/* Desktop 2-column layout — placed AFTER base title styles so it correctly overrides them */
@media (min-width: 900px) {
    #title-screen { align-items: center; padding: 24px 40px; overflow-y: auto; }
    .title-container {
        display: grid !important;
        grid-template-columns: 1fr 300px;
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "logo    auth"
            "sub     auth"
            "config  actions";
        max-width: 1000px;
        gap: 12px 40px;
        align-items: start;
        width: 100%;
    }
    .title-logo     { grid-area: logo;    text-align: left !important; margin-bottom: 0 !important; }
    .title-subtitle { grid-area: sub;     text-align: left !important; margin-bottom: 0 !important; }
    .config-card    { grid-area: config;  align-self: start; width: 100%; }
    .auth-card      { grid-area: auth;    align-self: start; width: 100%; }
    .action-buttons { grid-area: actions; align-self: start; width: 100%; }
    /* Stack big play buttons vertically in the narrow right column */
    .action-buttons .primary-actions { flex-direction: column; align-items: stretch; gap: 10px; }
    .action-buttons .btn-large { min-width: unset !important; width: 100%; text-align: center; }
    .action-buttons .secondary-actions { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .action-buttons .btn-secondary { padding: 9px 10px; font-size: 0.82rem; letter-spacing: 0; }
}
.title-config {
    display: flex; flex-direction: column; gap: 16px;
    align-items: center; margin-bottom: 36px;
    width: min(90vw, 400px);
}
.diff-row {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 12px 16px;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.08);
}
.diff-row label {
    font-size: 0.95rem; color: var(--text-secondary);
    display: flex; align-items: center; gap: 8px;
}
.diff-row .dot {
    width: 12px; height: 12px; border-radius: 50%; display: inline-block;
}
.diff-row select {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--text-primary); padding: 6px 12px;
    border-radius: 6px; font-size: 0.9rem; cursor: pointer;
}
.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* Buttons */
.btn {
    padding: 14px 48px; border: none; border-radius: var(--radius-md);
    font-size: 1.1rem; font-weight: 700; cursor: pointer;
    transition: all 0.2s ease; text-transform: uppercase; letter-spacing: 2px;
}
.btn:active { transform: scale(0.97); }
.btn-play {
    background: linear-gradient(135deg, var(--color-blue), #1a6faa);
    color: #fff; box-shadow: 0 4px 20px rgba(52,152,219,0.4); min-width: 220px;
}
.btn-play:hover { box-shadow: 0 6px 30px rgba(52,152,219,0.6); transform: translateY(-2px); }
.btn-secondary {
    background: rgba(255,255,255,0.06); color: var(--text-secondary);
    border: 1px solid rgba(255,255,255,0.12); padding: 10px 32px; font-size: 0.9rem;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }
.btn-small { padding: 8px 20px; font-size: 0.85rem; border-radius: var(--radius-sm); }

/* ========== OVERLAYS ========== */
.overlay {
    position: fixed; inset: 0; z-index: 900;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(8px);
}
.overlay.active { display: flex; z-index: 1001; }
.overlay-card {
    background: var(--bg-secondary); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg); padding: 32px;
    max-width: min(90vw, 560px); max-height: 85vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.overlay-card h2 {
    font-size: 1.5rem; margin-bottom: 20px; color: var(--accent-gold);
    text-transform: uppercase; letter-spacing: 2px;
}

/* Tutorial */
.tut-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
@media (max-width: 500px) { .tut-grid { grid-template-columns: 1fr; } }
.tut-item {
    padding: 14px; background: rgba(255,255,255,0.03);
    border-radius: var(--radius-sm); border-left: 3px solid var(--text-muted);
}
.tut-item h4 { font-size: 0.95rem; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.tut-item p { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.4; }
.tut-item.push { border-left-color: var(--card-push); }
.tut-item.pull { border-left-color: var(--card-pull); }
.tut-item.drill { border-left-color: var(--card-drill); }
.tut-item.magnet { border-left-color: var(--card-magnet); }
.tut-item.explosion { border-left-color: var(--card-explosion); }
.tut-rules { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; margin-bottom: 20px; padding-left: 20px; }
.tut-rules li { margin-bottom: 4px; }

/* Interactive tutorial */
.tutorial-card { max-width: min(92vw, 620px); }
.tut-instruction {
    font-size: 0.95rem; color: var(--text-primary); padding: 12px 16px;
    background: rgba(255,255,255,0.04); border-radius: var(--radius-sm);
    margin-bottom: 12px; line-height: 1.5; text-align: center;
}
.tut-instruction .highlight { color: var(--accent-gold); font-weight: 700; }
.tut-result {
    font-size: 0.85rem; color: var(--accent-gold); text-align: center;
    min-height: 24px; padding: 6px 0; font-weight: 600;
}
#tut-mini-board { display: flex; justify-content: center; margin: 8px 0; }
#tut-mini-board svg { border-radius: 6px; border: 1px solid rgba(100,120,150,0.3); background: rgba(10,15,30,0.95); }
.tut-nav {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.06);
}
.tut-step-ind { font-size: 0.8rem; color: var(--text-muted); letter-spacing: 1px; }
.tut-step-desc {
    font-size: 0.9rem; color: var(--text-secondary); line-height: 1.6;
    padding: 16px; background: rgba(255,255,255,0.03); border-radius: var(--radius-sm);
}
.tut-step-desc h4 { font-size: 1rem; margin-bottom: 8px; color: var(--text-primary); }
.tut-step-desc p { margin-bottom: 8px; }
.tut-step-desc .tut-action { color: var(--accent-gold); font-weight: 600; font-style: italic; }
.tut-mini-cell { cursor: pointer; transition: fill 0.15s; }
.tut-mini-cell:hover { fill: rgba(60,80,100,0.5); }
.tut-mini-cell.tut-highlight { fill: rgba(240,208,128,0.2); stroke: var(--accent-gold); stroke-width: 2; animation: pulse 1.2s infinite; }
.tut-mini-piece { cursor: pointer; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }
.tut-mini-piece.tut-highlight { stroke: var(--accent-gold); stroke-width: 3; filter: drop-shadow(0 0 6px rgba(240,208,128,0.6)); }

/* Settings */
.settings-content { min-width: 300px; }
.settings-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.settings-row:last-child { border-bottom: none; }
.settings-row label { font-size: 0.9rem; color: var(--text-secondary); }
.settings-row input[type="range"] { width: 120px; accent-color: var(--accent-gold); }
.settings-row select {
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
    color: var(--text-primary); padding: 6px 12px; border-radius: 6px;
    font-size: 0.9rem; cursor: pointer;
}
.settings-section-title {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 2px;
    color: var(--accent-gold); margin: 16px 0 8px; padding-bottom: 4px;
    border-bottom: 1px solid rgba(240,208,128,0.2);
}
.settings-section-title:first-child { margin-top: 0; }
.settings-hint {
    font-size: 0.75rem; color: var(--text-muted); font-style: italic;
    padding: 4px 0 0; line-height: 1.3;
}
.toggle-btn { min-width: 54px; text-align: center; }
.toggle-btn.on { background: linear-gradient(135deg, #27ae60, #2ecc71); color: #fff; }
.toggle-btn.off { background: rgba(255,255,255,0.06); color: var(--text-muted); }

/* ========== GAME SCREEN ========== */
#game-screen { display: none; height: 100vh; height: 100dvh; width: 100vw; }
#game-screen.active { display: flex; }

#layout {
    display: flex; height: 100%; width: 100%;
    padding: 12px; gap: 12px;
}
#sidebar {
    width: 320px; display: flex; flex-direction: column;
    gap: 10px; flex: 0 0 320px; z-index: 10; overflow-y: auto;
}
#sidebar { pointer-events: none; }
#sidebar > * { pointer-events: auto; }
#main {
    flex: 1 1 auto; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-width: 0; min-height: 0;
}

.panel {
    background: var(--bg-panel); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md); padding: 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* Header bar */
.header-bar { display: flex; align-items: center; justify-content: space-between; }
.header-bar h2 {
    margin: 0; font-size: 1.05em; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 1px;
}
.gear-btn {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.3rem; cursor: pointer; padding: 4px; transition: color 0.2s;
}
.gear-btn:hover { color: var(--text-primary); }

/* Turn indicator */
.turn-indicator {
    font-size: 1.2em; font-weight: bold; padding: 10px 14px;
    border-radius: var(--radius-sm); text-align: center;
    margin: 8px 0; transition: all 0.3s ease;
}
.turn-blue { background: linear-gradient(135deg, #2980b9, #3498db); }
.turn-red { background: linear-gradient(135deg, #c0392b, #e74c3c); }
.turn-green { background: linear-gradient(135deg, #27ae60, #2ecc71); }

.phase-display {
    text-align: center; padding: 6px;
    background: rgba(255,255,255,0.04); border-radius: 6px;
    font-size: 0.9em; color: var(--text-secondary);
}

/* Timer bar */
.timer-bar-track {
    height: 3px; background: rgba(255,255,255,0.06);
    border-radius: 2px; margin-top: 6px; overflow: hidden;
}
.timer-bar-fill {
    height: 100%; background: var(--accent-gold);
    border-radius: 2px; transition: width 0.25s linear; width: 100%;
}
.timer-bar-fill.danger { background: var(--color-red); }

/* Stats */
.panel h3 {
    margin: 0 0 10px 0; font-size: 0.95em; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 1px;
}
.player-stat {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; margin-bottom: 6px; border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.03); transition: all 0.25s ease;
}
.player-stat.active {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
}
.stat-left { display: flex; align-items: center; gap: 8px; }
.stat-right { display: flex; align-items: baseline; gap: 8px; }
.color-dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
.dot-blue { background: var(--color-blue); color: var(--color-blue); }
.dot-red { background: var(--color-red); color: var(--color-red); }
.dot-green { background: var(--color-green); color: var(--color-green); }
.player-name { font-size: 0.9em; font-weight: 500; }
.piece-count { font-size: 1.15em; font-weight: bold; color: #fff; }
.score { font-size: 0.8em; color: var(--accent-gold); font-weight: 700; min-width: 40px; text-align: right; }

/* Combo badge */
.combo-badge {
    display: none; padding: 2px 8px; border-radius: 10px;
    font-size: 0.7em; font-weight: 800;
    background: linear-gradient(135deg, #f06, #f90); color: #fff;
    animation: comboPulse 0.6s ease infinite;
}
.combo-badge.active { display: inline-block; }
@keyframes comboPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* Hand */
.hand-panel { transition: box-shadow 0.35s ease, border-color 0.35s ease; }
.hand-panel.human-active {
    border-color: rgba(52,152,219,0.65);
    box-shadow: 0 0 18px rgba(52,152,219,0.35), 0 4px 16px rgba(0,0,0,0.3);
}
.hand-panel h3 { display: flex; align-items: center; justify-content: space-between; }
#hand-panel-title { font-size: 1em; color: var(--text-secondary); }
.hand-display { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards */
.card {
    width: 64px; height: 88px; border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.15s ease; position: relative;
    border: 2px solid rgba(255,255,255,0.12);
    background: linear-gradient(145deg, #2a3a4a, #1a2a3a);
}
.card::before {
    content: ''; position: absolute; top: 0; left: 0;
    right: 0; height: 3px; border-radius: 8px 8px 0 0;
}
.card.type-push { border-color: rgba(33,150,243,0.4); }
.card.type-push::before { background: var(--card-push); }
.card.type-pull { border-color: rgba(156,39,176,0.4); }
.card.type-pull::before { background: var(--card-pull); }
.card.type-drill { border-color: rgba(255,152,0,0.4); }
.card.type-drill::before { background: var(--card-drill); }
.card.type-magnet { border-color: rgba(0,188,212,0.4); }
.card.type-magnet::before { background: var(--card-magnet); }
.card.type-explosion { border-color: rgba(244,67,54,0.4); }
.card.type-explosion::before { background: var(--card-explosion); }
.card.type-swap { border-color: rgba(233,30,99,0.4); }
.card.type-swap::before { background: var(--card-swap); }
.card.type-charge { border-color: rgba(255,87,34,0.4); }
.card.type-charge::before { background: var(--card-charge); }
.card.type-quake { border-color: rgba(121,85,72,0.4); }
.card.type-quake::before { background: var(--card-quake); }
.piece.swap-selectable { cursor: pointer; filter: brightness(1.3); }

.card:hover:not(.disabled):not(.selected) {
    transform: translateY(-6px); box-shadow: 0 10px 24px rgba(0,0,0,0.4);
}
.card.selected {
    border-color: var(--accent-gold);
    box-shadow: 0 0 24px rgba(240,208,128,0.4); transform: translateY(-4px);
}
.card.disabled { opacity: 0.35; cursor: default; }
.card-value { font-size: 1.8em; font-weight: bold; color: #fff; }
.card-label { font-size: 0.6em; text-transform: uppercase; margin-top: 2px; color: var(--text-muted); }
.card.selected .card-label { color: var(--accent-gold); }

/* Action Guide (above board) */
#action-guide {
    width: 100%; max-width: 720px;
    text-align: center; padding: 10px 16px;
    margin-bottom: 8px; border-radius: var(--radius-md);
    background: rgba(20, 25, 40, 0.95);
    border: 2px solid rgba(100,120,150,0.3);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
#action-guide.guide-blue { border-color: rgba(52,152,219,0.6); box-shadow: 0 4px 24px rgba(52,152,219,0.2); }
#action-guide.guide-red { border-color: rgba(231,76,60,0.6); box-shadow: 0 4px 24px rgba(231,76,60,0.2); }
#action-guide.guide-green { border-color: rgba(46,204,113,0.6); box-shadow: 0 4px 24px rgba(46,204,113,0.2); }
#action-guide-turn {
    font-size: 1.3rem; font-weight: 900; text-transform: uppercase;
    letter-spacing: 3px; margin-bottom: 4px;
}
#action-guide-prompt {
    font-size: 1rem; font-weight: 600; color: var(--accent-gold);
    letter-spacing: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 900px) {
    #action-guide { padding: 8px 12px; margin-bottom: 6px; }
    #action-guide-turn { font-size: 1.05rem; letter-spacing: 2px; }
    #action-guide-prompt { font-size: 0.85rem; }
}

/* Board */
#board-wrap {
    width: min(calc(100vh - 100px), calc(100vw - 360px));
    height: min(calc(100vh - 100px), calc(100vw - 360px));
    max-width: 840px; max-height: 840px;
    flex-shrink: 0;
}
#board-wrap svg {
    width: 100%; height: 100%;
    border-radius: var(--radius-sm);
    border: 2px solid rgba(100,120,150,0.4);
    background: rgba(10,15,30,0.95);
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

/* Screen shake */
#board-wrap.shake { animation: boardShake 0.3s ease-out; }
@keyframes boardShake {
    0% { transform: translate(0,0); }
    15% { transform: translate(-4px,3px); }
    30% { transform: translate(3px,-4px); }
    45% { transform: translate(-3px,2px); }
    60% { transform: translate(2px,-2px); }
    75% { transform: translate(-1px,1px); }
    100% { transform: translate(0,0); }
}

/* Card FX */
#card-fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.card-fx {
    position: fixed; width: 60px; height: 80px; border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 2px solid #4a5a6a; background: linear-gradient(145deg, #2a3a4a, #1a2a3a);
    box-shadow: 0 10px 24px rgba(0,0,0,0.4); transform-origin: center;
}
.card-fx .card-value { font-size: 1.8em; font-weight: bold; color: #fff; }
.card-fx .card-label { font-size: 0.65em; color: var(--text-muted); text-transform: uppercase; margin-top: 2px; }

/* SVG */
.p1 { fill: url(#gradBlue); }
.p2 { fill: url(#gradRed); }
.p3 { fill: url(#gradGreen); }
.piece { cursor: pointer; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.piece:hover { filter: brightness(1.15) drop-shadow(0 2px 4px rgba(0,0,0,0.5)); }

/* Turn banner removed — replaced by action guide bar above board */

/* Auto-play button */
#auto-play-btn {
    position: absolute; bottom: 12px; right: 12px; z-index: 20;
    padding: 10px 18px; border: 2px solid var(--accent-gold);
    border-radius: var(--radius-sm); background: rgba(20,25,40,0.9);
    color: var(--accent-gold); font-weight: 700; font-size: 0.9rem;
    cursor: pointer; text-transform: uppercase; letter-spacing: 1px;
    transition: all 0.2s ease; display: none;
}
#auto-play-btn:hover { background: rgba(240,208,128,0.15); }
#auto-play-btn.visible { display: block; }

/* Cancel card selection */
.btn-cancel-card {
    margin-top: 8px; width: 100%; text-align: center;
    background: rgba(255,255,255,0.06); color: var(--text-secondary);
    border: 1px solid rgba(255,255,255,0.12);
}
.btn-cancel-card:hover { background: rgba(255,255,255,0.12); color: var(--text-primary); }

/* Forfeit */
.forfeit-panel { padding: 8px 12px; text-align: center; }
.btn-danger {
    background: linear-gradient(135deg, rgba(192,57,43,0.8), rgba(231,76,60,0.6));
    color: #fff; border: 1px solid rgba(231,76,60,0.5);
}
.btn-danger:hover { background: linear-gradient(135deg, #c0392b, #e74c3c); }

/* Tutorial reset */
#btn-tut-reset { font-size: 0.8rem; }

/* Tutorial piece states */
.tut-mini-piece.tut-selected { stroke: var(--accent-gold); stroke-width: 3; }
.tut-mini-piece.tut-highlight { stroke: var(--accent-gold); stroke-width: 2; }

.cell { fill: rgba(30,40,55,0.8); stroke: rgba(80,100,120,0.35); stroke-width: 1; transition: fill 0.15s ease, stroke 0.15s ease; }
.cell:hover { fill: rgba(50,70,90,0.5); stroke: rgba(120,150,180,0.5); }
.cell.valid-destination { fill: rgba(100,120,80,0.4); stroke: rgba(150,180,100,0.6); }
.cell.valid-puller { fill: rgba(120,100,180,0.3); stroke: rgba(160,120,200,0.8); stroke-width: 2; animation: pulse 1.5s infinite; }
.cell.hole { fill: url(#hazardPattern); stroke: rgba(255,160,80,0.6); stroke-width: 2; filter: url(#hazardGlow); animation: hazardPulse 2.2s infinite ease-in-out; }
.cell.valid-drill-target { fill: rgba(255,140,0,0.18); stroke: rgba(255,160,60,0.75); stroke-width: 2; animation: drillPulse 1.2s infinite ease-in-out; }
@keyframes drillPulse { 0% { opacity: 0.55; } 50% { opacity: 1; } 100% { opacity: 0.55; } }

.cell.nav-area { fill: url(#hazardPattern); stroke: rgba(255,160,80,0.28); stroke-width: 1; filter: url(#hazardGlow); }
.hazard-anim { animation: hazardPulse 2.2s infinite ease-in-out; }
@keyframes hazardPulse { 0% { opacity: 0.75; } 50% { opacity: 1; } 100% { opacity: 0.75; } }

.cell.play-area { fill: var(--board-cell, rgba(20,30,50,0.1)); stroke: rgba(60,80,100,0.2); stroke-width: 1; }
.cell.play-area.hole { fill: url(#hazardPattern); stroke: rgba(255,160,80,0.28); stroke-width: 1; filter: url(#hazardGlow); animation: hazardPulse 2.2s infinite ease-in-out; }

.pull-arrow { pointer-events: none; opacity: 0.8; font-size: 20px; font-weight: bold; text-anchor: middle; dominant-baseline: middle; fill: var(--accent-gold); }
@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }

.direction-overlay { cursor: pointer; opacity: 0; transition: opacity 0.2s ease; }
.direction-overlay.visible { opacity: 0.3; }
.direction-overlay:hover { opacity: 0.6; fill: rgba(150,200,100,0.8); }
.dir-arrow { pointer-events: none; opacity: 0.95; font-size: 22px; font-weight: 800; text-anchor: middle; dominant-baseline: middle; fill: rgba(255,255,255,0.92); }

.piece.pull-preview { stroke: var(--accent-gold); stroke-width: 4; filter: drop-shadow(0 0 8px rgba(240,208,128,0.55)); }
.piece.push-selectable { stroke: rgba(120,210,255,0.85); stroke-width: 3; filter: drop-shadow(0 0 7px rgba(120,210,255,0.35)); }
.piece.swap-selectable { cursor: pointer; stroke: rgba(233,30,99,0.6); stroke-width: 2; }
.piece.swap-selected { stroke: rgba(233,30,99,1); stroke-width: 5; filter: drop-shadow(0 0 12px rgba(233,30,99,0.7)); animation: swapPulse 0.8s infinite ease-in-out; }
@keyframes swapPulse { 0% { filter: drop-shadow(0 0 8px rgba(233,30,99,0.5)); } 50% { filter: drop-shadow(0 0 18px rgba(233,30,99,0.9)); } 100% { filter: drop-shadow(0 0 8px rgba(233,30,99,0.5)); } }
.destroy-burst { pointer-events: none; mix-blend-mode: screen; }

/* ===== PIECE SET EMOJI LABELS ===== */
.piece-label { pointer-events: none; text-anchor: middle; dominant-baseline: central; user-select: none; }

/* ===== PIECE SKINS ===== */
.piece.skin-neon { stroke: rgba(255,255,80,0.9); stroke-width: 3; filter: drop-shadow(0 0 6px rgba(255,255,80,0.7)) drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.piece.skin-crystal { opacity: 0.78; stroke: rgba(160,240,255,0.85); stroke-width: 2; filter: drop-shadow(0 0 8px rgba(100,220,255,0.65)); }
.piece.skin-flame { stroke: rgba(255,100,0,0.95); stroke-width: 2; filter: drop-shadow(0 0 8px rgba(255,80,0,0.7)); animation: skinFlame 0.4s infinite alternate; }
@keyframes skinFlame { from { filter: drop-shadow(0 0 5px rgba(255,80,0,0.7)); } to { filter: drop-shadow(0 0 14px rgba(255,160,0,0.95)); } }
.piece.skin-galaxy { stroke: rgba(180,100,255,0.75); stroke-width: 2; filter: drop-shadow(0 0 10px rgba(150,80,255,0.65)); }
.piece.skin-stealth { opacity: 0.62; stroke: rgba(80,100,120,0.45); stroke-width: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.85)); }
.piece.skin-metallic { stroke: rgba(200,220,235,0.85); stroke-width: 2; filter: brightness(1.12) drop-shadow(0 2px 4px rgba(0,0,0,0.5)); }
.piece.skin-marble { stroke: rgba(235,235,235,0.65); stroke-width: 2; filter: brightness(1.05); }
.piece.skin-plasma { stroke: rgba(0,220,255,0.95); stroke-width: 3; animation: skinPlasma 0.9s infinite ease-in-out; }
@keyframes skinPlasma { 0%,100% { filter: drop-shadow(0 0 7px rgba(0,200,255,0.7)); } 50% { filter: drop-shadow(0 0 16px rgba(0,230,255,1)); } }
.piece.skin-void { opacity: 0.82; stroke: rgba(160,50,255,0.95); stroke-width: 3; filter: drop-shadow(0 0 12px rgba(120,30,255,0.85)); }
.piece.skin-ice { stroke: rgba(150,220,255,0.85); stroke-width: 2; filter: drop-shadow(0 0 6px rgba(100,200,255,0.55)); }
.piece.skin-gilded { stroke: rgba(255,215,0,0.95); stroke-width: 2; filter: drop-shadow(0 0 6px rgba(255,200,0,0.55)); }
.piece.skin-toxic { stroke: rgba(80,255,0,0.95); stroke-width: 3; filter: drop-shadow(0 0 9px rgba(50,220,0,0.75)); }
.piece.skin-shadow { opacity: 0.68; stroke: rgba(160,0,210,0.65); stroke-width: 2; filter: drop-shadow(0 0 8px rgba(100,0,180,0.45)); }
.piece.skin-prism { stroke-width: 3; animation: skinPrism 2s infinite linear; }
@keyframes skinPrism { 0%{stroke:rgba(255,50,50,0.9)} 16%{stroke:rgba(255,165,0,0.9)} 33%{stroke:rgba(240,240,0,0.9)} 50%{stroke:rgba(50,255,50,0.9)} 66%{stroke:rgba(50,120,255,0.9)} 83%{stroke:rgba(160,0,255,0.9)} 100%{stroke:rgba(255,50,50,0.9)} }
.piece.skin-rust { stroke: rgba(180,80,0,0.75); stroke-width: 2; opacity: 0.88; }
.piece.skin-pearl { stroke: rgba(255,240,248,0.85); stroke-width: 2; opacity: 0.92; filter: drop-shadow(0 0 5px rgba(255,220,240,0.55)); }
.piece.skin-obsidian { stroke: rgba(40,40,50,0.95); stroke-width: 2; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.9)); }
.piece.skin-nebula { stroke: rgba(200,100,255,0.85); stroke-width: 2; filter: drop-shadow(0 0 10px rgba(180,80,255,0.65)); }
.piece.skin-bronze { stroke: rgba(160,100,30,0.85); stroke-width: 2; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.55)); }
.piece.skin-diamond { stroke: rgba(255,255,255,0.98); stroke-width: 3; animation: skinDiamond 1.6s infinite ease-in-out; }
@keyframes skinDiamond { 0%,100% { filter: drop-shadow(0 0 7px rgba(200,240,255,0.65)); } 50% { filter: drop-shadow(0 0 20px rgba(255,255,255,1)); } }

/* Log */
.log-panel { max-height: 200px; }
.action-log {
    max-height: 160px; overflow-y: auto; padding: 8px;
    border-radius: var(--radius-sm); background: rgba(255,255,255,0.03);
    border: 1px solid rgba(100,120,150,0.15);
    font-size: 0.8em; line-height: 1.25; color: #c0c8d0;
}
.action-log-line { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.action-log-line:last-child { border-bottom: none; }

/* ========== TOAST ========== */
#toast-container {
    position: fixed; bottom: 16px; left: 16px;
    z-index: 800; display: flex; flex-direction: column-reverse;
    align-items: flex-start; gap: 8px; pointer-events: none;
}
.toast {
    padding: 10px 24px; border-radius: var(--radius-sm);
    font-size: 0.95rem; font-weight: 600; color: #fff;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    white-space: normal;
    display: flex; align-items: center; gap: 4px;
    max-width: calc(100vw - 48px);
}
.toast.elim { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.toast.combo { background: linear-gradient(135deg, #f06, #f90); }
.toast.info { background: linear-gradient(135deg, #2980b9, #3498db); }
.toast.warn { background: linear-gradient(135deg, #e67e22, #d35400); }
.toast.drill { background: linear-gradient(135deg, #ff9800, #e65100); }
.toast.win { background: linear-gradient(135deg, var(--accent-gold), #d4a020); color: #1a1a2e; }
.toast.error { background: linear-gradient(135deg, #c0392b, #e74c3c); }
.toast.success { background: linear-gradient(135deg, #27ae60, #2ecc71); }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(10px) scale(0.95); } }

/* ========== GAME OVER ========== */
#game-over-overlay {
    position: fixed; inset: 0; z-index: 950;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.88); backdrop-filter: blur(12px);
}
#game-over-overlay.active { display: flex; }
.go-card {
    background: var(--bg-secondary); border: 2px solid var(--border-subtle);
    border-radius: var(--radius-lg); padding: 40px; text-align: center;
    min-width: min(90vw, 420px);
    box-shadow: 0 20px 80px rgba(0,0,0,0.6);
    animation: goCardIn 0.5s ease;
}
@keyframes goCardIn { from { opacity: 0; transform: scale(0.85) translateY(30px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.go-card.winner-blue { border-color: var(--color-blue); box-shadow: 0 0 60px rgba(52,152,219,0.3); }
.go-card.winner-red { border-color: var(--color-red); box-shadow: 0 0 60px rgba(231,76,60,0.3); }
.go-card.winner-green { border-color: var(--color-green); box-shadow: 0 0 60px rgba(46,204,113,0.3); }
.go-card.winner-draw { border-color: var(--accent-gold); box-shadow: 0 0 60px rgba(240,208,128,0.3); }

.go-title { font-size: 2rem; font-weight: 900; text-transform: uppercase; letter-spacing: 3px; margin-bottom: 8px; }
.go-subtitle { font-size: 1rem; color: var(--text-secondary); margin-bottom: 28px; }
.go-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 28px; }
.go-stat { padding: 12px; background: rgba(255,255,255,0.04); border-radius: var(--radius-sm); }
.go-stat .stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.go-stat .stat-value { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.go-buttons { display: flex; gap: 12px; justify-content: center; }

/* ========== TOUCH ERGONOMICS ========== */
/* WCAG: all interactive targets >= 44px on touch devices */
@media (pointer: coarse) {
    .btn, .btn-small, .btn-secondary, .btn-play, .btn-large {
        min-height: 44px;
        min-width: 44px;
    }
    .btn-small {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    .card {
        width: 68px;
        height: 92px;
    }
    .diff-row select, .diff-row input {
        min-height: 44px;
        font-size: 1rem;
        padding: 8px 14px;
    }
    .settings-row select, .settings-row input[type="range"] {
        min-height: 44px;
    }
    .toggle-btn {
        min-width: 60px;
        min-height: 44px;
        font-size: 0.95rem;
    }
    .gear-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .lb-tab {
        min-height: 44px;
        padding: 10px 16px;
    }
    /* Larger direction arrows on touch */
    .direction-overlay {
        opacity: 0.25;
    }
    .direction-overlay.visible {
        opacity: 0.4;
    }
    /* Disable hover effects that cause sticky state on touch */
    .card:hover:not(.disabled):not(.selected) {
        transform: none;
        box-shadow: none;
    }
    .btn-play:hover {
        transform: none;
    }
    .btn-large:hover {
        transform: none;
    }
}

/* ========== RESPONSIVE ========== */

/* --- iPad landscape / small laptops (1024px) --- */
@media (max-width: 1024px) {
    #sidebar { width: 260px; flex: 0 0 260px; }
    #board-wrap { width: min(calc(100vh - 100px), calc(100vw - 290px)); height: min(calc(100vh - 100px), calc(100vw - 290px)); max-width: 640px; max-height: 640px; }
    .card { width: 58px; height: 82px; }
}

/* --- Tablets portrait + large phones (900px) --- */
@media (max-width: 900px) {
    #layout { flex-direction: column; align-items: center; padding: 8px; gap: 8px; }
    #sidebar {
        width: 100%; flex: 0 0 auto;
        flex-direction: row; flex-wrap: wrap; gap: 6px; overflow-y: visible;
    }
    #sidebar > * { pointer-events: auto; }
    #sidebar .panel { flex: 1 1 auto; min-width: 140px; }
    #sidebar .log-panel { display: none; }
    #board-wrap { width: min(calc(100vw - 20px), calc(100vh - 280px)); height: min(calc(100vw - 20px), calc(100vh - 280px)); max-width: 600px; max-height: 600px; }
    #action-guide { max-width: 600px; }
    .card { width: 52px; height: 72px; }
    .card-value { font-size: 1.5em !important; }
    .overlay-card { padding: 24px; max-height: 90vh; }
    .go-card { padding: 28px; min-width: min(90vw, 380px); }
    .go-stats { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
}

/* --- iPad portrait (768px) --- */
@media (max-width: 768px) and (min-width: 501px) {
    .title-container { gap: 16px; }
    .config-card, .auth-card { padding: 16px; }
    .secondary-actions { grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .btn-large { min-width: 160px; padding: 14px 24px; font-size: 1rem; }
    #board-wrap { width: min(calc(100vw - 16px), calc(100vh - 260px)); height: min(calc(100vw - 16px), calc(100vh - 260px)); }
    .hand-display { justify-content: center; }
}

/* --- Phones (500px and below) --- */
@media (max-width: 500px) {
    #sidebar { flex-direction: column; }
    .hand-display { justify-content: center; }
    #board-wrap { width: min(calc(100vw - 12px), calc(100vh - 300px)); height: min(calc(100vw - 12px), calc(100vh - 300px)); }
    #action-guide { max-width: calc(100vw - 12px); padding: 6px 10px; }
    #action-guide-turn { font-size: 0.95rem; letter-spacing: 1px; }
    #action-guide-prompt { font-size: 0.8rem; }
    .card { width: 48px; height: 66px; }
    .card-value { font-size: 1.3em !important; }
    .card-label { font-size: 0.5em; }
    .title-logo { font-size: clamp(1.8rem, 8vw, 2.5rem); letter-spacing: 2px; }
    .title-subtitle { font-size: 0.8rem; letter-spacing: 3px; margin-bottom: 24px; }
    .config-card, .auth-card { padding: 14px; }
    .primary-actions { gap: 10px; }
    .btn-large { min-width: 140px; padding: 12px 20px; font-size: 0.95rem; }
    .secondary-actions { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .btn-secondary { padding: 8px 12px; font-size: 0.8rem; }
    .overlay-card { padding: 20px 16px; max-width: 95vw; }
    .overlay-card h2 { font-size: 1.2rem; margin-bottom: 14px; }
    .go-card { padding: 24px 16px; }
    .go-title { font-size: 1.5rem; }
    .go-stats { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
    .go-stat .stat-value { font-size: 1.1rem; }
    .go-buttons { flex-wrap: wrap; gap: 8px; }
    .settings-content { min-width: unset; }
    .player-stat { padding: 6px 8px; }
    .piece-count { font-size: 1em; }
    .turn-indicator { font-size: 1em; padding: 8px 10px; }
    .phase-display { font-size: 0.8em; }
}

/* ========== MOBILE HUD (hidden on desktop, flex on phones) ========== */
#mobile-hud {
    display: none;
    flex-direction: column;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 2px;
    padding-top: env(safe-area-inset-top, 0px);
}
#mob-turn-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px 3px;
}
.mob-turn-pill {
    font-size: 0.75rem; font-weight: 700;
    padding: 4px 10px; border-radius: 20px; color: #fff;
    white-space: nowrap; flex-shrink: 0;
    max-width: 130px; overflow: hidden; text-overflow: ellipsis;
    background: rgba(100,120,150,0.3);
}
.mob-turn-pill.turn-blue  { background: rgba(52,152,219,0.75); }
.mob-turn-pill.turn-red   { background: rgba(231,76,60,0.75); }
.mob-turn-pill.turn-green { background: rgba(46,204,113,0.75); }
.mob-turn-pill.human-turn {
    animation: humanPillPulse 1.4s ease-in-out infinite;
    letter-spacing: 0.5px;
}
@keyframes humanPillPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
    50% { box-shadow: 0 0 10px 2px rgba(255,255,255,0.25); }
}
#mob-turn-status {
    font-size: 0.72rem; color: var(--text-secondary);
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mob-timer-track {
    width: 36px; height: 4px; background: rgba(255,255,255,0.1);
    border-radius: 2px; overflow: hidden; flex-shrink: 0;
}
#mob-score-strip {
    display: flex; gap: 5px; padding: 3px 8px 6px;
}
.mob-score-pill {
    flex: 1; display: flex; align-items: center; gap: 4px;
    padding: 5px 6px; border-radius: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid transparent; transition: all 0.25s;
    min-width: 0;
}
.mob-score-pill.active {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.25);
    animation: mobPillGlow 1.2s ease-in-out infinite;
}
.mob-score-pill.eliminated {
    opacity: 0.38; filter: grayscale(0.6);
    animation: none !important;
}
#mob-stat-0.active { border-color: rgba(52,152,219,0.5); }
#mob-stat-1.active { border-color: rgba(231,76,60,0.5); }
#mob-stat-2.active { border-color: rgba(46,204,113,0.5); }
@keyframes mobPillGlow {
    0%,100% { box-shadow: none; }
    50% { box-shadow: 0 0 8px rgba(255,255,255,0.15); }
}
.mob-pname {
    font-size: 0.64rem; font-weight: 600; color: var(--text-secondary);
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mob-count { font-size: 0.95rem; font-weight: 800; color: #fff; flex-shrink: 0; }
.mob-delta { font-size: 0.6rem; font-weight: 700; color: var(--accent-gold); flex-shrink: 0; }
.mob-combo {
    display: none; font-size: 0.55rem; font-weight: 800;
    background: linear-gradient(135deg, #f06, #f90); color: #fff;
    padding: 1px 5px; border-radius: 8px; flex-shrink: 0;
    animation: comboPulse 0.6s ease infinite;
}

/* ========== HAND DOCK (mobile bottom bar) ========== */
#hand-dock {
    display: none;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)) 10px;
    align-items: center; gap: 8px;
    min-height: 76px; max-height: 92px;
    width: 100%;
}
#hand-dock-inner {
    flex: 1; display: flex; gap: 7px; align-items: center;
    overflow-x: auto; scrollbar-width: none; padding: 2px 0;
}
#hand-dock-inner::-webkit-scrollbar { display: none; }
.dock-waiting {
    font-size: 0.75rem; color: var(--text-muted); font-style: italic; padding: 4px;
}
#hand-dock-inner .card {
    flex-shrink: 0; width: 52px; height: 70px; touch-action: manipulation;
}
#hand-dock-actions {
    display: flex; flex-direction: column; gap: 5px; flex-shrink: 0;
}
.dock-action-btn {
    width: 34px; height: 34px; border-radius: 8px;
    border: 1px solid var(--border-subtle); background: rgba(255,255,255,0.07);
    color: var(--text-primary); font-size: 0.9rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s; touch-action: manipulation;
}
.dock-action-btn:active { background: rgba(255,255,255,0.15); }
.dock-forfeit {
    background: rgba(192,57,43,0.2); border-color: rgba(192,57,43,0.4); color: #e74c3c;
}
.dock-forfeit:active { background: rgba(192,57,43,0.35); }
.dock-discard-pile {
    width: 34px; height: 28px; border-radius: 6px;
    border: 1px solid var(--border-subtle); background: rgba(255,255,255,0.05);
    color: var(--text-muted); font-size: 0.75rem;
    display: flex; align-items: center; justify-content: center;
}

/* ========== PHONE LAYOUT OVERHAUL (≤520px) ========== */
@media (max-width: 520px) {
    /* Full-screen column layout, no padding waste */
    #layout {
        flex-direction: column; padding: 0; gap: 0;
        height: 100dvh; overflow: hidden;
    }
    /* Show mobile HUD */
    #mobile-hud { display: flex !important; }
    /* Hide the sidebar entirely — info is in mobile-hud + hand-dock */
    #sidebar { display: none !important; }
    /* Main: column, board + dock centered in remaining space */
    #main {
        flex: 1; min-height: 0; display: flex;
        flex-direction: column; align-items: center; justify-content: center;
        padding: 4px 4px 0; gap: 0; overflow: hidden; width: 100%;
    }
    /* Board: maximize — constrained by width AND available height */
    #board-wrap {
        width: min(calc(100vw - 8px), calc(100dvh - 196px));
        height: min(calc(100vw - 8px), calc(100dvh - 196px));
        max-width: none; max-height: none; flex-shrink: 0;
    }
    /* Action guide: hidden (info in mob-turn-row) */
    #action-guide { display: none !important; }
    /* Auto-play btn: tiny, above dock */
    #auto-play-btn { font-size: 0.62rem; padding: 3px 7px; margin-top: 4px; position: static; }
    /* Show hand dock: sticks to bottom of #main */
    #hand-dock { display: flex !important; width: 100%; margin-top: auto; flex-shrink: 0; }
    /* Toasts: top-right corner, NOT over the board centre */
    #toast-container {
        bottom: auto;
        top: calc(104px + env(safe-area-inset-top, 0px));
        left: auto; right: calc(8px + env(safe-area-inset-right, 0px));
        align-items: flex-end;
    }
    /* Turn banner: keep but compact */
    #turn-banner { font-size: 0.8rem; padding: 6px 10px; }
    /* Game-over card mobile */
    .go-card { min-width: min(94vw, 360px); padding: 20px 14px; }
    .go-title { font-size: 1.4rem; }
    .go-stats { grid-template-columns: 1fr 1fr 1fr; gap: 5px; }
    .go-stat .stat-value { font-size: 1rem; }
    .go-buttons { flex-wrap: wrap; gap: 8px; }
}

/* Desktop / tablet: hide mobile-only elements */
@media (min-width: 521px) {
    #mobile-hud { display: none !important; }
    #hand-dock  { display: none !important; }
}

/* --- Small phones (375px and below, e.g. iPhone SE) --- */
@media (max-width: 375px) {
    .title-logo { font-size: 1.6rem; }
    .title-subtitle { font-size: 0.7rem; margin-bottom: 16px; }
    .btn-large { min-width: 120px; padding: 10px 16px; font-size: 0.85rem; }
    .secondary-actions { grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .btn-secondary { padding: 6px 8px; font-size: 0.75rem; letter-spacing: 0; }
    .card { width: 42px; height: 58px; }
    .card-value { font-size: 1.1em !important; }
    #board-wrap { width: min(calc(100vw - 8px), calc(100vh - 280px)); height: min(calc(100vw - 8px), calc(100vh - 280px)); }
    .overlay-card { padding: 16px 12px; }
}

/* --- Title screen: scrollable on short screens --- */
#title-screen {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Title screen orbiting pieces --- */
#title-orbit {
    position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0;
}
#title-orbit .orbit-piece {
    position: absolute; border-radius: 50%; opacity: 0.15;
    animation: orbitFloat linear infinite;
}
@keyframes orbitFloat {
    0%   { transform: translate(0, 0) scale(1); }
    25%  { transform: translate(30px, -20px) scale(1.05); }
    50%  { transform: translate(-10px, -40px) scale(0.95); }
    75%  { transform: translate(-30px, 10px) scale(1.02); }
    100% { transform: translate(0, 0) scale(1); }
}
.title-container { position: relative; z-index: 1; }
.title-container {
    max-height: none;
    padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* --- Landscape phones: prioritize board, minimize UI chrome --- */
@media (max-height: 500px) and (orientation: landscape) {
    #layout { flex-direction: row; padding: 4px; gap: 6px; }
    #sidebar {
        width: 200px; flex: 0 0 200px;
        flex-direction: column; overflow-y: auto;
    }
    #sidebar .log-panel { display: none; }
    #sidebar .panel { padding: 8px; }
    .turn-indicator { font-size: 0.9em; padding: 6px 8px; margin: 4px 0; }
    .card { width: 44px; height: 60px; }
    #action-guide { padding: 4px 8px; margin-bottom: 4px; }
    #action-guide-turn { font-size: 0.85rem; }
    #action-guide-prompt { font-size: 0.75rem; }
    #board-wrap { width: min(calc(100vh - 20px), calc(100vw - 230px)); max-width: none; }
}

/* --- Safe area insets (notch phones) --- */
@supports (padding: env(safe-area-inset-top)) {
    /* Desktop only: #mobile-hud already handles this on phones */
    @media (min-width: 521px) {
        #layout { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
    }
    #toast-container { bottom: calc(16px + env(safe-area-inset-bottom)); left: calc(16px + env(safe-area-inset-left)); }
    #auto-play-btn { bottom: calc(12px + env(safe-area-inset-bottom)); right: calc(12px + env(safe-area-inset-right)); }
}

/* ========== CARD-FX FLYING ANIMATION ========== */
#card-fx-layer {
    position: fixed; inset: 0; pointer-events: none; z-index: 900;
}
.card-fx {
    position: fixed;
    width: 52px; height: 72px;
    background: linear-gradient(145deg, rgba(30,40,64,0.97), rgba(15,22,44,0.97));
    border: 2px solid rgba(100,140,200,0.55);
    border-radius: 8px;
    box-shadow: 0 6px 22px rgba(0,0,0,0.55), 0 0 14px rgba(80,130,255,0.25);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    will-change: transform, opacity;
}
.card-fx .card-value { font-size: 1.4rem; font-weight: 800; color: #e8ecf5; line-height: 1; }
.card-fx .card-label { font-size: 0.48rem; font-weight: 700; color: rgba(180,200,240,0.75); text-transform: uppercase; letter-spacing: 1px; }

/* OAuth buttons */
.btn-oauth {
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    letter-spacing: 0.5px;
}
.btn-oauth:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.btn-oauth:active {
    transform: scale(0.98);
}
