/* ==========================================================
   badge.bar — Translucent Frost Observatory
   ========================================================== */

/* --- CSS Custom Properties --- */
:root {
    --void: #0E0F14;
    --panel-surface: rgba(22, 27, 38, 0.72);
    --panel-border: rgba(255, 255, 255, 0.08);
    --panel-border-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #E8EDF2;
    --text-secondary: #9BA4B0;
    --text-tertiary: #6B7A8D;
    --accent-cyan: #7FCCDF;
    --accent-amber: #D4A857;
    --accent-jade: #5BA88C;
    --text-hover: #C5D0E0;
    --grid-line: rgba(255, 255, 255, 0.04);
    --glow-cyan: rgba(127, 204, 223, 0.15);
    --frost-opacity: 1;
    --grid-opacity: 0.04;
    --panel-fallback: #161B26;

    --font-heading: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-data: 'JetBrains Mono', monospace;

    --gutter: 24px;
    --chrome-height: 40px;
}

@media (max-width: 768px) {
    :root {
        --gutter: 16px;
    }
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--void);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a, .interactive-text {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover, .interactive-text:hover {
    color: var(--text-hover);
}

/* --- Layer 0: Background Grid --- */
.background-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: var(--grid-opacity);
    background-image:
        repeating-linear-gradient(
            to right,
            rgba(255, 255, 255, 1) 0px,
            rgba(255, 255, 255, 1) 1px,
            transparent 1px,
            transparent 40px
        ),
        repeating-linear-gradient(
            to bottom,
            rgba(255, 255, 255, 1) 0px,
            rgba(255, 255, 255, 1) 1px,
            transparent 1px,
            transparent 40px
        );
    transition: opacity 0.8s ease;
}

/* Grid initially hidden, fades in */
.background-grid.grid-visible {
    opacity: var(--grid-opacity);
}

/* --- Firefly Layer --- */
.firefly-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.firefly {
    position: absolute;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--accent-cyan);
    box-shadow: 0 0 6px 2px var(--glow-cyan);
    opacity: 0;
    animation: fireflyPulse 1.5s ease-in-out forwards;
}

@keyframes fireflyPulse {
    0% { opacity: 0; transform: scale(0.5); }
    30% { opacity: 0.8; transform: scale(1.2); }
    100% { opacity: 0; transform: scale(0.5); }
}

/* --- Layer 3: Fixed Chrome --- */
#chrome-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--chrome-height);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--gutter);
    background: rgba(14, 15, 20, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--panel-border);
}

.chrome-domain {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.chrome-scroll-indicator {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    width: 22px;
    height: 22px;
}

.scroll-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-tertiary);
    opacity: 0.3;
    transition: opacity 0.3s ease, background-color 0.3s ease;
}

.scroll-dot.lit {
    opacity: 1;
    background: var(--accent-cyan);
}

/* --- Reading Sections --- */
.reading {
    position: relative;
    min-height: 100vh;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--chrome-height) + var(--gutter)) var(--gutter) var(--gutter);
}

.reading-inner {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* --- Tatami Layouts --- */
.tatami-layout-1 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: auto;
    gap: var(--gutter);
}

.tatami-layout-1 .panel-4x2 {
    grid-column: span 4;
}

.tatami-layout-1 .panel-2x2 {
    grid-column: span 2;
}

.tatami-layout-2 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: minmax(200px, auto);
    gap: var(--gutter);
}

.tatami-layout-2 .panel-2x4 {
    grid-column: span 2;
    grid-row: span 2;
}

.tatami-layout-2 .panel-4x2 {
    grid-column: span 4;
}

.tatami-layout-2 .panel-2x2 {
    grid-column: span 2;
}

.tatami-layout-3 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: minmax(180px, auto);
    gap: var(--gutter);
}

.tatami-layout-3 .panel-6x1 {
    grid-column: span 6;
}

.tatami-layout-3 .panel-2x2 {
    grid-column: span 2;
}

.tatami-layout-3 .panel-4x2 {
    grid-column: span 4;
}

.tatami-layout-4 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--gutter);
    min-height: 60vh;
    align-items: center;
}

.tatami-layout-4 .panel-4x2 {
    grid-column: 2 / 6;
}

/* --- Frost Panels (Layer 1) --- */
.frost-panel {
    background: var(--panel-surface);
    backdrop-filter: blur(24px) saturate(120%);
    -webkit-backdrop-filter: blur(24px) saturate(120%);
    border: 2px solid var(--panel-border);
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Frost noise texture overlay */
.frost-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.02'/%3E%3C/svg%3E");
    background-size: 128px 128px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.4;
    mix-blend-mode: overlay;
}

.frost-panel:hover {
    border-color: var(--panel-border-hover);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.frost-panel:hover .sparkline {
    stroke-opacity: 0.7;
}

.frost-panel:hover .dot-matrix .dot {
    opacity: calc(var(--dot-base-opacity) + 0.2);
}

/* Fallback for no backdrop-filter support */
@supports not (backdrop-filter: blur(24px)) {
    .frost-panel {
        background: var(--panel-fallback);
    }
}

.panel-content {
    position: relative;
    z-index: 2;
    padding: var(--gutter);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.panel-centered {
    align-items: center;
    justify-content: center;
}

.panel-horizontal {
    flex-direction: column;
    gap: 16px;
}

/* --- Typography --- */
h1, h2, .panel-title, .section-heading, .closing-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.125rem, 2.5vw, 1.75rem);
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.domain-title {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    position: relative;
    z-index: 3;
}

.panel-title {
    font-weight: 500;
    margin-bottom: 16px;
}

.section-heading {
    font-size: clamp(1.5rem, 3vw, 2.25rem);
    text-align: center;
    margin-bottom: 48px;
}

.closing-title {
    font-size: clamp(1.25rem, 2.5vw, 2rem);
    margin-bottom: 12px;
}

.closing-text {
    font-family: var(--font-body);
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 24px;
}

.data-label {
    font-family: var(--font-data);
    font-weight: 400;
    font-size: 12px;
    line-height: 1.4;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.coordinate-label {
    margin-top: auto;
}

.data-labels-row {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

/* --- Sparkline SVGs (Layer 2) --- */
.sparkline-ribbon {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    z-index: 1;
}

.sparkline {
    fill: none;
    stroke: var(--accent-cyan);
    stroke-width: 1.5;
    stroke-opacity: 0.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke-opacity 0.2s ease;
}

.sparkline-offset {
    stroke-opacity: 0.25;
}

.sparkline-offset-2 {
    stroke-opacity: 0.15;
}

.sparkline-tall {
    width: 100%;
    height: 80%;
    position: absolute;
    top: 60px;
    left: 0;
    padding: 0 16px;
}

.sparkline-dense {
    width: 100%;
    height: 160px;
    flex-shrink: 0;
}

.sparkline-wide {
    position: relative;
    height: 60px;
    margin-top: 16px;
}

.closing-sparkline {
    position: relative;
    width: 100%;
    height: 40px;
    margin-bottom: 16px;
}

/* --- Radial Gauges --- */
.radial-gauge {
    width: 120px;
    height: 120px;
}

.gauge-small {
    width: 100px;
    height: 100px;
}

.gauge-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.04);
    stroke-width: 4;
    stroke-dasharray: 236 314;
    stroke-dashoffset: -39;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: center;
}

.gauge-inner-track {
    stroke-dasharray: 170 226;
    stroke-dashoffset: -28;
}

.gauge-fill {
    fill: none;
    stroke: var(--accent-cyan);
    stroke-width: 4;
    stroke-dasharray: 172 314;
    stroke-dashoffset: -39;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dasharray 0.8s ease;
}

.gauge-fill-amber {
    stroke: var(--accent-amber);
    stroke-dasharray: 215 314;
}

.gauge-fill-jade {
    stroke: var(--accent-jade);
    stroke-dasharray: 190 314;
}

.gauge-inner {
    stroke-dasharray: 120 226;
    stroke-dashoffset: -28;
}

.gauge-label {
    font-family: var(--font-data);
    font-size: 16px;
    fill: var(--text-primary);
    letter-spacing: 0.02em;
}

.gauge-sublabel {
    font-family: var(--font-data);
    font-size: 8px;
    fill: var(--text-tertiary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* --- Dot Matrix --- */
.dot-matrix {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    width: fit-content;
    padding: 8px 0;
}

.dot-matrix-large {
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.dot-matrix-badge {
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-cyan);
    transition: opacity 0.3s ease;
}

/* --- Metrics --- */
.metrics-row {
    display: flex;
    gap: 40px;
    flex-wrap: wrap;
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-value {
    font-family: var(--font-data);
    font-size: 24px;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* --- Log Entries --- */
.log-entries {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.log-entry {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 8px 0;
    border-bottom: 1px solid var(--panel-border);
}

.log-entry:last-child {
    border-bottom: none;
}

.log-value {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 14px;
    color: var(--text-secondary);
    flex: 1;
}

.log-status {
    font-family: var(--font-data);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 2px;
}

.status-jade {
    color: var(--accent-jade);
    background: rgba(91, 168, 140, 0.1);
}

.status-cyan {
    color: var(--accent-cyan);
    background: rgba(127, 204, 223, 0.1);
}

.status-amber {
    color: var(--accent-amber);
    background: rgba(212, 168, 87, 0.1);
}

.closing-label {
    display: block;
    text-align: center;
}

/* --- Badge Showcase --- */
.badge-showcase-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 60px;
}

.badge-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--gutter);
    width: 100%;
    max-width: 800px;
}

.badge-container {
    aspect-ratio: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.badge-surface {
    width: 100%;
    height: 100%;
    background: var(--panel-surface);
    backdrop-filter: blur(24px) saturate(120%);
    -webkit-backdrop-filter: blur(24px) saturate(120%);
    border: 2px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.badge-surface:hover {
    border-color: var(--panel-border-hover);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.badge-surface:hover .badge-interior-line {
    stroke-dashoffset: 0 !important;
}

.badge-surface:hover .dot {
    opacity: calc(var(--dot-base-opacity) + 0.2);
}

/* Badge shapes */
.badge-rounded-rect .badge-surface {
    border-radius: 16px;
}

.badge-shield .badge-surface {
    border-radius: 8px 8px 50% 50%;
}

.badge-circle .badge-surface {
    border-radius: 50%;
}

.badge-hexagon .badge-surface {
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    border: none;
}

.badge-rounded-rect-wide .badge-surface {
    border-radius: 24px;
}

.badge-shield-alt .badge-surface {
    border-radius: 12px 12px 40% 40%;
}

.badge-id {
    font-family: var(--font-data);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    position: absolute;
    bottom: 12px;
}

.badge-sparkline {
    width: 80%;
    height: 50%;
}

.badge-gauge {
    width: 60%;
    height: 60%;
}

.badge-gauge-wide {
    width: 50%;
    height: 50%;
}

.badge-interior-line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 1.2s ease;
}

.badge-interior-line.animated {
    stroke-dashoffset: 0;
}

/* --- Slide-Reveal Animation --- */
.reveal-element {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal-element.revealed {
    opacity: 1;
    transform: translateY(0);
}

.badge-reveal {
    transform: translateY(20px) rotateY(5deg);
}

.badge-reveal.revealed {
    transform: translateY(0) rotateY(0);
}

/* Staggered children within panels */
.reveal-element .panel-content > * {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.reveal-element.revealed .panel-content > * {
    opacity: 1;
    transform: translateY(0);
}

.reveal-element.revealed .panel-content > *:nth-child(1) { transition-delay: 0ms; }
.reveal-element.revealed .panel-content > *:nth-child(2) { transition-delay: 80ms; }
.reveal-element.revealed .panel-content > *:nth-child(3) { transition-delay: 160ms; }
.reveal-element.revealed .panel-content > *:nth-child(4) { transition-delay: 240ms; }
.reveal-element.revealed .panel-content > *:nth-child(5) { transition-delay: 320ms; }

/* --- Grid breathing for section transitions --- */
body.grid-breathing .background-grid {
    opacity: 0.07;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .tatami-layout-1,
    .tatami-layout-2,
    .tatami-layout-3 {
        grid-template-columns: 1fr;
    }

    .tatami-layout-1 .panel-4x2,
    .tatami-layout-1 .panel-2x2,
    .tatami-layout-2 .panel-2x4,
    .tatami-layout-2 .panel-4x2,
    .tatami-layout-2 .panel-2x2,
    .tatami-layout-3 .panel-6x1,
    .tatami-layout-3 .panel-2x2,
    .tatami-layout-3 .panel-4x2 {
        grid-column: span 1;
        grid-row: span 1;
    }

    .tatami-layout-4 .panel-4x2 {
        grid-column: 1 / -1;
    }

    .badge-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .metrics-row {
        gap: 20px;
    }

    .log-entry {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .reading {
        min-height: auto;
        padding-top: calc(var(--chrome-height) + var(--gutter));
        padding-bottom: 60px;
    }
}

@media (max-width: 480px) {
    .badge-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .domain-title {
        font-size: clamp(1.5rem, 8vw, 2.5rem);
    }
}
