/* historygrapher.com — swiss typography clean meets data-viz dashboard */

:root {
    --bg: #fafafa;
    --canvas: #ffffff;
    --grid: #e5e5e5;
    --axis: #9ca3af;
    --text: #1f2937;
    --text-soft: #6b7280;
    --panel: #f5f5f0;
    --war: #dc6868;
    --culture: #6888dc;
    --science: #68b88a;
    --politics: #d4a03c;
    --rule: #e5e5e5;
    --panel-w: 240px;
}

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

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "tnum" 1, "ss01" 1;
}

body {
    min-height: 100vh;
}

/* ===== App shell ===== */

.app-shell {
    display: grid;
    grid-template-columns: var(--panel-w) 1fr;
    min-height: 100vh;
}

/* ===== Tool panel ===== */

.tool-panel {
    width: var(--panel-w);
    background: var(--panel);
    border-right: 1px solid var(--rule);
    padding: 24px 20px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--rule);
}

.brand-mark {
    width: 32px;
    height: 32px;
    background: var(--canvas);
    border: 1px solid var(--rule);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
}

.brand-mark svg {
    display: block;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.brand-name {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 0.98rem;
    letter-spacing: -0.01em;
    color: var(--text);
}

.brand-meta {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-soft);
    margin-top: 3px;
    font-feature-settings: "tnum" 1;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.panel-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--rule);
}

/* Period control */

.period-control {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.period-input {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    background: var(--canvas);
    border: 1px solid var(--rule);
    padding: 8px 10px;
    border-radius: 2px;
}

.period-key {
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.period-val {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    font-feature-settings: "tnum" 1;
}

.period-slider {
    margin-top: 4px;
}

.period-slider input[type="range"] {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    height: 18px;
}

.period-slider input[type="range"]::-webkit-slider-runnable-track {
    height: 2px;
    background: var(--axis);
}

.period-slider input[type="range"]::-moz-range-track {
    height: 2px;
    background: var(--axis);
}

.period-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--canvas);
    border: 2px solid var(--text);
    margin-top: -5px;
    cursor: pointer;
}

.period-slider input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--canvas);
    border: 2px solid var(--text);
    cursor: pointer;
}

.slider-meta {
    margin-top: 6px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.72rem;
    color: var(--text-soft);
    font-feature-settings: "tnum" 1;
    text-align: right;
}

/* Category pills */

.category-pills {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pill {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--canvas);
    border: 1px solid var(--rule);
    border-radius: 2px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--text);
    transition: opacity 160ms ease, background 160ms ease;
}

.pill[aria-pressed="false"] {
    opacity: 0.42;
    background: var(--bg);
}

.pill:hover {
    background: #fff;
}

.pill-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: block;
}

.pill-text {
    text-align: left;
    font-weight: 500;
}

.pill-count {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    color: var(--text-soft);
    font-feature-settings: "tnum" 1;
}

/* Display options */

.display-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.opt-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    background: var(--canvas);
    border: 1px solid var(--rule);
    padding: 8px 10px;
    border-radius: 2px;
    cursor: pointer;
    position: relative;
}

.opt-row input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.opt-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--text);
}

.opt-toggle {
    width: 26px;
    height: 14px;
    background: var(--rule);
    border-radius: 8px;
    position: relative;
    transition: background 160ms ease;
}

.opt-toggle::after {
    content: "";
    position: absolute;
    top: 1px;
    left: 1px;
    width: 12px;
    height: 12px;
    background: var(--canvas);
    border: 1px solid var(--axis);
    border-radius: 50%;
    transition: transform 160ms ease, border-color 160ms ease;
}

.opt-row input[type="checkbox"]:checked ~ .opt-toggle {
    background: var(--text);
}

.opt-row input[type="checkbox"]:checked ~ .opt-toggle::after {
    transform: translateX(12px);
    border-color: var(--text);
}

/* Panel meta */

.panel-meta {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--rule);
}

.meta-row {
    display: flex;
    justify-content: space-between;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.78rem;
    color: var(--text-soft);
    padding: 3px 0;
    font-feature-settings: "tnum" 1;
}

.meta-row span:last-child {
    color: var(--text);
    font-weight: 500;
}

/* ===== Canvas area ===== */

.canvas-area {
    background: var(--bg);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 36px 40px 24px;
    border-bottom: 1px solid var(--rule);
    background: var(--bg);
    gap: 40px;
}

.canvas-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.75rem, 4vw, 3rem);
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.05;
}

.canvas-sub {
    margin-top: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-soft);
    max-width: 60ch;
}

.coord-display {
    background: var(--canvas);
    border: 1px solid var(--rule);
    padding: 10px 14px;
    border-radius: 2px;
    min-width: 160px;
}

.coord-row {
    display: flex;
    justify-content: space-between;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.78rem;
    color: var(--text-soft);
    padding: 3px 0;
    font-feature-settings: "tnum" 1;
}

.coord-val {
    color: var(--text);
    font-weight: 500;
}

/* Hero canvas */

.hero-canvas {
    padding: 24px 40px 40px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.tb-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tb-divider {
    width: 1px;
    height: 18px;
    background: var(--rule);
    margin: 0 4px;
}

.tb-btn {
    background: var(--canvas);
    border: 1px solid var(--rule);
    padding: 6px 12px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.82rem;
    color: var(--text);
    cursor: pointer;
    border-radius: 2px;
    transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
    font-feature-settings: "tnum" 1;
}

.tb-btn:hover {
    background: #fff;
    border-color: var(--text-soft);
}

.tb-btn.active {
    background: var(--text);
    color: var(--canvas);
    border-color: var(--text);
}

.tb-pill {
    border-radius: 999px;
    padding: 5px 12px;
}

.tb-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.72rem;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-right: 4px;
}

/* Canvas frame */

.canvas-frame {
    position: relative;
    background: var(--canvas);
    border: 1px solid var(--rule);
    border-radius: 2px;
    height: clamp(440px, 60vh, 560px);
    overflow: hidden;
    cursor: grab;
}

.canvas-frame.is-panning {
    cursor: grabbing;
}

.canvas-frame.mode-select {
    cursor: crosshair;
}

.dot-grid {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle, var(--grid) 1px, transparent 1.2px);
    background-size: 20px 20px;
    background-position: 0 0;
    pointer-events: none;
    transition: opacity 200ms ease;
}

.dot-grid.hidden {
    opacity: 0;
}

.timeline-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.timeline-svg .axis-line {
    stroke: var(--axis);
    stroke-width: 2;
}

.timeline-svg .tick {
    stroke: var(--axis);
    stroke-width: 1;
}

.timeline-svg .tick.major {
    stroke-width: 2;
}

.timeline-svg .tick-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 11px;
    fill: var(--text-soft);
    font-feature-settings: "tnum" 1;
    text-anchor: middle;
}

.timeline-svg .tick-label.major {
    fill: var(--text);
    font-weight: 500;
}

.timeline-svg .connector {
    stroke: var(--axis);
    stroke-width: 1;
    opacity: 0.6;
}

.timeline-svg .event-node {
    transition: r 160ms ease, opacity 200ms ease;
    cursor: pointer;
}

.timeline-svg .event-node:hover {
    r: 6;
}

.timeline-svg .event-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 11px;
    fill: var(--text);
    font-feature-settings: "tnum" 1;
}

.timeline-svg .event-anno {
    font-family: 'Inter', sans-serif;
    font-style: italic;
    font-size: 10px;
    fill: var(--text-soft);
}

.timeline-svg .filtered-out {
    opacity: 0.08;
}

.timeline-svg .label-hidden {
    opacity: 0;
}

.timeline-svg .anno-hidden {
    opacity: 0;
}

.timeline-svg .ticks-hidden .tick,
.timeline-svg .ticks-hidden .tick-label {
    opacity: 0;
}

/* Tooltip */

.event-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--canvas);
    border: 1px solid var(--text);
    border-radius: 2px;
    padding: 10px 12px;
    min-width: 200px;
    max-width: 280px;
    box-shadow: 0 6px 18px rgba(31, 41, 55, 0.08);
    z-index: 10;
    transform: translate(-50%, -110%);
    transition: opacity 120ms ease;
}

.event-tooltip[hidden] {
    display: none;
}

.event-tooltip .tt-year {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    font-feature-settings: "tnum" 1;
}

.event-tooltip .tt-title {
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 0.88rem;
    margin-top: 2px;
    color: var(--text);
}

.event-tooltip .tt-desc {
    font-family: 'Inter', sans-serif;
    font-style: italic;
    font-size: 0.78rem;
    color: var(--text-soft);
    line-height: 1.45;
    margin-top: 6px;
}

.event-tooltip .tt-cat {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--rule);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-soft);
}

/* Canvas corners */

.canvas-corner {
    position: absolute;
    pointer-events: none;
    font-family: 'Space Grotesk', sans-serif;
    font-feature-settings: "tnum" 1;
    z-index: 2;
}

.canvas-corner.tl {
    top: 12px;
    left: 12px;
}

.canvas-corner.br {
    bottom: 12px;
    right: 12px;
    text-align: right;
}

.corner-key {
    font-size: 0.65rem;
    color: var(--text-soft);
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.corner-val {
    font-size: 0.78rem;
    color: var(--text);
    font-weight: 500;
    margin-top: 2px;
}

/* Legend strip */

.legend-strip {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 0 0;
    border-top: 1px solid var(--rule);
    margin-top: 4px;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    color: var(--text-soft);
    flex-wrap: wrap;
}

.legend-spacer {
    flex: 1;
}

.legend-pos, .legend-neg {
    color: var(--text);
    font-weight: 600;
    margin-right: 4px;
}

.legend-tab {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ===== Section heads ===== */

.section-head {
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 20px;
    align-items: baseline;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 24px;
}

.section-num {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.6rem;
    color: var(--text);
    font-feature-settings: "tnum" 1;
}

.section-title h2 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 1.4rem;
    letter-spacing: -0.01em;
    color: var(--text);
    line-height: 1.2;
}

.section-title p {
    font-family: 'Inter', sans-serif;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--text-soft);
    margin-top: 6px;
    max-width: 64ch;
}

/* ===== Showcase ===== */

.showcase {
    padding: 40px;
    border-top: 1px solid var(--rule);
}

.showcase-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.showcase-card {
    background: var(--canvas);
    border: 1px solid var(--rule);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 180ms ease, transform 180ms ease;
}

.showcase-card:hover {
    border-color: var(--text-soft);
    transform: translateY(-2px);
}

.showcase-thumb {
    aspect-ratio: 16 / 9;
    background: var(--canvas);
    border-bottom: 1px solid var(--rule);
    position: relative;
    overflow: hidden;
}

.showcase-thumb svg {
    display: block;
    width: 100%;
    height: 100%;
}

.showcase-meta {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.showcase-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text);
}

.showcase-period {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    color: var(--text-soft);
    font-feature-settings: "tnum" 1;
}

/* ===== How strip ===== */

.how-strip {
    padding: 40px;
    border-top: 1px solid var(--rule);
}

.step-rail {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    flex-wrap: wrap;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 160px;
    max-width: 220px;
    text-align: center;
}

.step-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--text);
    background: var(--canvas);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
    font-feature-settings: "tnum" 1;
    transition: background 200ms ease, color 200ms ease;
}

.step.active .step-circle {
    background: var(--text);
    color: var(--canvas);
}

.step-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 8px;
}

.step-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text);
}

.step-desc {
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-soft);
}

.step-connector {
    flex: 0 0 60px;
    height: 2px;
    background: var(--axis);
    margin-top: 19px;
}

/* ===== Data spec strip ===== */

.data-strip {
    padding: 40px;
    border-top: 1px solid var(--rule);
}

.data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
}

.data-card {
    background: var(--canvas);
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dc-key {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--rule);
}

.dc-code {
    font-family: 'Space Grotesk', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--rule);
    padding: 12px;
    border-radius: 2px;
    overflow-x: auto;
    white-space: pre;
    font-feature-settings: "tnum" 1;
}

.dc-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.8rem;
    font-feature-settings: "tnum" 1;
}

.dc-table th {
    text-align: left;
    font-weight: 600;
    color: var(--text-soft);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 4px 0;
    border-bottom: 1px solid var(--rule);
}

.dc-table td {
    padding: 6px 0;
    border-bottom: 1px solid var(--rule);
    color: var(--text);
    vertical-align: middle;
}

.dc-table tr:last-child td {
    border-bottom: none;
}

.sw {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

/* ===== Footer ===== */

.canvas-footer {
    padding: 32px 40px 28px;
    border-top: 1px solid var(--rule);
    background: var(--panel);
    margin-top: auto;
}

.footer-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--rule);
}

.footer-brand {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    letter-spacing: -0.01em;
}

.footer-meta {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.footer-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 24px;
}

.footer-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fc-head {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--rule);
}

.fc-link {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--text-soft);
    cursor: pointer;
    transition: color 140ms ease;
}

.fc-link:hover {
    color: var(--text);
}

.footer-mono {
    font-family: 'Space Grotesk', sans-serif;
    display: flex;
    justify-content: space-between;
    font-feature-settings: "tnum" 1;
}

/* ===== Responsive ===== */

@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .tool-panel {
        position: relative;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--rule);
    }

    .canvas-header {
        flex-direction: column;
        gap: 20px;
        padding: 24px 24px 16px;
    }

    .hero-canvas, .showcase, .how-strip, .data-strip {
        padding: 24px;
    }

    .canvas-footer {
        padding: 24px;
    }

    .step-rail {
        flex-direction: column;
        align-items: stretch;
    }

    .step {
        flex-direction: row;
        max-width: none;
        text-align: left;
        gap: 14px;
    }

    .step-body {
        padding: 0;
    }

    .step-connector {
        width: 2px;
        height: 30px;
        margin-left: 19px;
        background: var(--axis);
    }
}

@media (max-width: 520px) {
    .canvas-title {
        font-size: 1.6rem;
    }

    .canvas-frame {
        height: 380px;
    }
}
