:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-hover: #1a4a7a;
    --border-color: #2a2a5e;
    --text-primary: #dde;
    --text-secondary: #aab;
    --text-muted: #aab;
    --text-dim: #889;
    --accent: #4a8;
    --accent-warm: #e8a838;
}

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

body {
    font-family: 'Segoe UI', 'Arial', sans-serif;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    margin: 0;
    padding: 48px 0 0 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.skip-link { position: absolute; top: -100%; z-index: 9999; background: #3b82f6; color: white; padding: 10px; border-radius: 4px; transition: top 0.1s; }
.skip-link:focus { top: 0; left: 0; outline: 3px solid #93c5fd; }

.top-nav {
    position: absolute; top: 6px; left: 50%; transform: translateX(-50%); z-index: 35;
    display: flex; justify-content: center;
    background: rgba(255,255,255,0.95);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 10px;
    pointer-events: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.nav-links {
    display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
    justify-content: center; pointer-events: auto; padding: 5px 10px;
}
.nav-links a {
    color: #0f172a; text-decoration: none; font-size: 14px;
    padding: 5px 12px; border-radius: 6px; transition: all 0.15s;
    white-space: nowrap; opacity: 0.9; font-weight: 600;
}
.nav-links a:hover { color: #2563eb; opacity: 1; background: rgba(37,99,235,0.12); }
.nav-links a.nav-home { font-size: 13px; opacity: 0.5; font-weight: 400; }
.nav-links a.nav-home:hover { opacity: 1; }

header {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    color: white;
    padding: 0.7rem 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.1rem;
    font-weight: 300;
    letter-spacing: 1px;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--bg-primary);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.controls input {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    width: 200px;
    font-size: 0.85rem;
}

.controls input::placeholder { color: var(--text-muted); }

.controls button {
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.2s;
}

.controls button:hover { background: var(--bg-hover); color: #fff; }

#toggleInstructions {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.2s;
}

#toggleInstructions:hover { background: var(--bg-hover); color: #fff; }

#helpModal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    z-index: 1000;
    max-width: 400px;
    width: 90%;
    border: 1px solid var(--border-color);
}

#helpModal.hidden { display: none; }

#helpModal h2 {
    font-size: 1rem;
    margin-bottom: 0.8rem;
    color: #fff;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#helpModal h2 button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

#helpModal h2 button:hover { color: #fff; }

#helpModal p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
    padding: 3px 0;
}

main {
    flex: 1;
    overflow: hidden;
    display: flex;
    position: relative;
    background: var(--bg-primary);
}

#chronostratigraphicTree {
    flex: 1;
    overflow: auto;
    padding: 0.8rem 1rem 0.8rem 0.5rem;
}

.color-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.8rem;
    padding: 0.5rem 0.8rem;
    background: var(--bg-secondary);
    border-radius: 6px;
    margin-bottom: 0.8rem;
    border: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.1);
}

.tree-node {
    margin-left: 16px;
    position: relative;
}

.tree-connector {
    position: absolute;
    left: -13px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: #2a2a5e;
}

.tree-node:last-child > .tree-connector { height: 14px; }

.tree-node > .content {
    padding: 5px 8px;
    margin: 2px 0;
    background: #16213e;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
    border: 1px solid transparent;
}

.tree-node > .content:hover {
    background: #1a2a5e;
    border-color: #2a2a5e;
}

.color-strip {
    width: 4px;
    height: 22px;
    border-radius: 2px;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.12);
}

.rank-badge {
    font-size: 0.55rem;
    background: #0f3460;
    color: #bbc;
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.toggle {
    cursor: pointer;
    user-select: none;
    color: #dde;
    font-weight: 500;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.toggle::before {
    content: "\25B6";
    display: inline-block;
    font-size: 0.6rem;
    color: #889;
    transition: transform 0.15s;
}

.expanded > .content > .toggle::before { transform: rotate(90deg); }

.time-bar {
    height: 4px;
    border-radius: 2px;
    min-width: 4px;
    flex-shrink: 0;
    opacity: 0.6;
    border: 1px solid rgba(255,255,255,0.1);
}

.time-bar-wrap {
    flex: 0 1 120px;
    max-width: 120px;
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    flex-shrink: 0;
}

.time-range-text {
    color: #889;
    font-size: 0.7rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.tree-node > .children { display: none; }
.tree-node.expanded > .children { display: block; }

.info-icon {
    cursor: pointer;
    font-size: 0.85rem;
    color: #99a;
    flex-shrink: 0;
    padding: 1px 3px;
    border-radius: 3px;
    line-height: 1;
    margin-left: auto;
}

.info-icon:hover { color: #aab; background: #0f3460; }

.highlight > .content { border-color: #e8a838 !important; background: #1a2a4e !important; }

#infoPanel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #16213e;
    color: #dde;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    z-index: 1000;
    max-width: 560px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

#infoPanel.hidden { display: none; }

#infoPanelTitle {
    font-size: 1.2rem;
    margin-bottom: 0.8rem;
    color: #fff;
    border-bottom: 1px solid #2a2a5e;
    padding-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

#infoPanelTitle .title-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

.info-main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.info-section { margin-bottom: 1rem; }

.info-section h4 {
    font-size: 0.75rem;
    color: #889;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.3rem;
}

.unit-description {
    font-size: 0.85rem;
    color: #aab;
    margin-bottom: 0.8rem;
    padding: 0.5rem;
    background: #0f3460;
    border-radius: 4px;
    border-left: 3px solid #4a8;
}

.time-big {
    font-size: 1rem;
    font-weight: 600;
    color: #4a8;
    margin-bottom: 0.2rem;
}

.rank-label {
    font-size: 0.8rem;
    color: #889;
}

.nomen-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.nomen-table th, .nomen-table td {
    padding: 3px 6px;
    text-align: left;
    border-bottom: 1px solid #2a2a5e;
}

.nomen-table th { color: #889; font-weight: 500; width: 50%; }

.sub-units {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.sub-unit-tag {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.72rem;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.corr-tools {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.corr-tool { font-size: 0.78rem; color: #aab; }
.corr-icon { margin-right: 4px; }

.gssp-section { border-left: 3px solid #e8a838; padding-left: 0.8rem; }
.gssp-section p { font-size: 0.78rem; margin-bottom: 0.2rem; }

.info-text { font-size: 0.78rem; color: #aab; line-height: 1.5; }

.info-list { list-style: none; padding: 0; margin: 0; }
.info-list li {
    font-size: 0.78rem;
    color: #aab;
    padding: 2px 0 2px 14px;
    position: relative;
}
.info-list li::before {
    content: "›";
    position: absolute;
    left: 2px;
    color: #4a8;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.tag {
    font-size: 0.72rem;
    background: #0f3460;
    color: #aab;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

#closeInfoPanel {
    display: block;
    margin: 0.8rem auto 0;
    padding: 0.4rem 1.5rem;
    background: #0f3460;
    color: #aab;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

#closeInfoPanel:hover { background: #1a4a7a; color: #fff; }

footer {
    text-align: center;
    padding: 0.4rem;
    background: #16213e;
    color: var(--text-dim);
    font-size: 0.65rem;
    flex-shrink: 0;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #1a1a2e; }
::-webkit-scrollbar-thumb { background: #2a2a5e; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a7e; }

@media (max-width: 768px) {
    .top-nav { display: none; }
    header { padding: 0.5rem 1rem; }
    header h1 { font-size: 0.95rem; }
    .controls { gap: 0.3rem; padding: 0.4rem 0.5rem; }
    .controls input { width: 100%; font-size: 0.8rem; }
    .controls button { font-size: 0.7rem; padding: 0.3rem 0.5rem; }
    #chronostratigraphicTree { padding: 0.5rem; }
    .tree-node { margin-left: 10px; }
    .tree-connector { left: -9px; }
    .tree-node > .content { flex-wrap: wrap; gap: 3px; padding: 4px 6px; }
    .rank-badge { font-size: 0.5rem; padding: 1px 4px; }
    .toggle { font-size: 0.78rem; }
    .time-bar-wrap { flex-basis: 50px; max-width: 50px; }
    .time-range-text { font-size: 0.6rem; }
    .color-legend { gap: 0.2rem 0.4rem; padding: 0.3rem 0.5rem; }
    .legend-item { font-size: 0.6rem; }
    .legend-swatch { width: 8px; height: 8px; }
    #infoPanel { padding: 1rem; max-width: 95%; }
    .info-main-grid { grid-template-columns: 1fr; }
    #helpModal { max-width: 95%; padding: 1rem; }
}

@media (max-width: 480px) {
    header h1 { font-size: 0.85rem; letter-spacing: 0; }
    .controls { padding: 0.3rem 0.4rem; gap: 0.2rem; }
    .controls input { font-size: 0.75rem; }
    .controls button { font-size: 0.65rem; padding: 0.25rem 0.4rem; }
    .tree-node { margin-left: 8px; }
    .tree-connector { left: -7px; }
    .tree-node > .content { padding: 3px 4px; gap: 2px; }
    .toggle { font-size: 0.72rem; }
    .time-bar-wrap { flex-basis: 30px; max-width: 30px; }
    .time-range-text { font-size: 0.55rem; }
    .rank-badge { font-size: 0.45rem; padding: 0 3px; }
    .color-strip { width: 3px; height: 18px; }
    .info-icon { font-size: 0.75rem; }
}
