/* AllOfHistory - Functional Design */

:root {
    /* Category colors - distinct, solid */
    --cat-cosmic: #9966cc;
    --cat-geological: #cc6633;
    --cat-biological: #339966;
    --cat-prehistoric: #cc9933;
    --cat-political: #cc3333;
    --cat-cultural: #3366cc;
    --cat-scientific: #cccc33;
    --cat-technological: #666666;
    --cat-economic: #993366;
    --cat-social: #cc6699;

    /* UI colors */
    --bg: #111;
    --bg-raised: #1a1a1a;
    --bg-input: #222;
    --border: #333;
    --border-focus: #555;
    --text: #e0e0e0;
    --text-dim: #888;
    --text-bright: #fff;
    --accent: #4a9eff;

    /* Layout */
    --header-h: 48px;
    --era-h: 40px;
    --footer-h: 32px;
    --panel-w: 360px;

    /* Type */
    --font: 'IBM Plex Sans', -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

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

body {
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.btn:hover {
    border-color: var(--border-focus);
    background: var(--bg-input);
}

.btn:active {
    background: var(--border);
}

.btn-sq {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 16px;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.btn-icon:hover {
    color: var(--text);
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.logo {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-bright);
}

.logo-sub {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
}

.header-center {
    flex: 1;
    max-width: 300px;
}

.search-container {
    position: relative;
}

#search-input {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
}

#search-input:focus {
    border-color: var(--accent);
}

#search-input::placeholder {
    color: var(--text-dim);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-top: none;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 200;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--bg-input);
}

.search-result-title {
    font-weight: 500;
    color: var(--text-bright);
    margin-bottom: 2px;
}

.search-result-date {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
}

.header-right {
    display: flex;
    gap: 8px;
}

/* Category Panel */
.category-panel {
    position: fixed;
    top: var(--header-h);
    right: -260px;
    width: 240px;
    background: var(--bg-raised);
    border-left: 1px solid var(--border);
    height: calc(100vh - var(--header-h));
    z-index: 150;
    transition: right 0.2s;
    display: flex;
    flex-direction: column;
}

.category-panel.active {
    right: 0;
}

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

.panel-title {
    font-weight: 600;
    font-size: 13px;
}

.category-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.category-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 13px;
}

.category-item:hover {
    background: var(--bg-input);
}

.category-item input {
    width: 14px;
    height: 14px;
    margin: 0;
    cursor: pointer;
}

.cat-color {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

.category-item[data-category="cosmic"] .cat-color { background: var(--cat-cosmic); }
.category-item[data-category="geological"] .cat-color { background: var(--cat-geological); }
.category-item[data-category="biological"] .cat-color { background: var(--cat-biological); }
.category-item[data-category="prehistoric"] .cat-color { background: var(--cat-prehistoric); }
.category-item[data-category="political"] .cat-color { background: var(--cat-political); }
.category-item[data-category="cultural"] .cat-color { background: var(--cat-cultural); }
.category-item[data-category="scientific"] .cat-color { background: var(--cat-scientific); }
.category-item[data-category="technological"] .cat-color { background: var(--cat-technological); }
.category-item[data-category="economic"] .cat-color { background: var(--cat-economic); }
.category-item[data-category="social"] .cat-color { background: var(--cat-social); }

.panel-actions {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.panel-actions .btn {
    flex: 1;
}

/* Era Navigation */
.era-nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    height: var(--era-h);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 4px;
    overflow-x: auto;
    z-index: 90;
}

.era-nav::-webkit-scrollbar {
    height: 0;
}

.era-btn {
    padding: 4px 10px;
    background: none;
    border: 1px solid transparent;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}

.era-btn:hover {
    color: var(--text);
    border-color: var(--border);
}

.era-btn.active {
    color: var(--accent);
    border-color: var(--accent);
}

/* Main Content */
.main-content {
    position: fixed;
    top: calc(var(--header-h) + var(--era-h));
    left: 0;
    right: 0;
    bottom: var(--footer-h);
}

.timeline-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-x;
}

.timeline-container:active {
    cursor: grabbing;
}

.timeline {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    min-width: 100%;
}

.timeline-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border);
    transform: translateY(-50%);
}

.events-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Event Markers */
.event-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    cursor: pointer;
}

.event-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg);
    transition: transform 0.15s;
}

.event-marker:hover .event-dot {
    transform: scale(1.3);
}

.event-marker.importance-10 .event-dot { width: 18px; height: 18px; }
.event-marker.importance-9 .event-dot { width: 16px; height: 16px; }
.event-marker.importance-8 .event-dot { width: 14px; height: 14px; }

.event-marker[data-category="cosmic"] .event-dot { background: var(--cat-cosmic); }
.event-marker[data-category="geological"] .event-dot { background: var(--cat-geological); }
.event-marker[data-category="biological"] .event-dot { background: var(--cat-biological); }
.event-marker[data-category="prehistoric"] .event-dot { background: var(--cat-prehistoric); }
.event-marker[data-category="political"] .event-dot { background: var(--cat-political); }
.event-marker[data-category="cultural"] .event-dot { background: var(--cat-cultural); }
.event-marker[data-category="scientific"] .event-dot { background: var(--cat-scientific); }
.event-marker[data-category="technological"] .event-dot { background: var(--cat-technological); }
.event-marker[data-category="economic"] .event-dot { background: var(--cat-economic); }
.event-marker[data-category="social"] .event-dot { background: var(--cat-social); }

.event-label {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.event-label.above {
    bottom: calc(100% + 4px);
}

.event-label.below {
    top: calc(100% + 4px);
}

.event-marker:hover .event-label,
.event-marker.show-label .event-label {
    opacity: 1;
    color: var(--text);
}

.event-marker.selected .event-dot {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.event-marker.search-highlight .event-dot {
    animation: blink 0.8s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Controls */
.controls {
    position: fixed;
    bottom: calc(var(--footer-h) + 12px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    z-index: 80;
}

.zoom-controls, .pan-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    padding: 6px 10px;
}

#zoom-slider {
    width: 120px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    outline: none;
}

#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--text);
    border-radius: 50%;
    cursor: pointer;
}

#zoom-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--text);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Detail Panel */
.detail-panel {
    position: fixed;
    top: var(--header-h);
    right: calc(-1 * var(--panel-w));
    width: var(--panel-w);
    height: calc(100vh - var(--header-h));
    background: var(--bg-raised);
    border-left: 1px solid var(--border);
    z-index: 120;
    transition: right 0.2s;
    overflow-y: auto;
}

.detail-panel.active {
    right: 0;
}

.detail-panel .panel-header {
    position: sticky;
    top: 0;
    background: var(--bg-raised);
    z-index: 1;
}

.detail-category {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px;
}

.detail-category.cosmic { background: var(--cat-cosmic); color: #fff; }
.detail-category.geological { background: var(--cat-geological); color: #fff; }
.detail-category.biological { background: var(--cat-biological); color: #fff; }
.detail-category.prehistoric { background: var(--cat-prehistoric); color: #000; }
.detail-category.political { background: var(--cat-political); color: #fff; }
.detail-category.cultural { background: var(--cat-cultural); color: #fff; }
.detail-category.scientific { background: var(--cat-scientific); color: #000; }
.detail-category.technological { background: var(--cat-technological); color: #fff; }
.detail-category.economic { background: var(--cat-economic); color: #fff; }
.detail-category.social { background: var(--cat-social); color: #fff; }

.detail-content {
    padding: 16px;
}

#detail-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-bright);
    line-height: 1.3;
    margin-bottom: 8px;
}

.detail-date {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
    margin-bottom: 16px;
}

.detail-short {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 12px;
    font-weight: 500;
}

.detail-full {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 20px;
}

.detail-related {
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
}

.detail-related .label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    display: block;
    margin-bottom: 8px;
}

#related-list {
    list-style: none;
}

#related-list li {
    padding: 4px 0;
}

#related-list a {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
}

#related-list a:hover {
    text-decoration: underline;
}

.detail-wiki {
    text-decoration: none;
}

/* Footer */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-h);
    background: var(--bg-raised);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 80;
}

.time-range {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}

.hint {
    font-size: 11px;
    color: var(--text-dim);
}

/* Time Markers */
.time-marker {
    position: absolute;
    top: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

.time-marker-line {
    width: 1px;
    height: 16px;
    background: var(--border);
}

.time-marker-label {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
    margin-top: 4px;
    white-space: nowrap;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-focus);
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --panel-w: 100%;
        --header-h: 44px;
        --era-h: 36px;
    }

    .header-center {
        max-width: 160px;
    }

    .logo-sub {
        display: none;
    }

    .controls {
        gap: 8px;
    }

    .zoom-controls {
        padding: 4px 8px;
    }

    #zoom-slider {
        width: 80px;
    }

    .detail-panel {
        top: auto;
        bottom: -80vh;
        right: 0;
        width: 100%;
        height: 80vh;
        transition: bottom 0.2s;
    }

    .detail-panel.active {
        bottom: 0;
    }

    .hint {
        display: none;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0 8px;
        gap: 8px;
    }

    .logo {
        font-size: 14px;
    }

    .era-btn {
        font-size: 10px;
        padding: 4px 8px;
    }

    .controls {
        left: 8px;
        right: 8px;
        transform: none;
        justify-content: space-between;
    }

    .zoom-controls {
        flex: 1;
    }

    #zoom-slider {
        flex: 1;
        width: auto;
    }
}
