* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #eee;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #16213e;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

h1 {
    text-align: center;
    margin: 0 0 20px 0;
    color: #e94560;
    font-size: 1.6rem;
}

.controls-row {
    display: flex;
    gap: 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.controls-row .control-group {
    flex: 1;
    min-width: 200px;
}

.sliders-row {
    display: flex;
    gap: 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.sliders-row .control-group {
    flex: 1;
    min-width: 150px;
}

.control-group {
    margin-bottom: 12px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    color: #aaa;
}

select, input[type="range"] {
    width: 100%;
}

select {
    padding: 8px 10px;
    font-size: 0.95rem;
    background: #0f3460;
    color: #fff;
    border: 1px solid #e94560;
    border-radius: 6px;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: #ff6b6b;
}

input[type="range"] {
    -webkit-appearance: none;
    height: 8px;
    background: #0f3460;
    border-radius: 4px;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #e94560;
    border-radius: 50%;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #e94560;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.radio-group {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    color: #ddd;
    font-size: 0.9rem;
}

.radio-group input[type="radio"] {
    accent-color: #e94560;
    width: 16px;
    height: 16px;
}

.transport-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.transport-btn {
    flex: 1;
    min-width: 70px;
    padding: 10px 14px;
    font-size: 0.95rem;
    font-weight: 600;
    background: #0f3460;
    color: #fff;
    border: 2px solid #e94560;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.transport-btn:hover:not(:disabled) {
    background: #e94560;
}

.transport-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.transport-btn.active {
    background: #e94560;
}

.beat-volume-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 0 0 auto;
    min-width: 36px;
}

.beat-volume-control label {
    font-size: 0.65rem;
    color: #888;
    margin: 0;
}

.beat-volume-control input[type="range"] {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 18px;
    height: 50px;
    -webkit-appearance: none;
    background: #0f3460;
    border-radius: 4px;
    cursor: pointer;
}

.beat-volume-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #e94560;
    border-radius: 50%;
    cursor: pointer;
}

.beat-volume-control input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #e94560;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}


/* Flip Deck */
.flip-deck-controls {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.view-toggle-btn {
    min-width: 200px;
    font-size: 1rem;
}

.flip-deck {
    perspective: 2000px;
    margin-bottom: 16px;
    overflow: hidden;
}

.flip-deck-inner {
    position: relative;
    width: 100%;
    transition: transform 0.6s ease;
    transform-style: preserve-3d;
}

.flip-deck-inner.flipped {
    transform: rotateY(180deg);
}

.flip-face {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.flip-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    transform: rotateY(180deg);
    visibility: hidden;
}

/* Tablature Display */
.tablature-section {
    background: #0f3460;
    border-radius: 8px;
    padding: 16px;
    margin-top: 16px;
    overflow-x: auto;
}

.tab-header {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 12px;
}

.part-label {
    font-weight: 600;
    font-size: 0.95rem;
    padding: 4px 12px;
    border-radius: 4px;
}

.kushaura-label {
    background: #3b82f6;
    color: white;
}

.kutsinhira-label {
    background: #ef4444;
    color: white;
}

.shift-info {
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 0.8rem;
    color: #999;
    text-align: center;
    line-height: 1.4;
}

.shift-title {
    text-align: center;
    font-weight: 800;
    font-size: 1.4rem;
    color: #e94560;
    margin-bottom: 6px;
}

/* Review banner */
.review-banner {
    background: linear-gradient(135deg, #ff6b00, #ff9800);
    color: #000;
    padding: 14px 20px;
    border-radius: 10px;
    text-align: center;
    margin: 10px 0;
    box-shadow: 0 2px 8px rgba(255, 107, 0, 0.3);
    animation: pulse-review 2s ease-in-out infinite;
}
.review-banner.hidden {
    display: none;
}
.review-warning {
    font-weight: 900;
    font-size: 1.3rem;
    display: block;
    margin-bottom: 8px;
    letter-spacing: 1px;
}
.review-check-label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(0,0,0,0.15);
    padding: 6px 14px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}
.review-check-label:hover {
    background: rgba(0,0,0,0.25);
}
.review-check-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
@keyframes pulse-review {
    0%, 100% { box-shadow: 0 2px 8px rgba(255, 107, 0, 0.3); }
    50% { box-shadow: 0 4px 20px rgba(255, 107, 0, 0.6); }
}

/* Source image bar */
.source-image-bar {
    display: flex;
    justify-content: center;
    margin: 8px 0;
}
.source-image-bar.hidden {
    display: none;
}
.view-original-btn {
    flex: 0 1 auto;
    min-width: 160px;
    background: #0f3460;
    border-color: #3b82f6;
    font-size: 0.9rem;
}
.view-original-btn:hover {
    background: #3b82f6;
}

/* Shift controls */
.shift-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 12px;
}

.shift-btn {
    width: 36px;
    height: 30px;
    background: #1a1a2e;
    color: #fff;
    border: 1px solid #e94560;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.shift-btn:hover {
    background: #e94560;
}

.shift-btn.shift-reset {
    width: auto;
    padding: 0 12px;
    font-size: 0.8rem;
}

#shift-display {
    font-size: 0.85rem;
    color: #aaa;
    min-width: 60px;
    text-align: center;
}

.lock-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #aaa;
    margin-left: 10px;
    padding: 4px 10px;
    background: #1a1a2e;
    border: 1px solid #e94560;
    border-radius: 6px;
}

.lock-toggle input[type="checkbox"] {
    accent-color: #e94560;
    width: 14px;
    height: 14px;
}

.lock-toggle .unlocked {
    color: #fbbf24;
}

#tablature-display {
    display: flex;
    flex-direction: column;
    gap: 16px;
    cursor: grab;
    user-select: none;
}

#tablature-display.dragging {
    cursor: grabbing;
}

.quadrant-row {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.quadrant {
    background: #1a1a2e;
    border-radius: 8px;
    padding: 12px;
}

.quadrant-title {
    text-align: center;
    font-weight: 600;
    font-size: 1rem;
    color: #888;
    margin-bottom: 8px;
}

.tab-grid {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tab-row {
    display: flex;
    align-items: center;
    gap: 3px;
}

.row-label {
    width: 48px;
    font-size: 1rem;
    color: #888;
    text-align: right;
    padding-right: 4px;
    flex-shrink: 0;
}

.tab-cells {
    display: flex;
    gap: 3px;
}

.tab-cell {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 5px;
    transition: all 0.15s ease;
}

/* Kushaura cells */
.tab-cell.kushaura {
    background: #1e3a5f;
    color: #7db8f0;
}

.tab-cell.kushaura.has-note {
    background: #2563eb;
    color: white;
}

.tab-cell.kushaura.playing {
    background: #60a5fa;
    color: white;
    box-shadow: 0 0 12px #60a5fa;
    transform: scale(1.15);
}

/* Kutsinhira cells */
.tab-cell.kutsinhira {
    background: #3d1f1f;
    color: #f0a0a0;
}

.tab-cell.kutsinhira.has-note {
    background: #dc2626;
    color: white;
}

.tab-cell.kutsinhira.playing {
    background: #f87171;
    color: white;
    box-shadow: 0 0 12px #f87171;
    transform: scale(1.15);
}

/* Beat markers */
.beat-row .tab-cell {
    background: transparent;
    color: #666;
    font-size: 0.85rem;
}

.beat-row .tab-cell.beat {
    color: #fbbf24;
}

/* Pulse position indicator */
.pulse-indicator {
    position: relative;
}

.pulse-indicator::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: #fbbf24;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.1s;
}

.pulse-indicator.current::after {
    opacity: 1;
}

/* Dimmed when part not selected */
.tab-cell.dimmed {
    opacity: 0.3;
}

.save-controls {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    justify-content: center;
}

.save-btn {
    flex: 0 1 auto;
    min-width: 140px;
}

.corrections-badge {
    display: inline-flex;
    align-items: center;
    background: #f59e0b;
    color: #000;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 12px;
    white-space: nowrap;
}

.corrections-badge.hidden {
    display: none;
}

.loading {
    text-align: center;
    padding: 10px;
    background: #0f3460;
    border-radius: 6px;
    margin-top: 12px;
    font-size: 0.9rem;
    color: #ff6b6b;
}

.loading.hidden {
    display: none;
}

.loading.ready {
    color: #4ade80;
}

/* Mbira Keys Visualization */
.mbira-section {
    background: #0f3460;
    border-radius: 8px;
    padding: 16px 8px;
    margin-bottom: 16px;
}

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

.mbira-header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mbira-title {
    font-weight: 600;
    font-size: 1rem;
    color: #fff;
}

.bx-toggle-row {
    display: flex;
    justify-content: flex-start;
    padding: 4px 0 0 0;
}

.bx-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #aaa;
}

.bx-toggle input[type="checkbox"] {
    accent-color: #e94560;
    width: 16px;
    height: 16px;
}

#mbira-keys {
    display: flex;
    justify-content: center;
    padding: 0;
    overflow: hidden;
}

#mbira-keys svg {
    max-width: 860px;
    width: 100%;
    height: auto;
}

/* SVG key styling */
.mbira-key-shape {
    stroke: #000;
    stroke-width: 2;
    transition: all 0.12s ease;
    cursor: default;
}

.mbira-key-shape.playing {
    filter: brightness(1.4) saturate(1.8) drop-shadow(0 0 10px currentColor);
    stroke-width: 3;
}

.mbira-key-shape.bx-hidden {
    fill: #333 !important;
    stroke: #222;
}

.mbira-key-text {
    font-family: sans-serif;
    font-weight: bold;
    font-size: 11px;
    fill: #000;
    pointer-events: none;
    text-anchor: middle;
}

.mbira-key-text.light-text {
    fill: #fff;
}

.mbira-key-label {
    font-family: sans-serif;
    font-size: 8px;
    fill: #000;
    pointer-events: none;
    text-anchor: middle;
    opacity: 0.7;
}

.mbira-key-label.light-text {
    fill: #fff;
}

/* Dual Mbira View */
.mbira-dual.hidden {
    display: none;
}

.mbira-dual {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.dual-layout {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 10px;
}

.mbira-dual-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 0;
    transition: transform 0.6s ease;
    transform-style: preserve-3d;
    perspective: 800px;
}

.mbira-dual-inner.flipping {
    transform: rotateX(180deg);
}

.dual-sidebar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
    width: 90px;
}

.dual-sidebar .shift-btn {
    width: auto;
    padding: 4px 14px;
    font-size: 0.8rem;
}

.dual-mbira-half {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.dual-mbira-half.flipped .dual-keys svg {
    transform: scaleY(-1);
}

.dual-label {
    font-weight: 600;
    font-size: 0.8rem;
    padding: 3px 10px;
    border-radius: 4px;
}

.dual-keys {
    display: flex;
    justify-content: center;
    padding: 0;
    overflow: hidden;
}

.dual-keys svg {
    max-width: 860px;
    width: 100%;
    height: auto;
}

.dual-divider {
    width: 90%;
    height: 1px;
    background: linear-gradient(90deg, transparent, #e94560, transparent);
    margin: 2px 0;
}

/* Note Drag Ghost */
.note-drag-ghost {
    position: fixed;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    border-radius: 5px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.9;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transform: translate(-50%, -50%);
}

.note-drag-ghost.kushaura {
    background: #2563eb;
}

.note-drag-ghost.kutsinhira {
    background: #dc2626;
}

.ghost-count-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #fbbf24;
    color: #000;
    font-size: 0.65rem;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Drag source cell dims while being dragged */
.tab-cell.drag-source {
    opacity: 0.3;
    border: 2px dashed #888;
}

/* Drop target highlight */
.tab-cell.drop-target {
    outline: 2px solid #fbbf24;
    outline-offset: -2px;
    background: rgba(251, 191, 36, 0.15) !important;
}

/* Crosshair cursor during note drag */
#tablature-display.note-dragging .tab-cell[data-part] {
    cursor: crosshair;
}

/* Multi-select: selected cells */
.tab-cell.selected {
    outline: 2px solid #22d3ee;
    outline-offset: -2px;
    box-shadow: 0 0 8px rgba(34, 211, 238, 0.5);
    animation: pulse-select 1.5s ease-in-out infinite;
}

@keyframes pulse-select {
    0%, 100% { box-shadow: 0 0 8px rgba(34, 211, 238, 0.5); }
    50% { box-shadow: 0 0 14px rgba(34, 211, 238, 0.8); }
}

/* Delete bar */
.delete-bar {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

.delete-bar.hidden {
    display: none;
}

.delete-btn {
    background: #7f1d1d;
    border-color: #ef4444;
    color: #fca5a5;
}

.delete-btn:hover:not(:disabled) {
    background: #ef4444;
    color: white;
}

/* Paste bar */
.paste-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    padding: 6px 12px;
    background: #1e3a5f;
    border: 1px solid #38bdf8;
    border-radius: 6px;
}

.paste-bar.hidden {
    display: none;
}

.paste-info {
    color: #7dd3fc;
    font-size: 0.9rem;
}

.paste-cancel-btn {
    background: #334155;
    border-color: #64748b;
    color: #94a3b8;
    font-size: 0.8rem;
    padding: 2px 10px;
}

.paste-cancel-btn:hover {
    background: #475569;
    color: white;
}

/* Paste mode: crosshair cursor on all cells */
#tablature-display.paste-mode .tab-cell[data-part] {
    cursor: crosshair;
}

#tablature-display.paste-mode .tab-cell[data-part]:hover {
    outline: 2px solid #38bdf8;
    outline-offset: -2px;
}

/* Responsive */
@media (max-width: 1100px) {
    .quadrant {
        min-width: 100%;
    }
}

@media (max-width: 700px) {
    .container {
        padding: 12px;
    }

    .tab-cell {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }

    .row-label {
        width: 36px;
        font-size: 0.8rem;
    }
}
