/* Base styling */
:root {
    --bg-color: #07080c;
    --text-color: #f4f5f8;
    --text-dim: rgba(244, 245, 248, 0.55);
    --accent-color: #6db4f5;
    --accent-color-2: #f08a8a;
    --glass-bg: rgba(16, 18, 26, 0.55);
    --glass-border: rgba(255, 255, 255, 0.08);
    --transition-duration: 0.8s;
    --transition-timing: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Montserrat', sans-serif;
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(120% 90% at 50% 8%, color-mix(in oklab, var(--accent-color) 12%, transparent) 0%, transparent 55%),
        radial-gradient(100% 80% at 50% 120%, color-mix(in oklab, var(--accent-color-2) 10%, transparent) 0%, transparent 50%),
        radial-gradient(140% 140% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.85) 100%);
    transition: background-image 1.2s var(--transition-timing);
}

/* Canvas background */
#backgroundCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* Main container for the name */
.main-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.6rem;
    z-index: 10;
    pointer-events: none;
}

/* The name styling */
#main-name {
    font-size: clamp(2.6rem, 7vw, 7rem);
    font-weight: 200;
    letter-spacing: 0.14em;
    text-indent: 0.14em;
    line-height: 1;
    text-align: center;
    color: var(--text-color);
    text-shadow:
        0 0 40px color-mix(in oklab, var(--accent-color) 38%, transparent),
        0 2px 34px rgba(0, 0, 0, 0.6);
}

#main-name span {
    transition: transform 0.5s var(--transition-timing), color 0.5s var(--transition-timing);
}

/* Hairline divider + hint under the name */
.name-flourish {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    opacity: 0;
    transform: translateY(12px);
    animation: fadeUp 1.4s var(--transition-timing) forwards;
    animation-delay: 2.4s;
}

.name-rule {
    width: clamp(120px, 22vw, 260px);
    height: 1px;
    border: none;
    background: linear-gradient(90deg, transparent, color-mix(in oklab, var(--accent-color) 70%, white 0%), transparent);
    opacity: 0.7;
}

.name-hint {
    font-size: 0.72rem;
    font-weight: 300;
    letter-spacing: 0.42em;
    text-indent: 0.42em;
    text-transform: uppercase;
    color: var(--text-dim);
}

/* Abstract elements container */
.abstract-elements {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

/* Interaction area */
.interaction-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    cursor: default;
}

/* Instructions panel */
.instructions {
    position: fixed;
    bottom: 100px;
    left: 50%;
    width: min(360px, 88vw);
    margin-left: calc(min(360px, 88vw) / -2);
    background: var(--glass-bg);
    color: var(--text-color);
    padding: 20px 22px;
    border-radius: 18px;
    font-size: 0.78rem;
    z-index: 100;
    opacity: 0;
    transform: translateY(20px);
    animation: panelIn 0.7s var(--transition-timing) forwards;
    animation-delay: 3.1s;
    max-height: 62vh;
    overflow-y: auto;
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    border: 1px solid var(--glass-border);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
    transition: opacity 0.35s ease;
}

.instructions:hover {
    opacity: 1;
}

.instructions h3 {
    margin-bottom: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent-color);
}

.instructions ul {
    list-style: none;
    margin-left: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.instructions li {
    font-weight: 300;
    opacity: 0.82;
    line-height: 1.45;
}

.instructions .key {
    display: inline-block;
    min-width: 18px;
    text-align: center;
    padding: 1px 7px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    margin-right: 6px;
    font-family: 'Montserrat', monospace;
    font-size: 0.72rem;
    color: var(--text-color);
}

.instructions-toggle {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    cursor: pointer;
    z-index: 101;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    opacity: 0;
    animation: fadeIn 1s var(--transition-timing) forwards;
    animation-delay: 3s;
}

.instructions-toggle:hover {
    background-color: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.instructions-icon {
    width: 20px;
    height: 20px;
    position: relative;
}

.instructions-icon::before {
    content: '?';
    color: var(--accent-color);
    font-size: 20px;
    font-weight: bold;
}

/* Audio indicator */
.audio-indicator {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    cursor: pointer;
    z-index: 101;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    opacity: 0;
    animation: fadeIn 1s var(--transition-timing) forwards;
    animation-delay: 3.5s;
}

.audio-indicator:hover {
    background-color: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.audio-icon {
    width: 20px;
    height: 20px;
    position: relative;
}

.audio-icon::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: var(--accent-color);
    border-radius: 1px;
    top: 50%;
    left: 2px;
    transform: translateY(-50%);
}

.audio-icon::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border-right: 2px solid var(--accent-color);
    border-radius: 50%;
    border-top: 2px solid var(--accent-color);
    border-bottom: 2px solid var(--accent-color);
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

.audio-indicator.muted .audio-icon::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background-color: var(--accent-color-2);
    transform: translateY(-50%) rotate(45deg);
    top: 50%;
    left: 0;
    border: none;
}

/* Theme switcher */
.theme-switcher {
    position: absolute;
    bottom: 20px;
    left: 70px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    cursor: pointer;
    z-index: 101;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    opacity: 0;
    animation: fadeIn 1s var(--transition-timing) forwards;
    animation-delay: 4s;
}

.theme-switcher:hover {
    background-color: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.theme-icon {
    width: 20px;
    height: 20px;
    position: relative;
}

.theme-icon::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--accent-color);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, var(--accent-color) 0%, transparent 50%);
}

/* Save button */
.save-button {
    position: absolute;
    bottom: 20px;
    left: 120px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    cursor: pointer;
    z-index: 101;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    opacity: 0;
    animation: fadeIn 1s var(--transition-timing) forwards;
    animation-delay: 4.5s;
}

.save-button:hover {
    background-color: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.save-icon {
    width: 20px;
    height: 20px;
    position: relative;
}

.save-icon::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border: 2px solid var(--accent-color);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.save-icon::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 3px;
    background-color: var(--accent-color);
    top: 70%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* ===== Unified control dock ===== */
.control-dock {
    position: fixed;
    bottom: 18px;
    left: 50%;
    margin-left: -122px;
    width: 244px;
    height: 60px;
    border-radius: 30px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(14px) saturate(1.3);
    -webkit-backdrop-filter: blur(14px) saturate(1.3);
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07);
    z-index: 100;
    opacity: 0;
    animation: fadeUp 1s var(--transition-timing) forwards;
    animation-delay: 2.9s;
    pointer-events: none;
}

.audio-indicator,
.theme-switcher,
.save-button,
.instructions-toggle {
    position: fixed;
    bottom: 26px;
    top: auto;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
    border: 1px solid transparent;
    z-index: 101;
    transition: background 0.25s ease, transform 0.25s var(--transition-timing), border-color 0.25s ease;
}

.audio-indicator      { left: calc(50% - 103px); }
.theme-switcher       { left: calc(50% - 49px);  right: auto; }
.save-button          { left: calc(50% + 5px); }
.instructions-toggle  { left: calc(50% + 59px);  right: auto; }

.audio-indicator:hover,
.theme-switcher:hover,
.save-button:hover,
.instructions-toggle:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateY(-3px);
}

/* Tooltips */
[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 4px 10px;
    font-size: 0.62rem;
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--text-color);
    background: rgba(10, 12, 18, 0.92);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s var(--transition-timing);
}

[data-tip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Dock icons: suppress the old CSS-shape icons, use injected SVG (currentColor) */
.audio-icon::before,
.audio-icon::after,
.theme-icon::before,
.save-icon::before,
.save-icon::after,
.instructions-icon::before {
    content: none !important;
}

.audio-indicator,
.theme-switcher,
.save-button,
.instructions-toggle {
    color: rgba(244, 245, 248, 0.78);
}

.audio-indicator:hover,
.theme-switcher:hover,
.save-button:hover,
.instructions-toggle:hover {
    color: var(--accent-color);
}

.audio-icon,
.theme-icon,
.save-icon,
.instructions-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
}

.audio-icon svg,
.theme-icon svg,
.save-icon svg,
.instructions-icon svg {
    width: 22px;
    height: 22px;
    display: block;
}

.audio-indicator.muted {
    color: var(--accent-color-2);
}
.audio-indicator.muted .audio-icon {
    opacity: 0.65;
}

/* Save dialog */
.save-dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(12, 14, 20, 0.82);
    color: var(--text-color);
    padding: 28px;
    border-radius: 20px;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s var(--transition-timing);
    backdrop-filter: blur(24px) saturate(1.3);
    -webkit-backdrop-filter: blur(24px) saturate(1.3);
    border: 1px solid var(--glass-border);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
    min-width: 320px;
    text-align: center;
}

.save-dialog.active {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.save-dialog h3 {
    margin-bottom: 18px;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent-color);
}

.save-dialog input[type="text"],
#composition-name {
    width: 100%;
    padding: 11px 14px;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: var(--text-color);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.9rem;
    font-weight: 300;
    text-align: center;
    transition: border-color 0.2s ease;
}

.save-dialog input[type="text"]:focus,
#composition-name:focus {
    outline: none;
    border-color: color-mix(in oklab, var(--accent-color) 55%, transparent);
}

.save-dialog input::placeholder {
    color: var(--text-dim);
}

.save-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.action-button {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.85rem;
    font-weight: 300;
}

.action-button:hover {
    background: color-mix(in oklab, var(--accent-color) 22%, transparent);
    border-color: color-mix(in oklab, var(--accent-color) 45%, transparent);
    transform: translateY(-2px);
}

.save-message {
    min-height: 20px;
    font-size: 0.9rem;
    opacity: 0.8;
}

.save-message.success {
    color: #4caf50;
}

.save-message.error {
    color: #f44336;
}

/* Dynamically created abstract shapes */
.abstract-shape {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.8);
    animation: shapeAppear 1.5s var(--transition-timing) forwards;
}

.abstract-line {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    animation: lineAppear 1.2s var(--transition-timing) forwards;
}

/* Piano keyboard (easter egg) */
.piano-keyboard {
    position: absolute;
    bottom: -200px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 5px 5px 0 0;
    z-index: 100;
    transition: bottom 0.5s var(--transition-timing);
}

.piano-keyboard.active {
    bottom: 0;
}

.piano-key {
    width: 40px;
    height: 120px;
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.3);
    border-radius: 0 0 5px 5px;
    margin: 0 2px;
    cursor: pointer;
    transition: all 0.1s ease;
    position: relative;
}

.piano-key:hover {
    background-color: rgba(255, 255, 255, 1);
}

.piano-key:active, .piano-key.pressed {
    background-color: var(--accent-color);
    transform: translateY(5px);
}

.piano-key::after {
    content: attr(data-note);
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: rgba(0, 0, 0, 0.7);
}

/* Animations */
@keyframes fadeIn {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 0.8;
        transform: translateY(0);
    }
}

@keyframes letterIn {
    0% {
        opacity: 0;
        transform: translateY(0.5em) rotateX(40deg);
        filter: blur(6px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) rotateX(0);
        filter: blur(0);
    }
}

@keyframes fadeUp {
    0% {
        opacity: 0;
        transform: translateY(12px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes panelIn {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 0.94;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    0% {
        opacity: 0.8;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(20px);
    }
}

@keyframes shapeAppear {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 0.6;
        transform: scale(1);
    }
}

@keyframes lineAppear {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 0.15;
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes float {
    0% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
    100% {
        transform: translateY(0);
    }
}

/* Mouse trail effect */
.mouse-particle {
    position: absolute;
    pointer-events: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-color);
    mix-blend-mode: screen;
    opacity: 0;
    z-index: 15;
    transform: scale(0);
    animation: particleFade 1s forwards;
}

@keyframes particleFade {
    0% {
        opacity: 0.8;
        transform: scale(0);
    }
    100% {
        opacity: 0;
        transform: scale(2);
    }
}

/* Ripple effect on click */
.ripple {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(0);
    animation: ripple 1s linear;
    pointer-events: none;
    z-index: 15;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Color themes - will be toggled by JavaScript */
body.theme-blue {
    --accent-color: #6db4f5;
    --accent-color-2: #f08a8a;
}

body.theme-purple {
    --accent-color: #b08cf0;
    --accent-color-2: #6fd0e0;
}

body.theme-green {
    --accent-color: #5fd0a8;
    --accent-color-2: #e8d28a;
}

body.theme-orange {
    --accent-color: #f0b06a;
    --accent-color-2: #f08aa6;
}

body.theme-pink {
    --accent-color: #ef8ab8;
    --accent-color-2: #9a8cf0;
}

/* Responsive design */
@media (max-width: 768px) {
    #main-name {
        font-size: clamp(2rem, 9vw, 3.4rem);
    }
    
    .instructions {
        bottom: 92px;
        font-size: 0.74rem;
    }
    
    .piano-keyboard {
        transform: translateX(-50%) scale(0.7);
    }
}

@media (max-width: 380px) {
    .control-dock {
        width: 214px;
        margin-left: -107px;
    }
    .audio-indicator     { left: calc(50% - 90px); }
    .theme-switcher      { left: calc(50% - 42px); }
    .save-button         { left: calc(50% + 6px); }
    .instructions-toggle { left: calc(50% + 54px); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-delay: 0s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }

    /* Guarantee the reveal end-states are visible without motion */
    #main-name span {
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
    }
    .name-flourish {
        opacity: 1 !important;
        transform: none !important;
    }
    .control-dock {
        opacity: 1 !important;
    }
    .audio-indicator,
    .theme-switcher,
    .save-button,
    .instructions-toggle {
        opacity: 1 !important;
    }
    .instructions {
        animation: none !important;
    }
}