* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000;
    color: #fff;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Header */
header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 0.75rem 1rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    z-index: 100;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #0a0e27;
}

#glCanvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* ── PiP Close-up Viewport ─────────────────────────────────────────────── */
.pip-frame {
    position: fixed;
    top: 56px;   /* below header */
    right: 10px;
    width: 64vmin;
    min-width: 200px;
    max-width: 420px;
    /* Never tall enough to overlap the playback bar (~140px) at bottom */
    max-height: calc(100vh - 56px - 150px);
    border: 1.5px solid rgba(0, 255, 136, 0.6);
    border-radius: 8px;
    overflow: hidden;
    background: #050810;
    box-shadow: 0 0 16px rgba(0,255,136,0.15), 0 4px 20px rgba(0,0,0,0.6);
    z-index: 30;   /* above playback bar (z-index 50 uses stacking context inside .app) */
    display: flex;
    flex-direction: column;
}

#cuCanvas {
    width: 100%;
    aspect-ratio: 1;
    display: block;
    background: #050810;
}

.pip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    background: rgba(0,0,0,0.7);
    border-bottom: 1px solid rgba(0,255,136,0.2);
}

.pip-title {
    font-size: 9px;
    font-family: monospace;
    color: #00ff88;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pip-modes {
    display: flex;
    gap: 2px;
}

.pip-mode {
    font-size: 8px;
    padding: 2px 4px;
    border-radius: 3px;
    border: 1px solid #333;
    background: rgba(0,0,0,0.5);
    color: #666;
    cursor: pointer;
    font-family: monospace;
    transition: all 0.15s;
}

.pip-mode.active {
    background: rgba(0,255,136,0.15);
    color: #00ff88;
    border-color: rgba(0,255,136,0.5);
}

.pip-scale {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 6px;
    background: rgba(0,0,0,0.5);
    gap: 4px;
}

.pip-scale span {
    font-size: 8px;
    font-family: monospace;
    color: #666;
}

#scaleBar {
    flex: 1;
    height: 6px;
    border-radius: 3px;
}

.pip-idle {
    position: absolute;
    top: 28px; /* below header */
    left: 0; right: 0; bottom: 22px; /* above scale bar */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 10px;
    font-family: monospace;
    color: rgba(0,255,136,0.4);
    line-height: 1.5;
    pointer-events: none;
}

/* Velocity Display (Bottom Left) */
.velocity-box {
    position: absolute;
    bottom: 20px;
    left: 10px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    border: 2px solid #00ff88;
    border-radius: 12px;
    padding: 0.75rem;
    min-width: 140px;
    box-shadow: 0 4px 20px rgba(0, 255, 136, 0.3);
}

.vel-row {
    display: flex;
    justify-content: space-between;
    margin: 0.25rem 0;
    font-size: 0.85rem;
    font-family: 'Courier New', monospace;
}

.vel-row strong {
    color: #00ff88;
}

.vel-row.speed {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #00ff88;
    font-size: 0.95rem;
}

.vel-row.speed strong {
    color: #ffcc00;
}

/* Instructions Overlay */
.instructions {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    padding: 2rem;
    border-radius: 16px;
    max-width: 90%;
    pointer-events: none;
}

.instructions h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.instructions p {
    opacity: 0.7;
    font-size: 0.95rem;
}

/* Loading */
.loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #00ff88;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Playback Controls */
.playback {
    background: rgba(0, 0, 0, 0.95);
    border-top: 1px solid #333;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 50;
}

.btn-play {
    background: linear-gradient(135deg, #00ff88 0%, #00cc66 100%);
    color: #000;
    border: none;
    padding: 1rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 255, 136, 0.4);
    transition: transform 0.2s;
}

.btn-play:active {
    transform: scale(0.95);
}

.timeline {
    width: 100%;
    height: 8px;
    background: #333;
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
}

.timeline::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: #00ff88;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 255, 136, 0.5);
}

.timeline::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #00ff88;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.time-info {
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: #00ff88;
}

.speed-selector {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.btn-speed {
    background: #1a1a2e;
    color: #fff;
    border: 1px solid #333;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-speed.active {
    background: #00ff88;
    color: #000;
    border-color: #00ff88;
}

.btn-speed:active {
    transform: scale(0.95);
}

/* Bottom Sheet */
.bottom-sheet {
    background: linear-gradient(to bottom, #1a1a2e 0%, #0f0f1e 100%);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 1.5rem;
    max-height: 50vh;
    overflow-y: auto;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    margin: 0 auto 1rem;
}

.bottom-sheet h3 {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.2rem;
    color: #00ff88;
}

/* Pitch Grid */
.pitch-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.pitch-card {
    background: linear-gradient(135deg, #16213e 0%, #1a1a2e 100%);
    border: 2px solid transparent;
    border-radius: 16px;
    padding: 1.5rem 1rem;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.pitch-card:active {
    transform: scale(0.95);
    border-color: #00ff88;
}

.pitch-emoji {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.pitch-name {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
    color: #fff;
}

.pitch-speed {
    font-size: 0.85rem;
    color: #00ff88;
    opacity: 0.8;
}

/* Divider */
.divider {
    text-align: center;
    color: #666;
    margin: 1.5rem 0;
    position: relative;
}

.divider::before,
.divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: #333;
}

.divider::before { left: 0; }
.divider::after { right: 0; }

/* File Button */
.file-button {
    display: block;
    background: #16213e;
    border: 2px dashed #00ff88;
    border-radius: 12px;
    padding: 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1rem;
}

.file-button:active {
    background: #1a1a2e;
    transform: scale(0.98);
}

/* Parameter Controls */
.params-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #333;
}

.param-group {
    margin-bottom: 1rem;
}

.param-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #00ff88;
}

.param-group input[type="range"] {
    width: 100%;
    height: 8px;
    background: #16213e;
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
}

.param-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: #00ff88;
    border-radius: 50%;
    cursor: pointer;
}

.param-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #00ff88;
    border-radius: 50%;
    border: none;
}

.param-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.param-group.small label {
    font-size: 0.85rem;
}

.spin-axis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.spin-axis input {
    background: #16213e;
    border: 1px solid #00ff88;
    color: #fff;
    padding: 0.75rem 0.5rem;
    border-radius: 8px;
    text-align: center;
    font-size: 0.9rem;
}

.btn-simulate {
    width: 100%;
    background: linear-gradient(135deg, #ff6b6b 0%, #ff4757 100%);
    color: #fff;
    border: none;
    padding: 1.25rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    margin-top: 1rem;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
}

.btn-simulate:active {
    transform: scale(0.98);
}

/* Info Section */
.info-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #333;
}

details {
    background: #16213e;
    border-radius: 12px;
    padding: 1rem;
}

summary {
    cursor: pointer;
    font-weight: 600;
    color: #00ff88;
    list-style: none;
}

summary::-webkit-details-marker {
    display: none;
}

details p {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #ccc;
}

details code {
    display: block;
    background: #0a0e27;
    padding: 0.75rem;
    border-radius: 8px;
    margin: 0.5rem 0;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: #00ff88;
    overflow-x: auto;
    white-space: nowrap;
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    header h1 {
        font-size: 1rem;
    }
    
    header {
        padding: 0.5rem 1rem;
    }
    
    .bottom-sheet {
        max-height: 60vh;
    }
    
    .velocity-box {
        bottom: 10px;
        right: 10px;
        padding: 0.5rem;
        font-size: 0.75rem;
    }
}

/* Large screens */
@media (min-width: 768px) {
    .pitch-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .bottom-sheet {
        max-height: 40vh;
    }
}

/* Smooth scrolling */
.bottom-sheet {
    -webkit-overflow-scrolling: touch;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .app {
        height: -webkit-fill-available;
    }
}
