/* =============================================
   kakuritsu.com - Neomorphic Probability Laboratory
   ============================================= */

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

:root {
    --surface: #d8d8e0;
    --shadow-light: #ffffff;
    --shadow-dark: #b0b0be;
    --chrome-1: #8c8ca0;
    --chrome-2: #c0c0d0;
    --chrome-highlight: #e8e8f5;
    --text-primary: #2d2d3a;
    --text-muted: #7a7a90;
    --accent: #6366f1;
    --glitch: #f43f5e;

    --shadow-inset: inset 4px 4px 8px var(--shadow-dark), inset -4px -4px 8px var(--shadow-light);
    --shadow-extruded: 6px 6px 12px var(--shadow-dark), -6px -6px 12px var(--shadow-light);
    --shadow-extruded-sm: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
    --shadow-flat: 0px 0px 0px var(--shadow-dark), 0px 0px 0px var(--shadow-light);

    --sidebar-width: 280px;
    --font-headline: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Noto Sans JP', sans-serif;
    --font-code: 'Fira Code', monospace;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(15px, 1.5vw, 18px);
    line-height: 1.75;
    color: var(--text-primary);
    background: var(--surface);
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Sidebar --- */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    box-shadow: var(--shadow-extruded);
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: 40px 24px;
    transform: translateX(-280px);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#sidebar.visible {
    transform: translateX(0);
}

.sidebar-header {
    margin-bottom: 48px;
    text-align: center;
}

.sidebar-title {
    font-family: var(--font-headline);
    font-size: 52px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#sidebar.visible .sidebar-title {
    opacity: 1;
}

.sidebar-subtitle {
    font-family: var(--font-code);
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 8px;
    letter-spacing: 0.1em;
}

/* --- Nav Items --- */
.nav-list {
    list-style: none;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 48px;
}

.nav-item {
    position: relative;
    padding: 16px 20px;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: var(--shadow-inset);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    opacity: 0;
    transform: translateY(10px);
}

.nav-item.revealed {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.2s ease;
}

.nav-item.active {
    box-shadow: var(--shadow-extruded);
}

.nav-item:hover:not(.active) {
    box-shadow: 2px 2px 4px var(--shadow-dark), -2px -2px 4px var(--shadow-light);
}

.nav-indicator {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 0;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
    transition: height 0.3s ease;
}

.nav-item.active .nav-indicator {
    height: 60%;
}

.nav-label-jp {
    display: block;
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 18px;
    color: var(--text-primary);
}

.nav-label-en {
    display: block;
    font-family: var(--font-code);
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* --- Sidebar Footer / Dice --- */
.sidebar-footer {
    margin-top: auto;
    padding-top: 32px;
}

.dice-motif {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.dice {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-inset);
    display: grid;
    padding: 6px;
    animation: diceRotate 8s ease-in-out infinite;
}

.dice[data-face="2"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}
.dice[data-face="2"] .dot:nth-child(1) { grid-area: 1/2; justify-self: end; }
.dice[data-face="2"] .dot:nth-child(2) { grid-area: 2/1; }

.dice[data-face="3"] {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}
.dice[data-face="3"] .dot:nth-child(1) { grid-area: 1/3; justify-self: end; }
.dice[data-face="3"] .dot:nth-child(2) { grid-area: 2/2; justify-self: center; align-self: center; }
.dice[data-face="3"] .dot:nth-child(3) { grid-area: 3/1; }

.dice[data-face="5"] {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}
.dice[data-face="5"] .dot:nth-child(1) { grid-area: 1/1; }
.dice[data-face="5"] .dot:nth-child(2) { grid-area: 1/3; justify-self: end; }
.dice[data-face="5"] .dot:nth-child(3) { grid-area: 2/2; justify-self: center; align-self: center; }
.dice[data-face="5"] .dot:nth-child(4) { grid-area: 3/1; }
.dice[data-face="5"] .dot:nth-child(5) { grid-area: 3/3; justify-self: end; }

.dice[data-face="6"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}
.dice[data-face="6"] .dot { justify-self: center; align-self: center; }

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chrome-1);
}

@keyframes diceRotate {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(3deg); }
    75% { transform: rotate(-3deg); }
}

/* --- Mobile Bottom Bar --- */
#mobile-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--surface);
    box-shadow: 0 -4px 12px var(--shadow-dark);
    z-index: 100;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
}

.mobile-nav-item {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 14px;
    color: var(--text-muted);
    background: none;
    border: none;
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: var(--shadow-inset);
    transition: box-shadow 0.2s ease, color 0.2s ease;
}

.mobile-nav-item.active {
    box-shadow: var(--shadow-extruded-sm);
    color: var(--accent);
}

/* --- Main Content --- */
#main-content {
    margin-left: var(--sidebar-width);
    padding: 60px 48px 100px;
    min-height: 100vh;
}

/* --- Content Cards --- */
.content-card {
    max-width: 800px;
    margin: 0 auto clamp(32px, 5vh, 64px);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow-flat);
    transition: box-shadow 0.6s ease;
    overflow: hidden;
}

.content-card.risen {
    box-shadow: var(--shadow-extruded);
}

.card-inner {
    padding: 32px;
    position: relative;
}

.card-title {
    font-family: var(--font-headline);
    font-size: clamp(24px, 4vw, 52px);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 24px;
    line-height: 1.2;
}

.card-title-en {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(14px, 1.5vw, 18px);
    color: var(--text-muted);
    margin-left: 12px;
}

/* --- SVG Visualizations --- */
.card-visual {
    margin-bottom: 28px;
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-inset);
    padding: 24px;
    overflow: hidden;
}

.card-visual svg {
    width: 100%;
    height: auto;
    display: block;
}

.axis-line {
    stroke: var(--chrome-1);
    stroke-width: 1.5;
}

.svg-label {
    font-family: var(--font-code);
    font-size: 13px;
    fill: var(--text-muted);
    text-anchor: middle;
}

/* Distribution */
.uniform-path {
    stroke: var(--accent);
    stroke-width: 2.5;
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 1.2s ease;
}

.content-card.risen .uniform-path {
    stroke-dashoffset: 0;
}

/* Expected Value */
.prob-bar {
    fill: var(--chrome-2);
    opacity: 0;
    transition: opacity 0.6s ease, fill 0.3s ease;
}

.content-card.risen .prob-bar {
    opacity: 1;
}

.prob-bar:hover {
    fill: var(--accent);
}

.ev-line {
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 6 4;
    opacity: 0;
    transition: opacity 0.8s ease 0.5s;
}

.content-card.risen .ev-line {
    opacity: 1;
}

.ev-label {
    fill: var(--accent);
    font-weight: 500;
}

/* --- Card Text --- */
.card-text p {
    margin-bottom: 12px;
}

.card-text-en {
    color: var(--text-muted);
    font-size: clamp(13px, 1.2vw, 15px);
}

.equation-block {
    margin-top: 20px;
    padding: 16px 24px;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-inset);
    text-align: center;
}

.equation-block code {
    font-family: var(--font-code);
    font-size: 16px;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

/* --- Coin Motifs --- */
.coin-motif {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

.coin {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    box-shadow: var(--shadow-extruded-sm);
    animation: coinSpin 6s ease-in-out infinite;
}

.coin-heads {
    background: linear-gradient(135deg, var(--chrome-highlight), var(--chrome-2));
}

.coin-tails {
    background: linear-gradient(135deg, var(--chrome-1), var(--chrome-2));
    animation-delay: -3s;
}

@keyframes coinSpin {
    0%, 100% { transform: rotateY(0deg); }
    50% { transform: rotateY(180deg); }
}

/* --- Dice Pair Motif --- */
.dice-pair-motif {
    display: flex;
    gap: 16px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* --- Independence Visual --- */
.independence-visual {
    display: flex;
    justify-content: center;
}

.independence-demo {
    display: flex;
    align-items: center;
    gap: 60px;
    padding: 20px 40px;
}

.event-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow-extruded);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.event-circle:hover {
    box-shadow: var(--shadow-inset);
    transform: scale(0.96);
}

.event-label {
    font-family: var(--font-headline);
    font-size: 36px;
    font-weight: 700;
    color: var(--accent);
}

/* --- Bayes Visual --- */
.bayes-svg .bayes-block {
    fill: var(--surface);
    stroke: var(--chrome-1);
    stroke-width: 1.5;
    transition: fill 0.3s ease;
}

.bayes-svg .prior-block { fill: var(--chrome-highlight); }
.bayes-svg .evidence-block { fill: var(--chrome-2); }
.bayes-svg .posterior-block { fill: var(--chrome-highlight); }

.bayes-label {
    font-family: var(--font-body);
    font-size: 15px;
    fill: var(--text-primary);
    font-weight: 500;
}

.bayes-sublabel {
    font-family: var(--font-code);
    font-size: 11px;
    fill: var(--text-muted);
}

.bayes-arrow {
    stroke: var(--chrome-1);
    stroke-width: 2;
}

.bayes-arrowhead {
    fill: var(--chrome-1);
}

/* --- Bell Curve Feature Section --- */
.bell-curve-section {
    margin: clamp(40px, 8vh, 100px) calc(-48px) clamp(40px, 8vh, 100px);
    padding: 60px 48px;
    background: var(--surface);
    position: relative;
}

.bell-curve-inner {
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

.bell-curve-title {
    font-family: var(--font-headline);
    font-size: clamp(28px, 5vw, 60px);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.bell-curve-title-en {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(14px, 1.5vw, 20px);
    color: var(--text-muted);
    margin-left: 12px;
}

.bell-curve-visual {
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow-inset);
    padding: 32px;
    margin: 32px 0;
    cursor: pointer;
    position: relative;
}

.bell-stroke {
    stroke: var(--accent);
    stroke-width: 3;
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 1.5s ease;
}

.bell-curve-section.visible .bell-stroke {
    stroke-dashoffset: 0;
}

.bell-fill {
    opacity: 0;
    transition: opacity 1s ease 0.8s;
}

.bell-curve-section.visible .bell-fill {
    opacity: 1;
}

.bell-axis {
    stroke-width: 2;
}

.bell-label {
    font-size: 14px;
}

/* Histogram hover state */
.histogram-group rect {
    fill: var(--accent);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.bell-curve-visual.histogram-mode .histogram-group rect {
    opacity: 0.6;
}

.bell-curve-visual.histogram-mode .bell-stroke {
    opacity: 0.2;
}

.bell-curve-visual.histogram-mode .bell-fill {
    opacity: 0;
}

/* Glitch effect */
.bell-curve-visual.glitch .bell-label {
    animation: glitchText 0.15s steps(2) 1;
}

@keyframes glitchText {
    0% {
        opacity: 1;
    }
    25% {
        transform: translate(2px, -1px);
        fill: var(--glitch);
    }
    50% {
        transform: translate(-2px, 1px);
        fill: cyan;
    }
    75% {
        transform: translate(1px, 2px);
        fill: var(--glitch);
    }
    100% {
        transform: translate(0, 0);
        fill: var(--text-muted);
    }
}

.bell-curve-equation {
    margin-top: 20px;
}

.bell-curve-equation code {
    font-family: var(--font-code);
    font-size: clamp(14px, 1.5vw, 18px);
    color: var(--text-primary);
    letter-spacing: 0.03em;
    padding: 12px 24px;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-extruded-sm);
    display: inline-block;
}

/* --- Footer --- */
.footer-section {
    max-width: 800px;
    margin: clamp(40px, 6vh, 80px) auto 0;
    text-align: center;
    padding: 48px 32px;
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow-extruded);
}

.footer-title {
    font-family: var(--font-headline);
    font-size: clamp(24px, 4vw, 48px);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.footer-title-en {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(14px, 1.5vw, 18px);
    color: var(--text-muted);
    margin-left: 12px;
}

.flowing-waves {
    margin: 32px 0;
    border-radius: 16px;
    overflow: hidden;
    height: 200px;
}

.waves-svg {
    width: 100%;
    height: 100%;
}

.wave {
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-dasharray: 1600;
    animation: waveFlow 6s ease-in-out infinite;
}

.wave-1 {
    stroke: var(--chrome-1);
    animation-delay: 0s;
}

.wave-2 {
    stroke: var(--chrome-2);
    animation-delay: -1.5s;
}

.wave-3 {
    stroke: var(--chrome-highlight);
    animation-delay: -3s;
}

.wave-4 {
    stroke: var(--accent);
    stroke-opacity: 0.4;
    animation-delay: -4.5s;
}

@keyframes waveFlow {
    0%, 100% { stroke-dashoffset: 0; }
    50% { stroke-dashoffset: 200; }
}

.footer-quote {
    font-family: var(--font-headline);
    font-size: clamp(18px, 3vw, 28px);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.5;
}

.footer-quote-en {
    font-family: var(--font-body);
    font-size: clamp(13px, 1.2vw, 16px);
    color: var(--text-muted);
    font-style: italic;
}

/* --- Glitch Effect (Sidebar) --- */
.nav-item.glitch-active {
    animation: sidebarGlitch 0.15s steps(2) 1;
}

@keyframes sidebarGlitch {
    0% { transform: translateX(0); }
    25% { transform: translateX(3px); text-shadow: -2px 0 var(--glitch), 2px 0 cyan; }
    50% { transform: translateX(-2px); text-shadow: 2px 0 var(--glitch), -2px 0 cyan; }
    75% { transform: translateX(2px); text-shadow: -1px 0 var(--glitch), 1px 0 cyan; }
    100% { transform: translateX(0); text-shadow: none; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #sidebar {
        display: none;
    }

    #mobile-bar {
        display: flex;
    }

    #main-content {
        margin-left: 0;
        padding: 32px 20px 84px;
    }

    .bell-curve-section {
        margin-left: -20px;
        margin-right: -20px;
        padding: 40px 20px;
    }

    .card-inner {
        padding: 24px;
    }

    .independence-demo {
        gap: 30px;
        padding: 16px 20px;
    }

    .event-circle {
        width: 70px;
        height: 70px;
    }

    .event-label {
        font-size: 28px;
    }
}

@media (min-width: 769px) {
    #mobile-bar {
        display: none;
    }
}

/* --- Typewriter cursor --- */
.typewriter-cursor {
    display: inline-block;
    width: 3px;
    height: 1em;
    background: var(--accent);
    margin-left: 4px;
    animation: cursorBlink 0.8s step-end infinite;
    vertical-align: text-bottom;
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* --- Scroll reveal utility --- */
.content-card {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease, box-shadow 0.6s ease;
}

.content-card.risen {
    opacity: 1;
    transform: translateY(0);
}

/* Bell curve section scroll reveal */
.bell-curve-section {
    opacity: 0;
    transition: opacity 0.8s ease;
}

.bell-curve-section.visible {
    opacity: 1;
}
