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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #0a0f1e;
    min-height: 100vh;
    overflow: hidden;
    color: #e0e8f8;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ─── Header ─── */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #0b1220 0%, #1a2a4a 100%);
    padding: 10px 20px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    flex-shrink: 0;
    z-index: 100;
    border-bottom: 1px solid #2a4a7a;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-left h1 {
    color: #a0c4ff;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Header Navigation */
.header-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-link {
    padding: 7px 16px;
    text-decoration: none;
    color: #7a9cc8;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.25s ease;
    border: 1px solid transparent;
}

.nav-link:hover {
    background: rgba(42, 74, 122, 0.3);
    color: #a0c4ff;
    border-color: rgba(42, 74, 122, 0.5);
}

.nav-link.active {
    background: linear-gradient(135deg, #1e3a5f 0%, #2a5a8f 100%);
    color: #fff;
    font-weight: 600;
    border-color: #4a9eff;
    box-shadow: 0 2px 8px rgba(74, 158, 255, 0.3);
}

.header-right {
    display: flex;
    gap: 10px;
}

.toggle-menu-btn {
    background: #1a2a4a;
    color: #a0c4ff;
    border: 1px solid #2a4a7a;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.25s ease;
}
.toggle-menu-btn:hover { 
    background: #2a4a7a; 
    color: #fff;
    box-shadow: 0 2px 8px rgba(42, 74, 122, 0.4);
}

.header-btn {
    padding: 8px 16px;
    border: 1px solid #2a4a7a;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    background: #1a2a4a;
    color: #a0c4ff;
}
.header-btn:hover { 
    background: #2a4a7a; 
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(42, 74, 122, 0.3);
}

.save-btn { background: linear-gradient(135deg, #1e5a3a 0%, #2a7a4a 100%); border-color: #3a9a5a; color: #a5f0c0; }
.save-btn:hover { background: linear-gradient(135deg, #2a7a4a 0%, #3a9a5a 100%); }

.load-btn { background: linear-gradient(135deg, #1a4a7a 0%, #2a6a9a 100%); border-color: #3a8aba; color: #a0d0ff; }
.load-btn:hover { background: linear-gradient(135deg, #2a6a9a 0%, #3a8aba 100%); }

.print-btn { background: linear-gradient(135deg, #5a4a1a 0%, #7a6a2a 100%); border-color: #9a8a3a; color: #f0e0a0; }
.print-btn:hover { background: linear-gradient(135deg, #7a6a2a 0%, #9a8a3a 100%); }

/* ─── Main layout ─── */
main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ─── Control Panel ─── */
.control-panel {
    width: 320px;
    min-width: 320px;
    background: linear-gradient(180deg, #0b1220 0%, #0f1828 100%);
    border-right: 1px solid #1e2d3d;
    overflow-y: auto;
    transition: width 0.3s ease, min-width 0.3s ease, opacity 0.25s ease;
    flex-shrink: 0;
    box-shadow: 4px 0 16px rgba(0,0,0,0.3);
}

.control-panel.collapsed {
    width: 0;
    min-width: 0;
    opacity: 0;
    overflow: hidden;
}

.panel-inner {
    padding: 20px;
    min-width: 280px;
}

.control-panel h2 {
    color: #90caf9;
    font-size: 17px;
    margin-bottom: 18px;
    border-bottom: 2px solid #1e3a5f;
    padding-bottom: 10px;
    font-weight: 700;
}

.control-panel h3 {
    color: #78909c;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    margin: 18px 0 10px 0;
    font-weight: 600;
}

.control-group {
    margin-bottom: 20px;
}

/* ─── Buttons ─── */
.primary-btn, .secondary-btn, .add-btn, .import-btn, .reset-btn {
    padding: 12px 18px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    width: 100%;
    margin-bottom: 10px;
    display: block;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.primary-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 1px solid rgba(102, 126, 234, 0.5);
}
.primary-btn:hover { 
    filter: brightness(1.15); 
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.secondary-btn { 
    background: #1e2d3d; 
    color: #ccc; 
    border: 1px solid #2e3d4d;
}
.secondary-btn:hover { 
    background: #2e3d4d; 
    color: #fff;
    transform: translateY(-1px);
}

.add-btn { 
    background: linear-gradient(135deg, #2e7d32 0%, #388e3c 100%); 
    color: white;
    border: 1px solid rgba(46, 125, 50, 0.5);
}
.add-btn:hover { 
    background: linear-gradient(135deg, #388e3c 0%, #43a047 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(56, 142, 60, 0.3);
}

.import-btn { 
    background: linear-gradient(135deg, #1565c0 0%, #1976d2 100%); 
    color: white;
    border: 1px solid rgba(21, 101, 192, 0.5);
    margin-top: 8px;
}
.import-btn:hover { 
    background: linear-gradient(135deg, #1976d2 0%, #1e88e5 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
}

.reset-btn {
    background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
    color: white;
    border: 1px solid rgba(211, 47, 47, 0.5);
}
.reset-btn:hover {
    background: linear-gradient(135deg, #e53935 0%, #d32f2f 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(211, 47, 47, 0.4);
}

/* ─── Alliance City Config ─── */
.alliance-city-config {
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    padding: 14px;
    border-radius: 8px;
    border: 1px solid #2a4a7a;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}
.alliance-city-config label {
    display: block;
    margin-bottom: 7px;
    font-size: 12px;
    color: #90a4ae;
    font-weight: 600;
}
.alliance-city-config select {
    width: 100%;
    padding: 9px;
    border: 1px solid #2a4a7a;
    border-radius: 6px;
    font-size: 12px;
    background: #0a1628;
    color: #e0e8f8;
    cursor: pointer;
    transition: border-color 0.25s;
}
.alliance-city-config select:focus {
    outline: none;
    border-color: #4a9eff;
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

/* ─── Zoom Controls ─── */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    border: 1px solid #2a4a7a;
}
.zoom-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid #2a4a7a;
    background: #0a1628;
    color: #e0e8f8;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
    transition: all 0.2s;
}
.zoom-btn:hover { 
    background: #2a4a7a; 
    color: #fff;
    transform: scale(1.05);
}
#zoomLevel {
    font-weight: 700;
    color: #90caf9;
    min-width: 50px;
    text-align: center;
    font-size: 14px;
}

/* ─── Coordinate Toggle ─── */
.coordinate-toggle {
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid #2a4a7a;
}
.coordinate-toggle label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: #90a4ae;
    cursor: pointer;
}
.coordinate-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #667eea;
}

/* ─── Player List Stats ─── */
.player-list-stats {
    display: flex;
    justify-content: space-between;
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 12px;
    color: #90a4ae;
    border: 1px solid #2a4a7a;
}
.player-list-stats span { font-weight: 600; }

/* ─── Manual Add ─── */
.manual-add {
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    padding: 14px;
    border-radius: 8px;
    border: 1px solid #2a4a7a;
}
.manual-add label {
    display: block;
    margin-bottom: 5px;
    font-size: 11px;
    color: #90a4ae;
    font-weight: 600;
}
.manual-add input, .manual-add select {
    width: 100%;
    padding: 8px;
    border: 1px solid #2a4a7a;
    border-radius: 6px;
    font-size: 12px;
    margin-bottom: 10px;
    background: #0a1628;
    color: #e0e8f8;
    transition: border-color 0.25s;
}
.manual-add input:focus, .manual-add select:focus {
    outline: none;
    border-color: #4a9eff;
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

/* ─── Import Section ─── */
.import-section {
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    padding: 14px;
    border-radius: 8px;
    border: 1px solid #2a4a7a;
}
.import-section label {
    display: block;
    margin-bottom: 5px;
    font-size: 11px;
    color: #90a4ae;
    font-weight: 600;
}
.import-section input,
.import-section textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #2a4a7a;
    border-radius: 6px;
    font-size: 11px;
    margin-bottom: 8px;
    font-family: 'Courier New', monospace;
    resize: vertical;
    background: #0a1628;
    color: #e0e8f8;
    transition: border-color 0.25s;
}
.import-section input:focus, .import-section textarea:focus {
    outline: none;
    border-color: #4a9eff;
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

.help-text {
    display: block;
    font-size: 10px;
    color: #546e7a;
    margin-top: 5px;
    line-height: 1.5;
}

/* ─── Placed List ─── */
.placed-list {
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    padding: 12px;
    border-radius: 8px;
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid #2a4a7a;
    margin-top: 8px;
}
.placed-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 5px;
    background: #0a1628;
    border-radius: 6px;
    border-left: 3px solid #667eea;
    transition: all 0.2s;
}
.placed-item:hover {
    background: #1a2a4a;
    transform: translateX(2px);
}
.placed-item .item-name { font-weight: 600; font-size: 11px; color: #e0e8f8; }
.placed-item .item-position { font-size: 10px; color: #546e7a; }
.placed-item .item-remove {
    background: #c62828;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s;
}
.placed-item .item-remove:hover {
    background: #d32f2f;
    transform: scale(1.1);
}

/* ─── Legend ─── */
.legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.legend-item {
    display: flex;
    align-items: center;
    font-size: 11px;
    color: #90a4ae;
}
.legend-color {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    margin-right: 8px;
    border: 1px solid rgba(255,255,255,0.2);
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.legend-color.player-2x2 { background: linear-gradient(90deg, #FFD700 0%, #FF6B6B 20%, #4ECDC4 40%, #45B7D1 60%, #96CEB4 80%, #DDA0DD 100%); }
.legend-color.player-3x3 { background: linear-gradient(90deg, #FFD700 0%, #FF6B6B 20%, #4ECDC4 40%, #45B7D1 60%, #96CEB4 80%, #DDA0DD 100%); }
.legend-color.alliance-city-lv3 { background: #FF6B00; }
.legend-color.alliance-city-lv4 { background: #FF4500; }
.legend-color.rss-tile       { background: #4169E1; }
.legend-color.warehouse      { background: #9370DB; }
.legend-color.dead-spot      { background: #607D8B; }

/* ─── Grid Container ─── */
.grid-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: radial-gradient(ellipse at center, #1a2e1a 0%, #0a140a 100%);
    cursor: grab;
    user-select: none;
}
.grid-container.panning { cursor: grabbing; }

/* Pan area - this is what gets translated */
.grid-pan-area {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Additional pan/zoom applied via JS */
}

/* ─── Game Grid ─── */
.game-grid {
    display: grid;
    grid-template-columns: repeat(30, 25px);
    grid-template-rows: repeat(30, 25px);
    gap: 0;
    transform: rotateX(60deg) rotateZ(45deg);
    transform-style: preserve-3d;
    box-shadow: 0 30px 80px rgba(0,0,0,0.6);
    width: 750px;
    height: 750px;
}

.grid-cell {
    width: 25px;
    height: 25px;
    background: #5a8a2a;
    border: 1px solid #3d6020;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: background 0.15s;
}
.grid-cell:hover { background: #6fa030; }
.grid-cell.selected {
    background: #FFC107 !important;
    box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px #F57F17;
    z-index: 50;
}

/* ─── Player Name Label ─── */
.player-name-label {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0,0,0,1), 0 0 6px rgba(0,0,0,0.8);
    white-space: nowrap;
    overflow: visible;
    pointer-events: none;
    z-index: 500;
    transform: rotateZ(-45deg) translateZ(8px);
    text-align: center;
    line-height: 1.1;
}

.player-name-label.size-1x1 { font-size: 7px; }
.player-name-label.size-2x2 { font-size: 11px; }
.player-name-label.size-3x3 { font-size: 14px; }
.player-name-label.size-4x4 { font-size: 16px; }

/* ─── Player Coordinate Label ─── */
.player-coordinate-label {
    position: absolute;
    bottom: 2px;
    left: 2px;
    font-size: 6px;
    font-weight: bold;
    color: #fff;
    background: rgba(0,0,0,0.7);
    padding: 1px 3px;
    border-radius: 2px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 501;
    transform: rotateZ(-45deg) translateZ(8px);
}

/* ─── Perimeter Borders ─── */
.grid-cell.item-border-top    { border-top:    3px solid rgba(0,0,0,0.6) !important; }
.grid-cell.item-border-bottom { border-bottom: 3px solid rgba(0,0,0,0.6) !important; }
.grid-cell.item-border-left   { border-left:   3px solid rgba(0,0,0,0.6) !important; }
.grid-cell.item-border-right  { border-right:  3px solid rgba(0,0,0,0.6) !important; }

/* ─── Player Cells ─── */
.grid-cell.player-2x2 { /* Dynamic color applied via JavaScript */ }
.grid-cell.player-3x3 { /* Dynamic color applied via JavaScript */ }

/* ─── Building Cells ─── */
.grid-cell.alliance-city-lv3 { background: #FF6B00; border: none; }
.grid-cell.alliance-city-lv4 { background: #FF4500; border: none; }
.grid-cell.rss-tile           { background: #4169E1; border: none; }
.grid-cell.warehouse          { background: #9370DB; border: none; }
.grid-cell.dead-spot          { background: #607D8B !important; border: none !important; }

/* ─── Alliance City Border Lines ─── */
.grid-cell.alliance-city-border-lv3 { position: relative; }
.grid-cell.alliance-city-border-lv4 { position: relative; }

.grid-cell.border-top    { border-top:    3px solid #FF6D00 !important; }
.grid-cell.border-bottom { border-bottom: 3px solid #FF6D00 !important; }
.grid-cell.border-left   { border-left:   3px solid #FF6D00 !important; }
.grid-cell.border-right  { border-right:  3px solid #FF6D00 !important; }

.grid-cell.border-top-lv4    { border-top:    3px solid #E64A19 !important; }
.grid-cell.border-bottom-lv4 { border-bottom: 3px solid #E64A19 !important; }
.grid-cell.border-left-lv4   { border-left:   3px solid #E64A19 !important; }
.grid-cell.border-right-lv4  { border-right:  3px solid #E64A19 !important; }

/* ─── Drag Preview (kept for compatibility) ─── */
.grid-cell.drag-preview         { background: rgba(255,235,59,0.55) !important; border: 2px dashed #F57F17 !important; z-index: 100; }
.grid-cell.drag-preview-invalid { background: rgba(244,67,54,0.4)   !important; border: 2px dashed #D32F2F !important; z-index: 100; }

/* ─── Move Mode ─── */
.grid-cell.move-source          { background: rgba(255,200,0,0.35)  !important; border: 2px dashed #ffd700 !important; z-index: 100; }
.grid-cell.move-preview         { background: rgba(100,220,100,0.45) !important; border: 2px dashed #4caf50 !important; z-index: 100; }
.grid-cell.move-preview-invalid { background: rgba(244,67,54,0.4)   !important; border: 2px dashed #D32F2F !important; z-index: 100; }

/* ─── Move Banner ─── */
.move-banner {
    background: linear-gradient(90deg, #1a3a1a, #1e4a1e);
    border-bottom: 2px solid #4caf50;
    color: #a5d6a7;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 24px;
    text-align: center;
    z-index: 500;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ─── City Coordinates Row ─── */
.city-coords-row {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}
.city-coord-field {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}
.city-coord-field label {
    font-size: 12px;
    color: #7a9cc8;
    font-weight: 600;
    min-width: 14px;
}
.city-coord-field input[type="number"] {
    width: 100%;
    background: #0a1628;
    border: 1px solid #2a4a7a;
    border-radius: 6px;
    color: #e0e8f8;
    padding: 6px 10px;
    font-size: 13px;
    -moz-appearance: textfield;
    transition: all 0.25s;
}
.city-coord-field input[type="number"]::-webkit-inner-spin-button,
.city-coord-field input[type="number"]::-webkit-outer-spin-button { opacity: 0.5; }
.city-coord-field input[type="number"]:focus {
    outline: none;
    border-color: #4a9eff;
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

/* ─── Context Menu: Edit button ─── */
.context-edit { color: #a5d6a7 !important; }
.context-edit:hover { background: #1a3a1a !important; color: #4caf50 !important; }

/* ─── Context Menu: Remove button ─── */
.context-remove { color: #ef9a9a !important; }
.context-remove:hover { background: #3d1a1a !important; color: #ff6b6b !important; }

/* ─── Quick Add Player Row ─── */
.quick-add-player-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 14px;
    border-bottom: 1px solid #2a4a7a;
}
.quick-name-input {
    flex: 1;
    min-width: 0;
    background: #0a1628;
    border: 1px solid #2a4a7a;
    border-radius: 6px;
    color: #e0e8f8;
    padding: 7px 12px;
    font-size: 13px;
    transition: all 0.25s;
}
.quick-name-input:focus {
    outline: none;
    border-color: #4a9eff;
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}
.quick-size-select {
    background: #0a1628;
    border: 1px solid #2a4a7a;
    border-radius: 6px;
    color: #e0e8f8;
    padding: 7px 10px;
    font-size: 13px;
    min-width: 75px;
    transition: all 0.25s;
}
.quick-size-select:focus {
    outline: none;
    border-color: #4a9eff;
}
.quick-add-btn {
    background: linear-gradient(135deg, #2a5a3a 0%, #3a7a4a 100%);
    border: 1px solid #4a9a5a;
    border-radius: 6px;
    color: #a5f0c0;
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    white-space: nowrap;
}
.quick-add-btn:hover {
    background: linear-gradient(135deg, #3a7a4a 0%, #4a9a5a 100%);
    color: #c5ffb8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(58, 122, 74, 0.3);
}
.quick-add-btn:active {
    transform: translateY(0);
}

/* ─── Context Menu ─── */
.context-menu {
    position: fixed;
    display: none;
    flex-direction: column;
    background: linear-gradient(135deg, #0f1923 0%, #1a2a3a 100%);
    border: 1px solid #2e3d4d;
    border-radius: 10px;
    padding: 8px;
    z-index: 3000;
    min-width: 190px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.context-menu.visible { display: flex; }

.context-coords {
    font-size: 11px;
    color: #90caf9;
    font-weight: 700;
    padding: 5px 10px 8px;
    border-bottom: 1px solid #1e2d3d;
    margin-bottom: 6px;
}

.context-menu button {
    background: transparent;
    border: none;
    color: #ccc;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    transition: all 0.2s;
}
.context-menu button:hover { 
    background: #1e2d3d; 
    color: #fff;
    transform: translateX(2px);
}

.context-divider {
    border: none;
    border-top: 1px solid #1e2d3d;
    margin: 5px 0;
}

/* ─── Modal ─── */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(4px);
}
.modal-content {
    background: linear-gradient(135deg, #0f1923 0%, #1a2a3a 100%);
    margin: 8% auto;
    padding: 24px;
    border-radius: 14px;
    width: 90%;
    max-width: 620px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.5);
    border: 1px solid #1e2d3d;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid #1e3a5f;
}
.modal-header h2 { color: #90caf9; font-size: 17px; font-weight: 700; }
.close { font-size: 26px; font-weight: bold; color: #546e7a; cursor: pointer; transition: color 0.2s; }
.close:hover { color: #eee; }

/* ─── Building Options ─── */
.building-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}
.building-option {
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    border: 2px solid #1e3a5f;
    border-radius: 10px;
    padding: 18px 12px;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.building-option:hover { 
    border-color: #667eea; 
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}
.building-preview {
    width: 54px;
    height: 54px;
    border-radius: 6px;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.rss-tile-preview   { background: #4169E1; }
.warehouse-preview  { background: #9370DB; }
.dead-spot-preview  { background: #607D8B; }
.building-option span  { font-weight: 600; color: #e0e8f8; font-size: 13px; text-align: center; }
.building-option small { color: #546e7a; font-size: 11px; text-align: center; }
.building-option.disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ─── Player Options ─── */
.player-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    max-height: 440px;
    overflow-y: auto;
}
.player-option {
    background: linear-gradient(135deg, #1a2a3a 0%, #1e3a5f 100%);
    border: 2px solid #1e3a5f;
    border-radius: 10px;
    padding: 16px 12px;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    position: relative;
}
.player-option:hover { 
    border-color: #667eea; 
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}
.player-option .player-preview {
    border-radius: 6px;
    border: 2px solid rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    font-size: 11px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.player-option .player-preview.size-2x2 { background: #FFD700; width: 48px; height: 48px; }
.player-option .player-preview.size-3x3 { background: #FFA500; width: 70px; height: 70px; }
.player-option .player-name  { font-weight: 600; color: #e0e8f8; font-size: 13px; text-align: center; }
.player-option .player-size  { color: #546e7a; font-size: 11px; }

/* Edit / Delete buttons on player cards */
.player-option .edit-player-btn,
.player-option .delete-player-btn {
    position: absolute;
    top: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.25s;
    z-index: 10;
}
.player-option:hover .edit-player-btn,
.player-option:hover .delete-player-btn { opacity: 1; }
.player-option .edit-player-btn   { left: 8px;  background: #1565c0; color: #fff; }
.player-option .delete-player-btn { right: 8px; background: #c62828; color: #fff; }
.player-option .edit-player-btn:hover   { background: #1976d2; transform: scale(1.1); }
.player-option .delete-player-btn:hover { background: #d32f2f; transform: scale(1.1); }

/* ─── Modal Actions ─── */
.modal-actions {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid #1e2d3d;
}
.delete-all-btn {
    background: linear-gradient(135deg, #c62828 0%, #d32f2f 100%);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.25s;
}
.delete-all-btn:hover { 
    background: linear-gradient(135deg, #d32f2f 0%, #e53935 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(211, 47, 47, 0.3);
}

/* ─── Empty State ─── */
.empty-state { text-align: center; color: #546e7a; font-style: italic; font-size: 12px; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: #0f1923; }
::-webkit-scrollbar-thumb { background: #2e3d4d; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3e4d5d; }

/* ═══════════════════════════════════════════════════════════════════════════════
   MOBILE SUPPORT  (≤ 768px)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── Mobile bottom action bar ─── */
.mobile-action-bar {
    display: none;
}

@media (max-width: 768px) {

    /* ─── Body / container ─── */
    body {
        overflow: hidden;
        overscroll-behavior: none;
    }

    /* ─── Header ─── */
    header {
        padding: 8px 12px;
    }
    .header-left h1 {
        font-size: 14px;
    }
    .header-btn {
        padding: 7px 12px;
        font-size: 12px;
    }
    .toggle-menu-btn {
        padding: 7px 12px;
        font-size: 18px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Hide navigation on mobile */
    .header-nav {
        display: none;
    }

    /* ─── Control panel becomes a slide-over drawer ─── */
    .control-panel {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 300px !important;
        min-width: 300px !important;
        z-index: 500;
        transform: translateX(-100%);
        transition: transform 0.3s ease, opacity 0.25s ease;
        opacity: 1;
        box-shadow: 6px 0 32px rgba(0,0,0,0.7);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .control-panel.mobile-open {
        transform: translateX(0);
    }
    .control-panel.collapsed {
        width: 300px !important;
        min-width: 300px !important;
        opacity: 1;
        transform: translateX(-100%);
    }
    .control-panel.collapsed.mobile-open {
        transform: translateX(0);
    }

    /* Backdrop when drawer is open */
    .mobile-drawer-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 499;
    }
    .mobile-drawer-backdrop.visible {
        display: block;
    }

    /* ─── Grid container fills remaining space ─── */
    main {
        flex-direction: column;
    }
    .grid-container {
        flex: 1;
        width: 100%;
        touch-action: none;
    }

    /* ─── Touch-friendly tap targets ─── */
    .primary-btn, .secondary-btn, .add-btn,
    .import-btn, .reset-btn, .delete-all-btn {
        min-height: 48px;
        font-size: 14px;
        padding: 12px 18px;
    }
    .zoom-btn {
        min-width: 48px;
        min-height: 48px;
        font-size: 18px;
    }
    .manual-add input,
    .manual-add select,
    .import-section input,
    .import-section textarea,
    .alliance-city-config select {
        min-height: 44px;
        font-size: 14px;
        padding: 10px;
    }
    .item-remove {
        min-width: 40px;
        min-height: 40px;
        font-size: 14px;
        padding: 6px 10px;
    }

    /* ─── Modals: full-screen on mobile ─── */
    .modal-content {
        margin: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .modal {
        align-items: stretch;
        display: none;
    }
    .modal[style*="block"] {
        display: flex !important;
        flex-direction: column;
    }
    .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 14px;
    }
    .modal-header {
        padding: 14px 18px;
        flex-shrink: 0;
    }
    .close {
        font-size: 32px;
        padding: 6px 10px;
        min-width: 48px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ─── Player options: 2-column grid on mobile ─── */
    .player-options {
        grid-template-columns: repeat(2, 1fr);
        max-height: none;
    }
    .player-option {
        padding: 14px 10px;
    }
    /* Always show edit/delete buttons on mobile (no hover) */
    .player-option .edit-player-btn,
    .player-option .delete-player-btn {
        opacity: 1;
        width: 30px;
        height: 30px;
        font-size: 14px;
    }

    /* ─── Building options: single column on very small screens ─── */
    .building-options {
        grid-template-columns: repeat(2, 1fr);
    }
    .building-option {
        padding: 16px 10px;
    }

    /* ─── Context menu: larger touch targets ─── */
    .context-menu {
        min-width: 210px;
    }
    .context-menu button {
        padding: 14px 16px;
        font-size: 15px;
    }

    /* ─── Mobile bottom action bar ─── */
    .mobile-action-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: linear-gradient(135deg, #0f1923 0%, #1a2a3a 100%);
        border-top: 1px solid #1e2d3d;
        padding: 8px 10px;
        gap: 8px;
        z-index: 400;
        box-shadow: 0 -6px 24px rgba(0,0,0,0.5);
    }
    .mobile-action-bar button {
        flex: 1;
        padding: 12px 6px;
        border: none;
        border-radius: 10px;
        font-size: 11px;
        font-weight: 700;
        cursor: pointer;
        color: #fff;
        min-height: 52px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        transition: filter 0.2s;
    }
    .mobile-action-bar button:active { filter: brightness(1.3); }
    .mobile-action-bar .mob-btn-icon { font-size: 20px; line-height: 1; }
    .mob-add-player  { background: linear-gradient(135deg, #667eea, #764ba2); }
    .mob-add-building{ background: #1e3a5f; border: 1px solid #2e5a8f !important; }
    .mob-reset-view  { background: #1a2a3a; border: 1px solid #2e3d4d !important; }
    .mob-menu-toggle { background: #2a3a4a; border: 1px solid #3a4a5a !important; }

    /* Push grid container up so bottom bar doesn't cover it */
    .grid-container {
        padding-bottom: 72px;
    }

    /* ─── Long-press visual feedback ─── */
    .grid-cell.long-press-active {
        background: rgba(255, 235, 59, 0.4) !important;
        transition: background 0.15s;
    }

    /* ─── Placed list: larger remove buttons ─── */
    .placed-list {
        max-height: 180px;
    }
    .placed-item {
        padding: 10px 12px;
    }

    /* ─── Panel inner padding ─── */
    .panel-inner {
        padding: 14px;
        padding-bottom: 88px;
    }
}

/* Very small phones */
@media (max-width: 380px) {
    .header-left h1 { font-size: 12px; }
    .player-options { grid-template-columns: 1fr; }
    .building-options { grid-template-columns: 1fr; }
    .mobile-action-bar button { font-size: 10px; }
    .mob-btn-icon { font-size: 18px !important; }
}