:root {
    --bg-primary: #0f111a;
    --bg-secondary: #1a1d29;
    --text-primary: #ffffff;
    --text-secondary: #a0a5b5;
    --accent: #6c5ce7;
    --accent-hover: #5a4bce;
    --success: #00b894;
    --error: #d63031;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.05);

    --white-key: rgba(255, 255, 255, 0.9);
    --black-key: #111;
    --white-key-pressed: #e0e0e0;
    --black-key-pressed: #333;
}

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

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background: radial-gradient(circle at top right, #1a1333, var(--bg-primary) 60%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background-size: cover;
    background-attachment: fixed;
}

.app-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-x: hidden;
}

.main-content-wrapper {
    display: flex;
    flex-direction: row;
    gap: 20px;
    justify-content: center;
    align-items: stretch;
    flex-wrap: wrap;
    /* allow wrapping if needed */
    max-width: 100vw;
}

.app-core {
    flex: 1;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Base Ad Banner Styles */
.ad-banner-side,
.ad-banner-bottom {
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.8rem;
    overflow: hidden;
}

/* Side Banners for Desktop */
.ad-banner-side {
    width: 160px;
    min-width: 160px;
    min-height: 600px;
    flex-shrink: 0;
    /* Hide on screens too narrow for side banners + core */
    display: flex;
}

/* Bottom Banner */
.ad-banner-bottom {
    width: 320px;
    min-width: 320px;
    height: 50px;
    min-height: 50px;
    flex-shrink: 0;
    margin: 0 auto;
    /* Hide bottom banner on desktop if side banners are showing */
    display: none;
}


header {
    text-align: center;
    margin-bottom: 10px;
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #a8c0ff, #3f2b96);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    letter-spacing: -1px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 300;
}

.glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}



main {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.controls-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.mode-selector {
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px;
    border-radius: 12px;
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.3s ease;
}

.mode-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
}

.level-selector {
    display: flex;
    align-items: center;
    gap: 12px;
}

.level-selector label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

select {
    background: rgba(0, 0, 0, 0.4);
    color: white;
    border: 1px solid var(--glass-border);
    padding: 10px 16px;
    border-radius: 8px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.info-card,
.play-card {
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}



.play-btn {
    background: linear-gradient(135deg, #6c5ce7, #8e44ad);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 16px 40px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s ease;
    box-shadow: 0 8px 24px rgba(108, 92, 231, 0.4);
}

.play-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 12px 32px rgba(108, 92, 231, 0.6);
}

.play-btn:active {
    transform: translateY(2px) scale(0.95);
}

.play-btn.playing-audio {
    background: linear-gradient(135deg, #f39c12, #d35400);
    box-shadow: 0 8px 24px rgba(243, 156, 18, 0.4);
    cursor: wait;
    animation: pulseAudio 1.5s infinite alternate;
}

@keyframes pulseAudio {
    0% {
        transform: scale(1);
        box-shadow: 0 8px 24px rgba(243, 156, 18, 0.4);
    }

    100% {
        transform: scale(1.02);
        box-shadow: 0 12px 32px rgba(243, 156, 18, 0.8);
    }
}

.feedback-msg {
    font-size: 1.1rem;
    font-weight: 400;
    color: var(--text-secondary);
    min-height: 28px;
    transition: color 0.3s;
}

.feedback-msg.success {
    color: var(--success);
    font-weight: 600;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.feedback-msg.error {
    color: var(--error);
    font-weight: 600;
    animation: shake 0.4s ease-in-out;
}

.keyboard-container {
    position: relative;
    height: 200px;
    display: flex;
    justify-content: flex-start;
    /* changed from center to allow overflow */
    padding: 20px;
    user-select: none;
    overflow-x: auto;
    /* Hide scrollbar for cleaner look */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.keyboard-container::-webkit-scrollbar {
    display: none;
    /* WebKit */
}

.key {
    position: relative;
    border-radius: 0 0 8px 8px;
    cursor: pointer;
    transition: background-color 0.1s;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
    /* Prevent keys from breaking */
}

.keyboard-container.disabled .key {
    cursor: wait;
    pointer-events: none;
}

.key.white {
    width: 60px;
    height: 100%;
    background-color: var(--white-key);
    color: #333;
    z-index: 1;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.key.white:hover {
    background-color: #f0f0f0;
}

.key.white:active,
.key.white.active {
    background-color: var(--white-key-pressed);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transform: translateY(2px);
}

.shortcut-hint {
    position: absolute;
    bottom: 4px;
    font-size: 0.7rem;
    color: #888;
    font-weight: 400;
    pointer-events: none;
}

.key.black .shortcut-hint {
    color: #ccc;
    bottom: 2px;
}

.key.black {
    width: 36px;
    height: 60%;
    background-color: var(--black-key);
    color: white;
    z-index: 2;
    margin-left: -18px;
    margin-right: -18px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
    font-size: 0.8rem;
    padding-bottom: 15px;
}

.key.black:hover {
    background-color: #222;
}

.key.black:active,
.key.black.active {
    background-color: var(--black-key-pressed);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    transform: translateY(2px);
}

/* Specific styling for correctness highlighting */
.key.correct {
    background-color: var(--success) !important;
    color: white;
}

.key.incorrect {
    background-color: var(--error) !important;
    color: white;
}

.chord-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
    padding: 24px;
}

.chord-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 16px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.chord-options.disabled .chord-btn {
    cursor: wait;
    pointer-events: none;
}

.chord-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.chord-btn.correct {
    background: var(--success);
    border-color: var(--success);
}

.chord-btn.incorrect {
    background: var(--error);
    border-color: var(--error);
}

.ad-banner {
    background: rgba(0, 0, 0, 0.2);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    margin-top: 10px;
}

.ad-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    letter-spacing: 1px;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px;
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    font-size: 2.5rem;
    color: var(--error);
    margin-bottom: 10px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.modal-stats {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 10px;
}

.m-stat span {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.m-stat h3 {
    font-size: 2.5rem;
    color: white;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    justify-content: center;
    width: 100%;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
    border-radius: 50px;
    padding: 16px 40px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s ease, background 0.2s ease;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

@media (max-width: 600px) {
    .app-container {
        padding: 5px;
        gap: 16px;
    }

    h1 {
        font-size: 2.2rem;
    }

    .controls-panel {
        flex-direction: column;
        align-items: stretch;
    }

    .mode-selector {
        justify-content: center;
        flex-wrap: wrap;
    }

    .level-selector {
        justify-content: center;
    }

    .keyboard-container {
        justify-content: flex-start;
        padding: 10px;
        height: 150px;
    }

    .key.white {
        width: 45px;
    }

    .key.black {
        width: 28px;
        margin-left: -14px;
        margin-right: -14px;
        font-size: 0.7rem;
    }

    .play-btn {
        width: 100%;
        justify-content: center;
    }

    .chord-options {
        grid-template-columns: repeat(2, 1fr);
    }

    .ad-banner {
        height: 60px;
    }
}

/* Milestone Rank Tracker */
.milestone-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 30px 48px 30px;
    margin-bottom: 24px;
    position: relative;
    border-radius: 16px;
    width: 100%;
}

.milestone-gap {
    flex: 1;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    margin-top: 15px;
    /* Aligns with the center of the 36px node */
}

.milestone-dot {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    transition: all 0.3s ease;
}

.milestone-dot.completed {
    background: var(--accent);
    box-shadow: 0 0 5px var(--accent);
}

.milestone-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}

.milestone-label {
    position: absolute;
    top: 45px;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.2;
    transition: all 0.3s ease;
    text-align: center;
    word-break: keep-all;
}

.milestone-label.current {
    font-weight: 600;
    color: var(--accent);
}

.milestone-node {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 1;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}

.milestone-tooltip {
    position: absolute;
    bottom: calc(100% + 15px);
    left: 50%;
    transform: translate(-50%, 10px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    border: 1px solid var(--glass-border);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
    pointer-events: none;
}

.milestone-tooltip.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.milestone-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: var(--bg-secondary) transparent transparent transparent;
}

.milestone-node.completed {
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
    opacity: 0.8;
}

.milestone-node.current {
    background: var(--light-bg);
    border: 3px solid var(--accent);
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--accent);
}

.milestone-node.current.lives-3 {
    border-color: var(--success);
    box-shadow: 0 0 15px var(--success);
}

.milestone-node.current.lives-2 {
    border-color: #f39c12;
    /* orange */
    box-shadow: 0 0 15px #f39c12;
}

.milestone-node.current.lives-1 {
    border-color: var(--error);
    box-shadow: 0 0 15px var(--error);
}

@media (orientation: portrait) {
    body {
        padding: 10px;
        align-items: flex-start;
    }

    .app-container {
        gap: 12px;
        margin-top: 10px;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 4px;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    header {
        margin-bottom: 5px;
    }

    main {
        gap: 10px;
    }

    .milestone-container {
        padding: 16px 8px 36px 8px;
        margin-bottom: 4px;
    }

    .info-card,
    .play-card {
        padding: 16px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 4px;
    }

    .play-btn {
        padding: 12px 20px;
        font-size: 1.1rem;
    }

    .keyboard-container {
        height: 140px;
        padding: 10px;
    }

    .key {
        padding-bottom: 15px;
        font-size: 0.8rem;
    }

    .key.white {
        width: 45px;
    }

    .key.black {
        width: 28px;
        margin-left: -14px;
        margin-right: -14px;
        height: 60%;
    }

    .milestone-gap {
        margin-top: 11px;
    }

    .milestone-dot {
        width: 4px;
        height: 4px;
    }

    .milestone-node {
        width: 26px;
        height: 26px;
        font-size: 0.9rem;
    }

    .milestone-label {
        font-size: 0.65rem;
        top: 32px;
        width: 45px;
    }

    .ad-banner-side {
        display: none !important;
    }

    .ad-banner-bottom {
        display: flex !important;
    }

    .app-core {
        width: 100%;
        max-width: 100vw;
    }

    .main-content-wrapper {
        gap: 10px;
        flex-wrap: wrap;
        /* Added based on instruction */
    }

    .milestone-node.current {
        transform: scale(1.3);
    }
}