/* =========================================
   AIICE.IO - Through the Looking Glass
   Glassmorphism Narrative Design
   ========================================= */

/* --- CSS Custom Properties --- */
:root {
    --obsidian-ice: #0b1120;
    --midnight-frost: #162033;
    --frozen-membrane: #1e3a5f;
    --looking-glass-cyan: #38bdf8;
    --wonderland-rose: #f472b6;
    --cheshire-gold: #fbbf24;
    --breath-on-glass: #e2e8f0;
    --fog-script: #94a3b8;
    --deep-rose: #120b1a;

    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-inner-glow: rgba(255, 255, 255, 0.1);
    --glass-shadow: rgba(0, 0, 0, 0.12);

    --spring-ease: cubic-bezier(0.34, 1.56, 0.64, 1);
    --smooth-ease: cubic-bezier(0.4, 0, 0.2, 1);

    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Karla', sans-serif;
    --font-accent: 'Playfair Display', serif;
    --font-mono: 'Inconsolata', monospace;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--obsidian-ice);
    color: var(--breath-on-glass);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 17px;
    line-height: 1.8;
    overflow-x: hidden;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='20' viewBox='0 0 16 20'%3E%3Cpath d='M4 2 C4 2 2 4 2 6 C2 8 4 9 4 9 L4 14 C4 14 3 16 4 17 C5 18 7 18 8 18 C9 18 11 18 12 17 C13 16 12 14 12 14 L12 9 C12 9 14 8 14 6 C14 4 12 2 12 2 C12 2 10 0 8 0 C6 0 4 2 4 2 Z' fill='none' stroke='%2338bdf8' stroke-width='1.2'/%3E%3Ccircle cx='6' cy='5' r='1' fill='%2338bdf8'/%3E%3Ccircle cx='10' cy='5' r='1' fill='%2338bdf8'/%3E%3Cpath d='M5 14 L5 18' stroke='%2338bdf8' stroke-width='0.8'/%3E%3Cpath d='M11 14 L11 18' stroke='%2338bdf8' stroke-width='0.8'/%3E%3C/svg%3E") 8 10, auto;
}

::selection {
    background: rgba(56, 189, 248, 0.3);
    color: var(--breath-on-glass);
}

/* --- Hexagonal Ice Lattice --- */
#hex-lattice {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='138.56' viewBox='0 0 160 138.56'%3E%3Cpolygon points='80,0 160,34.64 160,103.92 80,138.56 0,103.92 0,34.64' fill='none' stroke='rgba(56,189,248,0.04)' stroke-width='0.5'/%3E%3C/svg%3E");
    background-size: 160px 138.56px;
    background-attachment: fixed;
    opacity: 1;
    transition: opacity 0.3s;
}

/* --- Cursor Trail --- */
#cursor-trail {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10000;
    overflow: hidden;
}

.trail-particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: white;
    border-radius: 50%;
    opacity: 0.3;
    pointer-events: none;
    animation: trail-fade 800ms ease-out forwards;
}

@keyframes trail-fade {
    0% { opacity: 0.3; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.3); }
}

/* --- Keyhole Navigation --- */
#keyhole-nav {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.keyhole-shape {
    width: 36px;
    height: 54px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 300ms var(--spring-ease);
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.3));
}

.keyhole-shape:hover {
    transform: scale(1.3);
}

.keyhole-svg {
    width: 36px;
    height: 54px;
    color: var(--looking-glass-cyan);
}

.radial-menu {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
    margin-top: -100px;
    margin-left: -100px;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 300ms var(--smooth-ease), transform 300ms var(--spring-ease);
}

.radial-menu.active {
    pointer-events: all;
    opacity: 1;
    transform: scale(1);
}

.radial-item {
    position: absolute;
    width: 80px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: transform 200ms var(--spring-ease), opacity 200ms;
}

.radial-item[data-angle="0"] {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}
.radial-item[data-angle="1"] {
    top: 25%;
    right: -10px;
}
.radial-item[data-angle="2"] {
    bottom: 10%;
    right: 0;
}
.radial-item[data-angle="3"] {
    bottom: 10%;
    left: 0;
}
.radial-item[data-angle="4"] {
    top: 25%;
    left: -10px;
}

.radial-label {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--looking-glass-cyan);
    background: rgba(11, 17, 32, 0.85);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--glass-border);
    white-space: nowrap;
    transition: color 200ms, border-color 200ms;
}

.radial-item:hover .radial-label {
    color: var(--wonderland-rose);
    border-color: rgba(244, 114, 182, 0.3);
}

.radial-arms {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.radial-arm {
    stroke: rgba(56, 189, 248, 0.15);
    stroke-width: 1;
    stroke-dasharray: 80;
    stroke-dashoffset: 80;
    transition: stroke-dashoffset 400ms var(--smooth-ease);
}

.radial-menu.active .radial-arm {
    stroke-dashoffset: 0;
}

.radial-menu.active .radial-arm:nth-child(1) { transition-delay: 0ms; }
.radial-menu.active .radial-arm:nth-child(2) { transition-delay: 80ms; }
.radial-menu.active .radial-arm:nth-child(3) { transition-delay: 160ms; }
.radial-menu.active .radial-arm:nth-child(4) { transition-delay: 240ms; }
.radial-menu.active .radial-arm:nth-child(5) { transition-delay: 320ms; }

/* --- Chapter Base --- */
.chapter {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* --- Glass Pane System --- */
.glass-pane {
    background: rgba(22, 32, 51, 0.45);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow:
        inset 0 1px 0 var(--glass-inner-glow),
        0 4px 24px var(--glass-shadow);
    position: relative;
    overflow: hidden;
    transition: transform 500ms var(--spring-ease), box-shadow 300ms;
}

.pane-inner {
    padding: 40px;
    position: relative;
    z-index: 2;
}

/* --- Condensation Droplets --- */
.condensation-drops {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.condensation-drop {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Typography --- */
.section-heading {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(36px, 5vw, 64px);
    letter-spacing: -0.02em;
    color: var(--breath-on-glass);
    margin-bottom: 24px;
    text-transform: none;
}

.pane-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 24px;
    letter-spacing: -0.02em;
    color: var(--looking-glass-cyan);
    margin-bottom: 12px;
}

.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 17px;
    line-height: 1.8;
    color: var(--breath-on-glass);
    margin-bottom: 16px;
}

.body-text:last-child {
    margin-bottom: 0;
}

/* --- Cheshire Grin --- */
.cheshire-grin {
    display: flex;
    justify-content: center;
    margin: 30px 0;
    opacity: 0;
    transition: opacity 600ms;
}

.cheshire-grin.visible {
    opacity: 1;
}

.grin-svg {
    width: 200px;
    height: 40px;
}

.cheshire-grin-garden .grin-svg {
    width: 300px;
    height: 50px;
}

.grin-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 1200ms cubic-bezier(0.37, 0, 0.63, 1);
}

.cheshire-grin.visible .grin-path {
    stroke-dashoffset: 0;
}

/* --- Thaw Lines --- */
.thaw-line {
    position: relative;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(56, 189, 248, 0.1) 20%,
        rgba(56, 189, 248, 0.3) 50%,
        rgba(56, 189, 248, 0.1) 80%,
        transparent 100%
    );
    overflow: hidden;
    transition: height 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 5;
}

.thaw-line.expanded {
    height: 60px;
    background: linear-gradient(180deg,
        transparent 0%,
        rgba(56, 189, 248, 0.05) 30%,
        rgba(56, 189, 248, 0.08) 50%,
        rgba(56, 189, 248, 0.05) 70%,
        transparent 100%
    );
}

/* ==========================================
   CHAPTER 1: THE SURFACE
   ========================================== */
.chapter-surface {
    height: 100vh;
    background: var(--obsidian-ice);
    position: relative;
    z-index: 10;
}

.frost-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 17, 32, 0.9);
    -webkit-backdrop-filter: blur(24px);
    backdrop-filter: blur(24px);
    z-index: 3;
    pointer-events: none;
    transition: opacity 1200ms var(--smooth-ease);
}

.frost-overlay.cleared {
    opacity: 0;
}

.aperture-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    clip-path: circle(0% at 50% 50%);
    z-index: 4;
    transition: clip-path 1.2s var(--spring-ease);
}

.aperture-mask.open {
    clip-path: circle(75% at 50% 50%);
}

.surface-content {
    text-align: center;
    padding: 20px;
    max-width: 800px;
}

.title-aiice {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(60px, 20vw, 240px);
    letter-spacing: -0.02em;
    color: var(--looking-glass-cyan);
    line-height: 1;
    margin-bottom: 40px;
    text-shadow: 0 0 60px rgba(56, 189, 248, 0.3), 0 0 120px rgba(56, 189, 248, 0.1);
}

.epigraph {
    font-family: var(--font-accent);
    font-style: italic;
    font-size: clamp(16px, 2.5vw, 24px);
    line-height: 1.6;
    color: var(--fog-script);
    max-width: 600px;
    margin: 0 auto;
}

.cheshire-grin-surface {
    margin-top: 40px;
}

/* ==========================================
   CHAPTER 2-3: THE LOOKING GLASS
   ========================================== */
.chapter-looking-glass {
    min-height: 200vh;
    padding: 10vh 5vw;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 40px;
    position: relative;
}

.pane-left,
.pane-right {
    flex: 1;
    max-width: 560px;
    position: sticky;
    top: 15vh;
}

.pane-right {
    transform: scaleX(-1);
    transition: transform 800ms var(--smooth-ease);
}

.pane-right .pane-inner {
    transform: scaleX(-1);
}

.pane-right.unmirrored {
    transform: scaleX(1);
}

.pane-right.unmirrored .pane-inner {
    transform: scaleX(1);
}

.pane-left .section-heading {
    color: var(--looking-glass-cyan);
}

.pane-right .section-heading {
    color: var(--wonderland-rose);
}

/* ==========================================
   CHAPTER 4-5: THE GARDEN OF FORKING PATHS
   ========================================== */
.chapter-garden {
    min-height: 100vh;
    padding: 10vh 5vw;
    flex-direction: column;
    position: relative;
}

.garden-cluster {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    max-width: 1000px;
    width: 100%;
    perspective: 1000px;
}

.hex-pane {
    transform: rotate(0deg) scale(0.85);
    opacity: 0;
    transition: transform 600ms var(--spring-ease),
                opacity 400ms var(--smooth-ease),
                box-shadow 300ms;
}

.hex-pane.fanned {
    transform: rotate(0deg) scale(1);
    opacity: 1;
}

.hex-pane[data-hex="0"].fanned { transition-delay: 0ms; }
.hex-pane[data-hex="1"].fanned { transition-delay: 150ms; }
.hex-pane[data-hex="2"].fanned { transition-delay: 300ms; }
.hex-pane[data-hex="3"].fanned { transition-delay: 450ms; }
.hex-pane[data-hex="4"].fanned { transition-delay: 600ms; }
.hex-pane[data-hex="5"].fanned { transition-delay: 750ms; }

.hex-pane:hover {
    transform: scale(1.05) translateZ(40px);
    box-shadow:
        inset 0 1px 0 var(--glass-inner-glow),
        0 8px 40px rgba(56, 189, 248, 0.15),
        0 4px 24px var(--glass-shadow);
    z-index: 10;
}

.hex-pane:hover ~ .hex-pane {
    transform: scale(0.97) translateZ(-20px);
    opacity: 0.8;
}

.cheshire-grin-garden {
    margin-top: 50px;
}

/* ==========================================
   CHAPTER 6-7: THE CHESS GAME
   ========================================== */
.chapter-chess {
    min-height: 100vh;
    padding: 10vh 5vw;
    flex-direction: column;
    position: relative;
}

.chess-title {
    margin-bottom: 40px;
    text-align: center;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    width: min(80vw, 640px);
    aspect-ratio: 4 / 3;
    position: relative;
    gap: 2px;
}

.chess-cell {
    aspect-ratio: 1;
    border-radius: 4px;
    transition: opacity 300ms;
}

.chess-cell.light {
    background: rgba(30, 58, 95, 0.4);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
}

.chess-cell.dark {
    background: rgba(30, 58, 95, 0.7);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
}

.chess-piece {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 5;
    pointer-events: none;
}

.piece-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.piece-icon {
    font-size: clamp(18px, 3vw, 32px);
    color: var(--cheshire-gold);
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.4));
}

.piece-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    color: var(--fog-script);
    text-transform: uppercase;
}

/* ==========================================
   CHAPTER 8: THE OTHER SIDE
   ========================================== */
.chapter-other-side {
    min-height: 100vh;
    padding: 10vh 5vw;
    flex-direction: column;
    position: relative;
    transition: background-color 1200ms var(--smooth-ease);
}

.chapter-other-side.warmed {
    background-color: var(--deep-rose);
}

.refrost-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    -webkit-backdrop-filter: blur(0px);
    backdrop-filter: blur(0px);
    z-index: 1;
    pointer-events: none;
    transition: backdrop-filter 2000ms var(--smooth-ease),
                -webkit-backdrop-filter 2000ms var(--smooth-ease);
}

.refrost-overlay.frosted {
    -webkit-backdrop-filter: blur(24px);
    backdrop-filter: blur(24px);
}

.other-side-content {
    position: relative;
    z-index: 2;
    text-align: center;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
}

.final-quote {
    font-family: var(--font-accent);
    font-style: italic;
    font-size: clamp(20px, 3vw, 32px);
    line-height: 1.6;
    color: var(--fog-script);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 800ms var(--smooth-ease), transform 800ms var(--spring-ease);
}

.final-quote.visible {
    opacity: 1;
    transform: translateY(0);
}

.alice-input-container {
    width: 100%;
    max-width: 480px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms var(--smooth-ease) 400ms, transform 600ms var(--spring-ease) 400ms;
}

.alice-input-container.visible {
    opacity: 1;
    transform: translateY(0);
}

.input-pane {
    padding: 24px 32px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(22, 32, 51, 0.6);
}

.keyhole-pulse {
    flex-shrink: 0;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(56, 189, 248, 0.3)); }
    50% { filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.6)); }
}

.input-keyhole-svg {
    width: 24px;
    height: 36px;
}

.input-prompt {
    font-family: var(--font-mono);
    font-size: 14px;
    letter-spacing: 0.06em;
    color: var(--fog-script);
    flex-shrink: 0;
    cursor: text;
}

.alice-text-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-family: var(--font-mono);
    font-size: 14px;
    letter-spacing: 0.06em;
    color: var(--looking-glass-cyan);
    caret-color: var(--looking-glass-cyan);
}

.alice-text-input::placeholder {
    color: rgba(148, 163, 184, 0.4);
}

/* ==========================================
   FOOTER: THE REFLECTION
   ========================================== */
.chapter-reflection {
    height: 50vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: hidden;
    position: relative;
    background: var(--obsidian-ice);
}

.reflection-content {
    text-align: center;
    transform: scaleY(-1);
    opacity: 0.2;
    filter: blur(6px);
    padding-top: 40px;
    pointer-events: none;
    -webkit-user-select: none;
    user-select: none;
}

.reflected-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(40px, 15vw, 180px);
    letter-spacing: -0.02em;
    color: var(--looking-glass-cyan);
    line-height: 1;
    margin-bottom: 24px;
}

.reflected-epigraph {
    font-family: var(--font-accent);
    font-style: italic;
    font-size: clamp(12px, 1.5vw, 18px);
    color: var(--fog-script);
    max-width: 500px;
    margin: 0 auto;
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
    .chapter-looking-glass {
        flex-direction: column;
        align-items: center;
        padding: 5vh 5vw;
    }

    .pane-left,
    .pane-right {
        position: relative;
        top: auto;
        max-width: 100%;
        width: 100%;
    }

    .garden-cluster {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .chess-board {
        width: 95vw;
    }

    .pane-inner {
        padding: 24px;
    }

    #keyhole-nav {
        top: 10px;
    }
}

@media (max-width: 480px) {
    .garden-cluster {
        grid-template-columns: 1fr;
    }

    .chess-board {
        grid-template-columns: repeat(6, 1fr);
    }

    .input-pane {
        padding: 16px 20px;
        flex-direction: column;
        gap: 12px;
    }
}
