:root {
    --bg: #eef2f5;
    --panel: #ffffff;
    --panel-soft: #f7f9fb;
    --panel-muted: #f2f5f8;
    --text: #18212c;
    --muted: #5d6976;
    --accent: #264a70;
    --accent-strong: #1d3957;
    --accent-soft: rgba(38, 74, 112, 0.08);
    --border: rgba(24, 33, 44, 0.10);
    --border-strong: rgba(38, 74, 112, 0.18);
    --shadow: 0 14px 34px rgba(22, 31, 42, 0.08);
    --radius: 14px;
    --font-ui: "Times New Roman", Times, serif;
    --font-mono: "Courier New", "Nimbus Mono PS", monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    background:
        radial-gradient(circle at top left, rgba(38, 74, 112, 0.06), transparent 24rem),
        radial-gradient(circle at bottom right, rgba(84, 103, 123, 0.08), transparent 26rem),
        var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    overflow: hidden;
}

button,
a,
input,
select,
summary {
    font: inherit;
    color: inherit;
}

button,
.save-link,
.toolbar-button {
    min-height: 2.05rem;
    padding: 0.36rem 0.72rem;
    border: 1px solid rgba(24, 33, 44, 0.14);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(242, 246, 250, 0.98));
    text-decoration: none;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

button:hover,
.save-link:hover,
.toolbar-button:hover,
.timeline-item:hover,
.field-chip:hover,
summary:hover {
    border-color: rgba(38, 74, 112, 0.36);
    background: rgba(38, 74, 112, 0.08);
    transform: translateY(-1px);
}

.toolbar-button.is-active,
.field-chip.is-active,
.timeline-item.is-active {
    border-color: rgba(38, 74, 112, 0.38);
    background: rgba(38, 74, 112, 0.11);
    color: var(--accent-strong);
}

.workspace {
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 0.45rem;
    height: 100vh;
    padding: 0.45rem;
}

.topbar,
.viewer-panel,
.timeline-bar,
.control-drawer,
.section-drawer {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 250, 252, 0.98));
    box-shadow: var(--shadow);
}

.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.65rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
}

.topbar-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.brand-block {
    min-width: 0;
}

.brand-block h1,
.viewer-heading h2,
.drawer-header h2,
.panel-card h3,
.section-result-header h3 {
    margin: 0;
    font-weight: 700;
}

.brand-block h1 {
    font-size: 1.02rem;
    line-height: 1.1;
}

.eyebrow {
    margin: 0 0 0.16rem;
    color: var(--accent);
    font-size: 0.68rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.subtle {
    margin: 0.14rem 0 0;
    color: var(--muted);
    line-height: 1.35;
    font-size: 0.82rem;
}

.current-strip,
.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.current-chip {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    min-width: 7rem;
    padding: 0.28rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.82);
}

.current-label {
    font-size: 0.66rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.current-value {
    font-size: 0.86rem;
    line-height: 1.1;
}

.drawer-scrim {
    position: absolute;
    inset: 0;
    background: rgba(24, 33, 44, 0.22);
    backdrop-filter: blur(2px);
    z-index: 10;
}

.workbench {
    position: relative;
    min-height: 0;
}

.viewer-shell {
    position: relative;
    min-height: 0;
    height: 100%;
}

.control-drawer,
.section-drawer {
    position: absolute;
    top: 0;
    bottom: 0;
    width: min(22rem, calc(100vw - 1.2rem));
    padding: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    z-index: 20;
    transition: transform 180ms ease, opacity 180ms ease;
}

.control-drawer {
    left: 0;
    transform: translateX(calc(-100% - 0.8rem));
}

.control-drawer.is-open {
    transform: translateX(0);
}

.section-drawer {
    right: 0;
    transform: translateX(calc(100% + 0.8rem));
}

.section-drawer.is-open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.drawer-content {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    overflow: auto;
    padding-right: 0.1rem;
}

.panel-card,
.panel-details,
.section-result-card {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.7rem;
    border: 1px solid rgba(24, 33, 44, 0.08);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.92);
}

.panel-card-fill {
    flex: 1;
    min-height: 14rem;
}

.panel-card h3,
.section-result-header h3 {
    font-size: 0.96rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.16rem;
}

.input-group span {
    font-size: 0.74rem;
    color: var(--muted);
}

input,
select {
    min-height: 2.05rem;
    width: 100%;
    border: 1px solid rgba(24, 33, 44, 0.14);
    border-radius: 10px;
    background: #ffffff;
    padding: 0.36rem 0.6rem;
}

#station-list {
    min-height: 100%;
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.compact-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
}

.toggle-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 2.05rem;
    padding: 0.32rem 0.58rem;
    border: 1px solid rgba(24, 33, 44, 0.12);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.96);
}

.field-chip-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.field-chip {
    min-height: 1.95rem;
    padding: 0.18rem 0.6rem;
    border: 1px solid rgba(24, 33, 44, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--muted);
}

.panel-details {
    padding: 0;
    overflow: hidden;
}

.panel-details summary {
    list-style: none;
    padding: 0.75rem 0.8rem;
    border-bottom: 1px solid transparent;
    cursor: pointer;
}

.panel-details summary::-webkit-details-marker {
    display: none;
}

.panel-details[open] summary {
    border-bottom-color: var(--border);
    background: var(--panel-muted);
}

.panel-details .metadata-list {
    padding: 0.8rem;
}

.metadata-list {
    display: grid;
    grid-template-columns: 5.2rem 1fr;
    gap: 0.35rem 0.5rem;
    margin: 0;
}

.metadata-list dt {
    color: var(--accent);
    font-size: 0.76rem;
}

.metadata-list dd {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    word-break: break-word;
}

.viewer-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    height: 100%;
    min-height: 0;
    padding: 0.45rem 0.55rem 0.55rem;
}

.viewer-header {
    display: flex;
    justify-content: space-between;
    gap: 0.4rem;
    align-items: flex-start;
}

.viewer-heading h2 {
    font-size: 1.08rem;
    line-height: 1.1;
}

.image-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(24, 33, 44, 0.08);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.98), rgba(236, 241, 246, 0.96));
    padding: 0.22rem;
}

#plot-canvas {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #f8fafc;
    cursor: grab;
}

#plot-canvas:active {
    cursor: grabbing;
}

#plot-canvas.is-section-mode {
    cursor: crosshair;
}

.canvas-hud {
    position: absolute;
    right: 0.7rem;
    bottom: 0.7rem;
    padding: 0.18rem 0.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(24, 33, 44, 0.08);
    color: var(--muted);
    font-size: 0.7rem;
}

.section-floating-hud {
    position: absolute;
    left: 0.7rem;
    bottom: 0.7rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    max-width: min(46rem, calc(100% - 8rem));
    padding: 0.4rem 0.55rem;
    border: 1px solid rgba(24, 33, 44, 0.08);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(6px);
}

.section-floating-copy {
    display: flex;
    flex-direction: column;
    gap: 0.04rem;
    min-width: 0;
}

.section-floating-label {
    font-size: 0.66rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.section-floating-status {
    font-size: 0.8rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.section-floating-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.32rem;
}

.section-floating-actions .toolbar-button {
    min-height: 1.9rem;
    padding-inline: 0.62rem;
}

.section-drawer-content {
    gap: 0.55rem;
}

.section-point-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
}

.section-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.38rem;
}

.section-actions > * {
    flex: 1 1 8rem;
}

.section-result-card {
    flex: 1;
    min-height: 16rem;
}

.section-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(247, 250, 252, 0.98), rgba(236, 241, 246, 0.96));
}

#section-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.section-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: center;
    padding: 1rem;
}

.timeline-bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.55rem;
    align-items: center;
    padding: 0.42rem 0.58rem;
}

.timeline-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.timeline-speed {
    min-width: 4.6rem;
}

.timeline-track {
    overflow: auto hidden;
}

.timeline-list {
    display: inline-flex;
    gap: 0.3rem;
    min-width: 100%;
    padding-bottom: 0.1rem;
}

.timeline-item {
    min-width: 5rem;
    min-height: 1.95rem;
    padding: 0.28rem 0.48rem;
    border: 1px solid rgba(24, 33, 44, 0.12);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.94);
    text-align: left;
}

.timeline-item-time {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.76rem;
}

.timeline-item-date {
    display: block;
    color: var(--muted);
    font-size: 0.68rem;
}

.status-line {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
}

.status-line.is-error {
    color: #9b2f2f;
}

@media (max-width: 1280px) {
    .current-chip {
        min-width: 6.3rem;
    }

    .control-drawer,
    .section-drawer {
        width: min(21rem, calc(100vw - 1rem));
    }
}

@media (max-width: 960px) {
    body {
        overflow: auto;
    }

    .workspace {
        height: auto;
        min-height: 100vh;
    }

    .topbar,
    .timeline-bar {
        grid-template-columns: 1fr;
    }

    .topbar {
        align-items: stretch;
    }

    .current-strip,
    .topbar-actions {
        justify-content: flex-start;
    }

    .control-drawer,
    .section-drawer {
        position: fixed;
        top: 0.45rem;
        bottom: 0.45rem;
        width: min(24rem, calc(100vw - 0.9rem));
    }

    .timeline-bar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .status-line {
        white-space: normal;
    }

    .section-floating-hud {
        right: 0.7rem;
        max-width: none;
        flex-direction: column;
        align-items: stretch;
    }

    .section-floating-status {
        white-space: normal;
    }
}

@media (max-width: 640px) {
    .section-point-grid {
        grid-template-columns: 1fr;
    }

    .current-chip {
        min-width: calc(50% - 0.2rem);
    }
}
