/* =========================================
   1. DESIGN SYSTEM & VARIABLES
   ========================================= */
:root {
    --primary: #ae6efc;
    --primary-dim: rgba(174, 110, 252, 0.15);
    --primary-contrast: #ffffff;
    
    /* Default Light Mode */
    --bg-app: #f2f2f7;
    --bg-surface: #ffffff;
    --bg-input: #f2f2f7;
    --text-main: #000000;
    --text-muted: #8e8e93;
    --border: #c6c6c8;  
    --shadow: 0 4px 20px rgba(0,0,0,0.06);
    
    /* Scrollbar */
    --scrollbar-track: transparent;
    --scrollbar-thumb: rgba(0,0,0,0.2);
    
    /* Scope / Sight Box Variables (Light) */
    --scope-bg: radial-gradient(circle at center, #ffffff 0%, #e5e5ea 100%);
    --scope-text: #000000;
    --scope-crosshair: rgba(0, 0, 0, 0.1);
    --scope-overlay-opacity: 0.05;
    
    /* Status Colors */
    --success: #32d74b;
    --warning: #ffcc00;
    --danger: #ff453a;
    
    --radius-l: 18px;
    --radius-m: 12px;
    --radius-s: 8px;
    
    --safe-bottom: env(safe-area-inset-bottom, 20px);
}

/* Dark Mode Class (Applied via JS) */
body.dark-mode {
    --bg-app: #000000;
    --bg-surface: #1c1c1e;
    --bg-input: #2c2c2e;
    --text-main: #ffffff;
    --text-muted: #98989f;
    --border: #38383a;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    
    --scrollbar-thumb: rgba(255,255,255,0.2);
    
    /* Scope / Sight Box Variables (Dark) */
    --scope-bg: radial-gradient(circle at center, #3a3a3c 0%, #1c1c1e 60%, #000000 100%);
    --scope-text: #ffffff;
    --scope-crosshair: rgba(255, 255, 255, 0.1);
    --scope-overlay-opacity: 0.1;
}

/* =========================================
   2. GLOBAL RESET & SCROLLBARS
   ========================================= */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Custom Themed Scrollbar (Minimalist) */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}
::-webkit-scrollbar-corner {
    background: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    margin: 0; padding: 0;
    height: 100vh;
    height: 100dvh;
    display: flex; 
    flex-direction: column;
    overflow: hidden; /* Prevent body bounce */
    overscroll-behavior-y: none;
    transition: background-color 0.3s, color 0.3s;
}

/* =========================================
   3. NAVIGATION (BOTTOM)
   ========================================= */
nav {
    order: 2; /* Moves nav to the bottom visually */
    background: var(--bg-surface);
    border-top: 0.5px solid var(--border);
    border-bottom: none;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 8px 5px;
    padding-bottom: var(--safe-bottom);
    z-index: 100;
    flex-shrink: 0;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(var(--bg-surface), 0.85);
}

.tab-btn {
    border: none; background: none;
    color: var(--text-muted);
    font-size: 10px; font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.2px;
    padding: 8px 0;
    cursor: pointer;
    border-radius: var(--radius-m);
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 4px;
}

.tab-btn::before {
    content: '';
    display: block;
    width: 20px; height: 2px;
    background: currentColor;
    border-radius: 2px;
    opacity: 0.3;
    margin-bottom: 2px;
}

.tab-btn.active { 
    color: var(--primary); 
    background-color: transparent; 
}
.tab-btn.active::before {
    opacity: 1;
    background: var(--primary);
    width: 24px;
}

/* =========================================
   4. LAYOUT & SCROLLING
   ========================================= */
main {
    order: 1; 
    flex: 1;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.tab-content {
    display: none;
    height: 100%;
    overflow-y: auto; /* Allow scroll if needed */
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: 20px;
}

.tab-content.active { display: block; }

/* Dashboard (Shoot Tab) Specifics */
#tab-shoot.active {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0;
}

.card {
    background: var(--bg-surface);
    border-radius: var(--radius-l);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
@media (prefers-color-scheme: light) {
    .card { border: 1px solid rgba(0,0,0,0.05); }
}

.card h3 {
    margin: 0 0 12px 0;
    font-size: 11px; font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

/* =========================================
   5. COMPONENT STYLING
   ========================================= */

/* --- Inputs --- */
.input-row { display: flex; gap: 10px; margin-bottom: 10px; }
.input-group { flex: 1; min-width: 0; }

label {
    display: block; font-size: 11px; font-weight: 600;
    color: var(--text-muted); margin-bottom: 5px;
    text-transform: uppercase; letter-spacing: 0.5px;
}

input, select {
    width: 100%; padding: 12px;
    border-radius: var(--radius-m);
    border: none; background-color: var(--bg-input);
    color: var(--text-main);
    font-size: 17px;
    font-weight: 600;
    font-family: inherit;
    appearance: none; -webkit-appearance: none;
    transition: box-shadow 0.2s;
}

input:focus, select:focus { 
    outline: none; 
    box-shadow: 0 0 0 2px var(--primary);
    background: var(--bg-surface); 
}

/* --- List Items --- */
.gear-list { list-style: none; padding: 0; margin: 0; }
.gear-item {
    padding: 14px 0; border-bottom: 0.5px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.gear-item:last-child { border-bottom: none; }

.gear-detail {
    display: block; font-size: 12px; 
    color: var(--text-muted); margin-top: 2px;
}

/* --- Action Buttons --- */
.action-btns { display: flex; gap: 8px; align-items: center; }

.edit-btn {
    background: var(--bg-input); 
    color: var(--primary);
    border: none; font-size: 11px; font-weight: 600;
    padding: 6px 12px; border-radius: 14px;
    cursor: pointer; text-transform: uppercase;
}

.del-btn {
    background: rgba(255, 69, 58, 0.1); color: var(--danger);
    width: 32px; height: 32px; border-radius: 50%; border: none;
    font-size: 18px; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}

/* --- Physics Grid --- */
.physics-grid { display: flex; gap: 12px; margin-top: 12px; }
.physics-item {
    flex: 1; background: var(--bg-input);
    padding: 12px; border-radius: var(--radius-m); text-align: center;
    border: 1px solid transparent;
}
@media (prefers-color-scheme: light) {
    .physics-item { border-color: rgba(0,0,0,0.03); }
}

.physics-num { font-size: 1.4rem; font-weight: 800; color: var(--primary); }
.physics-label { font-size: 9px; color: var(--text-muted); font-weight: 700; margin-top: 2px; }

/* --- Lethality Scale --- */
.lethality-scale { 
    display: flex; margin-top: 10px; 
    border-radius: var(--radius-s); overflow: hidden; 
    height: 32px; 
}
.tier {
    flex: 1; display: flex; align-items: center; justify-content: center;
    text-align: center; font-size: 8px; font-weight: 800;
    color: rgba(255,255,255,0.3); background: var(--bg-input);
    border-right: 1px solid var(--bg-surface);
    transition: all 0.3s;
}
.tier.active { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
#tier-1.active { background: #5ac8fa; }
#tier-2.active { background: #34c759; }
#tier-3.active { background: #ff9500; }
#tier-4.active { background: #ff3b30; }

/* --- Buttons --- */
.btn {
    width: 100%; padding: 14px; border-radius: var(--radius-m);
    border: none; font-size: 15px; font-weight: 700;
    background-color: var(--primary); color: #fff;
    margin-top: 12px;
    box-shadow: 0 4px 10px rgba(191, 90, 242, 0.3);
    cursor: pointer;
    transition: transform 0.1s;
}
.btn-primary { background-color: var(--primary); }
.btn:active { transform: scale(0.98); }

/* --- Modals --- */
.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); 
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    z-index: 2000; display: none;
    align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; animation: fadeIn 0.2s forwards; }

.modal-content {
    background: var(--bg-surface); width: 100%; max-width: 600px;
    border-radius: 24px 24px 0 0; padding: 30px 20px;
    padding-bottom: max(30px, var(--safe-bottom));
    max-height: 92vh; 
    overflow-y: auto; /* Default for simple modals */
    box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.close-modal {
    float: right; font-size: 28px; font-weight: bold;
    color: var(--text-muted); cursor: pointer;
    margin-top: -10px;
}

@media (min-width: 768px) {
    .modal { align-items: center; }
    .modal-content { border-radius: 24px; padding-bottom: 30px; }
}

@keyframes fadeIn { from {opacity:0} to {opacity:1} }
@keyframes slideUp { from {transform:translateY(100%)} to {transform:translateY(0)} }

/* =========================================
   6. CUSTOM STEPPERS
   ========================================= */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; margin: 0; 
}
input[type=number] { appearance: textfield; -moz-appearance: textfield; }

.stepper-wrapper {
    display: flex; align-items: center;
    background-color: var(--bg-input);
    border-radius: var(--radius-m);
    padding: 2px; border: 1px solid transparent;
    transition: all 0.2s; width: 100%;
}
.stepper-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
    background-color: var(--bg-surface);
}

.stepper-input {
    flex: 1; text-align: center; border: none;
    background: transparent; padding: 10px 0; margin: 0;
    font-weight: 700; box-shadow: none !important;
}
.stepper-input:focus { outline: none; background: transparent; }

.stepper-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent;
    color: var(--primary); font-size: 1.4rem;
    cursor: pointer; border-radius: var(--radius-m);
    user-select: none; touch-action: manipulation;
}
.stepper-btn:active { background-color: rgba(0,0,0,0.05); transform: scale(0.9); }
@media (prefers-color-scheme: dark) {
    .stepper-btn:active { background-color: rgba(255,255,255,0.1); }
}

/* FOC Badge */
.foc-badge {
    display: inline-block; background: var(--bg-input);
    color: var(--text-main); font-size: 10px;
    padding: 2px 6px; border-radius: 4px;
    margin-left: 6px; font-weight: 700;
    border: 1px solid var(--border);
}

/* =========================================
   7. SHOOT TAB LAYOUT
   ========================================= */

#tab-shoot.active {
    display: flex; flex-direction: column;
    height: 100%; overflow: hidden;
    padding: 0; gap: 0;
}

/* --- HUD Results (Fixed) --- */
.hud-grid {
    flex: 0 0 35%; /* Fixed height */
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1.5fr 1fr;
    gap: 1px; background-color: var(--border);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    z-index: 10;
}

.hud-cell {
    background-color: var(--bg-surface);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 5px; position: relative; overflow: hidden;
}

.cell-main {
    grid-column: 1 / -1; position: relative;
    background: var(--scope-bg); overflow: hidden;
    border-bottom: 2px solid var(--primary);
    transition: background 0.3s;
}

.cell-main::before {
    content: ""; position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: 
        linear-gradient(45deg, #000 25%, transparent 25%, transparent 75%, #000 75%, #000),
        linear-gradient(45deg, #000 25%, transparent 25%, transparent 75%, #000 75%, #000);
    background-size: 4px 4px; opacity: var(--scope-overlay-opacity);
    pointer-events: none;
}
.cell-main::after {
    content: ""; position: absolute;
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 200px; height: 200px;
    border: 1px solid var(--scope-crosshair);
    border-radius: 50%;
    box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}
.scope-dot {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 4px; height: 4px;
    background-color: var(--primary);
    border-radius: 50%; box-shadow: 0 0 10px var(--primary);
    z-index: 1;
}

.cell-main .hud-label, .cell-main .hud-value-lg, .cell-main .hud-unit {
    position: relative; z-index: 2;
    text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

.hud-value-lg {
    font-size: 8vh; font-weight: 800; color: var(--text-main);
    line-height: 0.9; font-variant-numeric: tabular-nums;
    letter-spacing: -2px;
}
.hud-value-md {
    font-size: 3.5vh; font-weight: 700; color: var(--text-main);
    text-align: center; line-height: 1;
}
.hud-label {
    font-size: 9px; font-weight: 700; color: var(--text-muted);
    letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 2px;
}
.hud-unit {
    font-size: 10px; font-weight: 700; color: var(--primary);
    background: var(--primary-dim); padding: 2px 6px;
    border-radius: 4px; margin-top: 4px;
}
.accent-wind { color: var(--warning); }
.accent-speed { color: var(--success); }

/* --- Controls (Scrollable if needed) --- */
.shoot-controls {
    flex: 1; 
    background-color: var(--bg-app);
    padding: 10px;
    display: flex; flex-direction: column; gap: 8px;
    overflow-y: auto; /* Enable scroll for small screens */
}

.shoot-controls .card {
    margin: 0; padding: 10px 12px;
    display: flex; flex-direction: column;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.03);
}

/* Adjust Card sizing to fill space efficiently */
.shoot-controls .card:first-child { flex: 2; justify-content: space-evenly; }
.shoot-controls .card:last-child { flex: 1; justify-content: center; min-height: 80px; }

.shoot-controls h3 { margin: 0 0 6px 0; font-size: 9px; padding-bottom: 4px; flex-shrink: 0; }
.shoot-controls .input-row { margin-bottom: 0; gap: 8px; }
.shoot-controls label { font-size: 9px; margin-bottom: 2px; }
.shoot-controls .stepper-btn { width: 32px; height: 32px; font-size: 1.2rem; }
.shoot-controls input, .shoot-controls select { padding: 6px; font-size: 14px; height: 32px; }
.shoot-controls .stepper-input { padding: 0; height: auto; }

/* =========================================
   8. COMPONENT LIBRARY
   ========================================= */
.comp-tabs {
    display: flex; gap: 5px; margin-bottom: 10px;
    background: var(--bg-input); padding: 4px;
    border-radius: var(--radius-m);
}
.comp-tab {
    flex: 1; padding: 8px; border: none;
    background: transparent; color: var(--text-muted);
    font-size: 10px; font-weight: 700;
    border-radius: 6px; cursor: pointer;
}
.comp-tab.active {
    background: var(--bg-surface); color: var(--primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.comp-list { list-style: none; padding: 0; max-height: 300px; overflow-y: auto; }
.comp-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.comp-add-row {
    display: flex; 
    flex-wrap: wrap; 
    gap: 8px; 
    margin-top: 10px;
    padding-top: 10px; 
    border-top: 1px solid var(--border);
    align-items: stretch; /* Ensures button and inputs are same height */
}

.comp-add-row input, 
.comp-add-row select { 
    flex: 2 1 120px; /* Allows inputs to grow */
    font-size: 14px;
    padding: 10px 12px;
    height: 44px; /* Explicit height for vertical clearance */
    background-color: var(--bg-input);
    color: var(--text-main);
    border-radius: var(--radius-s);
    border: none;
}

/* Specific sizing for the Add Button */
.comp-add-row .btn-primary {
    flex: 1 0 80px; /* Prevents button from shrinking too small */
    margin: 0;
    height: 44px;
    font-size: 14px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =========================================
   9. BUILDER MODAL (FLEX LAYOUT)
   ========================================= */

.modal-content.fullscreen {
    height: 92vh; max-height: 92vh;
    padding: 15px;
    display: flex; flex-direction: column;
    overflow: hidden; /* Main modal doesn't scroll */
}

/* Scrollable Content Area */
.build-grid {
    flex: 1; /* Takes available space */
    display: flex; flex-direction: column; gap: 8px;
    margin-bottom: 10px;
    overflow-y: auto; /* Internal scroll only */
    padding-right: 4px;
}

.modal-footer-fixed {
    flex-shrink: 0;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    display: flex; gap: 10px;
    background: var(--bg-surface);

    align-items: flex-end;
}

/* Accordion Cells */
.build-cell {
    flex: 0 0 auto; 
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Header */
.loader-zone {
    background-color: var(--bg-input);
    padding: 8px 12px;
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; min-height: 50px;
}

.loader-zone select {
    flex: 1; margin-right: 10px;
    background-color: transparent; font-size: 14px;
    height: 32px; padding: 0; border: none; color: var(--text-main);
}

.loader-label {
    font-size: 10px; font-weight: 700; 
    text-transform: uppercase; color: var(--text-muted);
    margin-bottom: 2px; display: block;
}

.expand-icon {
    font-size: 12px; color: var(--primary);
    transition: transform 0.3s; padding: 5px;
}
.build-cell.expanded .expand-icon { transform: rotate(180deg); }

/* Collapsible Content */
.input-zone {
    max-height: 0; opacity: 0;
    padding: 0 12px;
    transition: all 0.3s ease-out;
    background: var(--bg-surface);
}

.build-cell.expanded .input-zone {
    max-height: 400px; opacity: 1;
    padding: 10px 12px 15px 12px;
    border-top: 1px solid var(--border);
}

/* --- LOGIC: No Presets State --- */
.build-cell.no-presets .loader-zone {
    cursor: default;
    background-color: var(--bg-surface); /* Blend in */
    border-bottom: 1px solid var(--border);
}
.build-cell.no-presets .expand-icon { display: none; }
.build-cell.no-presets select { display: none; }
/* Force show input if no presets */
.build-cell.no-presets .input-zone {
    max-height: none; opacity: 1;
    padding: 10px 12px 15px 12px;
    border-top: none;
}

.input-zone .stepper-wrapper { margin-top: 6px; background: var(--bg-app); }
body.dark-mode .input-zone .stepper-wrapper:focus-within { background-color: var(--bg-input); }

/* =========================================
   10. SETTINGS SWITCH
   ========================================= */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc; transition: .4s; border-radius: 34px;
}
.slider:before {
  position: absolute; content: "";
  height: 24px; width: 24px; left: 2px; bottom: 2px;
  background-color: white; transition: .4s;
  border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(22px); }
/* --- Added for Beta Release --- */
.selection-label {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--primary);
    text-transform: none; /* Keep name case */
    vertical-align: middle;
}