:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #121829;
    --bg-card: #1a2035;
    --bg-hover: #222940;
    --border: #2a3050;
    --text: #e0e6f0;
    --text-dim: #8892a8;
    --accent: #4a9eff;
    --accent-hover: #6ab4ff;
    --solar: #ffd93d;
    --lunar: #c0c8d8;
    --total: #ff4444;
    --partial: #ff8844;
    --penumbral: #88aacc;
    --annular: #ffaa33;
    --success: #44dd88;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

#app { max-width: 1400px; margin: 0 auto; padding: 0 16px 32px; }

/* Header */
header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 0; border-bottom: 1px solid var(--border);
    flex-wrap: wrap; gap: 12px;
}
header h1 { font-size: 1.5rem; color: var(--text); font-weight: 700; }
.subtitle { color: var(--text-dim); font-size: 0.85rem; margin-left: 12px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.time-toggle {
    display: flex; border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden;
}
.toggle-btn {
    padding: 6px 12px; background: var(--bg-card); border: none;
    color: var(--text-dim); cursor: pointer; font-size: 0.8rem;
    transition: all 0.2s;
}
.toggle-btn:first-child { border-right: 1px solid var(--border); }
.toggle-btn.active { background: var(--accent); color: #fff; }
.toggle-btn:hover:not(.active) { background: var(--bg-hover); }

.location-display {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-card); padding: 8px 14px; border-radius: var(--radius);
    cursor: pointer; border: 1px solid var(--border); transition: border-color 0.2s;
}
.location-display:hover { border-color: var(--accent); }
.loc-icon { font-size: 1.1rem; }
.loc-edit { color: var(--text-dim); font-size: 0.85rem; }

/* Tabs */
.tabs {
    display: flex; gap: 4px; padding: 12px 0;
    border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tab {
    padding: 8px 18px; background: transparent; border: 1px solid transparent;
    color: var(--text-dim); cursor: pointer; border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.9rem; white-space: nowrap; transition: all 0.2s;
}
.tab:hover { color: var(--text); background: var(--bg-secondary); }
.tab.active {
    color: var(--accent); border-color: var(--border);
    border-bottom-color: var(--bg-primary); background: var(--bg-secondary);
}

.tab-content { display: none; padding: 20px 0; }
.tab-content.active { display: block; }

/* Eclipse Controls */
.eclipse-controls {
    display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
    padding: 12px 16px; background: var(--bg-secondary); border-radius: var(--radius);
    margin-bottom: 16px;
}
.eclipse-controls { row-gap: 10px; }
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-group > label { color: var(--text-dim); font-size: 0.85rem; }
.filter-group.kind-filter { gap: 10px; }
.filter-group .chk {
    display: inline-flex; align-items: center; gap: 4px;
    color: var(--text); font-size: 0.82rem; cursor: pointer;
    padding: 3px 8px; border: 1px solid var(--border); border-radius: 12px;
    background: var(--bg-card); user-select: none;
}
.filter-group .chk:hover { border-color: var(--accent); }
.filter-group .chk input { accent-color: var(--accent); cursor: pointer; }
.filter-actions { margin-left: auto; }
.filter-summary {
    color: var(--text-dim); font-size: 0.78rem; margin: 0 0 10px 2px;
}

select, input[type="number"], input[type="text"] {
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
    padding: 6px 10px; border-radius: 4px; font-size: 0.85rem;
}
input[type="number"] { width: 80px; }
select { cursor: pointer; }

.btn {
    padding: 8px 16px; border: 1px solid var(--border); background: var(--bg-card);
    color: var(--text); border-radius: 4px; cursor: pointer; font-size: 0.85rem;
    transition: all 0.2s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* Eclipse List */
.eclipse-list { display: grid; gap: 10px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.eclipse-card {
    display: grid; grid-template-columns: 50px 1fr auto; gap: 14px; align-items: center;
    padding: 14px 18px; background: var(--bg-secondary); border-radius: var(--radius);
    border: 1px solid var(--border); cursor: pointer; transition: all 0.2s;
}
.eclipse-card:hover { border-color: var(--accent); transform: translateX(2px); }
.eclipse-card.selected { border-color: var(--accent); background: var(--bg-hover); }
.eclipse-icon { font-size: 2rem; text-align: center; }
.eclipse-info h4 { font-size: 0.95rem; margin-bottom: 4px; }
.eclipse-info .meta { color: var(--text-dim); font-size: 0.8rem; }
.eclipse-badge {
    padding: 4px 10px; border-radius: 12px; font-size: 0.75rem;
    font-weight: 600; text-transform: uppercase;
}
.badge-total { background: rgba(255,68,68,0.2); color: var(--total); }
.badge-partial { background: rgba(255,136,68,0.2); color: var(--partial); }
.badge-penumbral { background: rgba(136,170,204,0.2); color: var(--penumbral); }
.badge-annular { background: rgba(255,170,51,0.2); color: var(--annular); }
.badge-hybrid { background: rgba(255,100,200,0.2); color: #ff64c8; }
.badge-transit { background: rgba(120,180,255,0.18); color: #78b4ff; }

/* Visibility indicators */
.visibility-info { margin-top: 4px; font-size: 0.78rem; }
.vis-computing { color: var(--text-dim); font-style: italic; }
.vis-yes { color: var(--success); }
.vis-partial { color: var(--annular); }
.vis-no { color: var(--text-dim); opacity: 0.7; }

.loading { text-align: center; color: var(--text-dim); padding: 40px; }

/* Simulation Layout */
.sim-layout { display: grid; grid-template-columns: 1fr 320px; gap: 20px; }
.sim-header h2 { font-size: 1.1rem; margin-bottom: 8px; }
.sim-header .meta { color: var(--text-dim); font-size: 0.85rem; }
.sim-map { height: 400px; border-radius: var(--radius); border: 1px solid var(--border); }
.sim-map-container { position: relative; }

/* Timeline */
.timeline-container {
    padding: 16px; background: var(--bg-secondary); border-radius: var(--radius);
    margin-top: 12px;
}
.timeline-labels {
    display: flex; justify-content: space-between; font-size: 0.7rem;
    color: var(--text-dim); margin-bottom: 4px; padding: 0 2px;
}
.timeline-slider {
    -webkit-appearance: none; width: 100%; height: 6px;
    background: var(--bg-card); border-radius: 3px; outline: none;
    border: 1px solid var(--border);
}
.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 18px; height: 18px;
    background: var(--accent); border-radius: 50%; cursor: pointer;
    border: 2px solid #fff;
}
.timeline-slider::-moz-range-thumb {
    width: 18px; height: 18px; background: var(--accent);
    border-radius: 50%; cursor: pointer; border: 2px solid #fff;
}
/* Observability marks under the timeline */
.timeline-horizon {
    position: relative; height: 3px; margin-top: 5px;
    border-radius: 2px; background: rgba(255,255,255,0.05);
}
/* lunar eclipses get a second row for the daylight warning */
.timeline-horizon.two-row { height: 8px; }
.timeline-horizon.has-segments { background: rgba(68,221,136,0.18); }
.timeline-horizon .horizon-seg {
    position: absolute; top: 0; height: 3px;
    background: var(--total); border-radius: 2px;
    box-shadow: 0 0 4px rgba(255,68,68,0.6);
}
.timeline-horizon .daylight-seg {
    position: absolute; bottom: 0; height: 3px;
    background: var(--solar); border-radius: 2px;
    box-shadow: 0 0 4px rgba(255,217,61,0.7);
}

.timeline-time {
    text-align: center; font-size: 1rem; font-weight: 600;
    margin: 8px 0; font-variant-numeric: tabular-nums;
}
.timeline-controls {
    display: flex; justify-content: center; gap: 8px; align-items: center;
}
.speed-select { width: 84px; }

/* Disk visualization */
.sim-side { display: flex; flex-direction: column; gap: 16px; }
.disk-container {
    background: var(--bg-secondary); border-radius: var(--radius);
    padding: 20px; text-align: center; border: 1px solid var(--border);
}
#eclipseDisk { max-width: 100%; }
.coverage-display {
    margin-top: 12px; display: flex; justify-content: center; gap: 12px;
    align-items: baseline;
}
.coverage-label { color: var(--text-dim); font-size: 0.85rem; }
.coverage-value { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.disk-frame {
    display: inline-flex; margin-top: 10px; border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
}
.disk-frame .frame-btn {
    padding: 4px 10px; background: var(--bg-card); border: none;
    color: var(--text-dim); cursor: pointer; font-size: 0.72rem; transition: all 0.2s;
}
.disk-frame .frame-btn:first-child { border-right: 1px solid var(--border); }
.disk-frame .frame-btn.active { background: var(--accent); color: #fff; }
.disk-frame .frame-btn:hover:not(.active) { background: var(--bg-hover); }

.body-position {
    margin-top: 6px; font-size: 0.78rem; color: var(--text-dim);
    min-height: 1.2em; text-align: center;
}

/* Phase info */
.phase-info {
    background: var(--bg-secondary); border-radius: var(--radius);
    padding: 16px; border: 1px solid var(--border);
}
.phase-info h3 { font-size: 0.9rem; margin-bottom: 10px; color: var(--text-dim); }
.phase-list { display: flex; flex-direction: column; gap: 6px; }
.phase-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 10px; border-radius: 4px; font-size: 0.82rem;
    cursor: pointer; transition: background 0.15s;
}
.phase-item:hover { background: rgba(74,158,255,0.10); }
.phase-item.active { background: rgba(74,158,255,0.15); }
.phase-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 8px;
}
.phase-time { font-variant-numeric: tabular-nums; color: var(--text-dim); }
.phase-horizon { border-left: 2px solid var(--annular); font-style: italic; opacity: 0.85; }
.phase-twilight { border-left: 2px solid var(--penumbral); font-style: italic; opacity: 0.7; font-size: 0.78rem; }

.eclipse-details {
    background: var(--bg-secondary); border-radius: var(--radius);
    padding: 16px; border: 1px solid var(--border); font-size: 0.85rem;
}
.eclipse-details .detail-row {
    display: flex; justify-content: space-between; padding: 4px 0;
    border-bottom: 1px solid var(--border);
}
.eclipse-details .detail-row:last-child { border: none; }
.detail-label { color: var(--text-dim); }

/* Optimal Locations */
.optimal-layout { display: grid; grid-template-columns: 350px 1fr; gap: 20px; }
.optimal-controls { display: flex; flex-direction: column; gap: 12px; }
.info-box {
    background: var(--bg-secondary); padding: 12px; border-radius: var(--radius);
    border: 1px solid var(--border); font-size: 0.85rem;
}
.optimal-map { height: 500px; border-radius: var(--radius); border: 1px solid var(--border); }
.optimal-results { max-height: 400px; overflow-y: auto; }
.optimal-item {
    padding: 10px 12px; background: var(--bg-secondary); border-radius: var(--radius);
    border: 1px solid var(--border); margin-bottom: 8px; font-size: 0.83rem;
    cursor: pointer; transition: border-color 0.2s;
}
.optimal-item:hover { border-color: var(--accent); }
.optimal-item .name { font-weight: 600; margin-bottom: 4px; }
.optimal-item .info { color: var(--text-dim); }
.optimal-item .btn-adopt {
    margin-top: 8px; background: var(--accent); color: #fff; border-color: var(--accent);
}
.optimal-item .btn-adopt:hover { background: var(--accent-hover); }

/* Statistics */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.stat-card {
    background: var(--bg-secondary); border-radius: var(--radius); padding: 20px;
    border: 1px solid var(--border);
}
.stat-card h3 { font-size: 0.9rem; color: var(--text-dim); margin-bottom: 12px; }
.stat-value {
    font-size: 1.6rem; font-weight: 700; margin-bottom: 4px;
}
.stat-value.solar { color: var(--solar); }
.stat-value.lunar { color: var(--lunar); }
.stat-value.accent { color: var(--accent); }
.stat-desc { color: var(--text-dim); font-size: 0.82rem; line-height: 1.5; }
.stat-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.82rem; }
.stat-table th { text-align: left; color: var(--text-dim); padding: 4px 8px; font-weight: 500; }
.stat-table td { padding: 4px 8px; border-top: 1px solid var(--border); }

/* Planets */
.planets-layout { display: grid; grid-template-columns: 250px 1fr; gap: 20px; }
.planet-selector h3 { font-size: 0.95rem; margin-bottom: 12px; }
.planet-buttons { display: flex; flex-direction: column; gap: 6px; }
.planet-btn {
    padding: 10px 14px; background: var(--bg-secondary); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius); cursor: pointer;
    text-align: left; font-size: 0.85rem; transition: all 0.2s;
}
.planet-btn:hover { border-color: var(--accent); }
.planet-btn.active { border-color: var(--accent); background: var(--bg-hover); }
.planet-info {
    display: grid; grid-template-columns: 320px 1fr; gap: 20px;
}
.planet-visual {
    background: var(--bg-secondary); border-radius: var(--radius);
    padding: 20px; text-align: center; border: 1px solid var(--border);
}
.planet-details {
    background: var(--bg-secondary); border-radius: var(--radius);
    padding: 20px; border: 1px solid var(--border); font-size: 0.85rem;
    line-height: 1.7;
}
.planet-details h3 { margin-bottom: 10px; color: var(--accent); }
.planet-details p { margin-bottom: 8px; }
.planet-details .highlight { color: var(--solar); font-weight: 600; }

/* Modal */
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); z-index: 10000; align-items: center; justify-content: center;
}
.modal.open { display: flex; }
.modal-content {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px; width: 400px; max-width: 90vw;
}
.modal-content h3 { margin-bottom: 16px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 0.82rem; color: var(--text-dim); }
.form-group input { width: 100%; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Coverage legend */
.coverage-legend {
    position: absolute; bottom: 20px; right: 10px; z-index: 1000;
    background: rgba(10,14,26,0.9); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 8px 10px; font-size: 0.72rem;
    pointer-events: auto;
}
.coverage-legend .legend-title {
    font-weight: 600; color: var(--text-dim); margin-bottom: 4px;
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px;
}
.coverage-legend .legend-item {
    display: flex; align-items: center; gap: 6px; padding: 1px 0;
}
.coverage-legend .legend-color {
    width: 14px; height: 10px; border-radius: 2px; flex-shrink: 0;
}
.coverage-legend { max-width: 230px; }
.legend-scale { height: 10px; border-radius: 2px; border: 1px solid var(--border); }
.legend-scale-labels {
    display: flex; justify-content: space-between;
    color: var(--text-dim); font-size: 0.65rem; margin: 2px 0 6px;
}
.legend-line { width: 16px; height: 0; border-top: 2px solid; flex-shrink: 0; }
.legend-line.umbra { border-color: #ff2d2d; }
.legend-line.iso { border-top-style: dashed; border-color: #ffbf5a; }
.legend-line.edge { border-color: #ffffff; }
.legend-detail {
    display: flex; align-items: center; gap: 6px; margin-top: 6px;
    padding-top: 6px; border-top: 1px solid var(--border);
}
.legend-detail label { color: var(--text-dim); font-size: 0.7rem; }
.legend-detail select { padding: 2px 4px; font-size: 0.7rem; flex: 1; }
.legend-note { color: var(--text-dim); font-size: 0.65rem; margin-top: 5px; line-height: 1.3; }

/* Map status / progress */
.map-status {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
    z-index: 1000; background: rgba(10,14,26,0.92); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 5px 12px; font-size: 0.75rem;
    color: var(--text-dim); pointer-events: none; display: none;
    max-width: 70%; text-align: center;
}

.eclipse-card.past { opacity: 0.62; }
.eclipse-card.past:hover { opacity: 1; }

/* Leaflet overrides */
.leaflet-container { background: var(--bg-primary); }
.leaflet-control-zoom a {
    background: var(--bg-card) !important; color: var(--text) !important;
    border-color: var(--border) !important;
}
.leaflet-tile-pane { filter: brightness(0.7) contrast(1.1) saturate(0.8); }

/* Responsive */
@media (max-width: 900px) {
    .sim-layout { grid-template-columns: 1fr; }
    .optimal-layout { grid-template-columns: 1fr; }
    .planets-layout { grid-template-columns: 1fr; }
    .planet-info { grid-template-columns: 1fr; }
    .planet-buttons { flex-direction: row; flex-wrap: wrap; }
    .optimal-map { height: 350px; }
}
@media (max-width: 600px) {
    .eclipse-controls { flex-direction: column; align-items: stretch; }
    .tabs { gap: 2px; }
    .tab { padding: 6px 10px; font-size: 0.8rem; }
    header h1 { font-size: 1.2rem; }
}
