/**
 * MPK Mini IV Demo App Styles
 * Body layout, keyboard sizing, and responsive adjustments
 */

* { box-sizing: border-box; }

body {
    font-family: var(--mpk4-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    background: #1a1a1a;
    color: #eee;
    min-height: 100vh;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior: none;
}

/* Keyboard component settings */
mpk4-keyboard {
    --mpk4-keyboard-height: 160px;
    --mpk4-white-key-width: 34px;
    --mpk4-key-active-color: #00d4ff;
}

/* Hide default component controls in overlays */
.overlay mpk4-screen-control .screen-container,
.overlay mpk4-pad-grid .pads-container {
    display: none;
}

/* ============================================
   Responsive Body Styles
   ============================================ */

/* Large tablets in landscape */
@media screen and (max-width: 1024px) and (orientation: landscape) {
    body {
        padding: 16px;
        max-width: 100%;
    }
}

/* Medium tablets in landscape */
@media screen and (max-width: 900px) and (orientation: landscape) {
    body {
        padding: 12px;
    }

    mpk4-keyboard {
        --mpk4-keyboard-height: 140px;
        --mpk4-white-key-width: 30px;
    }
}

/* Small tablets and large phones in landscape */
@media screen and (max-width: 800px) and (orientation: landscape) {
    body {
        padding: 10px;
    }

    mpk4-keyboard {
        --mpk4-keyboard-height: 120px;
        --mpk4-white-key-width: 26px;
    }
}

/* Phones in landscape */
@media screen and (max-width: 700px) and (orientation: landscape) {
    body {
        padding: 8px;
    }

    mpk4-keyboard {
        --mpk4-keyboard-height: 100px;
        --mpk4-white-key-width: 22px;
    }
}

/* Very small phones in landscape */
@media screen and (max-width: 600px) and (orientation: landscape) {
    body {
        padding: 6px;
    }

    mpk4-keyboard {
        --mpk4-keyboard-height: 85px;
        --mpk4-white-key-width: 20px;
    }
}

/* Ultra-small screens */
@media screen and (max-width: 500px) and (orientation: landscape) {
    body {
        padding: 4px;
    }

    mpk4-keyboard {
        --mpk4-keyboard-height: 75px;
        --mpk4-white-key-width: 18px;
    }
}

/* Prevent text selection on touch devices */
@media (pointer: coarse) {
    body {
        -webkit-user-select: none;
        user-select: none;
        touch-action: manipulation;
    }
}

/* ============================================
   Portrait Mode - Show Rotate Message
   ============================================ */
.rotate-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: #1a1a1a;
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    color: #fff;
    text-align: center;
    padding: 24px;
}

.rotate-overlay svg {
    width: 64px;
    height: 64px;
    stroke: #c75050;
    animation: wiggle 1.5s ease-in-out infinite;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-10deg); }
    50% { transform: rotate(10deg); }
}

.rotate-overlay h2 {
    margin: 0;
    font-size: 18px;
}

.rotate-overlay p {
    margin: 0;
    font-size: 14px;
    color: #888;
}

@media screen and (max-width: 900px) and (orientation: portrait) {
    .rotate-overlay {
        display: flex;
    }
}

/* ============================================
   Click-to-Start Overlay (Audio Context)
   ============================================ */
.start-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    color: #fff;
    text-align: center;
    padding: 24px;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.start-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.start-overlay-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c75050 0%, #a03030 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(199, 80, 80, 0.4);
    animation: pulse-glow 2s ease-in-out infinite;
}

.start-overlay-icon svg {
    width: 40px;
    height: 40px;
    fill: #fff;
    margin-left: 4px; /* Visual centering for play icon */
}

@keyframes pulse-glow {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 20px rgba(199, 80, 80, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 4px 30px rgba(199, 80, 80, 0.6);
    }
}

.start-overlay h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
}

.start-overlay p {
    margin: 0;
    font-size: 14px;
    color: #888;
    max-width: 300px;
}

.start-overlay-hint {
    position: absolute;
    bottom: 40px;
    font-size: 12px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
}

.start-overlay-hint kbd {
    background: #333;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: var(--mpk4-font-mono, monospace);
}

/* ============================================
   Learn Mode Section
   ============================================ */

.learn-mode-section {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-top: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.learn-mode-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.learn-mode-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.learn-mode-title {
    font-size: 11px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.learn-mode-toggle {
    font-size: 10px;
    color: #666;
    transition: transform 0.3s;
}

.learn-mode-toggle::before {
    content: '\25B6'; /* Right-pointing triangle */
}

.learn-mode-section.expanded .learn-mode-toggle {
    transform: rotate(90deg);
}

.learn-mode-content {
    display: none;
    padding: 0 16px 16px;
    flex-direction: column;
    gap: 12px;
}

.learn-mode-section.expanded .learn-mode-content {
    display: flex;
}

.learn-track-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.learn-track-selector label {
    font-size: 11px;
    font-weight: 500;
    color: #888;
}

.learn-track-selector select {
    flex: 1;
    max-width: 200px;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    background: linear-gradient(135deg, #444 0%, #333 100%);
    border: 2px solid #555;
    border-radius: 6px;
    cursor: pointer;
}

.learn-track-selector select:hover {
    border-color: #777;
}

.learn-track-selector select:focus {
    outline: none;
    border-color: #ffc107;
}

.learn-mode-toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #888;
    cursor: pointer;
    user-select: none;
}

.learn-mode-toggle-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #ffc107;
}

.learn-mode-toggle-label span {
    white-space: nowrap;
}

.learn-status {
    font-size: 13px;
    color: #ccc;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    text-align: center;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.learn-status .play-text {
    color: #ffc107;
    font-weight: 600;
}

.learn-status.preview {
    color: #4ecdc4;
}

.learn-status.completed {
    color: #4ade80;
}

.learn-progress {
    display: flex;
    align-items: center;
    gap: 12px;
}

.learn-progress-bar {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.learn-progress-bar::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: var(--progress, 0%);
    background: linear-gradient(90deg, #ffc107 0%, #ff9800 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.learn-progress-text {
    font-size: 11px;
    font-weight: 600;
    color: #888;
    min-width: 50px;
    text-align: right;
}

.learn-beat-position {
    font-size: 14px;
    font-weight: 700;
    font-family: var(--mpk4-font-mono, monospace);
    color: #ffc107;
    min-width: 40px;
    text-align: center;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 8px;
    border-radius: 4px;
}

.learn-controls {
    display: flex;
    gap: 8px;
}

.learn-btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #555 0%, #444 100%);
    border: 2px solid #666;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}

.learn-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #666 0%, #555 100%);
    border-color: #888;
}

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

.learn-btn#learnStartBtn:not(:disabled) {
    background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
    border-color: #ffc107;
    color: #1a1a1a;
}

.learn-btn#learnStartBtn:hover:not(:disabled) {
    background: linear-gradient(135deg, #ffca28 0%, #ffa726 100%);
}

/* ============================================
   Learn Mode Hint Highlighting
   ============================================ */

/* Hint highlight for pads - normal (far away) */
.pad.hint {
    --pad-led-color: #ffc107;
    --pad-led-intensity: 0.9;
    animation: pad-hint-slow 1.5s ease-in-out infinite;
}

/* Hint highlight for pads - soon (1-2 beats) */
.pad.hint-soon {
    --pad-led-color: #ff6600;
    --pad-led-intensity: 0.95;
    animation: pad-hint-medium 0.6s ease-in-out infinite;
}

/* Hint highlight for pads - now (< 1 beat) */
.pad.hint-now {
    --pad-led-color: #00ff66;
    --pad-led-intensity: 1;
    animation: pad-hint-fast 0.25s ease-in-out infinite;
}

@keyframes pad-hint-slow {
    0%, 100% {
        --pad-led-intensity: 0.5;
    }
    50% {
        --pad-led-intensity: 0.9;
    }
}

@keyframes pad-hint-medium {
    0%, 100% {
        --pad-led-intensity: 0.6;
    }
    50% {
        --pad-led-intensity: 1;
    }
}

@keyframes pad-hint-fast {
    0%, 100% {
        --pad-led-intensity: 0.7;
    }
    50% {
        --pad-led-intensity: 1;
    }
}

/* Error flash for pads */
.pad.error {
    --pad-led-color: #ff4444 !important;
    --pad-led-intensity: 1 !important;
    animation: pad-error-flash 0.2s ease-out;
}

@keyframes pad-error-flash {
    0% {
        --pad-led-intensity: 1;
    }
    100% {
        --pad-led-intensity: 0.5;
    }
}

/* ============================================
   Learn Mode Responsive
   ============================================ */

@media screen and (max-width: 700px) and (orientation: landscape) {
    .learn-mode-header {
        padding: 8px 12px;
    }

    .learn-mode-content {
        padding: 0 12px 12px;
        gap: 10px;
    }

    .learn-mode-title {
        font-size: 10px;
    }

    .learn-status {
        font-size: 12px;
        padding: 10px 12px;
    }

    .learn-btn {
        padding: 6px 10px;
        font-size: 10px;
    }
}
