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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #1a1a1a;
    color: #e0e0e0;
    overflow: hidden;
}

#container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

#scene-container {
    flex: 1;
    min-width: 0;
    position: relative;
    background: #0a0a0a;
}

#scene {
    width: 100%;
    height: 100%;
    display: block;
}

#controls-panel {
    width: 360px;
    flex-shrink: 0;
    background: #2a2a2a;
    padding: 24px;
    overflow-y: auto;
    border-left: 1px solid #404040;
    transition: width 0.3s ease;
}

/* ---------------------------------------------------------------------------
   LEFT PANEL — persistent Visibility Controls
--------------------------------------------------------------------------- */
#left-panel {
    order: -1;               /* render on the far left of the flex row */
    width: 280px;
    flex-shrink: 0;
    background: #2a2a2a;
    padding: 24px;
    overflow-y: auto;
    border-right: 1px solid #404040;
    transition: width 0.25s ease, padding 0.25s ease;
}

.panel-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.panel-title {
    font-size: 17px;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 0.01em;
}

/* Minimize / restore buttons on both panels */
.panel-min-btn {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    background: #1a1a1a;
    border: 1px solid #404040;
    color: #bbb;
    cursor: pointer;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s ease;
}

.panel-min-btn:hover {
    background: #333;
    border-color: #666;
    color: #fff;
}

/* Minimized state: collapse the body, keep the toggle button visible */
#left-panel.minimized,
#controls-panel.minimized {
    width: 56px;
    padding: 12px 10px;
    overflow: hidden;
}

#left-panel.minimized .panel-body,
#controls-panel.minimized .panel-body {
    display: none;
}

#left-panel.minimized .panel-title {
    display: none;
}

#controls-panel.minimized .header-title-block,
#controls-panel.minimized .home-link {
    display: none;
}

#left-panel.minimized .panel-header-row {
    justify-content: center;
    margin-bottom: 0;
}

#controls-panel.minimized .header-section {
    margin-bottom: 0;
}
#controls-panel.minimized .header-top-row {
    justify-content: center;
}


.header-section {
    display: flex;
    flex-direction: column;
    margin-bottom: 24px;
    gap: 12px;
}

/* Top row of the right panel: minimize button (left) + Home (right) */
.header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

/* Title block spans the full panel width so the subtitle can wrap wide */
.header-title-block {
    width: 100%;
}

h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #ffffff;
}

.subtitle {
    font-size: 13px;
    color: #888;
    margin-bottom: 0;
}

.build-marker {
    color: #c9a24a;
    font-weight: 600;
    margin-top: 2px;
}

.panel-header-btns {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.home-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    background: #1a1a1a;
    border: 1px solid #404040;
    border-radius: 4px;
    color: #c9a24a;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.home-link:hover {
    background: #333;
    border-color: #c9a24a;
    color: #e8c874;
}

/* Radio rows in the left panel */
.radio-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 14px;
    color: #d0d0d0;
}

.radio-row input {
    accent-color: #c9a24a;
    cursor: pointer;
}

/* Byline pinned to the very bottom of the right panel */
.panel-byline {
    margin-top: 28px;
    padding-top: 16px;
    border-top: 1px solid #404040;
    font-size: 12px;
    color: #777;
    text-align: center;
    letter-spacing: 0.02em;
}

.control-section {
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid #404040;
}

.control-section:last-of-type {
    border-bottom: none;
}

h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #ffffff;
}

.hint {
    font-size: 12px;
    color: #888;
    margin-bottom: 16px;
    line-height: 1.4;
}

.control-group {
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 13px;
    margin-bottom: 6px;
    color: #b0b0b0;
}

label span {
    float: right;
    color: #fff;
    font-weight: 500;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    background: #404040;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #3498db;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #5dade2;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #3498db;
    cursor: pointer;
    border-radius: 50%;
    border: none;
    transition: background 0.15s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    background: #5dade2;
}

.layer-info {
    margin-top: 8px;
    padding: 8px;
    background: #1a1a1a;
    border-radius: 4px;
}

.layer-label {
    font-size: 12px;
    color: #888;
    font-family: monospace;
}

.legend {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #404040;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    font-size: 13px;
}

.color-box {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    margin-right: 10px;
    flex-shrink: 0;
}

.color-box.octahedron {
    border: 2px dashed #f39c12;
    background: transparent !important;
}

.info {
    font-size: 12px;
    color: #888;
    line-height: 1.6;
}

.info strong {
    color: #b0b0b0;
    display: block;
    margin-bottom: 8px;
}

.info ul {
    list-style: none;
    padding-left: 0;
}

.info li {
    padding-left: 20px;
    position: relative;
    margin-bottom: 6px;
}

.info li::before {
    content: "•";
    position: absolute;
    left: 6px;
    color: #3498db;
}

/* Scrollbar styling */
#controls-panel::-webkit-scrollbar {
    width: 8px;
}

#controls-panel::-webkit-scrollbar-track {
    background: #1a1a1a;
}

#controls-panel::-webkit-scrollbar-thumb {
    background: #404040;
    border-radius: 4px;
}

#controls-panel::-webkit-scrollbar-thumb:hover {
    background: #505050;
}

/* ===== Personal Mode Styles ===== */

.mode-switcher {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
}

.mode-btn {
    flex: 1;
    padding: 9px 6px;
    background: #1a1a1a;
    border: 1px solid #404040;
    border-radius: 6px;
    color: #b0b0b0;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.mode-btn:hover {
    background: #2a2a2a;
}

.mode-btn.active {
    background: #3498db;
    color: #fff;
    border-color: #3498db;
}

.reset-btn {
    padding: 5px 12px;
    background: #1a1a1a;
    border: 1px solid #404040;
    border-radius: 5px;
    color: #b0b0b0;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.reset-btn:hover {
    background: #2a2a2a;
    color: #e8e8e8;
    border-color: #606060;
}

.personal-intro, .prompts-container, .results-container, .daily-draw-container, .journal-container {
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.intro-text {
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
    color: #b0b0b0;
}

.primary-btn, .secondary-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 6px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.primary-btn {
    background: #3498db;
    color: #fff;
}

.primary-btn:hover {
    background: #5dade2;
}

.secondary-btn {
    background: #2a2a2a;
    color: #b0b0b0;
    border: 1px solid #404040;
}

.secondary-btn:hover {
    background: #3a3a3a;
}

.axis-section {
    margin-bottom: 30px;
    padding: 16px;
    background: #1a1a1a;
    border-radius: 8px;
}

.axis-desc {
    font-size: 12px;
    color: #888;
    margin-bottom: 16px;
    font-style: italic;
}

.question {
    margin-bottom: 20px;
}

.question-text {
    font-size: 13px;
    margin-bottom: 12px;
    color: #e0e0e0;
    line-height: 1.5;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.slider-label {
    font-size: 11px;
    color: #888;
    flex: 0 0 auto;
    max-width: 140px;
    line-height: 1.3;
}

.prompt-slider {
    width: 100%;
    display: block;
    margin: 0;
    box-sizing: border-box;
}

.slider-scale {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 6px;
}

.slider-scale .scale-min,
.slider-scale .scale-max {
    font-size: 11px;
    color: #888;
    line-height: 1.3;
    flex: 1 1 0;
    min-width: 0;
}

.slider-scale .scale-max {
    text-align: right;
}

/* Octahedron / cross-section toggle */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: #e0e0e0;
    user-select: none;
}

.checkbox-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex: 0 0 auto;
}

/* Animation row: checkbox left of a speed slider */
.control-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #e0e0e0;
    user-select: none;
    white-space: nowrap;
    flex: 0 0 auto;
}

.checkbox-inline input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex: 0 0 auto;
}

.control-row #auto-rotate-speed {
    flex: 1 1 auto;
    min-width: 0;
}

/* Edge thumbnails shown all-at-once over the tesseract */
.edge-thumb {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 7;
    will-change: left, top;
}

.edge-thumb .et-card {
    width: 26px;
    height: 42px;
    border-radius: 4px;
    object-fit: cover;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.edge-thumb .et-name {
    font-size: 11px;
    font-weight: 600;
    color: #f0f0f4;
    background: rgba(10, 10, 16, 0.82);
    border-left: 3px solid #888;
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
}

/* Scene overlay for tooltips & edge labels */
#scene-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 5;
}

.edge-tooltip {
    position: absolute;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 15, 20, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    color: #fff;
    white-space: nowrap;
    transform: translate(-50%, calc(-100% - 12px));
    z-index: 10;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.edge-tooltip .tt-card {
    width: 40px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.edge-tooltip .tt-text {
    display: flex;
    flex-direction: column;
}

.edge-tooltip .tt-name {
    display: block;
    font-weight: 600;
    font-size: 13px;
}

.edge-tooltip .tt-axis {
    display: block;
    font-size: 10px;
    color: #aaa;
    margin-top: 2px;
}

/* ---------------------------------------------------------------------------
   I CHING EDGE LENS — dual cartouche tooltip
   Forward = gold (▶, 0→1) · Reversed = slate (◀, 1→0)
--------------------------------------------------------------------------- */
.edge-tooltip.iching-tt {
    display: block;
    white-space: normal;
    padding: 6px 7px;
    /* pointer-events: none — purely visual, follows the cursor */
}

/* Single-direction tooltip: large hexagram glyph + King Wen number & name.
   Which direction shows depends on which half of the edge the cursor is over. */
.iching-tooltip-single {
    display: flex;
    align-items: center;
    gap: 10px;
}

.its-glyph {
    /* The Unicode hexagram (e.g. ䷁). Rendered with the system's symbol font;
       Segoe UI Symbol on Windows covers U+4DC0–U+4DFF. */
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", sans-serif;
    font-size: 40px;
    line-height: 1;
    flex-shrink: 0;
}
.iching-tooltip-single.forward  .its-glyph { color: #e8b23a; }  /* gold */
.iching-tooltip-single.reversed .its-glyph { color: #c7ced6; }  /* silver */

.its-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.its-kw {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}
.iching-tooltip-single.forward  .its-kw { color: #f2d493; }
.iching-tooltip-single.reversed .its-kw { color: #e2e7ec; }

.its-dir {
    font-size: 10px;
    color: #8a9098;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.its-hint {
    font-size: 10px;
    color: #636b74;
    font-style: italic;
}

/* "Show all edge cards" I Ching mode: two glyph+number badges per edge
   (forward gold ▶, reversed silver ◀) side by side at the edge midpoint. */
.edge-thumb.iching {
    gap: 6px;
}
.edge-thumb.iching .etg {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    background: rgba(10, 10, 16, 0.82);
    border-radius: 4px;
    padding: 2px 5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
.edge-thumb.iching .etg-glyph {
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", sans-serif;
    font-size: 22px;
    line-height: 1;
}
.edge-thumb.iching .etg-kw {
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}
.edge-thumb.iching .etg.forward  .etg-glyph,
.edge-thumb.iching .etg.forward  .etg-kw { color: #e8b23a; }
.edge-thumb.iching .etg.reversed .etg-glyph,
.edge-thumb.iching .etg.reversed .etg-kw { color: #c7ced6; }

.hint-mini {
    font-size: 11px;
    color: #8a9098;
    margin-top: 10px;
    line-height: 1.4;
}

.edge-label {
    position: absolute;
    pointer-events: none;
    background: rgba(15, 15, 20, 0.85);
    border-left: 3px solid #fff;
    border-radius: 4px;
    padding: 3px 7px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    z-index: 8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.prompt-actions, .result-actions, .draw-actions, .journal-actions {
    margin-top: 24px;
}

.archetype-card {
    background: #1a1a1a;
    border-left: 3px solid #3498db;
    padding: 14px;
    margin-bottom: 14px;
    border-radius: 6px;
}

.archetype-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.archetype-name {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

.axis-badge {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    background: #2a2a2a;
    color: #b0b0b0;
}

.axis-badge[data-axis="a-posteriori"] { background: #e74c3c22; color: #e74c3c; }
.axis-badge[data-axis="a-priori"] { background: #3498db22; color: #3498db; }
.axis-badge[data-axis="a-spiritus"] { background: #9b59b622; color: #9b59b6; }
.axis-badge[data-axis="a-viviori"] { background: #2ecc7122; color: #2ecc71; }

.polarity-pair {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.pair-label {
    font-size: 11px;
    color: #888;
}

.partner-name {
    font-size: 13px;
    color: #3498db;
    font-weight: 500;
}

.pair-gloss {
    font-size: 12px;
    color: #b0b0b0;
    line-height: 1.5;
    font-style: italic;
}

.phase-display {
    margin-top: 24px;
}

.phase-card {
    background: #1a1a1a;
    border: 2px solid #f39c12;
    padding: 16px;
    border-radius: 8px;
}

.phase-name {
    font-size: 16px;
    font-weight: 600;
    color: #f39c12;
    margin-bottom: 8px;
}

.phase-details {
    display: flex;
    gap: 12px;
    font-size: 12px;
}

.phase-element, .phase-role {
    color: #b0b0b0;
}

.drawn-card, .card-archetype {
    background: #1a1a1a;
    border: 2px solid #3498db;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

.draw-prompt {
    font-size: 14px;
    color: #e0e0e0;
    margin-bottom: 20px;
    font-style: italic;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-archetype {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    background: transparent;
    border: none;
    padding: 0;
}

.card-note {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #404040;
    font-size: 12px;
    color: #888;
}

.journal-entries {
    max-height: 400px;
    overflow-y: auto;
}

.journal-entry {
    background: #1a1a1a;
    padding: 14px;
    margin-bottom: 12px;
    border-radius: 6px;
    border-left: 3px solid #3498db;
}

.entry-header {
    margin-bottom: 8px;
}

.entry-date {
    font-size: 11px;
    color: #888;
}

.entry-archetypes {
    font-size: 13px;
    color: #e0e0e0;
    margin-bottom: 6px;
    font-weight: 500;
}

.entry-phase {
    font-size: 12px;
    color: #f39c12;
    margin-bottom: 6px;
}

.entry-notes {
    font-size: 12px;
    color: #b0b0b0;
    font-style: italic;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #2a2a2a;
}

.empty-journal {
    font-size: 13px;
    color: #888;
    text-align: center;
    padding: 40px 20px;
}

.journal-desc, .result-desc {
    font-size: 12px;
    color: #888;
    margin-bottom: 16px;
}


/* ============================================================
   CARD SYSTEM — thumbnails, lightbox, flip cards
   ============================================================ */

/* --- Thumbnail row in results / draw / journal --- */
.card-thumb-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 4px 0 18px;
}

.card-thumb-row.single-draw {
    justify-content: center;
}

.card-thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    width: 92px;
    transition: transform 0.15s ease;
}

.card-thumb:hover {
    transform: translateY(-3px);
}

.card-thumb-frame {
    width: 92px;
    height: 148px; /* ~499:800 ratio */
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    background: #14141c;
}

.card-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-thumb-fallback,
.card-img-fallback {
    width: 100%;
    height: 100%;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(160deg, #23232f, #16161d);
    text-align: center;
    padding: 6px;
    box-sizing: border-box;
    border-radius: 6px;
}

.card-img-fallback .ph-mark {
    font-size: 30px;
    opacity: 0.5;
}

.card-img-fallback .ph-name {
    font-size: 11px;
    color: #9a9aa5;
    line-height: 1.2;
}

.card-thumb-fallback .ph-mark {
    font-size: 26px;
    opacity: 0.5;
}

.card-thumb-fallback .ph-name {
    font-size: 10px;
    color: #9a9aa5;
    line-height: 1.2;
}

.card-thumb-label {
    font-size: 11px;
    color: #cfcfd6;
    text-align: center;
    line-height: 1.2;
    max-width: 92px;
}

/* --- Compact archetype text (replaces old archetype-card in results) --- */
.archetype-mini {
    padding: 8px 0;
    border-bottom: 1px solid #232323;
}

.archetype-mini:last-of-type {
    border-bottom: none;
}

.archetype-mini-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.archetype-mini-head .archetype-name {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.archetype-mini-tension {
    font-size: 11px;
    color: #999;
    margin-top: 3px;
}

/* --- Octahedron toggle block in results --- */
.octa-toggle-block {
    margin: 16px 0;
    padding: 10px 0;
    border-top: 1px solid #232323;
    border-bottom: 1px solid #232323;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
#card-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 4, 8, 0.88);
    backdrop-filter: blur(3px);
}

.lightbox-panel {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    max-width: 94vw;
    max-height: 94vh;
    padding: 16px;
}

.lightbox-close {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    background: rgba(20, 20, 28, 0.95);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
}

.lightbox-close:hover {
    background: #e74c3c;
    transform: scale(1.08);
}

.lightbox-hint {
    font-size: 13px;
    color: #cfcfd6;
    text-align: center;
    opacity: 0.85;
}

.lightbox-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   FLIP CARDS
   ============================================================ */
.flip-card {
    aspect-ratio: 1100 / 1807; /* matches source card art (1100x1807) so object-fit:cover crops nothing — equal border all around */
    height: min(74vh, 48vw);
    max-height: 860px;
    perspective: 1400px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Single card: fill much more of the viewport */
.lightbox-cards.single .flip-card {
    height: min(88vh, 66vw);
    max-height: 940px;
}

/* Narrow screens: let multi-card layouts wrap and grow */
@media (max-width: 760px) {
    .flip-card {
        height: min(60vh, 80vw);
    }
    .lightbox-cards.single .flip-card {
        height: min(80vh, 92vw);
    }
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.flip-card.flipped .flip-card-inner {
    transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Two-value radius keeps the corner circular regardless of the card's
       tall aspect ratio (~1100x1807). ~2.8% of the width matches the printed
       rounded border, so the square jpg/png corners (white/black/colored) are
       clipped away cleanly for every image type. */
    border-radius: 2.8% / 1.7%;
    overflow: hidden;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.6);
    background: transparent;
}

/* The I Ching hexagram card art has a wider printed rounded frame than the
   MBTI art, so it needs a larger clip radius; otherwise its outer black
   corners look squared off (same class of fix applied earlier to MBTI). */
.flip-card--iching .flip-card-front,
.flip-card--iching .flip-card-back {
    border-radius: 4.6% / 2.8%;
}

.flip-card-back {
    transform: rotateY(180deg);
}

.flip-face-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: inherit;
}

.flip-face-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    background: linear-gradient(160deg, #262633, #15151c);
}

.flip-face-fallback.front .fb-mark {
    font-size: 60px;
    opacity: 0.5;
}

.flip-face-fallback .fb-name {
    font-size: 20px;
    font-weight: 700;
    color: #e8e8ee;
}

.flip-face-fallback .fb-sub {
    font-size: 12px;
    color: #9a9aa5;
}

.flip-face-fallback .fb-text {
    font-size: 13px;
    color: #c2c2cc;
    line-height: 1.5;
}

.flip-card-caption {
    margin-top: 10px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-align: center;
}

/* ============================================================
   STAGE LABELS (octahedron vertices — 6 alchemical stages)
   ============================================================ */
.stage-label {
    position: absolute;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(12, 12, 16, 0.9);
    border: 1.5px solid var(--stage-color, #f39c12);
    border-radius: 20px;
    padding: 3px 9px 3px 4px;
    transform: translate(-50%, -50%);
    z-index: 9;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.stage-label .stage-num {
    font-size: 15px;
    line-height: 1;
    color: var(--stage-color, #f39c12);
    font-weight: 700;
}

.stage-label .stage-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.stage-label .stage-name {
    font-size: 11px;
    font-weight: 700;
    color: #fff;
}

.stage-label .stage-el {
    font-size: 9px;
    color: var(--stage-color, #f39c12);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Current alchemical stage — emphasised (replaces the old "you are here" dot) */
.stage-label.current {
    background: var(--stage-color, #f39c12);
    border-color: #fff;
    border-width: 2px;
    padding: 5px 12px 5px 6px;
    box-shadow: 0 0 14px 3px var(--stage-color, #f39c12), 0 2px 12px rgba(0, 0, 0, 0.6);
    z-index: 11;
    animation: stage-current-pulse 2.4s ease-in-out infinite;
}

.stage-label.current .stage-num {
    color: #fff;
    font-size: 17px;
}

.stage-label.current .stage-name {
    color: #fff;
    font-size: 12px;
}

.stage-label.current .stage-el {
    color: rgba(255, 255, 255, 0.9);
}

@keyframes stage-current-pulse {
    0%, 100% { box-shadow: 0 0 10px 2px var(--stage-color, #f39c12), 0 2px 12px rgba(0, 0, 0, 0.6); }
    50%      { box-shadow: 0 0 20px 6px var(--stage-color, #f39c12), 0 2px 12px rgba(0, 0, 0, 0.6); }
}

/* ============================================================
   SELF MARKER (eye-in-disc) + label (the +1)
   ============================================================ */
/* The Self — a glowing sun-eye (no solid disc; rays radiate around a bright eye) */
.self-marker {
    position: absolute;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: radial-gradient(circle,
        rgba(255, 226, 130, 0.55) 0%,
        rgba(255, 196, 60, 0.30) 32%,
        rgba(255, 180, 40, 0.10) 55%,
        rgba(255, 180, 40, 0) 72%);
    border: none;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9;
    transition: transform 0.15s ease, filter 0.15s ease;
    filter: drop-shadow(0 0 8px rgba(255, 200, 70, 0.7));
}

/* Sun rays — a spoked ring that slowly rotates */
.self-marker::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: repeating-conic-gradient(
        rgba(255, 214, 90, 0.95) 0deg 3deg,
        rgba(255, 214, 90, 0) 3deg 15deg);
    -webkit-mask: radial-gradient(circle, transparent 46%, #000 50%, #000 70%, transparent 76%);
    mask: radial-gradient(circle, transparent 46%, #000 50%, #000 70%, transparent 76%);
    animation: self-rays-spin 22s linear infinite;
    pointer-events: none;
}

/* Soft inner halo behind the eye */
.self-marker::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 236, 170, 0.9), rgba(255, 200, 80, 0) 70%);
    animation: self-halo-pulse 3.2s ease-in-out infinite;
    pointer-events: none;
}

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

@keyframes self-halo-pulse {
    0%, 100% { transform: scale(0.85); opacity: 0.75; }
    50%      { transform: scale(1.15); opacity: 1; }
}

.self-marker:hover {
    transform: translate(-50%, -50%) scale(1.15);
    filter: drop-shadow(0 0 14px rgba(255, 210, 90, 0.95));
}

.self-marker .self-eye {
    position: relative;
    z-index: 1;
    font-size: 19px;
    line-height: 1;
    filter: drop-shadow(0 0 5px rgba(255, 220, 120, 0.95)) drop-shadow(0 0 2px rgba(255, 255, 255, 0.9));
}

.self-label {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(12, 12, 16, 0.9);
    border: 1.5px solid #f5d76e;
    border-radius: 6px;
    padding: 3px 8px;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 9;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.self-label .self-plus {
    font-size: 11px;
    font-weight: 800;
    color: #0b0b0e;
    background: #f5d76e;
    border-radius: 4px;
    padding: 1px 5px;
}

.self-label .self-name {
    font-size: 12px;
    font-weight: 700;
    color: #f5d76e;
}

/* ============================================================
   JOURNAL ENTRIES with thumbnails
   ============================================================ */
.journal-entry {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #232323;
}

.journal-entry-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}

.journal-entry-thumbs .card-thumb {
    width: 54px;
}

.journal-entry-thumbs .card-thumb-frame {
    width: 54px;
    height: 87px;
}

.journal-entry-thumbs .card-thumb-label {
    display: none;
}

.journal-entry-body {
    flex: 1;
    min-width: 0;
}

.entry-type {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #f39c12;
    margin-bottom: 4px;
}


/* ===========================================================================
   BUILD 9 — MBTI VERTEX LENS
   16 type labels on the tesseract vertices, a hover inspector (chord),
   temperament-face highlights, antipodal connectors, and panel microcopy.
   Temperament colours: SJ=blue · SP=green · NF=gold · NT=purple
=========================================================================== */

/* --- Vertex type label (a small pill at each of the 16 vertices) --------- */
.vertex-label {
    position: absolute;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    background: rgba(12, 12, 16, 0.9);
    border: 1.5px solid var(--temp-color, #c7ced6);
    border-radius: 8px;
    padding: 2px 7px;
    transform: translate(-50%, -50%);
    z-index: 9;
    box-shadow: 0 2px 9px rgba(0, 0, 0, 0.55);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.vertex-label .vl-type {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #fff;
    line-height: 1;
}

/* --- Per-selection label states ----------------------------------------- */
/* selected: bright white glow */
.vertex-label.selected {
    background: rgba(20, 20, 26, 0.96);
    border-color: #fff;
    border-width: 2px;
    transform: translate(-50%, -50%) scale(1.14);
    box-shadow: 0 0 14px 2px var(--temp-color, #e8b23a), 0 2px 12px rgba(0, 0, 0, 0.65);
    z-index: 11;
}
/* antipode: silver ring (the opposite corner through the core) */
.vertex-label.antipode {
    border-color: #c7ced6;
    border-width: 2px;
    box-shadow: 0 0 12px 1px rgba(199, 206, 214, 0.85), 0 2px 10px rgba(0, 0, 0, 0.6);
    z-index: 10;
}
/* chord: gold ring (the 4 adjacent vertices) */
.vertex-label.chord {
    border-color: #e8b23a;
    border-width: 2px;
    box-shadow: 0 0 12px 1px rgba(232, 178, 58, 0.8), 0 2px 10px rgba(0, 0, 0, 0.6);
    z-index: 10;
}
/* temperament: ring in the vertex's own temperament colour */
.vertex-label.temperament {
    border-color: var(--temp-color, #c7ced6);
    border-width: 2px;
    box-shadow: 0 0 12px 1px var(--temp-color, #c7ced6), 0 2px 10px rgba(0, 0, 0, 0.6);
    z-index: 10;
}

/* --- Vertex card tooltip (thumbnail only, reuses #edge-tooltip.mbti-tt) --- */
.edge-tooltip.mbti-tt {
    display: block;
    white-space: normal;
    padding: 6px;
    background: rgba(12, 12, 16, 0.94);
    /* pointer-events: none — purely visual, follows the cursor */
}

.mbti-tooltip { display: flex; flex-direction: column; align-items: center; gap: 5px; }

.mbti-tooltip .mt-thumb {
    display: block;
    width: 96px;
    height: auto;
    border-radius: 6px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.6);
}

.mbti-tooltip .mt-open-hint {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #8a93a3;
}

/* --- "Show all vertex cards" overlay thumbnails -------------------------- */
.vertex-thumb {
    position: absolute;
    pointer-events: none;
    transform: translate(-50%, -100%);
    z-index: 8;
}

.vertex-thumb img {
    display: block;
    width: 46px;
    height: auto;
    border-radius: 5px;
    border: 1px solid rgba(199, 206, 214, 0.5);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}

/* --- Build 10: Philosophical Vertices mode ------------------------------- */
/* Readable link colour inside the philo panel (default browser purple is
   illegible on the dark panel background). Uses the theme's warm gold. */
#philo-selection-modes a,
#philo-selection-modes a:visited {
    color: #d9b25a;
    text-decoration: underline;
    text-underline-offset: 2px;
}
#philo-selection-modes a:hover {
    color: #f0cf7e;
}

/* Philo vertex labels (colored by quad group A/B/C/D) */
.vertex-label.philo-label {
    border-color: var(--quad-color, #c7ced6);
}

.vertex-label .vl-quad-name {
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    line-height: 1.15;
    text-align: center;
}

/* Selected philo vertex: a WHITE glow, to distinguish it from the
   quad-coloured glow used by the cross-quad resonances. */
.vertex-label.philo-label.selected {
    border-color: #fff;
    box-shadow: 0 0 18px 4px rgba(255, 255, 255, 0.95), 0 2px 12px rgba(0, 0, 0, 0.65);
}

/* resonance: highlight cross-quad vertices sharing the same highlight group.
   Uses the vertex's own quad colour and a stronger glow so it stands out. */
.vertex-label.resonance {
    border-color: var(--quad-color, #c7ced6);
    border-width: 2px;
    box-shadow: 0 0 20px 4px var(--quad-color, #c7ced6), 0 2px 10px rgba(0, 0, 0, 0.6);
    z-index: 10;
}

/* Philo vertex tooltip (large icon + "Double-click to open") */
.edge-tooltip.philo-tt {
    display: block;
    white-space: normal;
    padding: 8px;
    background: rgba(12, 12, 16, 0.94);
}

.philo-tooltip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.philo-tooltip .pt-icon {
    display: block;
    /* Fixed square box + contain normalises the differing native aspect
       ratios so every icon reads at a consistent size. A bit larger than the
       on-vertex icons, but not dramatically so. */
    width: 64px;
    height: 64px;
    object-fit: contain;
    border-radius: 6px;
}

.philo-tooltip .pt-open-hint {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #8a93a3;
}

/* "Show all vertex icons at once" overlay icons */
.philo-icon {
    position: absolute;
    pointer-events: none;
    transform: translate(-50%, -100%);
    z-index: 8;
}

.philo-icon img {
    display: block;
    /* Fixed square box + contain gives every icon a consistent footprint
       regardless of its native aspect ratio. Larger than before, no border. */
    width: 46px;
    height: 46px;
    object-fit: contain;
}

/* --- "Vertex Selection modes" sub-heading -------------------------------- */
.control-section .subhead {
    margin: 14px 0 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: #c7ced6;
}

/* --- MBTI panel microcopy (the two epistemic-humility lines) ------------- */
.mbti-microcopy {
    font-size: 10px;
    font-style: italic;
    line-height: 1.4;
    color: rgba(199, 206, 214, 0.62);
    margin: 6px 0 0;
}

.panel-footer-note {
    font-size: 10px;
    font-style: italic;
    line-height: 1.5;
    color: rgba(199, 206, 214, 0.55);
    margin: 22px 0 0;
    padding-top: 16px;
    border-top: 1px solid rgba(199, 206, 214, 0.12);
}



/* ============================================================
   Build 11 — Cosmogony / Cosmology lens
   ============================================================ */

/* ---- Glyph color tokens ---- */
.cosmo-k-glyph { color: #c9a24a; }   /* warm amber — Kabbalah Hebrew / symbolic */
.cosmo-p-glyph { color: #5dd0f0; }   /* cool cyan  — Physics Elder Futhark rune */

/* ---- Hover tooltip (cosmo-tt) ---- */
.edge-tooltip.cosmo-tt {
    display: block;
    white-space: normal;
    padding: 6px 7px;
}

.cosmo-tooltip-single {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Large glyph: Hebrew letters or Futhorc runes */
.cts-glyph {
    font-size: 38px;
    line-height: 1;
    flex-shrink: 0;
}
.cosmo-tooltip-single.kabbalah .cts-glyph { color: #c9a24a; }
.cosmo-tooltip-single.physics  .cts-glyph { color: #5dd0f0; }

.cts-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.cts-name {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
}
.cosmo-tooltip-single.kabbalah .cts-name { color: #e8cd82; }
.cosmo-tooltip-single.physics  .cts-name { color: #a8e8f8; }
.cts-hint {
    font-size: 10px;
    color: #8a9098;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---- "Show all edge cards at once" cosmo mode: two glyph badges per edge ---- */
.edge-thumb.cosmo {
    gap: 5px;
}
.edge-thumb.cosmo .etco {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    background: rgba(10, 10, 16, 0.82);
    border-radius: 4px;
    padding: 3px 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    min-width: 38px;
}
.etco-glyph {
    font-size: 22px;
    line-height: 1;
}
.etco-name {
    font-size: 9px;
    font-weight: 600;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}
.edge-thumb.cosmo .etco.kabbalah .etco-glyph,
.edge-thumb.cosmo .etco.kabbalah .etco-name { color: #c9a24a; }
.edge-thumb.cosmo .etco.physics  .etco-glyph,
.edge-thumb.cosmo .etco.physics  .etco-name { color: #5dd0f0; }

/* ---- Cosmo card in the flip lightbox ---- */
/* Same rounded corners as the iching cards (they share the same print radius). */
.flip-card--cosmo .flip-card-front,
.flip-card--cosmo .flip-card-back {
    border-radius: 4.6% / 2.8%;
}

/* ---- Cosmo description block in the left panel ---- */
/* Cosmo "About" link, styled like The Keystone link in the philo panel */
.cosmo-description {
    margin-top: 10px;
}
.cosmo-description p {
    margin: 0;
}
.cosmo-description a,
.cosmo-description a:visited {
    color: #d9b25a;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}
.cosmo-description a:hover {
    color: #f0cf7e;
}

/* --- About cosmology cards modal ---------------------------------------- */
.cosmo-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6, 7, 10, 0.72);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.cosmo-modal {
    position: relative;
    max-width: 640px;
    width: 100%;
    max-height: 82vh;
    overflow-y: auto;
    background: #14161c;
    border: 1px solid rgba(201, 162, 74, 0.45);
    border-radius: 10px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.65);
    padding: 30px 34px 34px;
}
.cosmo-modal h2 {
    margin: 0 0 16px;
    font-size: 22px;
    font-weight: 700;
    color: #e8dfc4;
    letter-spacing: 0.01em;
}
.cosmo-modal p {
    margin: 0;
    font-size: 16px;
    line-height: 1.68;
    color: rgba(224, 218, 200, 0.92);
}
.cosmo-modal p em {
    font-style: italic;
    color: #f0e7cc;
}
.cosmo-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: rgba(224, 218, 200, 0.7);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.15s ease, background 0.15s ease;
}
.cosmo-modal-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

/* --- "Unprojectable observer" center highlight (self marker) ------------ */
.self-marker.center-highlight {
    filter: drop-shadow(0 0 16px rgba(120, 210, 255, 0.95))
            drop-shadow(0 0 30px rgba(93, 208, 240, 0.8));
    animation: center-highlight-pulse 1.8s ease-in-out infinite;
}
@keyframes center-highlight-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1.0); }
    50%      { transform: translate(-50%, -50%) scale(1.22); }
}
