:root {
    --bg-color: #4A4A4A;
    --tine-color: #cbd5e1;
    --tine-pressed-start: #bae6fd;
    --tine-pressed-end: #0284c7;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    touch-action: none;
    background-color: var(--bg-color);
}

body {
    font-family: 'Plus Jakarta Sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#kalimba-container {
    position: relative;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform 0.3s ease, width 0.3s ease, height 0.3s ease;
}

/* Portrait orientation -> Rotate interface to landscape */
@media (orientation: portrait) {
    #kalimba-container {
        width: 100vh;
        width: 100dvh;
        height: 100vw;
        height: 100dvw;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(90deg);
        transform-origin: center;
    }
}

/* Landscape orientation -> Display normally */
@media (orientation: landscape) {
    #kalimba-container {
        width: 100vw;
        width: 100dvw;
        height: 100vh;
        height: 100dvh;
        position: relative;
        top: auto;
        left: auto;
        transform: none;
    }
}

/* Optimize size for large desktop screens */
@media (orientation: landscape) and (min-width: 1024px) {
    #kalimba-container {
        width: 100vw;
        width: 100dvw;
        max-width: 1024px;
        height: 100vh;
        height: 100dvh;
        margin: 0 auto;
    }
}

/* Wooden trim at the top */
.top-trim {
    width: 100%;
    height: 10%;
    background: linear-gradient(to bottom, #111827, #1f2937);
    border-bottom: 2px solid #374151;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 25;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    box-sizing: border-box;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

@media (orientation: portrait) {
    .top-trim {
        padding-left: max(24px, env(safe-area-inset-top));
        padding-right: max(24px, env(safe-area-inset-bottom));
    }
}

.brand-logo {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.25);
    text-transform: uppercase;
    white-space: nowrap;
}

@media (min-width: 640px) {
    .brand-logo {
        font-size: 1.15rem;
        letter-spacing: 0.15em;
    }
}

/* Key bridge */
.bridge {
    width: 100%;
    height: 12px;
    background: linear-gradient(to right, #475569, #cbd5e1, #475569);
    position: absolute;
    top: 11%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
    z-index: 10;
}

#tines-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    width: 100%;
    height: 84%;
    position: relative;
    z-index: 20;
    padding-bottom: 30px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    box-sizing: border-box;
}

@media (orientation: portrait) {
    #tines-container {
        padding-left: max(12px, env(safe-area-inset-top));
        padding-right: max(12px, env(safe-area-inset-bottom));
    }
}

.tine-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    height: 100%;
}

.tine {
    background: linear-gradient(
        to bottom,
        #ffffff 0%,
        #f1f5f9 20%,
        #cbd5e1 60%,
        #94a3b8 90%,
        #475569 100%
    );
    border-radius: 0 0 16px 16px;
    width: 86%;
    min-width: 18px;
    max-width: 90px;
    box-shadow: 
        inset 1px 0 0px rgba(255,255,255,0.9),
        inset -1px 0 1px rgba(0,0,0,0.2),
        0 6px 15px rgba(0,0,0,0.4);
    position: absolute;
    transform-origin: top center;
    transition: transform 0.05s ease-out, box-shadow 0.05s ease-out;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 25px;
}

/* Note letter on the key */
.note-label {
    font-weight: 600;
    color: rgba(0, 0, 0, 0.4);
    font-size: 0.7rem;
    pointer-events: none;
    text-shadow: 0 1px 0px rgba(255,255,255,0.5);
    margin-top: 4px;
    letter-spacing: 0.05em;
}

/* Number and dots interface */
.number-label-container {
     display: flex;
     flex-direction: column;
     align-items: center;
     pointer-events: none;
}

.dots {
    display: flex;
    gap: 2px;
    color: #0284c7;
    font-size: 0.95rem;
    line-height: 1;
    margin-bottom: -4px;
    text-shadow: 0 1px 0px rgba(255,255,255,0.5);
}

.number {
     font-weight: 800;
     color: #0f172a;
     font-size: 1.25rem;
     text-shadow: 0 1px 0px rgba(255,255,255,0.5);
}

/* Key press effect */
.tine.active {
    transform: scaleY(1.03) translateY(8px);
    background: linear-gradient(
        to bottom,
        #f0f9ff 0%,
        #38bdf8 40%,
        #0284c7 80%,
        #0c4a6e 100%
    );
    box-shadow: 
        0 12px 25px rgba(56, 189, 248, 0.5),
        inset 0 1px 1px rgba(255,255,255,0.8);
    z-index: 30;
}

.tine.active .number,
.tine.active .dots {
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.tine.active .note-label {
    color: rgba(255, 255, 255, 0.7);
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.tine.vibrate {
    animation: vibrate 0.3s linear;
}

@keyframes vibrate {
    0% { transform: rotate(0deg); }
    20% { transform: rotate(-0.8deg); }
    40% { transform: rotate(0.8deg); }
    60% { transform: rotate(-0.4deg); }
    80% { transform: rotate(0.4deg); }
    100% { transform: rotate(0deg); }
}

/* Floating pill instructions at the bottom space */
#instructions {
    position: absolute;
    bottom: max(25px, calc(10px + env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: #94a3b8;
    font-size: 0.85rem;
    background: rgba(30, 41, 59, 0.7);
    padding: 8px 22px;
    border-radius: 25px;
    border: 1px solid rgba(255,255,255,0.08);
    pointer-events: none;
    backdrop-filter: blur(8px);
    z-index: 10;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
}

@media (max-width: 600px) {
    #instructions {
        font-size: 0.75rem;
        padding: 6px 16px;
        width: 80%;
        bottom: max(10px, env(safe-area-inset-bottom));
    }
    .note-label { font-size: 0.6rem; }
    .number { font-size: 1.05rem; }
    .dots { font-size: 0.8rem; }
    .tine {
        padding-bottom: 18px;
    }
}

/* High-quality sound start overlay */
#start-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.4);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: white;
    cursor: default;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transition: opacity 0.5s ease, visibility 0.5s;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    box-sizing: border-box;
}

@media (orientation: portrait) {
    #start-overlay {
        padding-left: max(16px, env(safe-area-inset-top));
        padding-right: max(16px, env(safe-area-inset-bottom));
    }
}

.start-card {
    background: rgba(24, 24, 35, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 28px;
    padding: 36px 30px;
    width: 90%;
    max-width: 320px;
    box-shadow: 
        0 25px 50px -12px rgba(0, 0, 0, 0.7),
        0 0 40px rgba(0, 0, 0, 0.3),
        inset 0 1px 1px rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transform: scale(0.92);
    animation: card-appear 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes card-appear {
    to {
        transform: scale(1);
    }
}

.start-icon-container {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1) 0%, rgba(217, 119, 6, 0.05) 100%);
    border: 1px solid rgba(245, 158, 11, 0.25);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 24px;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.05);
}

.start-icon {
    width: 32px;
    height: 32px;
    color: #f59e0b;
    filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.3));
    animation: icon-float 2.5s ease-in-out infinite;
}

@keyframes icon-float {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-5px) scale(1.03);
    }
}

.start-title {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
}

.start-subtitle {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 30px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 600;
}

.start-btn {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    padding: 14px 28px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.3);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    letter-spacing: 0.06em;
    cursor: pointer;
    width: 100%;
    text-transform: uppercase;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(245, 158, 11, 0.45);
    border-color: rgba(255, 255, 255, 0.2);
}

.start-btn:active {
    transform: translateY(1px) scale(0.98);
}

/* Spinner styling for loading */
.spinner {
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-left-color: #f59e0b;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Keyboard helper label on tines */
.keyboard-label {
    font-size: 0.65rem;
    font-weight: 800;
    color: rgba(15, 23, 42, 0.45);
    background: rgba(15, 23, 42, 0.05);
    border: 1px solid rgba(15, 23, 42, 0.15);
    border-radius: 4px;
    padding: 1px 5px;
    margin-bottom: 5px;
    pointer-events: none;
    text-transform: uppercase;
    font-family: monospace;
    min-width: 14px;
    text-align: center;
    box-shadow: 0 1px 0px rgba(255,255,255,0.4);
}

.tine.active .keyboard-label {
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: none;
}

/* Flying notes (Neon Blue) */
.flying-note {
    position: absolute;
    font-size: 20px;
    font-weight: bold;
    pointer-events: none;
    animation: floatUp 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    z-index: 50;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) scale(0.8);
        opacity: 0;
    }
    20% {
        opacity: 1;
    }
    100% {
        transform: translateY(-80px) scale(1.2);
        opacity: 0;
    }
}

/* Micro-animations for Recording */
@keyframes pulse-red {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 8px 2px rgba(239, 68, 68, 0.4);
    }
}
.recording-active #record-dot {
    animation: pulse-red 1.2s infinite;
}
