/* === RESET & BASE === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --midnight-walnut: #1a1209;
    --deep-walnut: #2a1f14;
    --aged-brass: #5c4a2e;
    --gold-proof: #c9a84c;
    --amber-glow: #d4913a;
    --verdigris: #8db4a8;
    --teal-axiom: #4a7c72;
    --parchment: #d4c8b0;
}

html { scroll-behavior: smooth; }

body {
    background: var(--midnight-walnut);
    color: var(--parchment);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(0.875rem, 1.2vw, 1.125rem);
    line-height: 1.7;
    overflow-x: hidden;
    min-height: 100vh;
}

/* === KANJI WATERMARK === */
.kanji-watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Noto Serif JP', serif;
    font-weight: 500;
    font-size: 30vw;
    color: var(--parchment);
    opacity: 0.03;
    pointer-events: none;
    z-index: 0;
    user-select: none;
}

/* === DASHBOARD LAYOUT === */
.dashboard {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 100vh auto auto;
    grid-template-areas:
        "observatory index"
        "theorems theorems"
        "ticker ticker";
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* === PANEL BASE & BORDER ANIMATION === */
.panel {
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(to right, var(--gold-proof), var(--gold-proof)) top left / 0% 1px no-repeat,
        linear-gradient(to bottom, var(--gold-proof), var(--gold-proof)) top right / 1px 0% no-repeat,
        linear-gradient(to left, var(--gold-proof), var(--gold-proof)) bottom right / 0% 1px no-repeat,
        linear-gradient(to top, var(--gold-proof), var(--gold-proof)) bottom left / 1px 0% no-repeat;
    transition:
        background-size 0.15s linear 0s,
        background-size 0.15s linear 0.15s,
        background-size 0.15s linear 0.3s,
        background-size 0.15s linear 0.45s;
}

.panel:hover {
    background:
        linear-gradient(to right, var(--gold-proof), var(--gold-proof)) top left / 100% 1px no-repeat,
        linear-gradient(to bottom, var(--gold-proof), var(--gold-proof)) top right / 1px 100% no-repeat,
        linear-gradient(to left, var(--gold-proof), var(--gold-proof)) bottom right / 100% 1px no-repeat,
        linear-gradient(to top, var(--gold-proof), var(--gold-proof)) bottom left / 1px 100% no-repeat;
}

.panel-border-anim { display: none; }

/* === OBSERVATORY (HERO) === */
.observatory {
    grid-area: observatory;
    background-color: var(--midnight-walnut);
    display: flex;
    align-items: center;
    justify-content: center;
}

.observatory-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero-text {
    position: absolute;
    text-align: center;
    z-index: 10;
    opacity: 0;
    animation: fadeIn 1.5s ease 0.5s forwards;
}

.hero-kanji {
    display: block;
    font-family: 'Noto Serif JP', serif;
    font-weight: 500;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--parchment);
    opacity: 0;
    animation: fadeIn 1.2s ease 1.3s forwards;
}

.hero-kanji::after {
    content: '';
    display: block;
    opacity: 0.6;
}

.hero-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--gold-proof);
    letter-spacing: -0.02em;
    margin-top: 0.2em;
}

.hero-subtitle {
    font-family: 'Source Serif 4', serif;
    font-weight: 300;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    color: var(--parchment);
    opacity: 0.6;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 0.5em;
}

/* === ISOMETRIC CITY === */
.city-container {
    perspective: 800px;
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%);
}

.building-grid {
    transform: rotateX(60deg) rotateZ(-45deg);
    transform-style: preserve-3d;
    display: grid;
    grid-template-columns: repeat(4, 50px);
    grid-template-rows: repeat(4, 50px);
    gap: 8px;
}

.building {
    width: 40px;
    height: 0;
    position: relative;
    transform-style: preserve-3d;
    animation: rise 2s ease calc(var(--delay) * 100ms) forwards;
}

@keyframes rise {
    from { height: 0; }
    to { height: var(--h); }
}

.building .top {
    position: absolute;
    width: 40px;
    height: 40px;
    background: var(--gold-proof);
    opacity: 0.8;
    transform: rotateX(90deg) translateZ(var(--h));
    top: 0;
}

.building .left {
    position: absolute;
    width: 40px;
    height: 100%;
    background: var(--aged-brass);
    transform: translateZ(0);
}

.building .right {
    position: absolute;
    width: 40px;
    height: 100%;
    background: var(--deep-walnut);
    transform: rotateY(90deg) translateZ(40px);
    transform-origin: right;
}

/* Building breathing transition */
.building.breathing {
    transition: height 3s ease-in-out;
}

/* === INDEX PANEL === */
.index-panel {
    grid-area: index;
    background-color: var(--deep-walnut);
    padding: 3rem 2rem;
    display: flex;
    flex-direction: column;
}

.index-heading {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 2.5vw, 2.2rem);
    color: var(--gold-proof);
    letter-spacing: -0.02em;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--aged-brass);
}

.index-nav {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 1;
}

.index-entry {
    display: block;
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    color: var(--parchment);
    text-decoration: none;
    padding: 1rem 0.8rem;
    border-bottom: 1px dashed var(--aged-brass);
    position: relative;
    background:
        linear-gradient(to right, var(--gold-proof), var(--gold-proof)) top left / 0% 1px no-repeat,
        linear-gradient(to bottom, var(--gold-proof), var(--gold-proof)) top right / 1px 0% no-repeat,
        linear-gradient(to left, var(--gold-proof), var(--gold-proof)) bottom right / 0% 1px no-repeat,
        linear-gradient(to top, var(--gold-proof), var(--gold-proof)) bottom left / 1px 0% no-repeat;
    transition:
        background-size 0.1s linear 0s,
        background-size 0.1s linear 0.1s,
        background-size 0.1s linear 0.2s,
        background-size 0.1s linear 0.3s;
}

.index-entry:hover {
    background:
        linear-gradient(to right, var(--gold-proof), var(--gold-proof)) top left / 100% 1px no-repeat,
        linear-gradient(to bottom, var(--gold-proof), var(--gold-proof)) top right / 1px 100% no-repeat,
        linear-gradient(to left, var(--gold-proof), var(--gold-proof)) bottom right / 100% 1px no-repeat,
        linear-gradient(to top, var(--gold-proof), var(--gold-proof)) bottom left / 1px 100% no-repeat;
    color: var(--gold-proof);
}

.index-entry::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 10px;
    margin-right: 0.6em;
    clip-path: polygon(0 100%, 50% 0, 100% 100%, 80% 100%, 50% 30%, 20% 100%);
    background: var(--aged-brass);
    vertical-align: middle;
}

.index-footer {
    margin-top: auto;
    text-align: center;
    padding-top: 2rem;
}

.index-notation {
    font-family: 'Cormorant Garamond', serif;
    font-size: 2.5rem;
    color: var(--gold-proof);
    opacity: 0.4;
}

/* === THEOREM GRID === */
.theorem-grid {
    grid-area: theorems;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.theorem-panel {
    background-color: var(--midnight-walnut);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 280px;
    border: 1px solid rgba(92, 74, 46, 0.3);
}

.theorem-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: clamp(1rem, 1.5vw, 1.4rem);
    color: var(--gold-proof);
    letter-spacing: -0.02em;
    margin-bottom: 0.8rem;
    text-align: center;
}

.theorem-title::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 8px;
    margin-right: 0.4em;
    background: var(--aged-brass);
    clip-path: polygon(0 100%, 30% 0, 100% 0, 100% 60%, 30% 60%);
    vertical-align: middle;
}

.theorem-viz {
    flex: 1;
    width: 100%;
    max-width: 220px;
}

.theorem-label {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.875rem);
    color: var(--verdigris);
    letter-spacing: 0.05em;
    text-align: center;
    margin-top: 0.8rem;
}

/* SVG line animations */
.viz-line {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 1.5s ease;
}

.viz-line.animated {
    stroke-dashoffset: 0;
}

/* === PROOF TRACE TICKER === */
.proof-trace {
    grid-area: ticker;
    background-color: var(--deep-walnut);
    overflow: hidden;
    height: 48px;
    display: flex;
    align-items: center;
    border-top: 1px solid var(--aged-brass);
}

.ticker-track {
    display: flex;
    white-space: nowrap;
    animation: tickerScroll 40s linear infinite;
    gap: 3rem;
}

@keyframes tickerScroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

.ticker-item {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.875rem);
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.ticker-item.true { color: var(--gold-proof); }
.ticker-item.false { color: var(--aged-brass); }
.ticker-item.undetermined { color: var(--teal-axiom); }

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

/* === RESPONSIVE === */
@media (max-width: 900px) {
    .dashboard {
        grid-template-columns: 1fr;
        grid-template-rows: 50vh auto auto auto;
        grid-template-areas:
            "observatory"
            "index"
            "theorems"
            "ticker";
    }

    .index-panel {
        padding: 1.5rem;
    }

    .index-nav {
        flex-direction: row;
        overflow-x: auto;
        gap: 0;
    }

    .index-entry {
        white-space: nowrap;
        padding: 0.8rem 1.2rem;
        border-bottom: none;
        border-right: 1px dashed var(--aged-brass);
    }

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

@media (max-width: 600px) {
    .theorem-grid {
        grid-template-columns: 1fr;
    }

    .building-grid {
        grid-template-columns: repeat(4, 35px);
        grid-template-rows: repeat(4, 35px);
        gap: 5px;
    }

    .building { width: 28px; }
    .building .top { width: 28px; height: 28px; }
    .building .left { width: 28px; }
    .building .right { width: 28px; transform: rotateY(90deg) translateZ(28px); }
}
