:root {
    --bg-main: #111111;
    --bg-panel: #181818;
    --bg-card: #1E1E1E;
    --bg-highlight: #2A2A2A;

    --text-main: #ffffff;
    --text-muted: #8b9bb4;
    --text-dim: #4a5a75;

    --accent-red: #ff3b3b;
    --accent-orange: #ff9d00;
    --accent-yellow: #ffd700;
    --accent-blue: #4a9eff;
    --accent-purple: #9d4aff;
    --accent-green: #2ecc71;
    /* Emerald/Light Green */

    --border-subtle: #2a2f3d;
    --border-highlight: #ff3b3b;

    --font-main: Inter, system-ui, sans-serif;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 100vw;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-main);
    padding: 1rem;
}

/* --- Left Panel --- */
/* Left Panel Removed */

/* Header Controls */
.header-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
    z-index: 20;
    width: 100%;
}

.logo-header {
    display: flex;
    align-items: center;
    font-weight: 800;
    font-size: 2rem;
    letter-spacing: 1px;
    color: var(--text-main);
}

.logo-header .icon {
    background: var(--accent-red);
    color: white;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    margin-right: 12px;
    font-size: 1.2rem;
}

.controls-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2rem;
    align-items: center;
    /* Align based on content height; wraps to two lines instead of
       overflowing when the transpose dropdown + relative-minor button
       don't both fit on one line (mobile widths). */
}

/* Specific styling for the boxes in the header */
.transpose-section {
    align-items: flex-start;
    /* Align label left */
}

.relative-minor-box {
    min-width: 150px;
    height: 100%;
    /* Match height if possible */
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
}

/* Wheel container adjustments */
.wheel-container {
    width: 100%;
    max-width: 800px;
    aspect-ratio: 1/1;
    position: relative;
    margin-top: -2rem;
    /* Pull it up slightly if gap is too big, or keep 0 */
}

.key-display {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.tonic-center h1 {
    font-size: 4rem;
    line-height: 1;
    color: var(--text-main);
}

.tonic-center span {
    color: var(--accent-red);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.concert-pitch {
    text-align: right;
    display: flex;
    flex-direction: column;
}

.concert-pitch span {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
}

.concert-pitch strong {
    font-size: 1.5rem;
    color: var(--accent-blue);
}

.key-meta {
    display: flex;
    gap: 1rem;
}

.meta-box {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.meta-box .label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.meta-box .value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent-orange);
}

/* Unified Inputs for Header */
.header-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
}

/* Specific override for Relative Minor to match label width and center text */
#relative-minor {
    min-width: 110px;
    justify-content: center;
    background: var(--accent-blue);
    color: white;
    font-weight: 700;
}

.header-input-group label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 1px;
}

.header-input-element {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.75rem;
    font-family: var(--font-main);
    font-size: 0.9rem;
    outline: none;
    min-width: 150px;
    display: flex;
    align-items: center;
    /* Ensure consistent height */
    height: 44px;
    /* Fixed height to match select */
    box-sizing: border-box;
}

select.header-input-element {
    cursor: pointer;
}

/* Transpose Dropdown (Legacy ID styles override if needed, but we try to match) */
.transpose-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.transpose-section label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 1px;
}

#transpose-select {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.75rem;
    font-family: var(--font-main);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

#transpose-select:focus {
    border-color: var(--accent-blue);
}

.progression-section {
    width: 100%;
    margin-top: 1rem;
    text-align: center;
    overflow-x: auto;
}

.progression-section h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.chord-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    /* Force single line */
    justify-content: center;
    gap: 0.5rem;
    padding-bottom: 10px;
    /* Space for scrollbar if needed */
}

.chord-item {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    flex-shrink: 0;
    /* Prevent shrinking too much */
    transition: all 0.2s ease;
}

.chord-item.active {
    border-color: var(--accent-red);
    background: var(--bg-highlight);
}

.chord-roman {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 700;
}

.chord-name {
    font-size: 1rem;
    font-weight: 600;
}

.scale-steps {
    display: flex;
    justify-content: space-between;
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
}

.scale-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.step-num {
    background: var(--bg-panel);
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    border-radius: 4px;
    color: var(--accent-red);
    font-weight: 700;
}

.step-note {
    font-weight: 600;
    font-size: 0.9rem;
}

/* --- Right Panel: Wheel --- */
.wheel-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    max-width: 100%;
    background: radial-gradient(circle at center, rgba(30, 30, 40, 0.5) 0%, rgba(10, 11, 16, 0) 70%);
}

.wheel-container {
    width: 100%;
    max-width: 800px;
    aspect-ratio: 1/1;
    position: relative;
}

#chord-wheel {
    width: 100%;
    height: 100%;
    cursor: default;
}

/* Notation Box */
.notation-box {
    position: absolute;
    left: 2rem;
    /* Move relative to wheel panel edge */
    top: 2rem;
    background: transparent;
    padding: 0;
    width: 450px;
    max-width: 500px;
    z-index: 10;
    pointer-events: none;
}

/* Piano Box */
.piano-box {
    position: absolute;
    right: 2rem;
    /* Move relative to wheel panel edge */
    top: 2rem;
    background: transparent;
    padding: 0;
    width: 320px;
    height: 120px;
    pointer-events: none;
    z-index: 10;
}

@media (max-width: 1600px) {

    /* On medium screens, move notation below the wheel or overlapping neatly */
    .notation-box,
    .piano-box {
        position: relative;
        left: auto;
        right: auto;
        top: auto;
        margin: 1rem auto;
        width: 100%;
        max-width: 400px;
    }
}

/* SVG Styles */
.slice {
    transition: fill 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
}

.slice:hover {
    filter: brightness(1.2);
}

.slice-label {
    font-family: var(--font-main);
    font-weight: 600;
    pointer-events: none;
    user-select: none;
}

.ring-concert-text {
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 16px;
    fill: #555;
    pointer-events: none;
}

.ring-dim .slice {
    fill: #1e222e;
    stroke: var(--bg-main);
    stroke-width: 2px;
}

.ring-major .slice {
    fill: #252a39;
    stroke: var(--bg-main);
    stroke-width: 2px;
}

.ring-minor .slice {
    fill: #1e222e;
    stroke: var(--bg-main);
    stroke-width: 2px;
}

/* Selection Highlighting Logic */
.slice.active {
    fill: var(--accent-red);
}

/* Legend */
/* Legend Styling - Compact Row/Grid */
.legend {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.75rem;
    text-align: left;
    margin-top: 1.5rem;
    /* Align visuals */
    min-width: 140px;
    grid-column: 3;
    justify-self: start;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    font-weight: 600;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot.red {
    background: var(--accent-red);
}

.dot.green {
    background: var(--accent-green);
}

.dot.blue {
    background: var(--accent-blue);
}

.dot.orange {
    background: var(--accent-orange);
}

@media (max-width: 1280px) {

    /* On medium screens, move notation below the wheel or overlapping neatly */
    .notation-box {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        margin-top: -3rem;
        /* overlap slightly or stack */
        margin-bottom: 2rem;
    }
}

@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        height: auto;
        overflow-y: auto;
    }

    .info-panel {
        flex: none;
        width: 100%;
    }

    .wheel-panel {
        aspect-ratio: auto;
        height: auto;
        min-height: 600px;
    }

    .notation-box {
        margin-top: 2rem;
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        width: 100%;
        max-width: 500px;
    }
}

/* Bottom Controls Wrapper */
/* Grid (not flex) so the progression grid centers on its own in the
   middle column -- previously this was a centered flex row holding both
   .progression-section and .legend, so the pair centered together and
   the chord grid always sat visibly left of the wheel's true center. */
.bottom-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 2rem;
    width: 100%;
    margin-top: 1rem;
    padding-bottom: 2rem;
}

.progression-section {
    grid-column: 2;
    margin: 0;
    width: auto;
    max-width: 100%;
    text-align: center;
}

@media (max-width: 600px) {
    .bottom-controls {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .legend {
        grid-column: 1;
        justify-self: center;
        align-items: center;
        margin-top: 0;
    }
}