/* Mobile First Layout Refactor */

:root {
    --primary: #5D5CDE;
    /* Indigo/Purple Accent */
    --primary-hover: #4f46e5;
    --bg-dark: #0F111A;
    /* Deep Navy */
    --bg-card: #1A1D2D;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-glow: rgba(93, 92, 222, 0.3);

    --header-height: auto;
    --footer-height: 80px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
    /* Remove tap highlight */
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100dvh;
    /* Dynamic viewport height */
    width: 100vw;
    overflow: hidden;
    /* No global scroll */
    position: fixed;
    /* Prevent bouncy scroll on iOS */
}

/* App Container - Vertical Stack */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
    position: relative;
    background: var(--bg-dark);
    margin: 0 auto;
    max-width: 100%;
    overflow: hidden;
}

/* Landscape Mode Support - Borders Removed for Edge-to-Edge */

/* 1. Header Region */
#app-header {
    flex: 0 0 auto;
    padding: 12px 16px;
    background: var(--bg-dark);
    z-index: 20;
    border-bottom: 1px solid var(--glass-border);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.brand {
    font-size: 1.5rem;
    font-weight: 600;
}

.brand span {
    color: var(--primary);
}

.header-utils {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.2s;
}

.icon-btn:disabled {
    cursor: not-allowed;
    opacity: 0.38;
}

.icon-btn.heart-btn {
    border-color: transparent;
    background: transparent;
}

.icon-btn.heart-btn.is-favorite {
    color: var(--primary);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
}

.header-utils .icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
}

.header-utils .icon-btn svg {
    width: 21px;
    height: 21px;
}

/* Quick Filters Carousel */
.header-filters-container {
    position: relative;
    margin: 0 -16px;
    padding: 0 16px;
}

.filters-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 0px 0 8px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.filters-scroll::-webkit-scrollbar {
    display: none;
}

.filter-pill {
    padding-top: 4px;
    flex: 0 0 auto;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    padding: 4px 14px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    min-width: 80px;
    text-align: left;
    /* Ensure text align for buttons */
}

button.filter-pill {
    cursor: pointer;
    transition: all 0.2s ease;
}

button.filter-pill:active {
    border-color: var(--primary);
    transform: scale(0.98);
}

.pill-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.pill-value {
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    max-width: 120px;
}

.filter-pill select {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0;
    width: 100%;
    outline: none;
}

.full-width-select {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 12px;
    border-radius: 12px;
    outline: none;
    margin-top: 8px;
    font-size: 1rem;
}

/* 2. Settings Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    width: 100%;
    max-width: 400px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.modal-header {
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.setting-item {
    margin-bottom: 24px;
}

.setting-item.horizontal {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.slider-with-value {
    display: flex;
    align-items: center;
    gap: 16px;
}

.slider-with-value input {
    flex: 1;
    accent-color: var(--primary);
}

.slider-with-value span {
    min-width: 42px;
    text-align: right;
    color: var(--text-muted);
    font-weight: 600;
}

#bpm-display {
    min-width: 32px;
    font-weight: 600;
}

.stepper {
    display: flex;
    align-items: center;
    gap: 20px;
    background: var(--bg-dark);
    padding: 6px;
    border-radius: 14px;
    border: 1px solid var(--glass-border);
}

.stepper button {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

#octave-display {
    font-weight: 600;
    font-size: 1.1rem;
    min-width: 20px;
    text-align: center;
}

.effects-rack {
    margin-top: 32px;
}

.effects-rack h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 16px;
    letter-spacing: 1px;
}

.fx-sliders {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.fx-control label {
    font-size: 0.8rem;
    margin-bottom: 4px;
    display: block;
}

.fx-control input {
    width: 100%;
    accent-color: var(--primary);
}

.modal-footer {
    padding: 20px 24px;
}

.full-width {
    width: 100%;
}

.hidden {
    display: none !important;
}

/* 3. Workspace Region */
#app-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 12px 0 0 0;
    overflow-y: auto;
    /* Allow scroll */
    width: 100%;
    gap: 12px;
    /* Prevent layout shift from scrollbar */
    scrollbar-gutter: stable;
}

/* Unified Visual Container Width */
.tabs-container,
.context-bar,
#active-grid-area,
.bank-section {
    width: 100%;
    max-width: 380px;
    margin: 0 auto;
    padding-left: 16px;
    padding-right: 16px;
}

/* Tabs (Segmented Control) */
.tabs-container {
    padding-bottom: 4px;
}

.segmented-control {
    display: flex;
    position: relative;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 4px;
    height: 48px;
    width: 100%;
}

.segmented-control input {
    display: none;
    /* Hide radios */
}

.segmented-control label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-muted);
    z-index: 2;
    cursor: pointer;
    transition: color 0.3s ease;
}

.segmented-control input:checked+label {
    color: white;
}

.tab-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(33.33% - 5.33px);
    height: calc(100% - 8px);
    background: var(--primary);
    border-radius: 10px;
    z-index: 1;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.segmented-control input#tab-bass-input:checked~.tab-slider {
    transform: translateX(100%);
}

.segmented-control input#tab-arp-input:checked~.tab-slider {
    transform: translateX(200%);
}

/* Context Bar */
.context-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--glass-bg);
    margin-bottom: 0px;
    width: 100%;
    border-radius: 12px;
}

.context-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    /* Allow equal distribution */
    min-width: 0;
    /* Enable shrinking */
}

.context-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    flex-shrink: 0;
    /* Keep label visible */
}

.context-bar select {
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    outline: none;
    width: 100%;
    min-width: 0;
    text-overflow: ellipsis;
}

/* The Grid (Stage) */
#active-grid-area {
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Variable progression grids */
.progression-grid,
#chord-grid,
#bass-grid,
#arp-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-auto-rows: auto !important;
    gap: 12px !important;
    width: 100% !important;
    margin: 8px 0 !important;
}

/* Visibility Control */
#chord-grid.hidden,
#bass-grid.hidden,
#arp-grid.hidden,
.hidden {
    display: none !important;
}

.grid-slot {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    height: 85px;
    /* Tighter look */
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.grid-slot.active,
.grid-slot:active {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--accent-glow);
    transform: scale(1.02);
}

.grid-slot.playing {
    background: rgba(93, 92, 222, 0.1);
}

.grid-slot.locked {
    border-color: rgba(93, 92, 222, 0.65);
    box-shadow: 0 0 16px rgba(93, 92, 222, 0.2);
}

.slot-lock {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.slot-lock[aria-pressed="true"] {
    color: var(--primary);
    background: rgba(93, 92, 222, 0.16);
}

.slot-lock svg {
    width: 16px;
    height: 16px;
}

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

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

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 4px;
    background: var(--glass-bg);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: var(--primary);
    transition: width 0.1s linear;
}

/* The Bank */
.bank-section {
    padding-bottom: 12px;
    width: 100%;
}

.bank-header {
    padding: 0 16px 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
}

#bank-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

.bank-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.bank-carousel-wrapper {
    position: relative;
    padding: 0 16px;
    width: 100%;
    min-height: 100px;
}

.bank-carousel {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.bank-carousel::-webkit-scrollbar {
    display: none;
}

.bank-item {
    flex: 0 0 auto;
    width: 92px;
    height: 80px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    cursor: pointer;
    text-align: center;
    padding: 6px;
}

.bank-item:active,
.bank-item.active {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--accent-glow);
    transform: scale(1.02);
}

.bank-carousel-wrapper .fader {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 2;
}

.fader.left {
    left: 16px;
    background: linear-gradient(to right, var(--bg-dark), transparent);
}

.fader.right {
    right: 16px;
    background: linear-gradient(to left, var(--bg-dark), transparent);
}

/* Visibility Classes */
.hidden {
    display: none !important;
}

.hidden-initially {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bank-section {
    padding-bottom: 12px;
    width: 100%;
    transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#app-footer {
    flex: 0 0 auto;
    width: 100%;
    z-index: 30;
    background: transparent;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
    transform: translateY(0);
    opacity: 1;
    padding-bottom: env(safe-area-inset-bottom);
}

#app-footer.hidden-initially {
    transform: translateY(150%);
    opacity: 0;
    pointer-events: none;
}

.action-deck {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 12px 20px !important;
    background: rgba(26, 29, 45, 0.8) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    width: 100% !important;
    height: 90px !important;
}

.side-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex: 1;
}

.side-actions.left {
    justify-content: flex-start;
}

.side-actions.right {
    justify-content: flex-end;
}

.main-action {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 20px;
}

.fab-btn {
    width: 64px !important;
    height: 64px !important;
    border-radius: 50% !important;
    background: var(--primary) !important;
    box-shadow: 0 8px 24px var(--accent-glow) !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    border: none !important;
    color: white !important;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.fab-btn:active {
    transform: scale(0.9);
}

.icon-only-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.2s ease;
}

.icon-only-btn:active {
    transform: scale(0.95);
    background: var(--glass-border);
}

.icon-only-btn svg {
    width: 24px;
    height: 24px;
}

.secondary-btn.heart-btn.is-favorite {
    color: #ff4d4d;
    border-color: rgba(255, 77, 77, 0.3);
    background: rgba(255, 77, 77, 0.1);
}

/* Utility to hide legacy elements during refactor */
.legacy-hidden {
    display: none !important;
}

/* History Bottom Sheet */
.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 70vh;
    background: var(--bg-card);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.bottom-sheet.open {
    transform: translateY(0);
}

.sheet-handle-bar {
    width: 100%;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    background: transparent;
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--glass-border);
    border-radius: 2px;
}

.sheet-header {
    padding: 0 24px 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.sheet-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.sheet-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    -webkit-overflow-scrolling: touch;
}

/* History Items */
.history-item {
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.2s;
}

.history-item:active {
    border-color: var(--primary);
}

.history-info strong {
    display: block;
    color: var(--primary);
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.history-info span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.history-actions button {
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-muted);
    padding: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-actions button svg {
    width: 16px;
    height: 16px;
}

/* Empty State Placeholder */
.grid-placeholder {
    width: 100%;
    /* 2 rows * 85px + 12px gap = 182px */
    height: 182px;
    background: var(--bg-card);
    border: 2px dashed var(--glass-border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    margin: 8px 0;
    transition: all 0.3s ease;
    cursor: pointer;
}

.grid-placeholder:hover,
.grid-placeholder:focus-visible {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.1);
    transform: scale(1.01);
    outline: none;
}

.placeholder-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

.placeholder-content svg {
    color: var(--glass-border);
}

.placeholder-content p {
    font-size: 0.9rem;
    font-weight: 500;
}

.icon-ref {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    color: var(--primary);
    background: rgba(93, 92, 222, 0.1);
    padding: 4px;
    border-radius: 4px;
    margin: 0 2px;
}

.icon-ref svg {
    color: var(--primary) !important;
}
