/* style.css */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

:root {
    --glass-bg: rgba(255,255,255,0.04);
    --glass-border: rgba(255,255,255,0.12);
    --glass-highlight: rgba(255,255,255,0.08);
    --blur: blur(24px);
    --accent: #a78bfa;
    --accent2: #38bdf8;
    --accent3: #fb7185;
    --surface: rgba(12,10,20,0.85);
    --text: #f1f0ff;
    --muted: rgba(200,195,240,0.4);
}

html, body {
    height: 100%;
    background: #07050f;
    font-family: 'Syne', sans-serif;
    color: var(--text);
    overflow-x: hidden;
}

/* animated mesh background */
.mesh {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}
.mesh::before {
    content: '';
    position: absolute;
    inset: -50%;
    background:
        radial-gradient(ellipse 60% 50% at 20% 30%, rgba(167,139,250,0.18) 0%, transparent 70%),
        radial-gradient(ellipse 50% 60% at 80% 70%, rgba(56,189,248,0.12) 0%, transparent 70%),
        radial-gradient(ellipse 40% 50% at 50% 50%, rgba(251,113,133,0.08) 0%, transparent 60%);
    animation: meshShift 18s ease-in-out infinite alternate;
}
.mesh::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    opacity: 0.6;
}
@keyframes meshShift {
    0% { transform: translate(0,0) rotate(0deg); }
    100% { transform: translate(3%, 2%) rotate(3deg); }
}

/* floating orbs */
.orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.22;
    pointer-events: none;
    z-index: 0;
}
.orb-1 { width: 500px; height: 500px; top: -15%; left: -10%; background: var(--accent); animation: orbFloat 20s ease-in-out infinite alternate; }
.orb-2 { width: 400px; height: 400px; bottom: -10%; right: -5%; background: var(--accent2); animation: orbFloat 25s ease-in-out infinite alternate-reverse; }
.orb-3 { width: 300px; height: 300px; top: 40%; left: 50%; background: var(--accent3); animation: orbFloat 15s ease-in-out infinite alternate; opacity: 0.12; }
@keyframes orbFloat {
    0% { transform: translate(0,0) scale(1); }
    100% { transform: translate(40px, -60px) scale(1.1); }
}

/* layout */
.stage {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 48px;
}

/* header */
.header {
    text-align: center;
    margin-bottom: 28px;
}

.wordmark {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px 8px 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 100px;
    backdrop-filter: var(--blur);
    margin-bottom: 20px;
}
.wordmark-icon {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 16px;
}
.wordmark-name {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 3px;
    background: linear-gradient(90deg, #fff, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.hero-title {
    font-size: clamp(38px, 8vw, 80px);
    font-weight: 800;
    line-height: 0.95;
    letter-spacing: -2px;
    background: linear-gradient(135deg, #ffffff 0%, rgba(167,139,250,0.9) 40%, rgba(56,189,248,0.8) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 8px;
}

.hero-sub {
    font-family: 'DM Mono', monospace;
    font-size: clamp(9px, 3vw, 12px);
    letter-spacing: 2px;
    color: var(--muted);
}

/* stats row - fully responsive wrap */
.stats {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    backdrop-filter: var(--blur);
    transition: border-color 0.3s;
    position: relative;
}

.stat-icon-wrap {
    width: 28px; height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 14px;
}
.stat-info { display: flex; flex-direction: column; }
.stat-lbl { font-family: 'DM Mono', monospace; font-size: 8px; letter-spacing: 2px; color: var(--muted); }
.stat-val {
    font-size: 18px; font-weight: 800; line-height: 1.1;
    background: linear-gradient(90deg, #fff, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
#statusBadge {
    font-size: 12px; font-weight: 700;
    font-family: 'DM Mono', monospace;
    color: #a3e635;
    text-shadow: 0 0 12px rgba(163,230,53,0.6);
}
#statusBadge.recording { color: #fb7185; text-shadow: 0 0 12px rgba(251,113,133,0.7); }
#statusBadge.playing { color: var(--accent2); text-shadow: 0 0 12px rgba(56,189,248,0.6); }

/* piano shell */
.piano-shell {
    width: 100%;
    max-width: 1100px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    backdrop-filter: var(--blur);
    padding: 24px 16px 20px;
    position: relative;
    margin-bottom: 20px;
    overflow: hidden;
}
.piano-label {
    font-family: 'DM Mono', monospace;
    font-size: 9px;
    letter-spacing: 3px;
    color: var(--muted);
    margin-bottom: 20px;
    text-align: center;
}

.piano {
    position: relative;
    display: flex;
    justify-content: center;
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: thin;
    padding-bottom: 6px;
}
.piano::-webkit-scrollbar { height: 4px; }
.piano::-webkit-scrollbar-track { background: transparent; }
.piano::-webkit-scrollbar-thumb { background: rgba(167,139,250,0.4); border-radius: 4px; }

.keys-white {
    display: flex;
    position: relative;
    gap: 0;
    background: transparent;
}

/* dynamic white key sizes via clamp */
.key-white {
    width: clamp(44px, 9vw, 72px);
    height: clamp(180px, 32vw, 230px);
    background: linear-gradient(170deg,
        rgba(255,255,255,0.92) 0%,
        rgba(240,238,255,0.88) 60%,
        rgba(220,218,240,0.95) 100%
    );
    border: 1px solid rgba(180,175,220,0.5);
    border-top: none;
    border-radius: 0 0 14px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 14px;
    font-size: 11px;
    font-weight: 700;
    color: #2d2050;
    position: relative;
    transition: all 0.07s ease;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.9);
}
.key-white:active,
.key-white.active-touch {
    background: linear-gradient(170deg,
        rgba(167,139,250,0.25) 0%,
        rgba(220,218,255,0.85) 40%,
        rgba(190,185,235,0.9) 100%);
    transform: scaleY(0.985) translateY(2px);
}
/* black keys dynamic width */
.key-black {
    position: absolute;
    width: clamp(32px, 7vw, 46px);
    height: clamp(115px, 20vw, 148px);
    background: linear-gradient(160deg,
        rgba(20,15,40,0.97) 0%,
        rgba(10,8,22,0.99) 60%,
        rgba(15,10,30,0.95) 100%);
    border-radius: 0 0 12px 12px;
    cursor: pointer;
    z-index: 2;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 12px;
    color: rgba(200,190,255,0.7);
    font-size: 10px;
    font-weight: 600;
    transition: all 0.07s ease;
    box-shadow: 0 8px 20px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
    border: 1px solid rgba(80,60,120,0.4);
    border-top: none;
}
.key-black:active,
.key-black.active-touch {
    background: linear-gradient(160deg,
        rgba(100,70,200,0.6) 0%,
        rgba(30,20,70,0.97) 60%,
        rgba(15,10,35,0.99) 100%);
    transform: scaleY(0.97) translateY(2px);
}
.key-badge {
    font-family: 'DM Mono', monospace;
    font-size: 9px;
    font-weight: 500;
    background: rgba(0,0,0,0.12);
    padding: 2px 6px;
    border-radius: 20px;
    margin-bottom: 3px;
}
.key-black .key-badge {
    background: rgba(167,139,250,0.12);
    color: rgba(200,190,255,0.9);
}
.kb-hint {
    font-family: 'DM Mono', monospace;
    font-size: 8px;
    opacity: 0.6;
}

/* controls */
.controls-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.ctrl-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border-radius: 100px;
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 1px;
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34,1.56,0.64,1);
    backdrop-filter: var(--blur);
}
.btn-rec {
    background: rgba(251,113,133,0.1);
    color: #fda4af;
    border-color: rgba(251,113,133,0.3);
}
.btn-rec.recording-active {
    background: rgba(251,113,133,0.25);
    border-color: rgba(251,113,133,0.6);
    animation: recPulse 1s ease-in-out infinite;
}
@keyframes recPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(251,113,133,0.4); }
    50% { box-shadow: 0 0 0 6px rgba(251,113,133,0); }
}
.btn-play {
    background: rgba(167,139,250,0.12);
    color: #c4b5fd;
    border-color: rgba(167,139,250,0.3);
}
.btn-clear {
    background: rgba(56,189,248,0.08);
    color: #7dd3fc;
    border-color: rgba(56,189,248,0.25);
}

/* visualizer */
.viz-panel {
    width: 100%;
    max-width: 1100px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    backdrop-filter: var(--blur);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}
.viz-label {
    font-family: 'DM Mono', monospace;
    font-size: 8px;
    letter-spacing: 2px;
    color: var(--muted);
    writing-mode: vertical-rl;
    transform: rotate(180deg);
}
.wave-spectrum {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 50px;
    flex: 1;
}
.freq-bar {
    flex: 1;
    min-width: 5px;
    height: 6px;
    background: linear-gradient(180deg, var(--accent2), var(--accent));
    border-radius: 4px;
    transition: height 0.05s ease-out;
    opacity: 0.4;
}

/* hint bar */
.hint-bar {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    color: var(--muted);
    text-align: center;
    letter-spacing: 0.3px;
    padding: 0 8px;
    line-height: 1.5;
}
.hint-bar kbd {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 5px;
    font-size: 9px;
}

/* extra responsiveness */
@media (max-width: 640px) {
    .stage { padding: 16px 12px 32px; }
    .piano-shell { padding: 16px 8px 12px; }
    .key-white { padding-bottom: 8px; }
    .key-badge { font-size: 8px; padding: 1px 4px; }
    .kb-hint { font-size: 7px; }
    .ctrl-btn { padding: 8px 16px; font-size: 11px; }
    .viz-panel { padding: 10px 12px; }
}
@media (max-width: 480px) {
    .key-white { width: clamp(36px, 10vw, 44px); font-size: 9px; }
    .key-black { width: clamp(26px, 6vw, 34px); }
    .stat-chip { padding: 6px 12px; }
    .stat-val { font-size: 16px; }
    .hero-title { letter-spacing: -1px; }
}
.piano {
    scrollbar-width: thin;
}