/* ========================================
   Ancient Life Family Tree
   Paleoart Book / Museum Style
   ======================================== */

/* CSS Variables */
:root {
    --bg-cream: #f5f2eb;
    --bg-paper: #faf8f3;
    --bg-dark: #2c2c2c;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-caption: #666666;
    --accent-cambrian: #3d6b8c;
    --accent-permian: #8c4a3d;
    --accent-triassic: #4a7c5c;
    --accent-cretaceous: #5a8c1a;
    --accent-gold: #8b7355;
    --border-light: #d4d0c8;
    --border-dark: #b8b4aa;
    --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.12);
    --font-serif: 'Georgia', 'Times New Roman', serif;
    --font-sans: 'Helvetica Neue', 'Arial', sans-serif;
    --card-width: 48%;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-serif);
    background: var(--bg-cream);
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 16px;
}

/* Views */
.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: opacity 0.5s ease;
}

.view.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ========================================
   List View - Natural History Book Style
   ======================================== */

#list-view {
    display: flex;
    flex-direction: column;
    background: var(--bg-cream);
    height: 100%;
}

.list-header {
    text-align: center;
    padding: 40px 20px 25px;
    background: var(--bg-paper);
    border-bottom: 1px solid var(--border-light);
}

.list-header h1 {
    font-family: var(--font-serif);
    font-size: 2.4rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.list-header .subtitle {
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--text-caption);
    font-size: 1rem;
    font-weight: 400;
    margin-bottom: 20px;
}

/* View Toggle */
.view-toggle {
    display: inline-flex;
    gap: 20px;
}

.toggle-btn {
    padding: 0;
    background: transparent;
    border: none;
    font-family: var(--font-serif);
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-caption);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.toggle-btn::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 1px;
    background: transparent;
    transition: background 0.2s ease;
}

.toggle-btn:not(:last-child)::before {
    content: '/';
    position: absolute;
    right: -12px;
    color: var(--border-dark);
    font-weight: 300;
}

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

.toggle-btn.active {
    color: var(--text-primary);
}

.toggle-btn.active::after {
    background: var(--text-primary);
}

/* List Content - 3 column layout */
.list-content {
    flex: 1;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

/* Side columns - max width, adjacent to content */
.list-sidebar {
    width: 160px;
    max-width: 160px;
    flex-shrink: 0;
    padding: 30px 15px;
    overflow-y: auto;
}

.list-sidebar-left {
    /* Era navigation - align to right edge */
    display: flex;
    justify-content: flex-end;
}

.list-sidebar-right {
    /* Size toggle - hidden for now but keeps space for centering */
    visibility: hidden;
}

/* Era Navigation */
.era-nav {
    /* Navigation scrolls with sidebar, no sticky */
}

.era-group {
    margin-bottom: 20px;
}

.era-group-title {
    font-family: var(--font-sans);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-caption);
    margin-bottom: 8px;
    padding-left: 4px;
}

.era-period-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--text-caption);
    border-radius: 4px;
}

/* Reserve space for bold text to prevent reflow on active */
.era-period-btn .era-text {
    display: flex;
    flex-direction: column;
}

.era-period-btn .era-text::after {
    content: attr(data-text);
    font-weight: 600;
    height: 0;
    visibility: hidden;
    overflow: hidden;
    pointer-events: none;
}

.era-period-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-secondary);
}

.era-period-btn.active {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
    font-weight: 500;
}

.era-period-btn .era-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Era dot colors */
.era-dot.hadean { background: #b03030; }
.era-dot.archean { background: #2a6b8a; }
.era-dot.proterozoic { background: #8b4a8b; }
.era-dot.cambrian { background: var(--accent-cambrian); }
.era-dot.ordovician { background: #009270; }
.era-dot.silurian { background: #5a9a85; }
.era-dot.devonian { background: #cb8c37; }
.era-dot.carboniferous { background: #67a599; }
.era-dot.permian { background: var(--accent-permian); }
.era-dot.triassic { background: var(--accent-triassic); }
.era-dot.jurassic { background: #34b4eb; }
.era-dot.cretaceous { background: var(--accent-cretaceous); }
.era-dot.paleocene { background: #fd9a52; }
.era-dot.eocene { background: #d9a066; }
.era-dot.oligocene { background: #c98b4a; }
.era-dot.miocene { background: #b8a000; }
.era-dot.pliocene { background: #a69000; }
.era-dot.pleistocene { background: #8b6914; }
.era-dot.holocene { background: #4a7a4a; }

/* Size Toggle */
.size-toggle {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.size-label {
    font-family: var(--font-sans);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-caption);
    margin-bottom: 4px;
}

.size-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-light);
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-caption);
    transition: all 150ms ease;
}

.size-btn:hover {
    border-color: var(--border-dark);
    color: var(--text-secondary);
}

.size-btn.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--bg-paper);
}

/* Main content column */
.list-main {
    width: 900px;
    max-width: 900px;
    flex-shrink: 1;
    overflow-y: auto;
    min-width: 0;
}

#creature-list {
    padding: 40px 30px 60px;
}

/* List size variations */

/* Icons view (small) - larger thumbnails */
#creature-list.size-small .creature-entries {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
}

#creature-list.size-small .creature-entry {
    flex-direction: column;
    padding: 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
}

#creature-list.size-small .creature-entry:hover {
    background: rgba(0, 0, 0, 0.03);
}

#creature-list.size-small .entry-illustration {
    width: 120px;
    height: 120px;
    margin: 0 auto 10px;
}

#creature-list.size-small .entry-illustration img {
    border-radius: 6px;
}

#creature-list.size-small .entry-content {
    text-align: center;
}

#creature-list.size-small .entry-name {
    font-size: 0.8rem;
    margin-bottom: 0;
}

#creature-list.size-small .entry-name .species {
    display: none;
}

#creature-list.size-small .entry-size,
#creature-list.size-small .entry-location,
#creature-list.size-small .entry-arrow {
    display: none;
}

/* Medium/List size (default) - no changes needed */

/* Period Sections */
.period-section {
    margin-bottom: 50px;
}

.period-section:last-child {
    margin-bottom: 0;
}

.period-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.period-ornament {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-dark), transparent);
    max-width: 100px;
}

.period-ornament.left {
    background: linear-gradient(90deg, transparent, var(--border-dark));
}

.period-ornament.right {
    background: linear-gradient(90deg, var(--border-dark), transparent);
}

.period-title-block {
    text-align: center;
}

.period-name {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    margin: 0;
}

.period-section.hadean .period-name { color: #b03030; }
.period-section.archean .period-name { color: #2a6b8a; }
.period-section.proterozoic .period-name { color: #8b4a8b; }
.period-section.cambrian .period-name { color: var(--accent-cambrian); }
.period-section.ordovician .period-name { color: #009270; }
.period-section.silurian .period-name { color: #5a9a85; }
.period-section.devonian .period-name { color: #cb8c37; }
.period-section.carboniferous .period-name { color: #67a599; }
.period-section.permian .period-name { color: var(--accent-permian); }
.period-section.triassic .period-name { color: var(--accent-triassic); }
.period-section.jurassic .period-name { color: #34b4eb; }
.period-section.cretaceous .period-name { color: var(--accent-cretaceous); }
.period-section.paleocene .period-name { color: #fd9a52; }
.period-section.eocene .period-name { color: #d9a066; }
.period-section.oligocene .period-name { color: #c98b4a; }
.period-section.miocene .period-name { color: #b8a000; }
.period-section.pliocene .period-name { color: #a69000; }
.period-section.pleistocene .period-name { color: #8b6914; }
.period-section.holocene .period-name { color: #4a7a4a; }

.period-range {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--text-caption);
    letter-spacing: 0.05em;
}

.period-description {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 0.9rem;
    color: var(--text-caption);
    text-align: center;
    margin: 0 0 25px;
    line-height: 1.6;
}

/* Creature Entries */
.creature-entries {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.creature-entry {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 18px 15px;
    background: var(--bg-paper);
    border: 1px solid var(--border-light);
    border-bottom: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.creature-entry:first-child {
    border-radius: 4px 4px 0 0;
}

.creature-entry:last-child {
    border-bottom: 1px solid var(--border-light);
    border-radius: 0 0 4px 4px;
}

.creature-entry:only-child {
    border-radius: 4px;
    border-bottom: 1px solid var(--border-light);
}

.creature-entry:hover {
    background: var(--bg-cream);
    border-color: var(--border-dark);
}

.creature-entry:hover + .creature-entry {
    border-top-color: var(--border-dark);
}

/* Entry Illustration */
.entry-illustration {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--bg-cream);
    border: 1px solid var(--border-light);
}

.entry-illustration img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.no-illustration {
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        var(--bg-cream),
        var(--bg-cream) 5px,
        var(--bg-paper) 5px,
        var(--bg-paper) 10px
    );
}

/* Entry Content */
.entry-content {
    flex: 1;
    min-width: 0;
}

.entry-name {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 400;
    margin: 0 0 6px;
    line-height: 1.3;
}

.entry-name .genus {
    font-style: italic;
}

.entry-name .species {
    font-style: italic;
    color: var(--text-secondary);
}

.entry-size {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0 0 4px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.entry-location {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--text-caption);
    margin: 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Entry Arrow */
.entry-arrow {
    flex-shrink: 0;
    color: var(--border-dark);
    transition: transform 0.2s ease, color 0.2s ease;
}

.creature-entry:hover .entry-arrow {
    color: var(--text-secondary);
    transform: translateX(3px);
}

/* List Footer */
.list-footer {
    background: var(--bg-paper);
    border-top: 1px solid var(--border-light);
    padding: 15px 20px;
}

.legend-bar {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.legend-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.legend-btn:hover {
    background: var(--bg-cream);
    border-color: var(--border-dark);
    color: var(--text-primary);
}

.legend-btn .legend-color {
    width: 8px;
    height: 8px;
}

.legend-bar .legend-item {
    font-size: 0.75rem;
}

.legend-color.hadean { background: #b03030; }
.legend-color.archean { background: #2a6b8a; }
.legend-color.proterozoic { background: #8b4a8b; }
.legend-color.ordovician { background: #009270; }
.legend-color.silurian { background: #5a9a85; }
.legend-color.devonian { background: #cb8c37; }
.legend-color.carboniferous { background: #67a599; }
.legend-color.jurassic { background: #34b4eb; }
.legend-color.paleocene { background: #fd9a52; }
.legend-color.eocene { background: #d9a066; }
.legend-color.oligocene { background: #c98b4a; }
.legend-color.miocene { background: #b8a000; }
.legend-color.pliocene { background: #a69000; }
.legend-color.pleistocene { background: #8b6914; }
.legend-color.holocene { background: #4a7a4a; }

/* ========================================
   Tree View
   ======================================== */

#tree-view {
    display: flex;
    flex-direction: column;
    background: var(--bg-cream);
}

.tree-header {
    text-align: center;
    padding: 40px 20px 25px;
    background: var(--bg-paper);
    border-bottom: 1px solid var(--border-light);
}

.tree-header h1 {
    font-family: var(--font-serif);
    font-size: 2.4rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.tree-header .subtitle {
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--text-caption);
    font-size: 1rem;
    font-weight: 400;
    margin-bottom: 20px;
}

/* Tree Toolbar */
#tree-toolbar {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 10px 20px;
    background: var(--bg-paper);
    border-bottom: 1px solid var(--border-light);
}

.tree-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-cream);
    border: 1px solid var(--border-light);
    border-radius: 3px;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tree-btn:hover {
    background: var(--bg-paper);
    border-color: var(--border-dark);
    color: var(--text-primary);
}

.tree-btn .btn-icon {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
}

#tree-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--bg-paper);
}

/* Fixed axis background */
.fixed-axis-layer {
    /* Background rect is added via JS */
}

#tree-svg {
    width: 100%;
    height: 100%;
    cursor: grab;
}

#tree-svg:active {
    cursor: grabbing;
}

/* Tree Links */
.tree-link {
    fill: none;
    stroke: #9a968c;
    stroke-width: 1.5px;
}

/* Tree Nodes */
.tree-node {
    cursor: pointer;
}

.tree-node circle {
    fill: var(--bg-paper);
    stroke-width: 2px;
    transition: all 0.2s ease;
}

.tree-node.hadean circle { stroke: #b03030; }
.tree-node.archean circle { stroke: #2a6b8a; }
.tree-node.proterozoic circle { stroke: #8b4a8b; }
.tree-node.cambrian circle { stroke: var(--accent-cambrian); }
.tree-node.ordovician circle { stroke: #009270; }
.tree-node.silurian circle { stroke: #5a9a85; }
.tree-node.devonian circle { stroke: #cb8c37; }
.tree-node.carboniferous circle { stroke: #67a599; }
.tree-node.permian circle { stroke: var(--accent-permian); }
.tree-node.triassic circle { stroke: var(--accent-triassic); }
.tree-node.jurassic circle { stroke: #34b4eb; }
.tree-node.cretaceous circle { stroke: var(--accent-cretaceous); }
.tree-node.paleocene circle { stroke: #fd9a52; }
.tree-node.eocene circle { stroke: #d9a066; }
.tree-node.oligocene circle { stroke: #c98b4a; }
.tree-node.miocene circle { stroke: #b8a000; }
.tree-node.pliocene circle { stroke: #a69000; }
.tree-node.pleistocene circle { stroke: #8b6914; }
.tree-node.holocene circle { stroke: #4a7a4a; }

.tree-node.category circle {
    stroke: var(--border-dark);
    fill: var(--bg-cream);
}

.tree-node:hover circle {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.tree-node .label-bg {
    fill: var(--bg-paper);
    pointer-events: none;
}

.tree-node .expand-bg {
    fill: var(--bg-paper);
    pointer-events: none;
}

.tree-node text {
    font-family: var(--font-sans);
    font-size: 11px;
    fill: #3a3a3a;
    /* text-anchor set by JS - don't override here */
    pointer-events: none;
    font-weight: 500;
}

.tree-node.creature text {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 11px;
    font-weight: 400;
}

.tree-node image {
    clip-path: circle(50%);
}

/* Legend */
#legend {
    display: flex;
    justify-content: center;
    gap: 40px;
    padding: 18px 20px;
    background: var(--bg-paper);
    border-top: 1px solid var(--border-light);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-caption);
    letter-spacing: 0.03em;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-color.cambrian {
    background: var(--accent-cambrian);
}

.legend-color.permian {
    background: var(--accent-permian);
}

.legend-color.triassic {
    background: var(--accent-triassic);
}

.legend-color.cretaceous {
    background: var(--accent-cretaceous);
}

/* ========================================
   Creature View - Book Layout
   ======================================== */

#creature-view {
    overflow-y: auto;
    background: var(--bg-cream);
}

.creature-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 56%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 0;
    transition: width 0.4s ease;
}

/* Expand background when card is minimized */
.creature-background.expanded,
#splat-container.expanded {
    width: 100%;
}

.creature-overlay {
    /* Gradient removed per user request */
    display: none;
}

.creature-content {
    position: relative;
    z-index: 2;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* Creature Navigation Bar */
.creature-nav {
    position: fixed;
    top: 25px;
    left: 25px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Back Button - Refined museum style */
.back-button {
    background: rgba(26, 26, 26, 0.5);
    border: none;
    border-radius: 2px;
    color: rgba(255, 255, 255, 0.85);
    padding: 10px 16px 10px 14px;
    font-family: var(--font-sans);
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    cursor: pointer;
    transition: all 0.25s ease;
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 8px;
}

.back-button:hover {
    background: rgba(26, 26, 26, 0.3);
    color: rgba(255, 255, 255, 1);
}

.back-arrow {
    font-size: 0.85em;
    opacity: 0.7;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.back-button:hover .back-arrow {
    transform: translateX(-2px);
    opacity: 1;
}

/* View Mode Toggle (Life/Fossil) - Elegant segmented control */
.view-mode-toggle {
    display: flex;
    background: rgba(26, 26, 26, 0.5);
    border-radius: 2px;
    padding: 3px;
    backdrop-filter: blur(12px);
    gap: 2px;
}

.view-mode-toggle.hidden {
    display: none;
}

.mode-btn {
    background: transparent;
    border: none;
    padding: 7px 16px;
    font-family: var(--font-sans);
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    border-radius: 1px;
}

.mode-btn:hover {
    color: rgba(255, 255, 255, 0.85);
}

.mode-btn.active {
    color: rgba(255, 255, 255, 0.95);
    background: rgba(255, 255, 255, 0.12);
}

/* Entry Navigation (Prev/Next) */
.entry-nav {
    position: fixed;
    bottom: 25px;
    left: 25px;
    right: calc(var(--card-width) + 25px);
    z-index: 10;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    transition: right 0.4s ease;
}

/* Expand nav when card is minimized */
.entry-nav.expanded {
    right: 25px;
}

.entry-nav-btn {
    background: rgba(26, 26, 26, 0.5);
    border: none;
    border-radius: 2px;
    color: rgba(255, 255, 255, 0.85);
    padding: 10px 14px;
    font-family: var(--font-sans);
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all 0.25s ease;
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 8px;
    width: 180px;
    pointer-events: auto;
}

.entry-nav-btn:hover {
    background: rgba(26, 26, 26, 0.3);
    color: rgba(255, 255, 255, 1);
}

.entry-nav-btn.disabled {
    opacity: 0;
    pointer-events: none;
}

.entry-nav-btn .nav-arrow {
    font-size: 0.9em;
    opacity: 0.7;
    transition: transform 0.2s ease, opacity 0.2s ease;
    flex-shrink: 0;
}

.entry-nav-btn .nav-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-style: italic;
    opacity: 0.85;
}

#nav-prev {
    justify-content: flex-start;
}

#nav-prev .nav-label {
    text-align: left;
}

#nav-next {
    justify-content: flex-end;
}

#nav-next .nav-label {
    text-align: right;
}

#nav-prev:hover .nav-arrow {
    transform: translateX(-2px);
    opacity: 1;
}

#nav-next:hover .nav-arrow {
    transform: translateX(2px);
    opacity: 1;
}

/* Splat Crossfade Animation */
#splat-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 56%;
    height: 100%;
    z-index: 1;
    transition: width 0.4s ease;
    background: #1a1a1a;
}

#splat-container.hidden {
    display: none;
}

#splat-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Secondary splat container for crossfade */
#splat-container-secondary {
    position: fixed;
    top: 0;
    left: 0;
    width: 56%;
    height: 100%;
    z-index: 2;
    background: #1a1a1a;
    pointer-events: none;
    clip-path: inset(0 100% 0 0);
    transition: width 0.4s ease;
}

#splat-container-secondary.hidden {
    display: none;
}

#splat-container-secondary canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Wipe animation - left to right reveal */
@keyframes wipeReveal {
    from {
        clip-path: inset(0 100% 0 0);
    }
    to {
        clip-path: inset(0 0 0 0);
    }
}

@keyframes wipeHide {
    from {
        clip-path: inset(0 0 0 0);
    }
    to {
        clip-path: inset(0 0 0 100%);
    }
}

#splat-container-secondary.wipe-in {
    animation: wipeReveal 0.6s ease-out forwards;
}

#splat-container-secondary.wipe-out {
    animation: wipeHide 0.6s ease-out forwards;
}

/* Creature Card - Right Side Panel */
.creature-card {
    position: relative;
    margin-left: auto;
    width: var(--card-width);
    min-height: 100vh;
    background: var(--bg-paper);
    padding: 60px 50px 80px 45px;
    border-left: 1px solid var(--border-light);
    transition: transform 0.4s ease, opacity 0.4s ease;
}

/* Card Toggle Button - Thin edge tab */
.card-toggle {
    position: fixed;
    top: 50%;
    right: var(--card-width);
    transform: translateY(-50%);
    width: 16px;
    height: 80px;
    background: var(--bg-paper);
    border: none;
    border-left: 1px solid var(--border-dark);
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    border-radius: 5px 0 0 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: right 0.4s ease, background 0.2s ease, width 0.2s ease;
    /* White extension to cover card border */
    box-shadow: 2px 0 0 0 var(--bg-paper);
}

/* Inner rounded corners - radial gradient cutouts at junction */
.card-toggle::before,
.card-toggle::after {
    content: '';
    position: absolute;
    right: -2px;  /* Overlap card border */
    width: 10px;
    height: 10px;
    z-index: 101;  /* Above card */
    pointer-events: none;
}

/* Top: dark is above-left, so circle at top-left (0% 0%) */
.card-toggle::before {
    top: -10px;
    background: radial-gradient(circle at 0% 0%, transparent 9px, var(--bg-paper) 10px);
}

/* Bottom: dark is below-left, so circle at bottom-left (0% 100%) */
.card-toggle::after {
    bottom: -10px;
    background: radial-gradient(circle at 0% 100%, transparent 9px, var(--bg-paper) 10px);
}

.card-toggle:hover {
    background: var(--bg-cream);
    width: 20px;
    box-shadow: 2px 0 0 0 var(--bg-cream);
}

/* Update corner fills on hover to match new background */
.card-toggle:hover::before {
    background: radial-gradient(circle at 0% 0%, transparent 9px, var(--bg-cream) 10px);
}

.card-toggle:hover::after {
    background: radial-gradient(circle at 0% 100%, transparent 9px, var(--bg-cream) 10px);
}

.card-toggle.shifted {
    right: 0;
    border-radius: 5px 0 0 5px;
    border-right: none;
}

/* Hide corner cutouts when card is minimized (tab at edge of screen) */
.card-toggle.shifted::before,
.card-toggle.shifted::after {
    display: none;
}

.toggle-icon {
    font-size: 16px;
    color: var(--text-caption);
    font-weight: 400;
    line-height: 1;
    font-family: var(--font-sans);
    opacity: 0.6;
}

.card-toggle:hover .toggle-icon {
    opacity: 1;
}

/* Minimized Card State - slides off to the right with fade */
.creature-card.minimized {
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
}

.creature-name {
    font-family: var(--font-serif);
    font-size: 2.4rem;
    font-weight: 400;
    font-style: italic;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.2;
}

.creature-nickname {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--text-caption);
    margin-bottom: 35px;
    font-weight: 400;
    letter-spacing: 0.02em;
}

/* Quick Facts - Horizontal Bar */
.creature-quick-facts {
    display: flex;
    gap: 0;
    margin-bottom: 35px;
    padding: 20px 0;
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

.fact {
    flex: 1;
    padding: 0 18px;
    border-right: 1px solid #c8c4ba;
}

.fact:last-child {
    border-right: none;
}

.fact:first-child {
    padding-left: 0;
}

.fact-label {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #5a5a5a;
    margin-bottom: 6px;
    font-weight: 600;
}

.fact-value {
    display: block;
    font-family: var(--font-serif);
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.5;
}

/* Sections */
.creature-section {
    margin-bottom: 30px;
}

.creature-section h2 {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: #5a5448;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.creature-section p {
    font-family: var(--font-serif);
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.8;
    text-align: justify;
    hyphens: auto;
}

.creature-section ul {
    list-style: none;
    padding: 0;
}

.creature-section li {
    font-family: var(--font-serif);
    color: var(--text-secondary);
    font-size: 0.95rem;
    padding: 8px 0;
    padding-left: 20px;
    position: relative;
    line-height: 1.6;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.creature-section li:last-child {
    border-bottom: none;
}

.creature-section li::before {
    content: "—";
    position: absolute;
    left: 0;
    color: var(--border-dark);
}

/* Video Container */
#video-container {
    margin-top: 30px;
    padding-top: 25px;
    border-top: 1px solid var(--border-light);
}

#video-container.hidden {
    display: none;
}

#video-container h2 {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: #5a5448;
    margin-bottom: 15px;
}

#creature-video {
    width: 100%;
    border: 1px solid var(--border-light);
    background: var(--bg-dark);
}

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

@media (max-width: 1024px) {
    /* Creature view - relative for nav positioning, scrolls internally */
    #creature-view {
        position: relative;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .creature-background {
        width: 100%;
        height: 50vh;
        position: relative;
    }

    .creature-overlay {
        width: 100%;
        height: 50vh;
        position: absolute;
        top: 0;
        left: 0;
        background: linear-gradient(
            to bottom,
            transparent 0%,
            transparent 70%,
            var(--bg-cream) 100%
        );
        pointer-events: none;
    }

    /* Splat containers match background on tablet/mobile */
    #splat-container,
    #splat-container-secondary {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 50vh;
        touch-action: none; /* Enable custom touch handling for camera drag */
        cursor: grab;
    }

    #splat-container:active,
    #splat-container-secondary:active {
        cursor: grabbing;
    }

    .creature-card {
        width: 100%;
        margin-left: 0;
        border-left: none;
        padding: 30px 25px 50px;
    }

    .creature-name {
        font-size: 1.8rem;
    }

    .creature-quick-facts {
        flex-direction: column;
        gap: 15px;
    }

    .fact {
        padding: 0;
        border-right: none;
        border-bottom: 1px solid var(--border-light);
        padding-bottom: 12px;
    }

    .fact:last-child {
        border-bottom: none;
    }

    /* Entry nav - sides of splat viewport for thumb access on tablet/mobile */
    .entry-nav {
        position: absolute;
        bottom: auto;
        top: 0;
        left: 0;
        right: 0;
        height: 50vh;
        pointer-events: none;
    }

    .entry-nav-btn {
        position: absolute;
        top: auto;
        bottom: 15px;
        transform: none;
        width: auto;
        padding: 16px 10px;
        pointer-events: auto;
    }

    #nav-prev {
        left: 8px;
    }

    #nav-next {
        right: 8px;
    }

    /* Creature nav - absolute within splat viewport */
    .creature-nav {
        position: absolute;
        top: 15px;
        left: 15px;
    }

    /* Hide card toggle on tablet/mobile - card always visible */
    .card-toggle {
        display: none;
    }
}

@media (max-width: 768px) {
    /* Splat viewport - taller on mobile for better viewing */
    .creature-background {
        height: 55vh;
        min-height: 280px;
    }

    .creature-overlay,
    #splat-container,
    #splat-container-secondary {
        height: 55vh;
        min-height: 280px;
    }

    /* List View Responsive */
    .list-header h1 {
        font-size: 1.6rem;
        letter-spacing: 0.04em;
    }

    .list-header .subtitle {
        font-size: 0.9rem;
    }

    /* Hide sidebars on mobile */
    .list-sidebar {
        display: none;
    }

    .list-main {
        width: 100%;
    }

    #creature-list {
        padding: 25px 15px 40px;
    }

    /* Disable small grid on mobile - too cramped */
    #creature-list.size-small .creature-entries {
        display: block;
    }

    #creature-list.size-small .creature-entry {
        flex-direction: row;
        padding: 14px 12px;
        border: none;
        background: var(--bg-paper);
        border-bottom: 1px solid var(--border-light);
    }

    #creature-list.size-small .entry-illustration {
        width: 60px;
        height: 60px;
        margin: 0;
    }

    #creature-list.size-small .entry-content {
        text-align: left;
    }

    #creature-list.size-small .entry-name {
        font-size: inherit;
    }

    #creature-list.size-small .entry-name .species {
        display: inline;
    }

    #creature-list.size-small .entry-size,
    #creature-list.size-small .entry-location {
        display: block;
    }

    #creature-list.size-small .entry-arrow {
        display: flex;
    }

    .period-header {
        gap: 12px;
    }

    .period-ornament {
        max-width: 40px;
    }

    .creature-entry {
        gap: 12px;
        padding: 14px 12px;
    }

    .entry-illustration {
        width: 60px;
        height: 60px;
    }

    .entry-name {
        font-size: 1rem;
    }

    .legend-bar {
        gap: 15px;
    }

    /* Tree View Responsive */
    #tree-view h1,
    .tree-header h1 {
        font-size: 1.5rem;
    }

    #legend {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    /* Creature nav - compact on mobile */
    .creature-nav {
        top: 10px;
        left: 10px;
        gap: 6px;
    }

    .back-button {
        padding: 8px 12px 8px 10px;
        font-size: 0.6rem;
    }

    .mode-btn {
        padding: 6px 10px;
        font-size: 0.55rem;
    }

    /* Entry nav - sides of splat viewport on mobile */
    .entry-nav {
        height: 55vh;
        min-height: 280px;
    }

    .entry-nav-btn {
        padding: 0;
        font-size: 1rem;
        width: 44px;
        height: 44px;
        min-width: unset;
        border-radius: 50%;
        justify-content: center;
        gap: 0;
    }

    #nav-prev,
    #nav-next {
        justify-content: center;
    }

    #nav-prev {
        left: 10px;
    }

    #nav-next {
        right: 10px;
    }

    .entry-nav-btn .nav-label {
        display: none;
    }

    .entry-nav-btn .nav-arrow {
        margin: 0;
        flex-shrink: 0;
    }

    /* Creature card adjustments for mobile */
    .creature-card {
        padding: 25px 18px 40px;
    }

    .creature-name {
        font-size: 1.5rem;
    }

    .creature-nickname {
        font-size: 0.85rem;
    }

    .section-heading {
        font-size: 0.7rem;
    }
}

/* ========================================
   Tooltips
   ======================================== */

.tooltip {
    position: absolute;
    background: var(--bg-paper);
    color: var(--text-primary);
    padding: 10px 14px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    pointer-events: none;
    z-index: 100;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-medium);
    max-width: 250px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tooltip.visible {
    opacity: 1;
}

.tooltip small {
    display: block;
    color: var(--text-caption);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ========================================
   Loading State
   ======================================== */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-family: var(--font-sans);
    color: var(--text-caption);
    font-size: 0.9rem;
    letter-spacing: 0.05em;
}

.loading::after {
    content: "";
    width: 16px;
    height: 16px;
    border: 1px solid var(--border-dark);
    border-top-color: transparent;
    border-radius: 50%;
    margin-left: 12px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .back-button {
        display: none;
    }

    .creature-background {
        position: relative;
        width: 100%;
        height: 40vh;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .creature-overlay {
        display: none;
    }

    .creature-card {
        width: 100%;
        border: none;
        box-shadow: none;
    }
}
