/**
 * 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: var(--mpk4-app-bg, #1a1a1a);
    color: var(--mpk4-app-color, #eee);
    min-height: 100vh;
    --mpk4-key-active-color: #2dd4bf;
    --mpk4-bass-key-active-color: #f7b731;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior: none;
}

.theme-toggle {
    border-color: var(--mpk4-theme-toggle-border, rgba(199, 80, 80, 0.55));
    background: var(--mpk4-theme-toggle-bg, rgba(24, 24, 24, 0.92));
    color: var(--mpk4-theme-toggle-color, #f2f2f2);
    box-shadow: 0 4px 14px var(--mpk4-theme-toggle-shadow, rgba(0, 0, 0, 0.18));
}

/* Keyboard component settings */
mpk4-keyboard {
    --mpk4-keyboard-height: 160px;
    --mpk4-white-key-width: 34px;
}

mpk4-piano-roll {
    --mpk4-piano-roll-accent: var(--mpk4-key-active-color);
}

mpk4-piano-roll.bass-mode {
    --mpk4-piano-roll-accent: var(--mpk4-bass-key-active-color);
}

/* 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;
    }
}

/* ============================================
   Startup Overlay
   ============================================ */
.start-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    padding: 24px;
    transition: opacity 0.3s ease;
}

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

.start-overlay-card {
    width: min(420px, calc(100vw - 32px));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
    padding: 24px 24px 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    background:
        radial-gradient(circle at top, rgba(199, 80, 80, 0.14), transparent 46%),
        linear-gradient(180deg, rgba(22, 22, 24, 0.96), rgba(10, 10, 12, 0.96));
    box-shadow:
        0 20px 52px rgba(0, 0, 0, 0.42),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.start-overlay-header {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.start-overlay-icon {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    background: linear-gradient(135deg, #c75050 0%, #a03030 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(199, 80, 80, 0.22);
}

.start-overlay[data-phase="waiting-device"] .start-overlay-icon {
    background: linear-gradient(135deg, #606774 0%, #40464f 100%);
    box-shadow: 0 8px 24px rgba(88, 96, 112, 0.18);
}

.start-overlay[data-phase="awaiting-user"] .start-overlay-icon {
    background: linear-gradient(135deg, #c75050 0%, #a03030 100%);
    box-shadow: 0 10px 28px rgba(199, 80, 80, 0.28);
}

.start-overlay[data-phase="loading"] .start-overlay-icon,
.start-overlay[data-phase="finishing"] .start-overlay-icon {
    background: linear-gradient(135deg, #d38c3f 0%, #a6601f 100%);
    box-shadow: 0 8px 24px rgba(211, 140, 63, 0.2);
}

.start-overlay-icon svg {
    width: 14px;
    height: 14px;
    fill: #fff;
    margin-left: 2px;
}

.start-overlay-phase {
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #c9b0b0;
    font-weight: 700;
}

.start-overlay[data-phase="awaiting-user"] .start-overlay-phase {
    color: #d9a7a7;
}

.start-overlay h2 {
    margin: 0;
    font-size: 21px;
    font-weight: 600;
    line-height: 1.15;
}

.start-overlay p {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: #acacb5;
    max-width: 320px;
}

.start-overlay-progress {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    max-width: 480px;
    margin-top: 2px;
}

.startup-progress-step {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 7px 11px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.025);
    color: #787f8a;
    font-size: 12px;
    text-align: center;
    min-height: 40px;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.startup-progress-step::before {
    content: '';
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.35;
    flex: 0 0 auto;
}

.startup-progress-step.active {
    color: #f2d2d2;
    background: rgba(199, 80, 80, 0.1);
    border-color: rgba(199, 80, 80, 0.26);
}

.startup-progress-step.active::before {
    opacity: 1;
}

.startup-progress-step.complete {
    color: #8fe2b1;
    background: rgba(44, 152, 89, 0.08);
    border-color: rgba(44, 152, 89, 0.2);
}

.startup-progress-step.complete::before {
    opacity: 1;
}

.audio-enable-btn#startupActionBtn {
    min-width: 250px;
    margin-top: 4px;
    padding-inline: 28px;
    box-shadow: 0 12px 28px rgba(199, 80, 80, 0.2);
}

.start-overlay[data-phase="awaiting-user"] #startupActionBtn {
    background: linear-gradient(180deg, #c75050 0%, #b63d3d 100%);
    border-color: rgba(255, 191, 191, 0.2);
    box-shadow: 0 14px 34px rgba(199, 80, 80, 0.24);
}

.start-overlay[data-phase="awaiting-user"] #startupActionBtn:hover {
    background: linear-gradient(180deg, #d35a5a 0%, #c14747 100%);
}

.start-overlay[data-phase="awaiting-user"] #startupActionBtn:active {
    background: linear-gradient(180deg, #b84343 0%, #a93636 100%);
}

.start-overlay[data-phase="loading"],
.start-overlay[data-phase="finishing"] {
    pointer-events: none;
}

.start-overlay[data-phase="loading"] .start-overlay-card,
.start-overlay[data-phase="finishing"] .start-overlay-card {
    gap: 12px;
}

.start-overlay[data-phase="loading"] #startupProgress,
.start-overlay[data-phase="finishing"] #startupProgress,
.start-overlay[data-phase="loading"] #startupHint,
.start-overlay[data-phase="finishing"] #startupHint {
    display: none;
}

.start-overlay[data-phase="loading"] #startupTitle,
.start-overlay[data-phase="finishing"] #startupTitle {
    font-size: 19px;
}

.start-overlay[data-phase="loading"] #startupDetail,
.start-overlay[data-phase="finishing"] #startupDetail {
    max-width: 280px;
}

.audio-enable-btn#startupActionBtn .audio-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.audio-enable-btn#startupActionBtn .audio-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.start-overlay-hint {
    font-size: 12px;
    color: #787f8a;
    max-width: 280px;
    min-height: 18px;
}

.start-overlay[data-phase="awaiting-user"] {
    cursor: pointer;
}

.start-overlay[data-phase="awaiting-user"] .start-overlay-card {
    box-shadow:
        0 20px 52px rgba(0, 0, 0, 0.42),
        0 0 0 1px rgba(199, 80, 80, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

@media (max-width: 640px) {
    .start-overlay-card {
        padding: 22px 18px 18px;
        gap: 14px;
    }

    .start-overlay h2 {
        font-size: 19px;
    }

    .startup-progress-step {
        font-size: 12px;
    }

    .audio-enable-btn#startupActionBtn {
        min-width: min(240px, 100%);
    }

    .start-overlay-progress {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   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;
    }
}
