@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@500;700&family=Roboto+Mono:wght@400;700&display=swap');

/* --- RESET E BLOCCO SISTEMA --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-user-select: none;
    user-select: none; 
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    /* touch-action: none è troppo restrittivo qui, lo gestiamo nei contenitori */
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden; 
    position: fixed; 
    background: #000;
    /* Impedisce il pull-to-refresh e il rimbalzo pagina */
    overscroll-behavior: none; 
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Roboto Mono', monospace;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#paintCanvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -10;
    pointer-events: none; /* Il canvas non deve intercettare i tocchi */
}

/* --- WRAPPER E CASE --- */
.wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px;
    touch-action: none; /* Impedisce lo scroll della pagina intera */
}

.machine-case {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1000px;
    background: #2b2b2b;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.9);
    border-top: 1px solid #444;
}

/* VITI ESTETICHE */
.screw {
    position: absolute;
    width: 8px; height: 8px;
    background: radial-gradient(circle, #777, #111);
    border-radius: 50%;
    z-index: 10;
}
.tl { top: 6px; left: 6px; } .tr { top: 6px; right: 6px; }
.bl { bottom: 6px; left: 6px; } .br { bottom: 6px; right: 6px; }

/* --- HEADER --- */
.machine-header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #111;
}

.brand h1 { font-family: 'Orbitron'; color: #eee; font-size: clamp(0.9rem, 4vw, 1.2rem); line-height: 1; }
.sub-brand { font-size: 0.5rem; color: #777; font-weight: bold; display: block; }

.lcd-display { background: #000; border: 1px solid #444; border-radius: 4px; padding: 4px; display: flex; gap: 6px; }
.lcd-screen { background: #151a15; padding: 2px 6px; border-radius: 2px; text-align: center; }
.label { font-size: 0.5rem; color: #4aff4a; display: block; }

#bpmInput { background: transparent; border: none; color: #4aff4a; font-family: 'Orbitron'; font-size: 1rem; width: 45px; text-align: center; outline: none; }

.transport-controls { display: flex; gap: 4px; }
.transport-btn { padding: 8px 10px; border: none; border-radius: 4px; color: #fff; font-weight: bold; font-size: 0.65rem; box-shadow: 0 3px 0 #111; cursor: pointer; }
.transport-btn:active { transform: translateY(2px); box-shadow: none; }
.transport-btn.clear { background: #444; }
.transport-btn#startStopBtn { background: #d32f2f; min-width: 60px; }
.transport-btn.export { background: #0288d1; }

/* --- INTERFACE GRID --- */
.interface-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Necessario per lo scroll flexbox */
}

.fixed-top-section { flex-shrink: 0; }

.drum-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    background: #1a1a1a;
    border-radius: 8px;
    margin-bottom: 8px;
}

.drum-pad {
    aspect-ratio: 1.6/1;
    background: #37474f;
    border: none;
    border-radius: 5px;
    color: #eee;
    font-size: 0.65rem;
    font-weight: bold;
    box-shadow: 0 3px 0 #111;
    touch-action: none; /* I pad non devono scorrere */
}
.drum-pad.active { background: #00bcd4; transform: translateY(2px); box-shadow: none; color: #000; }

.section-info { padding: 4px 0; }
.legend { font-size: 0.55rem; color: #666; text-align: center; font-weight: bold; text-transform: uppercase; }

/* --- SEQUENCER --- */
.sequencer-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #111;
    border-radius: 8px;
    padding: 6px;
    overflow: hidden;
}

.sequencer-scroll-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    /* Qui permettiamo lo scroll del browser ma gestiamo il tocco nel JS */
    touch-action: pan-x pan-y; 
    -webkit-overflow-scrolling: touch;
}

.sequencer-scroll-area::-webkit-scrollbar { display: none; }

.sequencer { min-width: 650px; }

.seq-row { display: flex; align-items: center; height: 38px; margin-bottom: 4px; }

.row-label {
    width: 42px; min-width: 42px; height: 100%;
    font-size: 0.75rem; color: #ff9800; font-weight: bold;
    background: #222; display: flex; justify-content: center; align-items: center;
    margin-right: 6px; border-radius: 4px; border: 1px solid #333;
    touch-action: pan-y; /* Permette lo scroll verticale toccando i nomi strumenti */
}

.steps { display: grid; grid-template-columns: repeat(16, 1fr); gap: 3px; height: 100%; flex: 1; }
.step { height: 100%; background: #2a2a2a; border-radius: 3px; transition: background 0.1s ease; }
.step.beat-marker { background: #3a3a3a; }
.step.playhead { box-shadow: inset 0 0 0 2px #fff; z-index: 5; }

/* --- ORIENTAMENTO ORIZZONTALE (LANDSCAPE) --- */
@media (orientation: landscape) and (max-height: 500px) {
    .machine-case { flex-direction: row; flex-wrap: wrap; padding: 8px; }
    .machine-header { width: 100%; margin-bottom: 4px; height: 45px; }
    .fixed-top-section { width: 25%; height: calc(100% - 50px); }
    .drum-grid { grid-template-columns: repeat(2, 1fr); height: 90%; margin-bottom: 0; }
    .sequencer-container { width: 75%; height: calc(100% - 50px); margin-top: 0; margin-left: 8px; }
    .drum-pad { aspect-ratio: auto; height: 100%; }
    .seq-row { height: 32px; }
    .legend { font-size: 0.45rem; }
    .brand h1 { font-size: 1rem; }
}

/* Fix iOS Zoom & Input */
@media (max-width: 600px) {
    input[type="number"] { font-size: 16px !important; }
}
