:root {
    --space-dark: #020205;
    --moon-light: #e0e0e0;
    --glow-blue: #00d2ff;
    --glow-purple: #9d50bb;
    --panel-bg: rgba(20, 20, 30, 0.85);
    --border-color: rgba(0, 210, 255, 0.3);
    --warning: #ff7474;
    --success: #73f5b1;
}

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

body {
    background: var(--space-dark);
    color: var(--moon-light);
    font-family: 'Roboto', sans-serif;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.stars, .twinkling {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.stars {
    background: #000 url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123163/stars.png') repeat top center;
}

.twinkling {
    background: transparent url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123163/twinkling.png') repeat top center;
    animation: move-twink-back 200s linear infinite;
}

@keyframes move-twink-back {
    from { background-position: 0 0; }
    to { background-position: -10000px 5000px; }
}

.container {
    max-width: 1240px;
    margin: 0 auto;
    padding: 2.5rem 2rem 3rem;
    flex: 1;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: 3.3rem;
    letter-spacing: 0.45rem;
    background: linear-gradient(to right, #00d2ff, #9d50bb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(0, 210, 255, 0.45);
}

.subtitle {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.95rem;
    color: var(--glow-blue);
    margin-top: 0.6rem;
    letter-spacing: 0.18rem;
    text-transform: uppercase;
}

main {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.control-panel,
.results-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 2rem;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(10px);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.4rem;
    color: var(--glow-blue);
}

.panel-header p {
    margin-top: 0.35rem;
    color: rgba(224, 224, 224, 0.72);
    font-size: 0.92rem;
    line-height: 1.45;
}

.upload-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.25rem;
    align-items: stretch;
}

.drop-zone {
    border: 1.5px dashed rgba(0, 210, 255, 0.45);
    border-radius: 12px;
    padding: 2rem;
    min-height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background:
        radial-gradient(circle at top, rgba(0, 210, 255, 0.12), transparent 40%),
        rgba(3, 8, 18, 0.7);
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

.drop-zone.is-active {
    border-color: var(--glow-blue);
    transform: translateY(-2px);
    box-shadow: 0 0 24px rgba(0, 210, 255, 0.2);
}

.drop-zone-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    color: var(--glow-blue);
    margin-bottom: 0.75rem;
}

.drop-zone-subtitle {
    color: rgba(224, 224, 224, 0.75);
    font-size: 0.95rem;
}

.drop-zone code {
    color: var(--success);
    font-family: 'Roboto', sans-serif;
}

.selected-file {
    margin-top: 1rem;
    color: #fff;
    font-weight: 700;
    word-break: break-word;
}

.button-group {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.panel-link-row {
    margin-top: 1rem;
    margin-bottom: 1rem;
    color: rgba(224, 224, 224, 0.78);
    font-size: 0.95rem;
    line-height: 1.5;
}

.panel-link-row a {
    color: var(--glow-blue);
    text-decoration: none;
}

.panel-link-row a:hover {
    text-decoration: underline;
}

button {
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

#analyzeBtn {
    flex: 1;
    padding: 1rem 1.25rem;
    background: linear-gradient(45deg, #00d2ff, #9d50bb);
    color: #04101c;
    font-weight: 700;
    letter-spacing: 0.12rem;
    box-shadow: 0 0 20px rgba(0, 210, 255, 0.2);
}

.json-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--glow-blue);
    padding: 0.95rem 1rem;
    letter-spacing: 0.08rem;
}

.upload-button {
    height: 100%;
    min-height: 220px;
}

.reset-zoom-btn {
    padding: 0.6rem 0.9rem;
    white-space: nowrap;
}

.status-message {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
}

.status-message.error {
    background: rgba(255, 116, 116, 0.12);
    border: 1px solid rgba(255, 116, 116, 0.35);
    color: #ffd1d1;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    background: rgba(7, 12, 22, 0.85);
    border: 1px solid rgba(0, 210, 255, 0.16);
    border-radius: 12px;
    padding: 1rem 1.1rem;
    min-height: 96px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.summary-label {
    color: rgba(224, 224, 224, 0.7);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08rem;
}

.summary-card strong {
    color: #fff;
    font-size: 1rem;
    line-height: 1.35;
    word-break: break-word;
}

.chart-card {
    background: rgba(4, 10, 19, 0.86);
    border: 1px solid rgba(0, 210, 255, 0.16);
    border-radius: 12px;
    padding: 1.2rem;
}

.chart-card-header {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.chart-card-header h3 {
    font-family: 'Orbitron', sans-serif;
    color: var(--glow-blue);
    margin-bottom: 0.35rem;
}

.chart-card-header p {
    color: rgba(224, 224, 224, 0.68);
    font-size: 0.92rem;
}

.chart-controls {
    display: flex;
    align-items: flex-end;
    gap: 0.85rem;
    flex-wrap: wrap;
}

.chart-layout {
    display: block;
}

.cut-range-bar {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(0, 210, 255, 0.12);
    display: flex;
    justify-content: center;
}

.cut-range-btn {
    min-width: 220px;
}

.chart-stage {
    position: relative;
    min-width: 0;
}

#fullNorpChart,
#rangeNorpChart {
    display: block;
    width: 100%;
    height: 420px;
    max-height: 420px;
    cursor: default;
}

.range-handle {
    position: absolute;
    top: 44px;
    bottom: 52px;
    width: 0;
    border-left: 2px dashed #ffcf5c;
    cursor: ew-resize;
    z-index: 3;
}

.range-handle::before {
    content: "";
    position: absolute;
    left: -7px;
    top: 0;
    width: 14px;
    height: 100%;
    background: transparent;
}

.range-handle span {
    position: absolute;
    top: -20px;
    left: 8px;
    font: 12px Roboto, sans-serif;
    white-space: nowrap;
}

#startPreFlareHandle {
    border-left-color: #ffcf5c;
}

#startPreFlareHandle span {
    color: #ffcf5c;
}

#endPreFlareHandle {
    border-left-color: #ff8a5b;
}

#endPreFlareHandle span {
    color: #ff8a5b;
}

#startFlareHandle {
    border-left-color: #73f5b1;
}

#startFlareHandle span {
    color: #73f5b1;
}

#endFlareHandle {
    border-left-color: #9ec5ff;
}

#endFlareHandle span {
    color: #9ec5ff;
}

.background-panel {
    margin-top: 1rem;
    background: rgba(7, 12, 22, 0.82);
    border: 1px solid rgba(0, 210, 255, 0.14);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.background-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.background-panel p {
    color: rgba(224, 224, 224, 0.72);
    font-size: 0.9rem;
    line-height: 1.45;
}

.time-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.time-field span {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08rem;
    color: rgba(224, 224, 224, 0.72);
}

.time-field input {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(0, 210, 255, 0.22);
    color: #fff;
    border-radius: 8px;
    padding: 0.7rem 0.85rem;
    font: inherit;
}

.time-input-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 0.55rem;
    align-items: center;
}

.time-input-row input {
    width: 100%;
}

.time-step-btn {
    min-height: 44px;
    padding: 0;
    background: rgba(0, 210, 255, 0.08);
    border: 1px solid rgba(0, 210, 255, 0.22);
    color: var(--glow-blue);
    font-size: 1.1rem;
    line-height: 1;
}

.remove-background-btn {
    width: 100%;
}

.background-subtracted-panel {
    position: relative;
}

.spectrum-panel {
    position: relative;
}

.final-results-panel {
    position: relative;
}

.flare-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
    margin-top: 1rem;
}

.flare-peak-btn {
    width: 100%;
    margin-top: 1rem;
}

.remove-frequencies-btn {
    width: 100%;
    margin-top: 1rem;
}

.final-download-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.flare-peak-result {
    margin-top: 0;
}

.flare-peak-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.spectrum-view-switcher {
    display: inline-flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    padding: 0.25rem;
    border: 1px solid rgba(0, 210, 255, 0.16);
    border-radius: 8px;
    background: rgba(2, 8, 16, 0.72);
}

.spectrum-view-btn {
    min-height: 36px;
    padding: 0.45rem 0.9rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: rgba(224, 224, 224, 0.78);
    box-shadow: none;
    font-size: 0.85rem;
}

.spectrum-view-btn.is-active {
    border-color: rgba(0, 210, 255, 0.36);
    background: rgba(0, 210, 255, 0.12);
    color: #fff;
}

.spectrum-image {
    width: 100%;
    max-height: 420px;
    object-fit: contain;
    border: 1px solid rgba(0, 210, 255, 0.14);
    border-radius: 8px;
    background: #fff;
}

.spectrum-table-wrap {
    margin-top: 1rem;
    overflow-x: auto;
}

.spectrum-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 520px;
}

.spectrum-table th,
.spectrum-table td {
    padding: 0.72rem 0.8rem;
    border-bottom: 1px solid rgba(0, 210, 255, 0.12);
    text-align: left;
}

.spectrum-table th {
    color: rgba(224, 224, 224, 0.68);
    font-size: 0.76rem;
    letter-spacing: 0.08rem;
    text-transform: uppercase;
}

.spectrum-table td {
    color: #fff;
}

.spectrum-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--glow-blue);
}

.background-averages-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.background-averages-label {
    margin-bottom: 0.8rem;
    color: rgba(224, 224, 224, 0.78);
    font-size: 0.92rem;
    line-height: 1.45;
}

.background-average-card {
    background: rgba(2, 8, 16, 0.88);
    border: 1px solid rgba(0, 210, 255, 0.14);
    border-radius: 10px;
    padding: 0.8rem 0.9rem;
}

.background-average-card strong,
.background-average-card span {
    display: block;
}

.background-average-card span {
    color: rgba(224, 224, 224, 0.68);
    font-size: 0.76rem;
    letter-spacing: 0.08rem;
    text-transform: uppercase;
}

.background-average-card strong {
    color: #fff;
    margin-top: 0.35rem;
    font-size: 1rem;
    line-height: 1.35;
}

#backgroundSubtractedChart {
    display: block;
    width: 100%;
    height: 420px;
    max-height: 420px;
}

#flarePeakChart {
    display: block;
    width: 100%;
    height: 360px;
    max-height: 360px;
}

.hidden {
    display: none !important;
}

.loader {
    position: fixed;
    inset: 0;
    background: rgba(2, 2, 5, 0.86);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    z-index: 10;
}

.moon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #f9f6e7, #8fc4ff 60%, #38588d);
    box-shadow: 0 0 25px rgba(0, 210, 255, 0.45);
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.08); opacity: 1; }
}

.footer {
    text-align: center;
    padding: 2rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    color: rgba(224, 224, 224, 0.5);
    letter-spacing: 2px;
}

.footer a {
    color: var(--glow-blue);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

@media (max-width: 900px) {
    .upload-layout {
        grid-template-columns: 1fr;
    }

    .upload-button {
        min-height: 56px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1.5rem 1rem 2rem;
    }

    header h1 {
        font-size: 2.2rem;
        letter-spacing: 0.2rem;
    }

    .panel-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .chart-card-header {
        flex-direction: column;
    }

    .chart-controls {
        width: 100%;
        align-items: stretch;
    }

    .background-fields {
        grid-template-columns: 1fr;
    }

    .flare-fields {
        grid-template-columns: 1fr;
    }

    .flare-peak-summary {
        grid-template-columns: 1fr;
    }

    .final-download-actions {
        grid-template-columns: 1fr;
    }

    #fullNorpChart,
    #rangeNorpChart {
        height: 300px;
        max-height: 300px;
    }

    #backgroundSubtractedChart,
    #flarePeakChart {
        height: 300px;
        max-height: 300px;
    }
}
