/* ============================================================================
   Brass: Birmingham - Styles
   Victorian Industrial Dark Theme — Visual & UX Overhaul
   ============================================================================ */

:root {
    /* Primary palette - deepened for atmosphere */
    --bg-dark: #16120d;
    --bg-medium: #262018;
    --bg-light: #36301f;
    --bg-card: #2d2519;
    --text-primary: #e8d5b7;
    --text-secondary: #b8a68e;
    --text-muted: #8a7a68;
    --accent-gold: #c9a84c;
    --accent-copper: #b87333;
    --accent-brass: #d4a843;
    --border-dark: #4a3c2e;
    --border-light: #6a5a48;

    /* Player colors */
    --player-red: #c0392b;
    --player-yellow: #d4a017;
    --player-purple: #8e44ad;
    --player-white: #d9d0c2;

    /* Resource colors */
    --coal-color: #2c2c2c;
    --iron-color: #d4760a;
    --beer-color: #c9a84c;

    /* Industry colors */
    --cotton-color: #e8d5b7;
    --coal-mine-color: #555;
    --iron-works-color: #d4760a;
    --manufacturer-color: #8b6914;
    --pottery-color: #b03a2e;
    --brewery-color: #d4a843;

    /* Region colors */
    --region-derbyshire: #537c80;
    --region-staffordshire: #1e5aa0;
    --region-midlands: #8c4e51;
    --region-blackcountry: #986627;
    --region-birmingham: #564a5e;

    /* Sizing */
    --panel-gap: 8px;
    --border-radius: 6px;
    --card-width: 90px;
    --card-height: 140px;
}

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

body {
    font-family: 'Source Sans Pro', 'Segoe UI', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

h1, h2, h3 {
    font-family: 'Cinzel', serif;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* ============================================================================
   Setup Screen
   ============================================================================ */

.screen {
    display: none;
    width: 100%;
    height: 100%;
}
.screen.active {
    display: flex;
}

#setup-screen {
    justify-content: center;
    align-items: center;
    /* CSS-only textile/linen background pattern */
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(201,168,76,0.015) 2px,
            rgba(201,168,76,0.015) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(201,168,76,0.015) 2px,
            rgba(201,168,76,0.015) 4px
        ),
        radial-gradient(ellipse at 30% 40%, #2a2018 0%, #1a1510 60%, #12100b 100%);
}

.setup-container {
    text-align: center;
    max-width: 500px;
    padding: 60px 40px;
    background: var(--bg-medium);
    border: 2px solid var(--accent-gold);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px rgba(201,168,76,0.1);
    animation: setup-fade-in 0.8s ease-out;
}

@keyframes setup-fade-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.game-title {
    font-size: 72px;
    color: var(--accent-gold);
    letter-spacing: 12px;
    text-transform: uppercase;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5), 0 0 20px rgba(201,168,76,0.15);
    margin-bottom: 0;
    line-height: 1;
    animation: title-entrance 1s ease-out;
}

@keyframes title-entrance {
    from { letter-spacing: 30px; opacity: 0; }
    to { letter-spacing: 12px; opacity: 1; }
}

.game-subtitle {
    font-size: 28px;
    color: var(--text-primary);
    letter-spacing: 8px;
    text-transform: uppercase;
    margin-bottom: 4px;
    font-weight: 400;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* Decorative ornament under title */
.game-subtitle::after {
    content: '— ✦ —';
    display: block;
    font-size: 14px;
    color: var(--accent-copper);
    letter-spacing: 6px;
    margin-top: 8px;
    margin-bottom: 4px;
    opacity: 0.7;
}

.game-tagline {
    color: var(--text-muted);
    font-family: 'Crimson Text', serif;
    font-style: italic;
    font-size: 16px;
    margin-bottom: 40px;
}

.setup-form {
    text-align: left;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-family: 'Cinzel', serif;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.player-count-selector {
    display: flex;
    gap: 12px;
}

.count-btn {
    flex: 1;
    padding: 14px;
    font-family: 'Cinzel', serif;
    font-size: 24px;
    background: var(--bg-light);
    color: var(--text-secondary);
    border: 2px solid var(--border-dark);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.count-btn:hover {
    border-color: var(--accent-copper);
    color: var(--text-primary);
}

.count-btn.active {
    background: var(--accent-gold);
    color: var(--bg-dark);
    border-color: var(--accent-gold);
    font-weight: 700;
}

.player-name-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-name-input {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-name-input .color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border-light);
    flex-shrink: 0;
}

.player-name-input input {
    flex: 1;
    padding: 10px 14px;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 16px;
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s;
}

.player-name-input input:focus {
    border-color: var(--accent-gold);
}

.btn-primary {
    display: block;
    width: 100%;
    padding: 16px;
    font-family: 'Cinzel', serif;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 3px;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-copper));
    color: var(--bg-dark);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(201,168,76,0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(201,168,76,0.4);
}

/* ============================================================================
   Game Screen Layout
   ============================================================================ */

#game-screen {
    flex-direction: column;
    height: 100vh;
}

/* Top Bar */
#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: linear-gradient(180deg, #2e2618 0%, #242018 100%);
    border-bottom: 1px solid var(--accent-copper);
    height: 44px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.era-indicator {
    display: flex;
    align-items: center;
    gap: 16px;
}

#era-label {
    font-family: 'Cinzel', serif;
    font-size: 16px;
    color: var(--accent-gold);
    letter-spacing: 2px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

#round-label {
    font-size: 13px;
    color: var(--text-muted);
}

.turn-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

#current-player-label {
    font-weight: 600;
    padding: 3px 12px;
    border-radius: 4px;
}

#actions-remaining-label {
    color: var(--text-secondary);
    font-size: 13px;
}

.market-summary {
    display: flex;
    gap: 16px;
    font-size: 13px;
}

.market-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.market-icon {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.coal-icon { background: var(--coal-color); border: 1px solid #555; }
.iron-icon { background: var(--iron-color); }

/* ============================================================================
   Action Phase Indicator Bar
   ============================================================================ */

#action-phase-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 6px 16px;
    background: linear-gradient(180deg, #2a2218 0%, #221c14 100%);
    border-bottom: 1px solid var(--border-dark);
    height: 38px;
    flex-shrink: 0;
}

#action-phase-bar.hidden {
    display: none;
}

.phase-steps {
    display: flex;
    align-items: center;
    gap: 8px;
}

.phase-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    transition: all 0.3s;
}

.phase-step.active {
    color: var(--bg-dark);
    background: var(--accent-gold);
    border-color: var(--accent-gold);
    font-weight: 600;
    box-shadow: 0 0 10px rgba(201,168,76,0.3);
}

.phase-step.completed {
    color: #5a9a5a;
    border-color: #4a7a4a;
    background: rgba(90,154,90,0.15);
}

.phase-step-num {
    font-weight: 700;
    font-size: 11px;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
}

.phase-step.active .phase-step-num {
    background: rgba(0,0,0,0.2);
}

.phase-step.completed .phase-step-num::after {
    content: '✓';
    font-size: 10px;
}

.phase-step.completed .phase-step-num {
    font-size: 0;
}

.phase-step-label {
    font-family: 'Source Sans Pro', sans-serif;
    letter-spacing: 0.5px;
}

.phase-step-arrow {
    color: var(--text-muted);
    font-size: 8px;
    opacity: 0.5;
}

.phase-instruction {
    font-size: 12px;
    color: var(--accent-copper);
    font-style: italic;
    min-width: 200px;
    text-align: center;
}

.phase-cancel-btn {
    padding: 3px 12px;
    font-size: 11px;
    font-family: 'Source Sans Pro', sans-serif;
    background: none;
    border: 1px solid var(--border-dark);
    border-radius: 3px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
}

.phase-cancel-btn:hover {
    border-color: #c0392b;
    color: #e74c3c;
}

/* Main Game Area */
#game-area {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 0;
}

/* Board Container */
#board-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    min-width: 0;
    /* Subtle sepia/aged-map board texture overlay */
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 40px,
            rgba(180,140,60,0.015) 40px,
            rgba(180,140,60,0.015) 41px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 40px,
            rgba(180,140,60,0.015) 40px,
            rgba(180,140,60,0.015) 41px
        ),
        radial-gradient(ellipse at 50% 50%, rgba(60,50,30,0.3) 0%, rgba(20,16,10,0.5) 100%),
        var(--bg-dark);
    position: relative;
}

/* Vignette edge effect for board area */
#board-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,0.4) 100%);
    pointer-events: none;
    z-index: 1;
}

#game-board {
    position: relative;
    z-index: 2;
}

#game-board {
    width: 100%;
    height: 100%;
    max-height: calc(100vh - 300px);
    position: relative;
    z-index: 2;
    touch-action: none;
}

/* Right Panel */
#right-panel {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    background: var(--bg-medium);
    border-left: 1px solid var(--border-dark);
    overflow-y: auto;
}

#right-panel h3 {
    font-size: 10px;
    color: var(--accent-copper);
    letter-spacing: 2.5px;
    text-transform: uppercase;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border-dark);
    padding-bottom: 4px;
}

/* Player Panels */
.player-panel {
    padding: 8px 10px 8px 14px;
    border-radius: var(--border-radius);
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    border-left: 4px solid var(--border-dark);
    font-size: 12px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

/* Dynamic left border color set by JS via style attribute */
.player-panel[style*="border-left-color"] {
    /* JS sets border-left-color inline */
}

.player-panel .player-panel-header {
    position: relative;
    z-index: 1;
}

.player-panel.active {
    border-color: var(--accent-gold);
    border-left-color: inherit;
    box-shadow: 0 0 12px rgba(201,168,76,0.2);
    animation: active-player-pulse 2s ease-in-out infinite;
}

@keyframes active-player-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(201,168,76,0.15); }
    50% { box-shadow: 0 0 20px rgba(201,168,76,0.35); }
}

.player-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.player-panel-name {
    font-family: 'Cinzel', serif;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.player-panel-vp {
    font-weight: 700;
    font-size: 14px;
    color: var(--accent-gold);
    text-shadow: 0 0 8px rgba(201,168,76,0.4);
}

.player-panel-stats {
    display: flex;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 11px;
    flex-wrap: wrap;
}

.player-panel-stat {
    display: flex;
    align-items: center;
    gap: 3px;
    background: rgba(255,255,255,0.04);
    padding: 2px 5px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.06);
}

/* Markets Panel */
#markets-panel {
    padding: 8px 10px;
    border-radius: var(--border-radius);
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
}

.market {
    margin-bottom: 8px;
}

.market:last-child {
    margin-bottom: 0;
}

.market-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.market-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.market-current-price {
    font-size: 10px;
    color: var(--accent-copper);
    font-weight: 600;
}

.market-track {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
}

.market-space {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid var(--border-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    color: var(--text-muted);
    position: relative;
    transition: all 0.2s;
    background: rgba(255,255,255,0.03);
}

.market-space.filled {
    border-color: transparent;
}

.market-space.filled.coal {
    background:
        linear-gradient(135deg, #4a4a4a 0%, #1a1a1a 60%, #111 100%);
    border: 1px solid #5a5a5a;
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.15),
        inset 0 -1px 0 rgba(0,0,0,0.4),
        0 2px 4px rgba(0,0,0,0.5);
}

.market-space.filled.iron {
    background:
        linear-gradient(135deg, #f09830 0%, #d07010 40%, #a04800 100%);
    border: 1px solid #e08020;
    box-shadow:
        inset 0 1px 0 rgba(255,220,100,0.3),
        inset 0 -1px 0 rgba(0,0,0,0.3),
        0 2px 4px rgba(0,0,0,0.4);
}

.market-space .price-label {
    position: absolute;
    bottom: -10px;
    font-size: 7px;
    color: var(--text-muted);
}

/* ============================================================================
   Game Log Panel
   ============================================================================ */

#game-log-panel {
    padding: 8px 10px;
    border-radius: var(--border-radius);
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#game-log {
    overflow-y: auto;
    max-height: 200px;
    flex: 1;
    font-size: 11px;
    line-height: 1.5;
}

.log-entry {
    padding: 3px 6px;
    border-bottom: 1px solid rgba(74,60,46,0.3);
    color: var(--text-secondary);
}

.log-entry:last-child {
    border-bottom: none;
}

.log-entry .log-player {
    font-weight: 600;
}

.log-entry.log-system {
    color: var(--text-muted);
    font-style: italic;
    font-size: 10px;
}

.log-entry.log-era {
    color: var(--accent-gold);
    font-family: 'Cinzel', serif;
    font-size: 12px;
    text-align: center;
    padding: 6px;
    border-bottom: 1px solid var(--border-dark);
    border-top: 1px solid var(--border-dark);
}

/* ============================================================================
   Turn Transition Overlay
   ============================================================================ */

#turn-transition {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    animation: turn-fade-in 0.3s ease-out;
    pointer-events: none;
}

#turn-transition.hidden {
    display: none;
}

#turn-transition.fade-out {
    animation: turn-fade-out 0.5s ease-in forwards;
}

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

@keyframes turn-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

.turn-transition-content {
    text-align: center;
    animation: turn-slide-in 0.3s ease-out;
}

@keyframes turn-slide-in {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.turn-transition-name {
    font-family: 'Cinzel', serif;
    font-size: 48px;
    font-weight: 700;
    letter-spacing: 6px;
    text-shadow: 0 4px 20px rgba(0,0,0,0.8);
}

.turn-transition-subtitle {
    font-family: 'Crimson Text', serif;
    font-size: 20px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 8px;
    letter-spacing: 4px;
    text-transform: uppercase;
}

/* ============================================================================
   Bottom Panel - Hand & Actions
   ============================================================================ */

#bottom-panel {
    display: flex;
    align-items: stretch;
    height: 175px;
    flex-shrink: 0;
    background:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 4px,
            rgba(0,0,0,0.06) 4px,
            rgba(0,0,0,0.06) 8px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 12px,
            rgba(201,168,76,0.015) 12px,
            rgba(201,168,76,0.015) 13px
        ),
        linear-gradient(180deg, #2a2218 0%, #1e1a12 100%);
    border-top: 2px solid var(--accent-copper);
    box-shadow: inset 0 1px 0 rgba(201,168,76,0.15), 0 -2px 8px rgba(0,0,0,0.4);
    gap: 0;
}

/* Card selection mode: dim action buttons and player mat */
#bottom-panel.card-select-mode #action-panel {
    opacity: 0.3;
    pointer-events: none;
}

#bottom-panel.card-select-mode #player-mat-container {
    opacity: 0.3;
    pointer-events: none;
}

#hand-container {
    flex: 1;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.hand-label, .action-label, .mat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 6px;
    font-family: 'Cinzel', serif;
}

#player-hand {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    flex: 1;
    align-items: flex-start;
}

/* Card Styles - Redesigned: larger, richer */
.card {
    width: var(--card-width);
    min-width: var(--card-width);
    height: var(--card-height);
    border-radius: 6px;
    background:
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 3px,
            rgba(201,168,76,0.015) 3px,
            rgba(201,168,76,0.015) 6px
        ),
        linear-gradient(160deg, #352c1e 0%, #2a2018 50%, #221a12 100%);
    border: 2px solid var(--border-dark);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px;
    font-size: 10px;
    text-align: center;
    position: relative;
    user-select: none;
    overflow: hidden;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 2px 4px rgba(0,0,0,0.4);
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    border-radius: 4px 4px 0 0;
}

.card:hover {
    transform: translateY(-8px);
    border-color: var(--accent-gold);
    box-shadow: 0 8px 20px rgba(0,0,0,0.5), 0 0 10px rgba(201,168,76,0.2);
}

.card.selected {
    transform: translateY(-12px);
    border-color: var(--accent-gold);
    box-shadow: 0 10px 24px rgba(201,168,76,0.4), 0 0 15px rgba(201,168,76,0.3);
}

/* Card selection mode: valid cards get pulse */
.card.valid-discard {
    animation: card-pulse 1.5s ease-in-out infinite;
    border-color: var(--accent-gold);
}

@keyframes card-pulse {
    0%, 100% { box-shadow: 0 0 5px rgba(201,168,76,0.3); }
    50% { box-shadow: 0 0 15px rgba(201,168,76,0.7); }
}

.card.invalid-discard {
    opacity: 0.3;
    pointer-events: none;
}

.card.scout-queued {
    border-color: #e74c3c;
    box-shadow: 0 0 10px rgba(231,76,60,0.5);
    opacity: 0.6;
    pointer-events: none;
}

.card-type {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
    font-variant: small-caps;
}

.card-name {
    font-family: 'Cinzel', serif;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.card-icon {
    font-size: 24px;
    margin: 6px 0;
}

/* Card type-specific colored top borders */
.card.location-card::before { background: #5a8a5a; }
.card.industry-card::before { background: #8a5a5a; }
.card.wild-card::before { background: linear-gradient(90deg, var(--accent-gold), var(--accent-copper), var(--accent-gold)); }

.card.location-card {
    border-color: #3a5a3a;
}

.card.location-card:hover {
    border-color: #6a9a6a;
}

.card.industry-card {
    border-color: #5a3a3a;
}

.card.industry-card:hover {
    border-color: #9a6a6a;
}

.card.wild-card {
    border-color: var(--accent-gold);
    background: linear-gradient(135deg, var(--bg-card) 0%, #3a3020 50%, var(--bg-card) 100%);
}

/* SVG icons for cards */
.card-svg-icon {
    width: 30px;
    height: 30px;
    margin: 4px 0;
}

/* Action Panel */
#action-panel {
    width: 310px;
    padding: 8px 12px;
    border-left: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s;
    /* Wood-grain texture effect */
    background:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 3px,
            rgba(0,0,0,0.04) 3px,
            rgba(0,0,0,0.04) 6px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 8px,
            rgba(201,168,76,0.02) 8px,
            rgba(201,168,76,0.02) 9px
        ),
        var(--bg-medium);
}

#action-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    flex: 1;
    align-items: stretch;
}

.action-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
    min-height: 48px;
    height: auto;
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    border-left: 4px solid var(--border-dark);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    transition: all 0.2s;
    overflow: hidden;
    position: relative;
    text-transform: uppercase;
}

/* Action pip — left indicator strip */
.action-pip {
    display: block;
    width: 0;
    height: 100%;
    flex-shrink: 0;
}

.action-label-text {
    padding: 6px 4px;
    text-align: center;
    flex: 1;
    line-height: 1.2;
}

/* Per-action color coding via left border */
.action-build   { border-left-color: #2ecc71; }
.action-network { border-left-color: #3498db; }
.action-develop { border-left-color: #e67e22; }
.action-sell    { border-left-color: #f1c40f; }
.action-loan    { border-left-color: #e74c3c; }
.action-scout   { border-left-color: #9b59b6; }
.action-pass    { border-left-color: #7f8c8d; }

.action-build:hover:not(:disabled)   { background: #1a3d25; border-left-color: #27ae60; color: #2ecc71; }
.action-network:hover:not(:disabled) { background: #1a2d3d; border-left-color: #2980b9; color: #3498db; }
.action-develop:hover:not(:disabled) { background: #3d2a1a; border-left-color: #d35400; color: #e67e22; }
.action-sell:hover:not(:disabled)    { background: #3d370a; border-left-color: #d4ac0d; color: #f1c40f; }
.action-loan:hover:not(:disabled)    { background: #3d1a1a; border-left-color: #c0392b; color: #e74c3c; }
.action-scout:hover:not(:disabled)   { background: #2a1a3d; border-left-color: #8e44ad; color: #9b59b6; }
.action-pass:hover:not(:disabled)    { background: #2a2a2a; border-left-color: #636e72; color: #95a5a6; }

.action-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.action-btn.active {
    border-left-color: var(--accent-gold);
    background: var(--bg-light);
    color: var(--accent-gold);
    box-shadow: inset 0 0 8px rgba(201,168,76,0.1);
}

.action-build.active   { border-left-color: #2ecc71; background: #1a3d25; color: #2ecc71; }
.action-network.active { border-left-color: #3498db; background: #1a2d3d; color: #3498db; }
.action-develop.active { border-left-color: #e67e22; background: #3d2a1a; color: #e67e22; }
.action-sell.active    { border-left-color: #f1c40f; background: #3d370a; color: #f1c40f; }
.action-loan.active    { border-left-color: #e74c3c; background: #3d1a1a; color: #e74c3c; }
.action-scout.active   { border-left-color: #9b59b6; background: #2a1a3d; color: #9b59b6; }
.action-pass.active    { border-left-color: #7f8c8d; background: #2a2a2a; color: #95a5a6; }

.pass-btn {
    grid-column: span 1;
}

/* Player Mat */
#player-mat-container {
    width: 310px;
    padding: 8px 12px;
    border-left: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: opacity 0.3s;
}

#player-mat {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
}

.mat-industry {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mat-industry-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mat-tiles {
    display: flex;
    gap: 2px;
}

.mat-tile {
    width: 28px;
    height: 28px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    border: 1px solid var(--border-dark);
    background: var(--bg-dark);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.mat-tile.available {
    border-color: var(--accent-copper);
    color: var(--text-primary);
    box-shadow: 0 0 4px rgba(184,115,51,0.2);
}

.mat-tile.used {
    opacity: 0.25;
}

/* Industry-colored mat tiles */
.mat-tile[data-type="cottonMill"].available { border-color: var(--cotton-color); }
.mat-tile[data-type="coalMine"].available { border-color: var(--coal-mine-color); }
.mat-tile[data-type="ironWorks"].available { border-color: var(--iron-works-color); }
.mat-tile[data-type="manufacturer"].available { border-color: var(--manufacturer-color); }
.mat-tile[data-type="pottery"].available { border-color: var(--pottery-color); }
.mat-tile[data-type="brewery"].available { border-color: var(--brewery-color); }

/* ============================================================================
   Board SVG Styles
   ============================================================================ */

/* Board background */
.board-bg {
    fill: #2a2a1f;
}

.board-water {
    fill: #1a2a3a;
    opacity: 0.3;
}

/* Connections */
.connection-line {
    stroke-linecap: round;
    cursor: pointer;
    transition: stroke-width 0.2s;
}

.connection-line:hover {
    stroke-width: 6;
}

.connection-line.canal {
    stroke: #4488aa;
    stroke-dasharray: none;
}

.connection-line.rail {
    stroke: #666;
    stroke-dasharray: 8 4;
}

.connection-line.canal-only {
    stroke: #4488aa;
}

.connection-line.rail-only {
    stroke: #888;
    stroke-dasharray: 8 4;
}

.connection-line.both {
    stroke: #4488aa;
}

.connection-line.built {
    stroke-width: 5;
    filter: none;
}

.connection-line.highlight {
    stroke: var(--accent-gold);
    stroke-width: 7;
    filter: drop-shadow(0 0 4px rgba(201,168,76,0.6));
}

/* City nodes */
.city-group {
    cursor: pointer;
}

.city-bg {
    rx: 8;
    ry: 8;
    stroke-width: 2;
    transition: all 0.2s;
}

.city-group:hover .city-bg {
    stroke: var(--accent-gold);
    filter: drop-shadow(0 0 6px rgba(201,168,76,0.4));
}

.city-label {
    font-family: 'Cinzel', serif;
    font-size: 10px;
    font-weight: 600;
    fill: var(--text-primary);
    text-anchor: middle;
    pointer-events: none;
}

.city-label-bg {
    fill: rgba(0,0,0,0.7);
    rx: 3;
    ry: 3;
}

/* Industry slots on board */
.industry-slot {
    cursor: pointer;
    transition: all 0.2s;
}

.industry-slot:hover {
    filter: drop-shadow(0 0 4px rgba(201,168,76,0.5));
}

.slot-bg {
    rx: 3;
    ry: 3;
    stroke-width: 1;
    stroke: rgba(255,255,255,0.2);
    fill: rgba(0,0,0,0.4);
}

.slot-icon {
    font-size: 10px;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.slot-level {
    font-size: 7px;
    fill: white;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    font-weight: 600;
}

/* Built industry tiles on board */
.built-tile {
    rx: 3;
    ry: 3;
    stroke-width: 2;
}

.built-tile.flipped {
    opacity: 0.85;
}

/* Resource cubes on tiles */
.resource-cube {
    stroke-width: 0.5;
    stroke: rgba(255,255,255,0.3);
}

.resource-cube.coal { fill: var(--coal-color); }
.resource-cube.iron { fill: var(--iron-color); }
.resource-cube.beer { fill: var(--beer-color); }

/* Merchant locations */
.merchant-group {
    cursor: pointer;
}

.merchant-bg {
    fill: #4a3a2a;
    stroke: var(--accent-copper);
    stroke-width: 1.5;
    rx: 6;
    ry: 6;
}

.merchant-label {
    font-family: 'Cinzel', serif;
    font-size: 9px;
    fill: var(--accent-copper);
    text-anchor: middle;
    pointer-events: none;
}

.merchant-slot {
    stroke: var(--accent-copper);
    stroke-width: 1;
    fill: rgba(0,0,0,0.3);
    rx: 2;
    ry: 2;
}

/* Brewery farm */
.brewery-farm {
    cursor: pointer;
}

.brewery-farm-bg {
    fill: #3a3020;
    stroke: var(--beer-color);
    stroke-width: 1;
    rx: 5;
    ry: 5;
}

/* Link tiles on board */
.link-tile {
    stroke-width: 0;
}

/* Highlight for valid placements */
.highlight-slot {
    animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 3px rgba(201,168,76,0.4)); }
    50% { filter: drop-shadow(0 0 8px rgba(201,168,76,0.8)); }
}

/* VP/Income indicators on tiles */
.tile-vp {
    font-size: 8px;
    fill: var(--accent-gold);
    font-weight: 700;
    text-anchor: middle;
    pointer-events: none;
}

.tile-income {
    font-size: 7px;
    fill: #7ec87e;
    text-anchor: middle;
    pointer-events: none;
}

/* ============================================================================
   Modal
   ============================================================================ */

#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#modal-overlay.hidden {
    display: none;
}

#modal-content {
    background: var(--bg-medium);
    border: 2px solid var(--accent-gold);
    border-radius: 10px;
    min-width: 400px;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

#modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-dark);
}

#modal-title {
    font-size: 18px;
    color: var(--accent-gold);
}

#modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

#modal-close:hover {
    color: var(--text-primary);
}

#modal-body {
    padding: 16px 20px;
}

#modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-dark);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Modal buttons */
.modal-btn {
    padding: 8px 20px;
    font-family: 'Cinzel', serif;
    font-size: 13px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 1px;
}

.modal-btn-primary {
    background: var(--accent-gold);
    color: var(--bg-dark);
    border: none;
    font-weight: 600;
}

.modal-btn-primary:hover {
    background: var(--accent-brass);
}

.modal-btn-secondary {
    background: none;
    color: var(--text-secondary);
    border: 1px solid var(--border-dark);
}

.modal-btn-secondary:hover {
    border-color: var(--accent-copper);
    color: var(--text-primary);
}

/* Modal choice list */
.choice-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.choice-item {
    padding: 10px 14px;
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.choice-item:hover {
    border-color: var(--accent-copper);
    background: var(--bg-light);
}

.choice-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.choice-item-icon {
    font-size: 20px;
}

.choice-item-text {
    flex: 1;
}

.choice-item-name {
    font-weight: 600;
    font-size: 14px;
}

.choice-item-detail {
    font-size: 11px;
    color: var(--text-muted);
}

.choice-item-cost {
    font-size: 12px;
    color: var(--accent-copper);
    font-weight: 600;
}

/* ============================================================================
   Toasts
   ============================================================================ */

#toast-container {
    position: fixed;
    top: 60px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast {
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-medium);
    border: 1px solid var(--border-dark);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    animation: toast-in 0.3s ease-out;
    max-width: 360px;
}

.toast.info { border-left: 3px solid #3498db; }
.toast.success { border-left: 3px solid #2ecc71; }
.toast.warning { border-left: 3px solid #f39c12; }
.toast.error { border-left: 3px solid #e74c3c; }

@keyframes toast-in {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ============================================================================
   Scoring Overlay
   ============================================================================ */

#scoring-overlay, #gameover-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
}

#scoring-overlay.hidden, #gameover-overlay.hidden {
    display: none;
}

.scoring-content, .gameover-content {
    background: var(--bg-medium);
    border: 2px solid var(--accent-gold);
    border-radius: 12px;
    padding: 30px 40px;
    min-width: 500px;
    max-width: 700px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

.scoring-content h2, .gameover-content h1 {
    color: var(--accent-gold);
    margin-bottom: 20px;
}

.scoring-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.scoring-table th, .scoring-table td {
    padding: 8px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border-dark);
    font-size: 14px;
}

.scoring-table th {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.scoring-table .total-row {
    font-weight: 700;
    font-size: 16px;
    color: var(--accent-gold);
    border-top: 2px solid var(--accent-gold);
}

/* ============================================================================
   Responsive & Scrollbar
   ============================================================================ */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--bg-dark);
    border: 1px solid var(--accent-copper);
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-primary);
    z-index: 500;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    max-width: 250px;
}

.tooltip-title {
    font-family: 'Cinzel', serif;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--accent-gold);
}

.tooltip-stat {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* Selection highlight for build targets */
.selectable {
    cursor: pointer;
}

.selectable:hover {
    filter: brightness(1.2);
}

.selected-target {
    stroke: var(--accent-gold) !important;
    stroke-width: 3 !important;
    filter: drop-shadow(0 0 6px rgba(201,168,76,0.6));
}

/* ============================================================================
   Mobile Layout (portrait phones / narrow windows) — see
   docs/superpowers/specs/2026-07-11-mobile-layout-design.md
   ============================================================================ */

#panel-tabs {
    display: none;
}

@media (max-width: 820px) {
    /* Flatten desktop containers so every region becomes a flex child of the
       #game-screen column and can be reordered. */
    #game-area,
    #right-panel,
    #bottom-panel {
        display: contents;
    }

    /* 1. Map */
    #board-container {
        order: 1;
        flex: none;
        height: 48vh;
        padding: 0;
    }
    #game-board {
        max-height: none;
    }

    /* 2. Pinned strip: actions row, then hand row */
    #action-panel {
        order: 2;
        width: auto;
        border-left: none;
        padding: 4px 8px 0;
    }
    #hand-container {
        order: 3;
        flex: none;
        padding: 4px 8px 6px;
    }

    /* 3. Tab bar */
    #panel-tabs {
        order: 4;
        display: flex;
        flex-shrink: 0;
        background: var(--bg-medium);
        border-top: 2px solid var(--accent-copper);
    }
    .panel-tab {
        flex: 1;
        padding: 10px 4px;
        font-family: 'Cinzel', serif;
        font-size: 12px;
        letter-spacing: 1px;
        text-transform: uppercase;
        background: none;
        border: none;
        border-bottom: 2px solid transparent;
        color: var(--text-muted);
        cursor: pointer;
    }
    .panel-tab.active {
        color: var(--accent-gold);
        border-bottom-color: var(--accent-gold);
    }

    /* 4. Panel area: exactly one panel visible, chosen by data-tab */
    #player-panels,
    #markets-panel,
    #game-log-panel,
    #player-mat-container {
        display: none;
        order: 5;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        margin: 0;
        border-radius: 0;
    }
    #game-screen[data-tab="players"] #player-panels {
        display: block;
        padding: 8px;
    }
    #game-screen[data-tab="markets"] #markets-panel {
        display: block;
    }
    #game-screen[data-tab="log"] #game-log-panel {
        display: flex;
        flex-direction: column;
    }
    #game-screen[data-tab="industries"] #player-mat-container {
        display: flex;
        flex-direction: column;
        padding: 8px;
    }
    #game-log {
        max-height: none;
    }

    /* Compact cards in the pinned hand strip (~70% of desktop 90x140) */
    :root {
        --card-width: 64px;
        --card-height: 98px;
    }

    /* Top bar: keep one row on narrow screens */
    #top-bar {
        padding: 4px 8px;
        height: 38px;
        gap: 6px;
    }
    #era-label {
        font-size: 13px;
    }
    #round-label {
        font-size: 10px;
    }
    .turn-info {
        font-size: 11px;
        min-width: 0;
    }
    #current-player-label {
        max-width: 90px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .market-summary {
        gap: 6px;
        font-size: 10px;
    }

    /* Action buttons: one horizontally scrollable row */
    #action-buttons {
        display: flex;
        gap: 4px;
        overflow-x: auto;
    }
    .action-btn {
        flex: 0 0 auto;
        min-width: 60px;
        min-height: 34px;
    }

    /* Section labels are redundant on mobile (tabs name the panels) */
    .hand-label,
    .action-label,
    .mat-label {
        display: none;
    }
}
