:root {
    --color-bg-primary: #0a0e17;
    --color-bg-secondary: #1a2332;
    --color-text-primary: #e6f2ff;
    --color-text-secondary: #8ab4f8;
    --color-accent-primary: #4fc3f7;
    --color-accent-secondary: #1976d2;
    --color-exhale: #b3e5fc;
    --color-exhale-core: #e0f7fa;
    --color-border: #2a3a4f;
    --color-ice-glow: #80deea;
    --color-ice-dark: #00838f;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;

    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(160deg, #050a12 0%, #0d1b2a 30%, #162a3d 60%, #0f2027 100%);
    color: var(--color-text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Container */
.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-lg);
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
}

.container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 30%, rgba(79, 195, 247, 0.03) 0%, transparent 60%);
    pointer-events: none;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: var(--spacing-sm);
    z-index: 1;
}

.header h1 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    margin-bottom: var(--spacing-xs);
    background: linear-gradient(90deg, var(--color-accent-primary), #81d4fa, var(--color-accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.06em;
}

.subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    opacity: 0.7;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

/* Dragon stage */
.dragon-stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 800px;
    position: relative;
}

/* Particle canvas */
#particle-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* Dragon visual container */
.dragon-visual {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease-out;
    z-index: 2;
}

.dragon-visual:hover {
    transform: scale(1.01);
}

.dragon-visual:active {
    transform: scale(0.97);
}

/* Dragon body */
.dragon-body {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    height: 320px;
}

/* Dragon head */
.dragon-head {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 160px;
    background: linear-gradient(145deg, #29b6f6 0%, #039be5 40%, #0182c9 100%);
    border-radius: 55% 55% 45% 45%;
    box-shadow:
        0 0 40px rgba(79, 195, 247, 0.3),
        0 0 80px rgba(79, 195, 247, 0.1),
        inset -12px -12px 24px rgba(0, 0, 0, 0.25),
        inset 12px 8px 20px rgba(179, 229, 252, 0.15);
    z-index: 5;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dragon horns */
.dragon-horn {
    position: absolute;
    top: -30px;
    width: 16px;
    height: 50px;
    background: linear-gradient(180deg, #b3e5fc 0%, #81d4fa 50%, #4fc3f7 100%);
    z-index: 6;
    transition: all 0.4s ease;
}

.dragon-horn.left {
    left: 30%;
    transform: rotate(-15deg);
    border-radius: 60% 40% 20% 30%;
    clip-path: polygon(50% 0%, 100% 80%, 80% 100%, 20% 100%, 0% 80%);
}

.dragon-horn.right {
    right: 30%;
    transform: rotate(15deg);
    border-radius: 40% 60% 30% 20%;
    clip-path: polygon(50% 0%, 100% 80%, 80% 100%, 20% 100%, 0% 80%);
}

/* Dragon eyes */
.dragon-eye {
    position: absolute;
    top: 32%;
    width: 28px;
    height: 36px;
    background: radial-gradient(circle at 40% 40%, #ffffff 0%, #e0f7fa 50%, #b3e5fc 80%);
    border-radius: 50%;
    box-shadow:
        0 0 20px rgba(255, 255, 255, 0.7),
        0 0 40px rgba(144, 202, 249, 0.4),
        inset -3px -3px 6px rgba(0, 0, 0, 0.15);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: idleBlink 4s ease-in-out infinite;
}

.dragon-eye::after {
    content: '';
    position: absolute;
    top: 25%;
    left: 20%;
    width: 10px;
    height: 10px;
    background: radial-gradient(circle, #ffffff 0%, rgba(255, 255, 255, 0.6) 100%);
    border-radius: 50%;
}

#dragon-eye-left {
    left: 22%;
    transform: translateX(-50%);
}

#dragon-eye-right {
    right: 22%;
    transform: translateX(50%);
}

/* Dragon mouth */
.dragon-mouth {
    position: absolute;
    bottom: 12%;
    left: 50%;
    transform: translateX(-50%);
    width: 90px;
    height: 10px;
    background: linear-gradient(90deg, #0a1e30 0%, #0d2740 50%, #0a1e30 100%);
    border-radius: 0 0 45px 45px;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.dragon-mouth::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 65px;
    height: 5px;
    background: linear-gradient(90deg, #4fc3f7, #81d4fa, #b3e5fc, #81d4fa, #4fc3f7);
    border-radius: 3px;
    box-shadow: 0 0 10px rgba(79, 195, 247, 0.5);
}

.dragon-mouth::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background: linear-gradient(90deg, transparent, #b3e5fc, transparent);
    border-radius: 2px;
}

/* Dragon neck */
.dragon-neck {
    position: absolute;
    top: 52%;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 120px;
    background: linear-gradient(180deg, #039be5 0%, #0288d1 50%, #01579b 100%);
    border-radius: 0 0 50px 50px;
    z-index: 2;
    box-shadow:
        inset -8px 0 16px rgba(0, 0, 0, 0.2),
        inset 8px 0 16px rgba(179, 229, 252, 0.05);
}

.dragon-neck::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 160px;
    height: 60px;
    background: linear-gradient(180deg, #01579b 0%, #0d47a1 100%);
    border-radius: 50%;
}

/* Dragon wings */
.dragon-wing {
    position: absolute;
    top: 45%;
    width: 170px;
    height: 130px;
    background: linear-gradient(135deg, #1976d2 0%, #0d47a1 60%, #0a3470 100%);
    opacity: 0.85;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.dragon-wing.left {
    left: -110px;
    transform: rotate(-12deg) skewY(8deg);
    border-radius: 70% 15% 40% 65%;
    box-shadow: -8px 6px 20px rgba(0, 0, 0, 0.35);
}

.dragon-wing.right {
    right: -110px;
    transform: rotate(12deg) skewY(-8deg);
    border-radius: 15% 70% 65% 40%;
    box-shadow: 8px 6px 20px rgba(0, 0, 0, 0.35);
}

.dragon-wing::before {
    content: '';
    position: absolute;
    inset: 15%;
    background: linear-gradient(135deg, rgba(79, 195, 247, 0.15) 0%, transparent 70%);
    border-radius: inherit;
}

/* Icy scale pattern overlay on wings */
.dragon-wing::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 8px,
        rgba(179, 229, 252, 0.03) 8px,
        rgba(179, 229, 252, 0.03) 9px
    );
    border-radius: inherit;
}

/* Exhale glow effect */
.exhale-effect {
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%);
    width: 250px;
    height: 250px;
    background: radial-gradient(circle,
        rgba(224, 247, 250, 0.7) 0%,
        rgba(128, 222, 234, 0.5) 20%,
        rgba(79, 195, 247, 0.25) 45%,
        rgba(0, 188, 212, 0.1) 65%,
        transparent 100%
    );
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-out;
    filter: blur(25px);
    z-index: 3;
}

/* Status display */
.status-display {
    position: absolute;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    font-size: var(--font-size-xs);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    white-space: nowrap;
    transition: all 0.3s ease;
    z-index: 20;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: 4px;
    background: rgba(10, 14, 23, 0.6);
    border: 1px solid var(--color-border);
}

/* Instructions */
.instructions {
    position: absolute;
    bottom: -90px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    opacity: 0.7;
    transition: opacity 0.4s ease;
    z-index: 20;
}

.instructions p {
    line-height: 1.6;
}

/* kbd style */
kbd {
    display: inline-block;
    padding: var(--spacing-xs) var(--spacing-sm);
    margin: var(--spacing-xs);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.85em;
    color: var(--color-accent-primary);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
    min-width: 40px;
    text-align: center;
}

/* Controls footer */
.controls {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) 0;
    z-index: 1;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    height: 48px;
    padding: var(--spacing-md);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text-primary);
    font-family: inherit;
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover {
    background: var(--color-accent-secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(25, 118, 210, 0.4);
}

.btn:focus {
    outline: 2px solid var(--color-accent-primary);
    outline-offset: 2px;
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.btn-label {
    margin-left: var(--spacing-sm);
    font-weight: 600;
    letter-spacing: 0.08em;
}

/* Volume icons */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.visible {
    display: inline-block;
}

.hidden {
    display: none;
}

/* === STATE: LOCKED === */
.dragon-stage.locked .dragon-visual {
    cursor: pointer;
}

.dragon-stage.locked .dragon-head {
    box-shadow:
        0 0 40px rgba(79, 195, 247, 0.2),
        0 0 80px rgba(79, 195, 247, 0.08),
        inset -12px -12px 24px rgba(0, 0, 0, 0.25),
        inset 12px 8px 20px rgba(179, 229, 252, 0.15);
}

.dragon-stage.locked .dragon-body {
    animation: lockedPulse 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* === STATE: CHARGING === */
.dragon-stage.charging .dragon-body {
    animation: chargeBreath 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.dragon-stage.charging .dragon-head {
    transform: translateX(-50%) scale(1.03);
    box-shadow:
        0 0 50px rgba(79, 195, 247, 0.4),
        0 0 100px rgba(79, 195, 247, 0.2),
        inset -12px -12px 24px rgba(0, 0, 0, 0.2),
        inset 12px 8px 20px rgba(179, 229, 252, 0.2);
}

.dragon-stage.charging .dragon-eye {
    animation: none;
    opacity: 0.9;
    transform: scale(0.95);
}

.dragon-stage.charging .dragon-mouth {
    height: 14px;
    width: 95px;
}

.dragon-stage.charging .exhale-effect {
    opacity: 0.15;
    transform: translateX(-50%) scale(0.6);
    filter: blur(20px);
}

/* === STATE: EXHALED === */
.dragon-stage.exhaled .dragon-body {
    animation: exhaleShake 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.dragon-stage.exhaled .dragon-head {
    transform: translateX(-50%) translateY(-8px) scale(1.08);
    box-shadow:
        0 0 60px rgba(79, 195, 247, 0.6),
        0 -20px 80px rgba(179, 229, 252, 0.3),
        inset -12px -12px 24px rgba(0, 0, 0, 0.15),
        inset 12px 8px 20px rgba(224, 247, 250, 0.25);
}

.dragon-stage.exhaled .dragon-eye {
    animation: none;
    opacity: 0.7;
    transform: scale(0.85);
    box-shadow:
        0 0 15px rgba(255, 255, 255, 0.5),
        0 0 30px rgba(144, 202, 249, 0.3);
}

.dragon-stage.exhaled .dragon-mouth {
    height: 22px;
    width: 120px;
    box-shadow: 0 4px 20px rgba(79, 195, 247, 0.5);
}

.dragon-stage.exhaled .dragon-wing.left {
    transform: rotate(-28deg) skewY(12deg) scale(1.15);
}

.dragon-stage.exhaled .dragon-wing.right {
    transform: rotate(28deg) skewY(-12deg) scale(1.15);
}

.dragon-stage.exhaled .dragon-neck {
    transform: translateX(-50%) scale(1.05);
}

.dragon-stage.exhaled .exhale-effect {
    opacity: 1;
    transform: translateX(-50%) scale(1.4);
    animation: exhalePulse 2.5s ease-out;
    filter: blur(30px);
}

.dragon-stage.exhaled .status-display {
    color: var(--color-exhale-core);
    border-color: var(--color-ice-glow);
    text-shadow: 0 0 10px rgba(179, 229, 252, 0.6);
}

/* === STATE: COOLDOWN === */
.dragon-stage.cooldown .dragon-body {
    animation: fadeSettle 0.8s ease-out;
}

.dragon-stage.cooldown .dragon-head {
    transform: translateX(-50%) scale(1.02);
}

.dragon-stage.cooldown .dragon-eye {
    animation: idleBlink 4s ease-in-out infinite;
    opacity: 0.9;
}

.dragon-stage.cooldown .dragon-mouth {
    height: 11px;
    width: 85px;
}

.dragon-stage.cooldown .exhale-effect {
    opacity: 0.1;
    transform: translateX(-50%) scale(0.8);
    filter: blur(20px);
}

.dragon-stage.cooldown .status-display {
    color: var(--color-text-secondary);
    border-color: var(--color-border);
}

/* === KEYFRAMES === */

@keyframes lockedPulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.015);
    }
}

@keyframes idleBlink {
    0%, 92%, 100% {
        transform: scaleY(1);
    }
    95% {
        transform: scaleY(0.1);
    }
}

@keyframes chargeBreath {
    0% {
        transform: translate(-50%, -50%) scale(1);
    }
    60% {
        transform: translate(-50%, -50%) scale(1.04);
    }
    100% {
        transform: translate(-50%, -50%) scale(1.02);
    }
}

@keyframes exhaleShake {
    0%, 100% {
        transform: translate(-50%, -50%);
    }
    10% {
        transform: translate(calc(-50% + 2px), -50%);
    }
    20% {
        transform: translate(calc(-50% - 2px), -50%);
    }
    30% {
        transform: translate(calc(-50% + 1px), -50%);
    }
}

@keyframes exhalePulse {
    0% {
        opacity: 0.3;
        transform: translateX(-50%) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translateX(-50%) scale(1.5);
    }
    50% {
        opacity: 0.9;
        transform: translateX(-50%) scale(1.4);
    }
    80% {
        opacity: 0.5;
        transform: translateX(-50%) scale(1.3);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) scale(1.2);
    }
}

@keyframes fadeSettle {
    0% {
        transform: translate(-50%, -50%) scale(1.02);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Responsive: tablet */
@media (max-width: 768px) {
    .header h1 {
        font-size: var(--font-size-xl);
    }

    .dragon-body {
        width: 240px;
        height: 240px;
    }

    .dragon-head {
        width: 150px;
        height: 120px;
    }

    .dragon-wing {
        width: 130px;
        height: 100px;
    }

    .dragon-wing.left {
        left: -80px;
    }

    .dragon-wing.right {
        right: -80px;
    }

    .dragon-eye {
        width: 22px;
        height: 28px;
    }

    .dragon-mouth {
        width: 70px;
        height: 8px;
    }

    .dragon-neck {
        width: 80px;
        height: 90px;
    }

    .dragon-horn {
        width: 12px;
        height: 38px;
    }

    .instructions {
        max-width: 90%;
    }
}

/* Responsive: mobile */
@media (max-width: 480px) {
    :root {
        --spacing-lg: 1rem;
        --spacing-xl: 1.5rem;
    }

    .header h1 {
        font-size: var(--font-size-lg);
    }

    .subtitle {
        font-size: var(--font-size-xs);
    }

    .dragon-body {
        width: 180px;
        height: 180px;
    }

    .dragon-head {
        width: 120px;
        height: 95px;
    }

    .dragon-wing {
        width: 90px;
        height: 70px;
    }

    .dragon-wing.left {
        left: -50px;
    }

    .dragon-wing.right {
        right: -50px;
    }

    .dragon-eye {
        width: 16px;
        height: 22px;
    }

    .dragon-mouth {
        width: 55px;
        height: 6px;
    }

    .dragon-neck {
        width: 65px;
        height: 75px;
    }

    .dragon-horn {
        width: 10px;
        height: 30px;
    }

    .btn {
        min-width: 44px;
        height: 44px;
        padding: var(--spacing-sm);
    }

    .btn-label {
        font-size: 0.75em;
    }

    .instructions {
        font-size: var(--font-size-xs);
    }

    .status-display {
        font-size: 0.65rem;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .dragon-body,
    .dragon-head,
    .dragon-eye,
    .dragon-mouth,
    .dragon-wing,
    .dragon-neck,
    .exhale-effect,
    .dragon-visual {
        animation: none !important;
        transition: none !important;
    }

    .exhale-effect {
        opacity: 1;
        filter: blur(15px);
    }

    .btn {
        transition: none;
    }
}

/* High contrast */
@media (prefers-contrast: high) {
    :root {
        --color-bg-primary: #000;
        --color-text-primary: #fff;
        --color-text-secondary: #ccc;
        --color-border: #666;
    }

    .dragon-head {
        box-shadow: 0 0 0 2px #fff, 0 0 40px rgba(79, 195, 247, 0.4);
    }

    .btn {
        border-width: 2px;
    }
}

/* Selection styling */
::selection {
    background: rgba(79, 195, 247, 0.3);
    color: var(--color-exhale-core);
}

/* Screen reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
