/* ─────────────────────────────────────────────────────────────
   Rally Planner - Alliance Tools style
   ───────────────────────────────────────────────────────────── */

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

:root {
    --bg:           #0a0f1e;
    --bg2:          #0f1829;
    --bg3:          #141f35;
    --panel:        #0b1220;
    --panel-border: #1e2d3d;
    --card:         #1a2a4a;
    --card2:        #0e1a2e;
    --card-hover:   #1f3360;
    --border:       #2a4a7a;
    --accent:       #4a9eff;
    --accent2:      #ffd700;
    --forge-color:  #ff9800;
    --civ-color:    #4fc3f7;
    --danger:       #e53935;
    --success:      #43a047;
    --text:         #e0e8f8;
    --text-muted:   #7a9cc8;
    --radius:       8px;
    --tr:           0.18s ease;
    --header-h:     48px;
}

html, body {
    height: 100%;
    overflow: hidden; /* prevent outer scroll */
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ── Page wrapper ─────────────────────────────────────────── */
.page-wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────── */
header {
    height: var(--header-h);
    min-height: var(--header-h);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg2);
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    z-index: 100;
    flex-shrink: 0;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
}
.logo-icon { font-size: 18px; }

.header-sep {
    color: var(--border);
    font-size: 18px;
}

.header-title {
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    opacity: 0.85;
}

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

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 13px;
    transition: background var(--tr), color var(--tr);
}
.nav-link:hover { color: var(--text); background: var(--bg3); }
.nav-link.active { background: var(--accent); color: #fff; pointer-events: none; }

/* ── App body: 3-column layout ────────────────────────────── */
.app-body {
    flex: 1;
    display: flex;
    min-height: 0;        /* critical for flex children to scroll */
    overflow: hidden;
}

/* ── Panels (left + right) ────────────────────────────────── */
.panel {
    width: 280px;
    min-width: 240px;
    max-width: 280px;
    background: var(--panel);
    border-color: var(--panel-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.panel-left  { border-right: 1px solid var(--panel-border); }
.panel-right { border-left:  1px solid var(--panel-border); }

.panel-inner {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 20px;
}

.panel-title {
    color: #90caf9;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 14px;
    padding-bottom: 6px;
    border-bottom: 2px solid #1e3a5f;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ── Center area ──────────────────────────────────────────── */
.center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: radial-gradient(ellipse at center, #0d1520 0%, #050910 100%);
    gap: 0;
}

/* ── Slots section (fixed height, no scroll) ──────────────── */
.slots-section {
    flex-shrink: 0;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(0,0,0,0.2);
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    margin-bottom: 10px;
}

.item-count {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.slots-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.slot-card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 10px 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 72px;
    transition: background var(--tr), border-color var(--tr),
                box-shadow var(--tr), transform var(--tr);
    position: relative;
}
.slot-card:hover {
    background: var(--card-hover);
    border-color: var(--accent);
    box-shadow: 0 4px 14px rgba(0,0,0,0.5);
    transform: translateY(-1px);
}
.slot-card.has-item { border-color: #3a6a9a; }

.slot-name {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 600;
}
.slot-gear-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}
.slot-empty {
    font-size: 11px;
    color: #455a64;
    font-style: italic;
}
.slot-stats {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 2px;
}
.slot-category {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.slot-category.forge        { background: rgba(255,152,0,0.15); color: var(--forge-color); border: 1px solid rgba(255,152,0,0.3); }
.slot-category.civilization { background: rgba(79,195,247,0.12); color: var(--civ-color);   border: 1px solid rgba(79,195,247,0.25); }

/* ── Library section (scrollable) ────────────────────────── */
.library-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 12px 16px 14px;
    overflow: hidden;
}

.items-list {
    flex: 1;
    overflow-y: auto;
    border-radius: var(--radius);
    background: var(--card2);
    border: 1px solid #1a2838;
    min-height: 0;
}

/* ── Item cards ───────────────────────────────────────────── */
.item-card {
    padding: 9px 12px;
    border-bottom: 1px solid #1a2838;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    transition: background var(--tr);
}
.item-card:last-child { border-bottom: none; }
.item-card:hover { background: rgba(74,158,255,0.1); }

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}
.item-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}
.item-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}
.item-star {
    font-size: 12px;
    white-space: nowrap;
    padding: 2px 7px;
    border-radius: 999px;
    font-weight: 600;
    flex-shrink: 0;
}
.item-star.forge { color: var(--forge-color); border: 1px solid rgba(255,152,0,0.4); background: rgba(255,152,0,0.08); }
.item-star.civ   { color: var(--civ-color);   border: 1px solid rgba(79,195,247,0.35); background: rgba(79,195,247,0.07); }

.item-buffs {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ── Controls (left panel) ────────────────────────────────── */
.control-group { margin-bottom: 14px; }

.control-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.1px;
    color: #78909c;
    margin-bottom: 5px;
    font-weight: 600;
}

.text-input, .select-input {
    width: 100%;
    padding: 7px 9px;
    border-radius: 6px;
    border: 1px solid #2e3d4d;
    background: #060e1c;
    color: var(--text);
    font-size: 13px;
    transition: border-color var(--tr), box-shadow var(--tr);
}
.text-input:focus, .select-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(74,158,255,0.25);
}

.primary-btn, .secondary-btn {
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 5px;
    transition: background var(--tr), transform var(--tr), box-shadow var(--tr);
}
.primary-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}
.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.secondary-btn {
    background: #1a2535;
    color: #cfd8dc;
    border: 1px solid #2e3d4d;
}
.secondary-btn:hover { background: #243040; }
.danger-btn {
    background: #1a1010;
    color: #ef9a9a;
    border: 1px solid #4e1c1c;
    width: 100%;
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.danger-btn:hover { background: #2d1010; border-color: #c62828; color: #ef5350; }

/* ── Right panel: Summary ─────────────────────────────────── */

/* Summary tab bar */
.summary-tab-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.summary-tab-btn {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #1a2535;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.summary-tab-btn:hover {
    background: #131f30;
    border-color: #2a3a4f;
}
.summary-tab-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Crafting list panel */
#craftingPanel,
#craftingPanelMobile {
    font-size: 12px;
    color: var(--text-muted);
}
.crafting-item-block {
    margin-bottom: 14px;
    padding: 10px;
    background: #0d1825;
    border: 1px solid #1a2535;
    border-radius: 8px;
    overflow: hidden;
}
.crafting-slot-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #546e7a;
    margin-bottom: 4px;
}
.crafting-path {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-size: 11px;
    color: var(--text);
    font-weight: 500;
    line-height: 1.6;
}
.crafting-path-step {
    white-space: nowrap;
}
.crafting-path-step.current {
    color: var(--accent2);
    font-weight: 700;
}
.crafting-path-arrow {
    color: var(--text-muted);
    font-size: 10px;
}
.crafting-materials {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}
.crafting-mat-row {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    padding: 2px 0;
    border-bottom: 1px solid #111c2a;
}
.crafting-mat-name {
    color: var(--text-muted);
}
.crafting-mat-qty {
    color: var(--text);
    font-weight: 600;
}
.crafting-start-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.crafting-start-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #546e7a;
    white-space: nowrap;
}
.crafting-start-select {
    flex: 1;
    min-width: 0;
    font-size: 11px;
    padding: 3px 6px;
    border-radius: 4px;
    border: 1px solid #1a2535;
    background: #111c2a;
    color: var(--text);
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
}
.crafting-start-select:focus {
    outline: none;
    border-color: var(--accent2);
}

#summaryPanel {
    font-size: 12px;
    color: var(--text-muted);
}

.summary-equipped-list {
    list-style: none;
    margin-bottom: 12px;
}
.summary-equipped-list li {
    padding: 5px 0;
    border-bottom: 1px solid #1a2535;
    font-size: 12px;
    line-height: 1.4;
}
.summary-equipped-list li:last-child { border-bottom: none; }

.summary-slot-name {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #546e7a;
    display: block;
}
.summary-item-name {
    color: var(--text);
    font-weight: 600;
    font-size: 12px;
}
.summary-item-buffs {
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 2px;
    line-height: 1.5;
}

/* Set bonus section */
.set-bonus-section {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #1e2d3d;
}
.set-bonus-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #546e7a;
    margin-bottom: 8px;
    font-weight: 700;
}
.set-bonus-group {
    margin-bottom: 10px;
}
.set-bonus-set-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.set-bonus-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    font-size: 11px;
}
.set-bonus-row.active  { color: #a5d6a7; }
.set-bonus-row.inactive{ color: #455a64; }
.set-bonus-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 999px;
    font-weight: 700;
}
.set-bonus-badge.active   { background: rgba(67,160,71,0.2);  color: #a5d6a7; border: 1px solid rgba(67,160,71,0.4); }
.set-bonus-badge.inactive { background: rgba(69,90,100,0.2);  color: #546e7a; border: 1px solid rgba(69,90,100,0.3); }

/* Set bonus buff lines */
.set-bonus-buffs {
    margin: 2px 0 6px 24px;
    border-left: 2px solid rgba(255,255,255,0.06);
    padding-left: 8px;
}
.set-bonus-buffs.active-buffs   { border-left-color: rgba(67,160,71,0.3); }
.set-bonus-buffs.inactive-buffs { border-left-color: rgba(69,90,100,0.3); opacity: 0.75; }
.set-bonus-buffs.collapsed      { display: none; }

/* Clickable set bonus rows */
.sb-toggle-row { user-select: none; border-radius: 4px; padding: 3px 4px; margin: 0 -4px; }
.sb-toggle-row:hover { background: rgba(255,255,255,0.04); }
.set-bonus-row.active.sb-toggle-row:hover  { background: rgba(67,160,71,0.08); }
.set-bonus-row.inactive.sb-toggle-row:hover{ background: rgba(69,90,100,0.12); }
.sb-chevron { font-size: 9px; flex-shrink: 0; }

/* Star rating edit button on slot cards */
.star-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    color: var(--accent2);
    cursor: pointer;
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid rgba(255,193,7,0.25);
    background: rgba(255,193,7,0.07);
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    user-select: none;
}
.star-edit-btn:hover { background: rgba(255,193,7,0.18); border-color: rgba(255,193,7,0.5); }

/* Star picker popover */
.star-picker {
    display: none;
    position: absolute;
    z-index: 200;
    background: #0d1b2a;
    border: 1px solid #1e3a5f;
    border-radius: 6px;
    padding: 6px;
    gap: 4px;
    flex-wrap: wrap;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    margin-top: 4px;
}
.star-picker.visible { display: flex; }
.star-option {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    color: #78909c;
    border: 1px solid transparent;
    white-space: nowrap;
    transition: background 0.12s;
}
.star-option:hover  { background: rgba(255,193,7,0.15); color: var(--accent2); border-color: rgba(255,193,7,0.3); }
.star-option.active { background: rgba(255,193,7,0.2);  color: var(--accent2); border-color: rgba(255,193,7,0.5); font-weight: 700; }

/* Make slot-gear-name relative for picker positioning */
.slot-gear-name { position: relative; }

/* Buff breakdown in summary */
.buff-breakdown {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #1e2d3d;
}
.buff-breakdown-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #546e7a;
    margin-bottom: 8px;
    font-weight: 700;
}
.buff-context-group {
    margin-bottom: 10px;
}
.buff-context-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 4px;
    font-weight: 600;
}
.buff-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    font-size: 11px;
    border-bottom: 1px solid #0e1a2e;
}
.buff-line:last-child { border-bottom: none; }
.buff-line-label { color: var(--text-muted); }
.buff-line-value { color: #a5d6a7; font-weight: 700; font-size: 12px; }
.buff-line-value.negative { color: #ef5350; }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 24px 10px;
    font-size: 12px;
    color: #455a64;
}

/* ── Import Modal ────────────────────────────────────────── */
.import-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 4999;
}
.import-modal-backdrop.open { display: block; }

.import-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 380px);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    z-index: 5000;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.import-modal.open { display: block; }

.import-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--panel-border);
}
.import-modal-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
}
.import-modal-body {
    padding: 14px 16px;
}
.import-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.5;
}
.import-desc strong {
    color: var(--accent);
}
.import-source-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}
.import-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    flex-shrink: 0;
}
.import-source-select {
    flex: 1;
    min-width: 0;
}
.import-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
    padding: 10px 12px;
    background: var(--card2);
    border-radius: 6px;
    border: 1px solid #1a2535;
}
.import-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
}
.import-check input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
}
.import-check.disabled {
    opacity: 0.35;
    pointer-events: none;
}
.import-warning {
    font-size: 11px;
    color: #e8a030;
    margin-bottom: 10px;
    min-height: 14px;
}
.import-actions {
    display: flex;
    gap: 8px;
}
.import-actions .primary-btn,
.import-actions .secondary-btn {
    flex: 1;
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e3a5f;
    color: #fff;
    padding: 7px 18px;
    border-radius: 999px;
    font-size: 13px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.5);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    white-space: nowrap;
}

/* ── Scrollbars ───────────────────────────────────────────── */
.panel-inner::-webkit-scrollbar,
.items-list::-webkit-scrollbar,
#summaryPanel::-webkit-scrollbar {
    width: 5px;
}
.panel-inner::-webkit-scrollbar-thumb,
.items-list::-webkit-scrollbar-thumb,
#summaryPanel::-webkit-scrollbar-thumb {
    background: #2e3d4d;
    border-radius: 3px;
}
.panel-inner::-webkit-scrollbar-track,
.items-list::-webkit-scrollbar-track,
#summaryPanel::-webkit-scrollbar-track {
    background: transparent;
}
.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);
}
/* Hide desktop donate button on mobile */
@media (max-width: 768px) {
  .kofi-header-btn { display: none !important; }
}

/* Hide drawer donate link on desktop */
@media (min-width: 769px) {
  .kofi-drawer-link { display: none !important; }
}


.kofi-header-btn {
  background: #0a1628;
  color: #a0c4ff;
}
.kofi-header-btn:hover {
  background: #2a4a7a;
  color: #fff;
}

.kofi-logo {
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Make sure the header button and drawer link align icon+text nicely */
.kofi-header-btn,
.kofi-drawer-link {
  display: flex;
  align-items: center;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1100px) {
    .slots-grid { grid-template-columns: repeat(3, 1fr); }
    .panel { width: 240px; min-width: 200px; }
}

@media (max-width: 860px) {
    html, body { overflow: auto; }
    .page-wrapper { height: auto; overflow: visible; }
    .app-body {
        flex-direction: column;
        overflow: visible;
    }
    .panel {
        width: 100%;
        max-width: 100%;
        border: none;
        border-bottom: 1px solid var(--panel-border);
    }
    .panel-inner { overflow: visible; }
    .center-area { overflow: visible; }
    .library-section { min-height: 400px; }
    .items-list { min-height: 300px; }
    .slots-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 500px) {
    header { padding: 0 12px; }
    .slots-grid { grid-template-columns: repeat(2, 1fr); }
    .nav-link { padding: 4px 7px; font-size: 12px; }
}

/* ============================================================
   MOBILE APP UX (no full-page scroll; internal scroll windows)
   ============================================================ */

.mobile-tools-btn,
.mobile-tabs,
.mobile-drawer,
.mobile-drawer-backdrop,
.mobile-sheet,
.mobile-sheet-backdrop {
  display: none;
}

@media (max-width: 860px) {
  /* Restore "no outer scroll" on mobile (you currently turn it on) */
  html, body { height: 100%; overflow: hidden !important; }
  .page-wrapper { height: 100dvh; overflow: hidden; }

  /* Header remains fixed height; main app uses remaining height */
  header { flex-shrink: 0; }

  /* Show mobile header button + tabs */
  .mobile-tools-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid #2a4a7a;
    background: #0a1628;
    color: #a0c4ff;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
    flex-shrink: 0;
  }
  .mobile-tab {
    border: 1px solid #2a4a7a;
    background: #0a1628;
    color: #a0c4ff;
    border-radius: 10px;
    padding: 10px 8px;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
  }
  .mobile-tab.is-active {
    background: #2a4a7a;
    color: #fff;
  }

  /* App body becomes a single "view host" (no giant scroll) */
  .app-body {
    flex-direction: row;  /* doesn’t matter much; we’ll hide panels per-view */
    overflow: hidden;
    min-height: 0;
  }

  /* Hide desktop left/right panels on mobile (they move to drawer / tab) */
  .panel-left,
  .panel-right {
    display: none !important;
  }

  /* Center area becomes the view host; we will toggle subviews */
  .center-area {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  /* Build view = slots + (optional) small help; keep slots scrollable if needed */
  .slots-section {
    flex-shrink: 0;
  }

  /* Library section becomes its own scroll window depending on view state */
  .library-section {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* Internal scroll is already on .items-list */
  .items-list { min-height: 0; }

  /* ---- Drawer ---- */
  .mobile-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
    z-index: 3000;
  }
  .mobile-drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(88vw, 380px);
    background: var(--panel);
    border-right: 1px solid var(--panel-border);
    transform: translateX(-102%);
    transition: transform .18s ease;
    z-index: 3001;
  }
  .mobile-drawer.is-open { transform: translateX(0); }

  .mobile-drawer-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid var(--panel-border);
    background: var(--bg2);
    flex-shrink: 0;
  }
  .mobile-drawer-title {
    font-weight: 900;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #90caf9;
    font-size: 12px;
  }
  .mobile-drawer-body {
    min-height: 0;
    overflow: auto;
    padding: 12px;
  }

  /* ---- Bottom Sheet ---- */
  .mobile-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
    z-index: 4000;
  }
  .mobile-sheet-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: min(86dvh, 780px);
    background: var(--bg2);
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
    border-top: 1px solid #2a4a7a;
    transform: translateY(105%);
    transition: transform .18s ease;
    z-index: 4001;
    overflow: hidden;
  }
  .mobile-sheet.is-open { transform: translateY(0); }

  .mobile-sheet-header {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display:flex;
    align-items:flex-start;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
  }
  .mobile-sheet-title { font-weight: 900; font-size: 13px; color: var(--text); }
  .mobile-sheet-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

  .mobile-sheet-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
  }
  .mobile-pill-btn {
    border: 1px solid #2a4a7a;
    background: #0a1628;
    color: #a0c4ff;
    border-radius: 999px;
    padding: 8px 10px;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
  }

  .mobile-sheet-body {
    min-height: 0;
    overflow: hidden;
    padding: 10px 12px 12px;
  }
  .mobile-sheet-items {
    height: 100%;
    min-height: 0;
    overflow: auto;
    border-radius: var(--radius);
  }

  .mobile-icon-btn {
    border: 1px solid #2a4a7a;
    background: #0a1628;
    color: #a0c4ff;
    border-radius: 10px;
    padding: 8px 10px;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
  }

  /* Hide the desktop library when in "Build" or "Summary" views via JS class */
  .center-area.view-build .library-section { display: none; }
  .center-area.view-library .library-section { display: flex; }
  .center-area.view-library .slots-section { display: none; }

  /* Summary view: we will show the RIGHT panel content as a view */
  .mobile-summary-view {
    display: none;
    height: 100%;
    overflow: auto;
    padding: 12px 12px 16px;
  }
  .center-area.view-summary .slots-section,
  .center-area.view-summary .library-section { display: none; }
  .center-area.view-summary .mobile-summary-view { display: block !important; }
}
@media (max-width: 860px) {
  .tools-fab {
    position: fixed;
    right: 14px;
    bottom: 14px;
    width: 54px;
    height: 54px;
    border-radius: 999px;
    border: 1px solid #2a4a7a;
    background: linear-gradient(135deg, #0a1628, #1a2a4a);
    color: #a0c4ff;
    display: grid;
    place-items: center;
    z-index: 5000; /* above tabs and content */
    box-shadow: 0 10px 22px rgba(0,0,0,.45);
    cursor: pointer;
  }
  .tools-fab:active { transform: translateY(1px); }
  .tools-fab-icon { font-size: 20px; line-height: 1; }

  /* Make sure toast doesn't overlap too badly */
  .toast { bottom: 84px; }
}

@media (min-width: 861px) {
  .tools-fab { display: none; }
  .mobile-summary-view { display: none !important; }
}
.mobile-sheet-filters {
  padding: 10px 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  background: rgba(0,0,0,.12);
}

.mobile-sheet-filters.collapsed { display: none; }

.sheet-filter-row { margin-bottom: 10px; }
.sheet-filter-row:last-child { margin-bottom: 0; }
.tools-fab.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .15s ease, transform .15s ease;
}

/* Hamburger button */
.toggle-menu-btn{
  background: #1a2a4a;
  color: #a0c4ff;
  border: 1px solid #2a4a7a;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.toggle-menu-btn:hover{
  background:#2a4a7a;
  color:#fff;
}

/* Site nav panel */
.site-nav-panel{
  position: fixed;
  top: var(--header-h);
  left: 0;
  height: calc(100dvh - var(--header-h));
  width: min(86vw, 340px);
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  transform: translateX(-105%);
  transition: transform .18s ease;
  z-index: 3500;
  overflow: hidden;
}
.site-nav-panel.open{
  transform: translateX(0);
}

.site-nav-links .drawer-link{
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  font-weight: 700;
  margin-bottom: 8px;
}
.site-nav-links .drawer-link:hover{
  background: var(--bg3);
}
.site-nav-links .drawer-link.active{
  background: rgba(74,158,255,0.12);
  color: var(--accent);
}

/* Clean up header row on mobile */
@media (max-width: 860px){
  .header-right{ display:none !important; } /* hide desktop nav links */
}

@media (max-width: 860px) {
  #sheetSlotFilter,
  label[for="sheetSlotFilter"] {
    display: none !important;
  }
}

.mobile-library-toolbar,
.mobile-library-filters { display: none; }

@media (max-width: 860px) {
  .mobile-library-toolbar,
  .mobile-library-filters { display: block; }

  .mobile-library-toolbar { margin-bottom: 8px; }
  .mobile-library-filters.collapsed { display: none; }
}




#siteFooter{
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg2);
}
#siteFooter a{
  color: var(--text-muted);
  text-decoration: none;
}
#siteFooter a:hover{ color: var(--text); text-decoration: underline; }

@media (max-width: 860px){
  #siteFooter{ display:none !important; }
}

/* ═══════════════════════════════════════════════════════════
   RALLY PLANNER
   ═══════════════════════════════════════════════════════════ */

/* ── Rally Toolbar ────────────────────────────────────────── */
.rally-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    background: var(--bg2);
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}
.mode-toggle {
    display: flex;
    gap: 4px;
}
.mode-btn {
    padding: 5px 18px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}
.mode-btn:hover {
    background: var(--bg3);
    color: var(--text);
}
.mode-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.toolbar-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-left: auto;
}
.toolbar-btn {
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.toolbar-btn:hover {
    background: var(--bg3);
    color: var(--text);
    border-color: var(--accent);
}
.rally-pdf-btn {
    width: auto;
    padding: 5px 12px;
    font-size: 12px;
    margin-top: 0 !important;
}
.rally-pdf-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}
.rally-reset-btn {
    width: auto;
    padding: 5px 12px;
}

/* ── Save Dialog ─────────────────────────────────────────── */
.save-dialog-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
.save-dialog-backdrop.open { display: block; }
.save-dialog {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    width: 340px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.save-dialog.open { display: block; }
.save-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--panel-border);
}
.save-dialog-title {
    font-weight: 800;
    font-size: 14px;
    color: var(--text);
}
.save-dialog-body {
    padding: 14px 16px 16px;
}
.save-filename-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    margin-bottom: 14px;
}
.save-filename-row .text-input {
    flex: 1;
    min-width: 0;
}
.save-ext {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}
.save-dialog-actions {
    display: flex;
    gap: 8px;
}
.save-dialog-actions .primary-btn,
.save-dialog-actions .secondary-btn {
    flex: 1;
    margin-top: 0 !important;
}

/* ── Rally Layout ─────────────────────────────────────────── */
.rally-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
.rally-right {
    width: 420px;
    min-width: 340px;
    background: var(--panel);
    border-left: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 14px;
    flex-shrink: 0;
}

/* ── Map Section ──────────────────────────────────────────── */
.map-section {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at center, #0d1520 0%, #050910 100%);
    display: flex;
}

/* ── Map Legend Panel (inside the map block) ──────────────── */
.map-legend-panel {
    width: 28%;
    min-width: 160px;
    max-width: 260px;
    flex-shrink: 0;
    background: var(--panel);
    border-left: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    overflow: hidden;
    z-index: 5;
}
.map-legend-panel .panel-title {
    flex-shrink: 0;
}
.map-legend-panel .panel-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.map-viewport {
    flex: 1;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    position: relative;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
.map-viewport.panning {
    cursor: grabbing;
}
.map-container {
    position: absolute;
    line-height: 0;
    transform-origin: 0 0;
}
.map-bg {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 340px);
    border-radius: 4px;
}
.map-icons {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    object-fit: contain;
}

/* ── Map Floating Button & Zoom Controls ─────────────────── */
.map-fab {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 15;
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: rgba(5,10,20,0.85);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    backdrop-filter: blur(6px);
}
.map-fab:hover {
    background: var(--accent);
    color: #fff;
}
.map-fab.map-save-btn {
    top: 44px;
}
.map-zoom-controls {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 15;
    display: flex;
    gap: 4px;
}
.map-zoom-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid #2a3a4a;
    background: rgba(5,10,20,0.85);
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s;
    backdrop-filter: blur(6px);
    line-height: 1;
}
.map-zoom-btn:hover {
    background: var(--bg3);
    border-color: var(--accent);
}
.map-zoom-reset {
    font-size: 14px;
}
/* ── SvS / Throne Mode Layout ────────────────────────────── */
/* Grid becomes the main panel (filling where the map was),
   role legend fills the entire bottom panel row.             */
.svs-mode .rally-left {
    flex: 1;
}
.svs-mode .map-section {
    display: none !important;
}
.svs-mode .map-legend-panel {
    display: none !important;
}
.svs-mode .bottom-panels {
    flex: 1;
    flex-direction: column;
    height: auto;
    min-height: 0;
}
.svs-mode .bpanel-grid {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.svs-mode .hive-grid-row {
    flex: 1;
    min-height: 0;
}
.svs-mode .hive-grid-wrap {
    flex: 1;
    min-height: 0;
}
.svs-mode .role-legend {
    flex: 0 0 auto;
    min-width: 160px;
    border-left: 1px solid var(--panel-border);
    padding-left: 12px;
}

/* ── Map Markers (building icons) ─────────────────────────── */
.map-markers {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.map-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    cursor: grab;
    user-select: none;
}
.map-marker:hover .map-marker-box {
    border-color: #fff;
    box-shadow: 0 0 8px rgba(74,158,255,0.5);
}
.map-marker.dragging {
    cursor: grabbing;
    z-index: 20;
    opacity: 0.85;
}
.map-marker-box {
    width: 26px;
    height: 26px;
    border: 2px solid var(--accent);
    border-radius: 4px;
    background: rgba(5,10,20,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    transition: border-color 0.12s, box-shadow 0.12s;
}
.map-marker.active .map-marker-box {
    border-color: var(--accent2);
    box-shadow: 0 0 10px rgba(255,180,50,0.5);
}


/* ── Bottom Panels ────────────────────────────────────────── */
.bottom-panels {
    display: flex;
    height: 220px;
    min-height: 150px;
    border-top: 1px solid var(--panel-border);
    flex-shrink: 0;
    background: var(--panel);
}
.bottom-panel {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    overflow: hidden;
}
.bottom-panel + .bottom-panel {
    border-left: 1px solid var(--panel-border);
}
.bpanel-grid { flex: 1; }

.panel-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* ── Hive Grid (interactive player arrangement) ───────────── */
.grid-mode-label {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
}

/* ── SvS Grid Size Editor ────────────────────────────────── */
.grid-size-edit {
    display: none;
    margin-left: 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--accent);
    position: relative;
    vertical-align: middle;
}
.app-body.svs-mode .grid-size-edit {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.grid-size-toggle {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
}
.grid-size-text {
    font-weight: 600;
    font-size: 10px;
}
.grid-size-pencil {
    font-size: 11px;
    opacity: 0.7;
    transition: opacity 0.12s;
}
.grid-size-edit:hover .grid-size-pencil {
    opacity: 1;
}
.grid-size-picker {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
    z-index: 200;
    padding: 4px;
    gap: 3px;
    flex-direction: row;
}
.grid-size-picker.open {
    display: flex;
}
.grid-size-opt {
    padding: 5px 12px;
    border: 1px solid #1e2d3d;
    border-radius: 4px;
    background: var(--card2);
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.12s;
    white-space: nowrap;
}
.grid-size-opt:hover {
    background: rgba(74,158,255,0.15);
    border-color: var(--accent);
}
.grid-size-opt.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.bpanel-grid {
    position: relative;
}
.hive-grid-row {
    flex: 1;
    display: flex;
    gap: 8px;
    min-height: 0;
    overflow: hidden;
}
.hive-grid-wrap {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.hive-grid {
    display: grid;
    gap: 3px;
    width: 100%;
    height: 100%;
}

/* ── Role Legend (inside Player Grid panel) ───────────────── */
.role-legend {
    width: 155px;
    flex-shrink: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding-left: 8px;
    border-left: 1px solid #1a2535;
}
.role-legend-title {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 1px;
    flex-shrink: 0;
}
.role-legend-entry {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
}
.role-legend-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.2);
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.12s;
}
.role-legend-swatch:hover {
    border-color: rgba(255,255,255,0.5);
}
.role-legend-select {
    flex: 1;
    min-width: 0;
    padding: 2px 3px;
    border-radius: 3px;
    border: 1px solid #1a2535;
    background: #060e1c;
    color: var(--text);
    font-size: 10px;
}
.role-legend-remove {
    background: none;
    border: none;
    color: #4a5a6a;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.12s;
}
.role-legend-remove:hover { color: var(--danger); }
.role-legend-add {
    font-size: 10px;
    padding: 3px 8px;
    margin-top: 2px;
    width: auto;
    align-self: flex-start;
}
.hive-cell {
    background: #1a2a3a;
    border: 1px solid #2a3d50;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    color: #3a4a5a;
    transition: background 0.12s, border-color 0.12s;
    padding: 1px 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    line-height: 1.2;
    position: relative;
    min-width: 0;
}
.hive-cell:hover {
    border-color: var(--accent);
    filter: brightness(1.3);
}
.hive-cell.assigned {
    border-color: rgba(74,158,255,0.35);
    color: var(--text);
}
.hive-cell .hive-coord {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 7px;
    font-weight: 400;
    color: rgba(255,255,255,0.2);
    pointer-events: none;
}

/* ── Coming Soon Overlay (All-Stars) ─────────────────────── */
.coming-soon-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(5,10,20,0.7);
    z-index: 5;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    pointer-events: none;
}
.coming-soon-overlay.visible {
    display: flex;
}
.coming-soon-text {
    font-size: 18px;
    font-weight: 800;
    color: rgba(255,255,255,0.5);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ── Cell Color Picker ───────────────────────────────────── */
.cell-popup-colors {
    display: flex;
    gap: 5px;
    padding: 6px 10px;
    border-top: 1px solid #1a2535;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
}
.cell-popup-colors-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-right: 2px;
    font-weight: 600;
}
.color-swatch {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.12s, transform 0.1s;
    flex-shrink: 0;
}
.color-swatch:hover {
    transform: scale(1.15);
    border-color: rgba(255,255,255,0.5);
}
.color-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 4px rgba(255,255,255,0.3);
}
.color-swatch.swatch-none {
    background: var(--card2);
    border-color: #3a4a5a;
    position: relative;
}
/* ── Custom Color Picker Popup ────────────────────────────── */
.cp-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 4000;
}
.cp-backdrop.open { display: block; }
.cp-popup {
    display: none;
    position: fixed;
    z-index: 4001;
    width: 200px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    padding: 10px 12px;
    flex-direction: column;
    gap: 8px;
}
.cp-popup.open { display: flex; }
.cp-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.cp-swatches {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}
.cp-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 5px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.1s, transform 0.1s;
}
.cp-swatch:hover {
    transform: scale(1.12);
    border-color: rgba(255,255,255,0.5);
}
.cp-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 6px rgba(255,255,255,0.3);
}
.cp-alpha-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.cp-alpha-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
    width: 46px;
}
.cp-alpha-slider {
    flex: 1;
    min-width: 0;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, transparent, var(--accent));
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}
.cp-alpha-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--accent);
    cursor: pointer;
}
.cp-alpha-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--accent);
    cursor: pointer;
}
.cp-alpha-val {
    font-size: 10px;
    color: var(--text);
    font-weight: 700;
    width: 30px;
    text-align: right;
    flex-shrink: 0;
}
.cp-preview-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.cp-preview-box {
    flex: 1;
    height: 22px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.15);
}

/* ── Cell Popup Role Dropdown ─────────────────────────────── */
.cell-popup-role {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px 2px;
    flex-shrink: 0;
}
.cell-popup-role-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
}
.cell-popup-role-select {
    flex: 1;
    min-width: 0;
    padding: 3px 4px;
    border-radius: 4px;
    border: 1px solid #1a2535;
    background: #060e1c;
    color: var(--text);
    font-size: 11px;
}

.color-swatch.swatch-none::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 14px; height: 2px;
    background: #5a6a7a;
    transform: translate(-50%,-50%) rotate(-45deg);
    border-radius: 1px;
}

/* ── Legend (bottom panel) ────────────────────────────────── */
.legend-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid #1a2535;
    font-size: 12px;
}
.legend-entry:last-child { border-bottom: none; }
.legend-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 22px;
    padding: 0 5px;
    border-radius: 4px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 10px;
    flex-shrink: 0;
}
.legend-badge.throne-badge {
    background: var(--accent2);
    color: #1a1000;
}
.legend-desc {
    color: var(--text);
    flex: 1;
    font-size: 11px;
}
.legend-badges {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}
.legend-entry-edit {
    cursor: pointer;
    transition: background 0.12s;
    border-radius: 4px;
    padding: 3px 4px;
    margin: 0 -4px;
}
.legend-entry-edit:hover {
    background: rgba(74,158,255,0.08);
}
.legend-edit-icon {
    font-size: 11px;
    color: #3a4a5a;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.12s;
}
.legend-entry-edit:hover .legend-edit-icon {
    opacity: 1;
    color: var(--accent);
}
.legend-badge-edit {
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}
.legend-badge-edit:hover {
    transform: scale(1.15);
    box-shadow: 0 0 4px rgba(74,158,255,0.4);
}
.legend-remove {
    background: none;
    border: none;
    color: #5a6a7a;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.12s;
}
.legend-remove:hover { color: var(--danger); }

/* ── Marker Edit Popup ───────────────────────────────────── */
.marker-popup-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 3000;
}
.marker-popup-backdrop.open { display: block; }

.marker-popup {
    display: none;
    position: fixed;
    z-index: 3001;
    width: 280px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    flex-direction: column;
    overflow: hidden;
}
.marker-popup.open { display: flex; }

.marker-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--panel-border);
}
.marker-popup-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}
.marker-popup-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.mp-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.mp-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
}
.mp-hint {
    font-weight: 400;
    font-size: 10px;
    color: #4a5a6a;
}
.mp-input {
    font-size: 12px;
}
.mp-pos-row {
    flex-direction: row;
    gap: 10px;
}
.mp-pos-row > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.mp-pos-input {
    width: 100%;
}
.mp-color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 2px;
}
.mp-color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.1s, transform 0.1s;
}
.mp-color-swatch:hover {
    transform: scale(1.12);
    border-color: rgba(255,255,255,0.5);
}
.mp-color-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 4px rgba(255,255,255,0.3);
}
.mp-color-swatch.mp-swatch-default {
    background: rgba(5,10,20,0.65);
    border-color: #3a4a5a;
    position: relative;
}
.mp-color-swatch.mp-swatch-default::after {
    content: 'D';
    color: #6a7a8a;
    font-size: 9px;
    font-weight: 700;
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mp-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}
.mp-actions .primary-btn,
.mp-actions .danger-btn {
    flex: 1;
    margin-top: 0 !important;
}
.danger-btn {
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--danger);
    background: transparent;
    color: var(--danger);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}
.danger-btn:hover {
    background: var(--danger);
    color: #fff;
}

/* ── Player List (right panel) ────────────────────────────── */
.player-table-wrap {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    margin-top: 10px;
    border-radius: var(--radius);
    border: 1px solid #1a2838;
    background: var(--card2);
}
.player-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}
.player-table th {
    background: var(--bg3);
    color: var(--text-muted);
    padding: 6px 5px;
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}
.player-table td {
    padding: 3px 4px;
    border-bottom: 1px solid #131e2e;
    color: var(--text);
    vertical-align: middle;
}
.player-table tr:last-child td { border-bottom: none; }
.player-table .pt-name {
    font-weight: 600;
    white-space: nowrap;
}
.player-table select,
.player-table input[type="text"] {
    width: 100%;
    padding: 3px 4px;
    border-radius: 4px;
    border: 1px solid #1a2535;
    background: #060e1c;
    color: var(--text);
    font-size: 11px;
}
.player-table select:focus,
.player-table input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(74,158,255,0.2);
}
.pt-remove-btn {
    background: none;
    border: none;
    color: #4a5a6a;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    line-height: 1;
    transition: color 0.12s;
}
.pt-remove-btn:hover { color: var(--danger); }

/* ── Cell Assignment Popup ────────────────────────────────── */
.cell-popup-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 2000;
}
.cell-popup-backdrop.open { display: block; }

.cell-popup {
    display: none;
    position: fixed;
    z-index: 2001;
    width: 220px;
    max-height: 340px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.55);
    flex-direction: column;
    overflow: hidden;
}
.cell-popup.open { display: flex; }

.cell-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}
.cell-popup-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
}
.cell-popup-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
}
.cell-popup-close:hover { color: var(--text); }

.cell-popup-search {
    margin: 8px 8px 4px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #1a2535;
    background: #060e1c;
    color: var(--text);
    font-size: 12px;
    flex-shrink: 0;
}
.cell-popup-search:focus {
    outline: none;
    border-color: var(--accent);
}

.cell-popup-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.cell-popup-player {
    padding: 7px 12px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text);
    transition: background 0.1s;
    border-bottom: 1px solid #0e1a2e;
}
.cell-popup-player:last-child { border-bottom: none; }
.cell-popup-player:hover {
    background: rgba(74,158,255,0.15);
    color: #fff;
}
.cell-popup-empty {
    padding: 16px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}
.cell-popup-clear {
    margin: 6px 8px 8px;
    flex-shrink: 0;
}

/* ── Rally Responsive ─────────────────────────────────────── */
@media (max-width: 1000px) {
    .rally-right { width: 320px; min-width: 280px; }
}
@media (max-width: 860px) {
    /* Rally planner: scrollable stacked layout on mobile */
    html, body { height: auto !important; overflow: auto !important; }
    .page-wrapper {
        height: auto !important;
        overflow: visible !important;
        min-height: 100dvh;
    }
    .app-body {
        flex-direction: column;
        overflow: visible !important;
        min-height: 0;
    }
    .rally-left {
        min-height: auto;
        overflow: visible;
    }
    .rally-right {
        width: 100%;
        min-width: 0;
        border-left: none;
        border-top: 1px solid var(--panel-border);
        max-height: none;
        overflow: visible;
    }

    /* Map section stacks vertically on mobile: map + legend below */
    .map-section {
        height: auto;
        min-height: 280px;
        max-height: none;
        flex: none;
        flex-direction: column;
    }
    .map-viewport {
        height: 50vh;
        min-height: 240px;
        max-height: 380px;
        flex: none;
    }
    .map-legend-panel {
        width: 100%;
        min-width: 0;
        max-width: none;
        border-left: none;
        border-top: 1px solid var(--panel-border);
        min-height: 80px;
        max-height: 140px;
        flex: 0 0 auto;
    }
    .map-bg {
        max-height: none;
        max-width: 100%;
    }

    /* Bottom panels stack vertically */
    .bottom-panels {
        flex-direction: column;
        height: auto;
        min-height: 0;
    }
    .bottom-panel + .bottom-panel {
        border-left: none;
        border-top: 1px solid var(--panel-border);
    }

    /* Player grid + role legend get enough room */
    .bpanel-grid {
        order: 0;
        flex: 0 0 auto;
    }
    .hive-grid-row {
        flex-direction: column;
    }
    .hive-grid-wrap {
        flex: none;
        height: auto;
    }
    .hive-grid {
        height: auto !important;
    }
    .hive-cell {
        min-height: 44px;
    }

    /* Player list panel needs room too */
    .player-table-wrap {
        max-height: 50vh;
    }

    /* Toolbar actions wrap */
    .toolbar-actions {
        gap: 4px;
    }
    .toolbar-btn {
        padding: 5px 8px;
        font-size: 11px;
    }

    /* Role legend stacks below grid on mobile */
    .role-legend {
        border-left: none;
        border-top: 1px solid var(--panel-border);
        padding-left: 0;
        padding-top: 10px;
        min-width: 0;
        width: 100%;
    }

    /* SvS mode on mobile */
    .svs-mode .hive-cell {
        min-height: 52px;
    }

    /* Hide footer scrollbar gutter */
    footer { flex-shrink: 0; }
}

.btn-row{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-row .secondary-btn{
  margin-top: 0; /* override existing margin-top from button class */
}

/* Small phones */
@media (max-width: 500px) {
    .rally-toolbar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 6px 10px;
    }
    .mode-toggle { flex: 1 1 100%; }
    .toolbar-actions { flex: 1 1 100%; justify-content: stretch; }
    .toolbar-btn { flex: 1; text-align: center; }
    .rally-pdf-btn { flex: 1; }
    .rally-reset-btn { flex: 1; margin-left: 0; }

    .map-section {
        height: 50vh;
        min-height: 240px;
    }

    .hive-cell { font-size: 8px; min-height: 40px; }
    .hive-cell .hive-coord { font-size: 6px; }
}
