* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Rotate Screen Overlay */
#rotate-screen {
    display: none;
    position: fixed;
    inset: 0;
    background: #0f172a;
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.rotate-message {
    color: #e2e8f0;
}

.phone-icon {
    font-size: 5rem;
    margin-bottom: 20px;
    animation: shake 1s infinite;
}

.rotate-arrow {
    font-size: 4rem;
    margin-top: 20px;
    animation: rotate 2s infinite;
}

@keyframes shake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Show rotate message in portrait mode */
@media (orientation: portrait) {
    #rotate-screen {
        display: flex !important;
    }
    #app {
        display: none !important;
    }
}

/* Main app - only visible in landscape */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: linear-gradient(135deg, #1e293b, #334155);
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #3b82f6;
    flex-shrink: 0;
}

.home-link {
    text-decoration: none;
    font-size: 1.3rem;
    padding: 4px 8px;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    transition: background 0.2s;
}
.home-link:hover {
    background: rgba(255,255,255,0.2);
}

header h1 {
    font-size: 1.2rem;
    background: linear-gradient(90deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#controls {
    display: flex;
    gap: 15px;
    font-size: 0.9rem;
    color: #94a3b8;
}

#game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 15px;
    overflow-y: auto;
}

#drum-machine {
    max-width: 100%;
    margin: 0 auto;
}

/* Main Controls */
#main-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.control-btn {
    background: linear-gradient(145deg, #1e293b, #334155);
    color: #e2e8f0;
    border: 2px solid #3b82f6;
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.control-btn:active {
    transform: translateY(0);
}

#tempo-control {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.05);
    padding: 6px 12px;
    border-radius: 10px;
}

#tempo-slider {
    width: 100px;
}

/* Sequencer */
#sequencer {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.track {
    display: flex;
    gap: 6px;
    align-items: center;
}

.track-label {
    width: 90px;
    padding: 6px;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    position: relative;
}

.track-label[data-instrument="kick"] { background: linear-gradient(145deg, #dc2626, #991b1b); }
.track-label[data-instrument="snare"] { background: linear-gradient(145deg, #2563eb, #1e40af); }
.track-label[data-instrument="hihat"] { background: linear-gradient(145deg, #16a34a, #15803d); }
.track-label[data-instrument="tom"] { background: linear-gradient(145deg, #ca8a04, #a16207); }
.track-label[data-instrument="cymbal"] { background: linear-gradient(145deg, #9333ea, #7e22ce); }
.track-label[data-instrument="clap"] { background: linear-gradient(145deg, #ec4899, #be185d); }
.track-label[data-instrument="cowbell"] { background: linear-gradient(145deg, #f97316, #c2410c); }
.track-label[data-instrument="rim"] { background: linear-gradient(145deg, #06b6d4, #0e7490); }
.track-label[data-instrument="openhat"] { background: linear-gradient(145deg, #10b981, #047857); }
.track-label[data-instrument="perc"] { background: linear-gradient(145deg, #8b5cf6, #6d28d9); }

.change-instrument-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.3);
    border: none;
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.change-instrument-btn:hover {
    background: rgba(0,0,0,0.5);
}

.instrument-icon {
    font-size: 1.5rem;
}

.instrument-name {
    font-size: 0.75rem;
}

.steps {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 3px;
    flex: 1;
}

.step {
    aspect-ratio: 1;
    background: rgba(255,255,255,0.1);
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.1s;
    touch-action: manipulation;
    min-width: 36px;
    min-height: 36px;
}

.step:hover {
    background: rgba(255,255,255,0.2);
}

.step.active {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    border-color: #60a5fa;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}

.step.playing {
    background: linear-gradient(145deg, #fbbf24, #f59e0b);
    border-color: #fcd34d;
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.8);
    transform: scale(1.15);
}

/* Beat markers - stronger borders on beats 1, 5, 9, 13 */
.step[data-beat="0"],
.step[data-beat="4"],
.step[data-beat="8"],
.step[data-beat="12"] {
    border-color: rgba(59, 130, 246, 0.6);
    border-width: 3px;
}

/* Instrument Selector Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(145deg, #1e293b, #334155);
    border: 2px solid #3b82f6;
    border-radius: 16px;
    padding: 20px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 15px;
    background: linear-gradient(90deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.instrument-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.instrument-option {
    background: rgba(255,255,255,0.05);
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.instrument-option:hover {
    background: rgba(255,255,255,0.1);
    border-color: #3b82f6;
    transform: scale(1.05);
}

.instrument-option .icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.instrument-option .name {
    font-size: 0.85rem;
    font-weight: 600;
}

#close-modal {
    width: 100%;
    margin-top: 10px;
}

/* Landscape optimizations for smaller screens */
@media (max-height: 500px) and (orientation: landscape) {
    header h1 {
        font-size: 1rem;
    }
    
    #game-area {
        padding: 6px 10px;
    }
    
    .track-label {
        width: 70px;
        padding: 4px;
    }
    
    .instrument-icon {
        font-size: 1.2rem;
    }
    
    .instrument-name {
        font-size: 0.65rem;
    }
    
    .step {
        min-width: 28px;
        min-height: 28px;
    }
    
    .control-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }
    
    #sequencer {
        gap: 4px;
    }
}

/* Very wide landscape screens - make steps even bigger */
@media (min-width: 900px) and (orientation: landscape) {
    .step {
        min-width: 45px;
        min-height: 45px;
    }
    
    .track-label {
        width: 100px;
    }
}
