:root {
    /* The keyboard keeps real key proportions; this only caps its height. */
    --piano-max-h: 38vh;
    --black-h: 63%;
    --text: rgba(255, 255, 255, 0.55);
}

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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #05050a;
    color: #fff;
    font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

body.no-fluid {
    background: radial-gradient(ellipse at 50% 30%, #1b1530 0%, #05050a 70%);
}

#fluid-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* ---------- Header ---------- */

.top {
    position: fixed;
    top: max(2rem, env(safe-area-inset-top));
    left: 0;
    right: 0;
    text-align: center;
    pointer-events: none;
    z-index: 1;
}

.app-title {
    font-weight: 200;
    font-size: 1.25rem;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
    text-shadow: 0 0 18px rgba(255, 255, 255, 0.15);
}

.instructions {
    margin-top: 0.6rem;
    padding: 0 1rem;
    font-size: 0.72rem;
    font-weight: 300;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.32);
}

/* ---------- Piano ---------- */

.piano-wrap {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    padding: 0 max(1vw, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(1vw, env(safe-area-inset-left));
    z-index: 2;
    pointer-events: none;
}

.piano {
    position: relative;
    /* width + aspect-ratio are set from JS (depends on the number of keys) */
    width: 100%;
    border-top: 4px solid #111;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
    pointer-events: auto;
    touch-action: none;
    cursor: pointer;
}

.key {
    position: absolute;
    top: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transform-origin: top center;
    transition: transform 60ms ease-out, background 120ms, box-shadow 120ms;
}

.key .label {
    pointer-events: none;
    font-size: 0.7rem;
    font-weight: 400;
    margin-bottom: 0.7rem;
    opacity: 0.55;
}

.key.white {
    height: 100%;
    z-index: 1;
    background: linear-gradient(to bottom, #e9e9ee 0%, #fdfdfd 100%);
    border: 1px solid #bbb;
    border-top: none;
    border-radius: 0 0 4px 4px;
    box-shadow: inset 0 -5px 3px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.4);
    color: #777;
}

.key.black {
    height: var(--black-h);
    z-index: 2;
    background: linear-gradient(to bottom, #2b2b2f 0%, #08080a 100%);
    border: 1px solid #000;
    border-top: none;
    border-radius: 0 0 3px 3px;
    box-shadow: inset 0 -4px 2px rgba(255, 255, 255, 0.08), 0 3px 6px rgba(0, 0, 0, 0.6);
    color: #bbb;
}

.key.black .label {
    margin-bottom: 0.5rem;
    font-size: 0.62rem;
}

/* Pressed keys: no colour, just a physical "pushed down" look */
.key.white.active {
    transform: scaleY(0.985);
    background: linear-gradient(to bottom, #d6d6dc 0%, #ececf0 100%);
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.22), 0 1px 2px rgba(0, 0, 0, 0.4);
}

.key.black.active {
    transform: scaleY(0.98);
    background: linear-gradient(to bottom, #1a1a1d 0%, #000 100%);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 2px rgba(0, 0, 0, 0.5);
}

.sound-status {
    margin-top: 0.5rem;
    font-size: 0.66rem;
    font-weight: 300;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.28);
}

.credits {
    text-align: right;
    line-height: 1.5;
    position: fixed;
    top: calc(0.5rem + env(safe-area-inset-top));
    right: calc(0.75rem + env(safe-area-inset-right));
    z-index: 1;
    font-size: 0.6rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.22);
    text-decoration: none;
}

.credits a {
    color: inherit;
    text-decoration: none;
}

.credits a:hover {
    color: rgba(255, 255, 255, 0.5);
}

/* ---------- Hide / show the top interface ---------- */

.ui-toggle {
    position: fixed;
    top: calc(0.75rem + env(safe-area-inset-top));      /* below the iPhone notch / status bar */
    left: calc(0.75rem + env(safe-area-inset-left));
    z-index: 3;
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    padding: 0;
    border-radius: 0.6rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(20, 20, 30, 0.35);
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 300ms, color 150ms, background 150ms, border-color 150ms;
}

.ui-toggle svg {
    grid-area: 1 / 1;
    width: 1.05rem;
    height: 1.05rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ui-toggle .icon-hidden,
body.ui-hidden .ui-toggle .icon-shown {
    display: none;
}

body.ui-hidden .ui-toggle .icon-hidden {
    display: block;
}

.ui-toggle:hover,
.ui-toggle:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    opacity: 1;
    outline: none;
}

.top,
.credits {
    transition: opacity 400ms ease, transform 400ms ease;
}

body.ui-hidden .top,
body.ui-hidden .credits {
    opacity: 0;
    transform: translateY(-12px);
    pointer-events: none;
}

body.ui-hidden .top * {
    pointer-events: none;
}

/* Almost invisible while hidden, comes back on hover */
body.ui-hidden .ui-toggle {
    opacity: 0.25;
}

/* ---------- Melody player ---------- */

.player {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 1rem;
    padding: 0.4rem 0.5rem 0.4rem 0.9rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;
    font-size: 0.8rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.75);
    max-width: calc(100vw - 1.5rem);
}

.player select,
.player button {
    font: inherit;
    color: inherit;
    background: transparent;
    border: none;
    outline: none;
    cursor: pointer;
}

.player select {
    max-width: 52vw;
    padding: 0.25rem 0;
}

.player .sep {
    width: 1px;
    align-self: stretch;
    margin: 0.2rem 0;
    background: rgba(255, 255, 255, 0.15);
}

.player select option {
    background: #15151c;
    color: #eee;
}

.player button {
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    white-space: nowrap;
    transition: background 120ms;
}

.player button:hover {
    background: rgba(255, 255, 255, 0.22);
}

.player button.playing {
    background: rgba(255, 120, 140, 0.3);
}




@media (max-width: 700px) {
    /* 88 keys don't fit on a phone: keep them playable and scroll sideways */
    .piano-wrap {
        display: block;
        overflow-x: auto;
        overflow-y: hidden;
        pointer-events: auto;
        scrollbar-width: thin;
    }

    .piano {
        min-width: calc(52 * 26px);
        touch-action: pan-x;
    }

    .key .label {
        display: none;
    }

    .instructions {
        display: none;
    }
}

@media (hover: hover) {
    .key.white:hover:not(.active) {
        background: linear-gradient(to bottom, #e2e2e8 0%, #f6f6f8 100%);
    }

    .key.black:hover:not(.active) {
        background: linear-gradient(to bottom, #36363b 0%, #111114 100%);
    }
}

/* ---------- Light fluid mode (ink on paper): dark interface text ---------- */

body.fluid-light .app-title {
    color: rgba(30, 25, 40, 0.6);
    text-shadow: none;
}

body.fluid-light .instructions,
body.fluid-light .sound-status,
body.fluid-light .credits {
    color: rgba(30, 25, 40, 0.45);
}

body.fluid-light .player {
    background: rgba(30, 25, 40, 0.06);
    border-color: rgba(30, 25, 40, 0.15);
    color: rgba(30, 25, 40, 0.8);
}

body.fluid-light .player button {
    background: rgba(30, 25, 40, 0.1);
}

body.fluid-light .player .sep {
    background: rgba(30, 25, 40, 0.2);
}

body.fluid-light .ui-toggle {
    color: rgba(30, 25, 40, 0.6);
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(30, 25, 40, 0.15);
}

/* ---------- MIDI drag & drop ---------- */

body.dropping::after {
    content: 'Dépose ton fichier MIDI ici';
    position: fixed;
    inset: 1rem;
    z-index: 10;
    display: grid;
    place-items: center;
    border: 2px dashed rgba(255, 255, 255, 0.5);
    border-radius: 1rem;
    background: rgba(10, 10, 20, 0.55);
    color: #fff;
    font: 500 1.3rem/1.2 system-ui, sans-serif;
    pointer-events: none;
}

/* ---------- Hide the keyboard ---------- */

/* Top-left row: back to the homepage, interface toggle, keyboard toggle */
#ui-toggle {
    left: calc(3.25rem + env(safe-area-inset-left));
}

.kb-toggle {
    left: calc(5.75rem + env(safe-area-inset-left));
}


/* Hidden with the rest of the interface; the eye button brings it back */
.kb-toggle .strike,
body.ui-hidden .kb-toggle {
    display: none;
}

body.keyboard-hidden .kb-toggle .strike {
    display: inline;
}

.piano-wrap {
    transition: transform 450ms cubic-bezier(0.4, 0, 0.2, 1), opacity 450ms;
}

body.keyboard-hidden .piano-wrap {
    transform: translateY(105%);
    opacity: 0;
    pointer-events: none;
}

body.keyboard-hidden .piano-wrap * {
    pointer-events: none;
}

/* ---------- Autoplay hint (when the browser blocks sound until a gesture) ---------- */

.start-hint {
    position: fixed;
    left: 50%;
    top: auto;
    bottom: 1.5rem;
    z-index: 4;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(15, 15, 25, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: rgba(255, 255, 255, 0.85);
    font: 500 0.9rem/1.2 system-ui, sans-serif;
    letter-spacing: 0.02em;
    pointer-events: none;
    opacity: 0;
    transition: opacity 500ms;
}

.start-hint.show {
    opacity: 1;
    animation: hint-pulse 2.4s ease-in-out infinite;
}

@keyframes hint-pulse {
    50% { opacity: 0.55; }
}

/* Touch screens: no hover, so keep the eye button clearly visible and easy to tap */
@media (pointer: coarse) {
    .ui-toggle {
        width: 2.6rem;
        height: 2.6rem;
    }

    #ui-toggle {
        left: calc(3.9rem + env(safe-area-inset-left));
    }

    .kb-toggle {
        left: calc(7.05rem + env(safe-area-inset-left));
    }

    body.ui-hidden .ui-toggle {
        opacity: 0.7;
    }
}

/* The back link stays fully visible, even when the interface is hidden */
body.ui-hidden .back-link {
    opacity: 1;
}
