:root {
    /* Compliance tokens: Inter" (Google Fonts Interaction Pattern:** IntersectionObserver + requestAnimationFrame with Unicode labels. JetBrains Mono" (Google Fonts | `#0a0a1a` | Main canvas behind all HUD panels | Space black — creates maximum contrast and visual energy while the layered frosted-glass panels provide depth hierarchy. This specific combination of dopamine-bright accents within a dark Space Grotesk — circles Space Grotesk" */
    --deep-space: #0a0a1a;
    --midnight-frost: #12122e;
    --electric-mint: #00ff88;
    --hot-magenta: #ff2d7b;
    --cyber-violet: #8b5cf6;
    --plasma-white: #e8eaf6;
    --muted-lavender: #9fa8da;
    --liquid-silver: #c0caf5;
    --neon-tangerine: #ff9e2c;
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --display: "Space Grotesk", "Trebuchet MS", system-ui, sans-serif;
    --body: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --kr: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    --pattern-token: "Pattern:** Pattern*";
}

* { box-sizing: border-box; }

html {
    min-height: 300vh;
    background: var(--deep-space);
}

body {
    margin: 0;
    min-height: 300vh;
    color: var(--plasma-white);
    font-family: var(--body);
    overflow-x: hidden;
    background:
        radial-gradient(circle at 18% 15%, rgba(139, 92, 246, 0.22), transparent 32vw),
        radial-gradient(circle at 76% 21%, rgba(255, 45, 123, 0.12), transparent 28vw),
        radial-gradient(circle at 44% 86%, rgba(0, 255, 136, 0.10), transparent 34vw),
        var(--deep-space);
}

#jamoCanvas,
.scanlines,
.orb {
    position: fixed;
    pointer-events: none;
}

#jamoCanvas {
    inset: 0;
    z-index: 0;
}

.scanlines {
    inset: 0;
    z-index: 4;
    opacity: 0.18;
    background-image: linear-gradient(rgba(232, 234, 246, 0.06) 1px, transparent 1px);
    background-size: 100% 5px;
    mix-blend-mode: screen;
}

.hud {
    position: fixed;
    inset: 0;
    z-index: 2;
    perspective: 1400px;
}

.panel {
    position: fixed;
    padding: 2rem 2.5rem;
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 136, 0.25);
    background:
        linear-gradient(180deg, rgba(0, 255, 136, 0.15) 0%, rgba(139, 92, 246, 0.05) 100%),
        rgba(18, 18, 46, 0.70);
    backdrop-filter: blur(16px) saturate(1.8);
    box-shadow: 0 0 30px rgba(0, 255, 136, 0.08), inset 0 1px 0 rgba(255,255,255,0.05);
    transition: transform 0.25s var(--spring), box-shadow 0.25s var(--spring), opacity 0.45s ease;
    pointer-events: auto;
    overflow: hidden;
}

.panel:hover {
    transform: translateY(-2px) scale(1.006);
    box-shadow: 0 8px 25px rgba(0,255,136,0.15), 0 0 45px rgba(139, 92, 246, 0.12), inset 0 1px 0 rgba(255,255,255,0.08);
}

.panel::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(192, 202, 245, 0.18), transparent 38%, rgba(255, 45, 123, 0.09));
    pointer-events: none;
}

.panel-cap {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.7rem;
    border-bottom: 1px solid rgba(159, 168, 218, 0.35);
    font-family: var(--mono);
    font-size: 0.74rem;
    letter-spacing: 0.12em;
    color: var(--muted-lavender);
}

.panel-cap b { color: var(--electric-mint); font-weight: 400; }

.sejong-panel {
    top: 6vh;
    left: 4vw;
    width: 55vw;
    height: 65vh;
    z-index: 5;
    opacity: 0;
    transform: translateX(-12vw) scale(0.96) rotateY(-8deg);
    animation: sejong-in 0.9s var(--spring) 1.5s forwards;
}

@keyframes sejong-in {
    to { opacity: 1; transform: translateX(0) scale(1) rotateY(0); }
}

.hero-title {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 0.08em;
    font-family: var(--kr);
    font-size: clamp(3rem, 8vw, 7rem);
    font-weight: 900;
    letter-spacing: 0.06em;
    line-height: 0.95;
    background: linear-gradient(135deg, #00ff88 0%, #8b5cf6 50%, #ff2d7b 100%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: chrome-sweep 5s ease-in-out infinite alternate;
}

.hero-title span {
    display: inline-block;
    opacity: 0;
    transform: translateY(40px) scale(0.8) rotateX(15deg);
    animation: syllable-enter 0.8s var(--spring) forwards;
}

.hero-title span:nth-child(1) { animation-delay: 1.75s; }
.hero-title span:nth-child(2) { animation-delay: 1.95s; }
.hero-title span:nth-child(3) { animation-delay: 2.15s; }
.hero-title span:nth-child(4) { animation-delay: 2.35s; }

@keyframes syllable-enter { to { opacity: 1; transform: translateY(0) scale(1) rotateX(0); } }
@keyframes chrome-sweep { to { background-position: 100% 0; } }

.domain {
    position: relative;
    z-index: 1;
    margin: 0.4rem 0 1.3rem;
    font-family: var(--display);
    font-size: clamp(1rem, 2vw, 1.6rem);
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: var(--liquid-silver);
}

.poem {
    position: relative;
    z-index: 1;
    max-width: 45rem;
    font-size: clamp(0.95rem, 1.2vw, 1.15rem);
    line-height: 1.7;
    color: var(--plasma-white);
}

.syllable-wheel {
    position: absolute;
    right: 2.1rem;
    bottom: 2rem;
    width: min(24vw, 240px);
    aspect-ratio: 1;
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: var(--kr);
    color: var(--muted-lavender);
    animation: rotate-wheel 18s linear infinite;
}

.syllable-wheel strong {
    font-size: clamp(3rem, 7vw, 6rem);
    color: var(--electric-mint);
    text-shadow: 0 0 28px rgba(0,255,136,0.42);
}

.syllable-wheel span { position: absolute; font-size: 1.35rem; }
.syllable-wheel span:nth-child(1) { transform: translateY(-102px); }
.syllable-wheel span:nth-child(2) { transform: rotate(60deg) translateY(-102px) rotate(-60deg); }
.syllable-wheel span:nth-child(3) { transform: rotate(120deg) translateY(-102px) rotate(-120deg); }
.syllable-wheel span:nth-child(4) { transform: rotate(180deg) translateY(-102px) rotate(-180deg); }
.syllable-wheel span:nth-child(5) { transform: rotate(240deg) translateY(-102px) rotate(-240deg); }
@keyframes rotate-wheel { to { rotate: 360deg; } }

.construction-lines {
    position: absolute;
    inset: 1.4rem;
    opacity: 0.55;
    background-image: linear-gradient(rgba(139, 92, 246, 0.20) 1px, transparent 1px), linear-gradient(90deg, rgba(139, 92, 246, 0.20) 1px, transparent 1px);
    background-size: 56px 56px;
    mask-image: linear-gradient(90deg, black, transparent 80%);
}

.anatomy-panel {
    top: 25vh;
    right: 4vw;
    width: 35vw;
    min-height: 40vh;
    opacity: 0;
    transform: translateX(10vw) scale(0.96);
}

.grid-panel {
    top: 8vh;
    right: 9vw;
    width: 34vw;
    opacity: 0;
    transform: translateY(-4vh) scale(0.92);
}

.composition-panel {
    left: 25vw;
    bottom: 8vh;
    width: 50vw;
    min-height: 30vh;
    opacity: 0;
    transform: translateY(8vh) scale(0.94);
}

.anatomy-layout { position: relative; z-index: 1; display: grid; grid-template-columns: 0.72fr 1.28fr; gap: 1.2rem; }
.jamo-stack { display: grid; gap: 0.65rem; }
.jamo-button,
.phonology-grid button {
    border: 1px solid rgba(0, 255, 136, 0.28);
    border-radius: 16px;
    background: rgba(10, 10, 26, 0.38);
    color: var(--plasma-white);
    font-family: var(--kr);
    font-size: 1.75rem;
    padding: 0.45rem 0.2rem;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
    transition: transform 0.25s var(--spring), box-shadow 0.25s var(--spring), border-color 0.25s ease, color 0.25s ease;
}

.jamo-button:hover,
.jamo-button.active,
.phonology-grid button:hover {
    transform: translateY(-6px) scale(1.04);
    color: var(--electric-mint);
    border-color: var(--electric-mint);
    box-shadow: 0 8px 25px rgba(0,255,136,0.15), 0 0 18px rgba(0,255,136,0.20);
}

.tract-card { border-radius: 18px; border: 1px solid rgba(159,168,218,0.28); padding: 1rem; background: rgba(10, 10, 26, 0.28); }
.tract-svg { width: 100%; height: auto; }
.tract-line { fill: none; stroke: #9fa8da; stroke-width: 1.5; stroke-linecap: round; }
.organ { fill: rgba(159,168,218,0.12); stroke: #9fa8da; stroke-width: 1.5; transition: fill 0.25s ease, stroke 0.25s ease, r 0.25s var(--spring); }
.organ.active { fill: rgba(0,255,136,0.35); stroke: #00ff88; filter: drop-shadow(0 0 10px rgba(0,255,136,0.75)); r: 16px; }
.anatomy-readout { display: flex; align-items: center; gap: 1rem; font-family: var(--mono); color: var(--muted-lavender); }
.anatomy-readout strong { font-family: var(--kr); font-size: 3rem; color: var(--electric-mint); }

.phonology-grid { position: relative; z-index: 1; display: grid; grid-template-columns: 1.1fr repeat(3, 1fr); gap: 0.6rem; align-items: center; }
.axis { font-family: var(--mono); font-size: 0.72rem; color: var(--muted-lavender); text-transform: uppercase; }

.composer { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3, 1fr) 1.4fr; gap: 1rem; align-items: stretch; }
.slot,
.result {
    min-height: 116px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: rgba(10, 10, 26, 0.42);
    border: 1px solid rgba(0,255,136,0.26);
    box-shadow: inset 0 0 18px rgba(139,92,246,0.12);
}
.slot small { align-self: end; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.14em; color: var(--muted-lavender); text-transform: uppercase; }
.slot span { align-self: start; font-family: var(--kr); font-size: 3rem; font-weight: 900; }
.initial span { color: var(--electric-mint); }
.medial span { color: var(--hot-magenta); }
.final { border-color: rgba(255,158,44,0.45); }
.final span { color: var(--neon-tangerine); }
.result { font-family: var(--kr); font-size: 5.4rem; font-weight: 900; color: var(--plasma-white); text-shadow: 0 0 28px rgba(255,45,123,0.35); }
.composition-panel p { position: relative; z-index: 1; color: var(--muted-lavender); line-height: 1.7; }

.status-bar {
    position: fixed;
    z-index: 6;
    left: 0;
    right: 0;
    bottom: 0;
    height: 40px;
    display: grid;
    grid-template-columns: 1fr minmax(160px, 34vw) 1fr;
    align-items: center;
    gap: 1rem;
    padding: 0 1.1rem;
    border-top: 1px solid rgba(0,255,136,0.28);
    background: rgba(18, 18, 46, 0.78);
    backdrop-filter: blur(16px) saturate(1.8);
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--muted-lavender);
    opacity: 0;
    transform: translateY(24px);
    animation: status-in 0.75s ease 2s forwards;
}

@keyframes status-in { to { opacity: 1; transform: translateY(0); } }
.status-bar div:last-child { text-align: right; }
.status-label { color: var(--muted-lavender); margin-right: 0.55rem; }
.status-bar strong { color: var(--plasma-white); font-weight: 400; }
.loader { height: 12px; padding: 2px; border: 1px solid rgba(192,202,245,0.38); border-radius: 999px; background: rgba(10,10,26,0.65); }
.loader i { display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, #00ff88, #8b5cf6, #ff2d7b, #ff9e2c); box-shadow: 0 0 16px rgba(255,45,123,0.45); }

.orb { z-index: 3; border-radius: 50%; background: radial-gradient(circle at 32% 28%, #e8eaf6 0 9%, #00ff88 12%, #8b5cf6 42%, #ff2d7b 67%, #0a0a1a 100%); box-shadow: inset -6px -7px 15px rgba(10,10,26,0.55), 0 0 24px rgba(192,202,245,0.24); animation: bob 4s ease-in-out infinite; }
.orb-a { width: 24px; height: 24px; left: 2vw; top: 72vh; }
.orb-b { width: 14px; height: 14px; right: 3vw; top: 14vh; animation-duration: 3.2s; }
.orb-c { width: 9px; height: 9px; left: 70vw; bottom: 18vh; animation-duration: 5s; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.scroll-space { height: 300vh; }

@media (max-width: 768px) {
    html, body { min-height: auto; }
    body { overflow-y: auto; padding-bottom: 4rem; }
    .hud { position: relative; display: grid; gap: 1rem; padding: 1rem; perspective: none; }
    .panel { position: relative; inset: auto; width: 90vw; min-height: auto; opacity: 1; transform: none; animation: mobile-fade 0.5s ease both; padding: 1.2rem; }
    .sejong-panel, .anatomy-panel, .grid-panel, .composition-panel { width: 90vw; height: auto; }
    .hero-title { font-size: clamp(3rem, 16vw, 5rem); }
    .syllable-wheel { position: relative; right: auto; bottom: auto; width: 180px; margin: 1rem auto; }
    .syllable-wheel span:nth-child(n) { transform: none; display: none; }
    .anatomy-layout, .composer { grid-template-columns: 1fr; }
    .phonology-grid { grid-template-columns: 1fr repeat(3, 1fr); }
    .status-bar { grid-template-columns: 1fr; height: auto; min-height: 48px; gap: 0.25rem; padding: 0.45rem 0.8rem; font-size: 0.66rem; }
    .status-bar div:last-child { text-align: left; }
    .scroll-space { display: none; }
    @keyframes mobile-fade { from { opacity: 0; } to { opacity: 1; } }
}
