/* ── Drum Machine - style.css ── */

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

:root {
    --bg-deep: #0f0f1a;
    --bg-surface: #1a1a2e;
    --bg-card: #22223a;
    --accent: #4ecdc4;
    --red: #e74c3c;
    --text: #eaeaea;
    --text-dim: #8888aa;
    --radius: 12px;
    --shadow: 0 8px 32px rgba(0,0,0,0.45);
}

html {
    font-size: 16px;
    background: var(--bg-deep);
}

/* ── Focus Visible ── */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */
header {
    width: 100%;
    max-width: 520px;
    padding: 1.25rem 1rem 0;
    text-align: center;
}
header h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
header p {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 0.2rem;
}

/* ── Machine wrapper ── */
.machine {
    width: 100%;
    max-width: 520px;
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ── Section card ── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 0.85rem;
    box-shadow: var(--shadow);
}

.section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

/* ── Waveform ── */
#waveformCanvas {
    width: 100%;
    height: 56px;
    border-radius: 8px;
    background: var(--bg-surface);
    display: block;
}

/* ── Pads ── */
.pads {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.pad {
    position: relative;
    aspect-ratio: 1;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 0.82rem;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
    transition: transform 0.08s, box-shadow 0.08s, filter 0.08s;
    -webkit-user-select: none;
    user-select: none;
    outline: none;
    overflow: hidden;
}
.pad:hover { transform: scale(1.04); }
.pad:active, .pad.active {
    transform: scale(0.93);
    filter: brightness(1.45);
    box-shadow: 0 0 28px rgba(255,255,255,0.25);
}

/* ── Pad Ripple Effect ── */
@keyframes ripple {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0.5; }
    100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; }
}

.pad-ripple {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.6);
    pointer-events: none;
    animation: ripple 0.5s ease-out forwards;
}

.pad .pad-name { pointer-events: none; }
.pad .pad-key {
    pointer-events: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62rem;
    font-weight: 600;
    background: rgba(0,0,0,0.35);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    opacity: 0.8;
}

.pad .pad-vol {
    position: absolute;
    bottom: 4px;
    right: 6px;
    width: 4px;
    height: 20px;
    background: rgba(0,0,0,0.3);
    border-radius: 2px;
    overflow: hidden;
    pointer-events: none;
}
.pad .pad-vol-fill {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: rgba(255,255,255,0.7);
    border-radius: 2px;
    transition: height 0.15s;
}

.pad-1 { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.pad-2 { background: linear-gradient(135deg, #e67e22, #d35400); }
.pad-3 { background: linear-gradient(135deg, #f1c40f, #e6a800); color: #333; text-shadow: none; }
.pad-4 { background: linear-gradient(135deg, #2ecc71, #27ae60); }
.pad-5 { background: linear-gradient(135deg, #3498db, #2176ae); }
.pad-6 { background: linear-gradient(135deg, #9b59b6, #7d3c98); }
.pad-7 { background: linear-gradient(135deg, #1abc9c, #148f77); }
.pad-8 { background: linear-gradient(135deg, #546e7a, #37474f); }
.pad-9 { background: linear-gradient(135deg, #e91e63, #ad1457); }

/* ── Per-pad volume popup ── */
.pad-volume-popup {
    display: none;
    position: fixed;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    padding: 4px 8px;
    z-index: 100;
    white-space: nowrap;
    align-items: center;
    gap: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.pad-volume-popup.visible { display: flex; }
.pad-volume-popup input[type=range] { width: 70px; }
.pad-volume-popup span {
    font-size: 0.6rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-dim);
    min-width: 28px;
    text-align: right;
}

/* ── Controls row ── */
.controls-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.ctrl-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.ctrl-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    white-space: nowrap;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.15);
    outline: none;
    cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
    cursor: pointer;
}
input[type=range]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
    cursor: pointer;
}

.ctrl-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent);
    min-width: 32px;
    text-align: right;
}

.slider-sm { width: 70px; }
.slider-md { width: 90px; }

/* ── Buttons ── */
.btn {
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: filter 0.1s, transform 0.08s;
    white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.96); }
.btn-accent { background: var(--accent); color: #111; }
.btn-red { background: var(--red); color: #fff; }
.btn-dim { background: rgba(255,255,255,0.1); color: var(--text); }
.btn-red.recording { animation: pulse 0.5s infinite alternate; }

@keyframes pulse {
    from { opacity: 1; }
    to { opacity: 0.5; }
}

/* ── Step Sequencer ── */
.sequencer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.45rem;
}

.seq-grid {
    display: grid;
    grid-template-columns: 56px repeat(16, 1fr);
    gap: 3px;
    font-size: 0.6rem;
}

.seq-label {
    display: flex;
    align-items: center;
    font-size: 0.58rem;
    font-weight: 600;
    color: var(--text-dim);
    padding-right: 4px;
    justify-content: flex-end;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.seq-step {
    aspect-ratio: 1;
    min-width: 0;
    border: none;
    border-radius: 3px;
    background: rgba(255,255,255,0.07);
    cursor: pointer;
    transition: background 0.1s, box-shadow 0.1s;
    outline: none;
}
.seq-step:hover { background: rgba(255,255,255,0.15); }
.seq-step.on { background: var(--accent); box-shadow: 0 0 6px rgba(78,205,196,0.4); }
.seq-step.beat-marker { border-bottom: 2px solid rgba(255,255,255,0.08); }
.seq-step.current-step { box-shadow: inset 0 0 0 2px #fff; }
.seq-step.on.current-step { box-shadow: inset 0 0 0 2px #fff, 0 0 6px rgba(78,205,196,0.4); }

.seq-step-numbers {
    display: grid;
    grid-template-columns: 56px repeat(16, 1fr);
    gap: 3px;
    margin-bottom: 3px;
}
.seq-step-numbers span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.5rem;
    color: var(--text-dim);
    text-align: center;
}
.seq-step-numbers span.beat-num { color: var(--accent); font-weight: 600; }

/* ── Footer ── */
footer {
    width: 100%;
    text-align: center;
    padding: 1rem 0 1.25rem;
    font-size: 0.72rem;
    color: var(--text-dim);
}
footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
footer a:hover { text-decoration: underline; }

/* ── Responsive ── */
@media (max-width: 768px) {
    html { font-size: 15px; }
    .btn { min-height: 44px; padding: 0.5rem 1rem; }
    .seq-step { min-width: 22px; min-height: 22px; }
    input[type=range] { height: 44px; }
}

@media (max-width: 420px) {
    header h1 { font-size: 1.35rem; }
    .pads { gap: 7px; }
    .pad { font-size: 0.72rem; border-radius: 10px; }
    .pad .pad-key { font-size: 0.55rem; }
    .seq-grid { grid-template-columns: 40px repeat(16, 1fr); gap: 2px; }
    .seq-label { font-size: 0.5rem; }
    .seq-step-numbers { grid-template-columns: 40px repeat(16, 1fr); gap: 2px; }
    .controls-row { gap: 0.4rem; }
    .slider-sm { width: 55px; }
    .slider-md { width: 65px; }
    footer { padding: 0.75rem 0; font-size: 0.68rem; }
}

/* ── 375px breakpoint (small phones) ── */
@media (max-width: 375px) {
    .machine { padding: 0.75rem; }
    /* 시퀀서 터치 개선: 최소 크기 확보 + 가로 스크롤 */
    .card:has(.seq-grid) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .seq-grid { min-width: 480px; }
    .seq-step-numbers { min-width: 480px; }
    .seq-step { min-width: 20px; min-height: 20px; }
}

@media (min-width: 520px) {
    .pad { font-size: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
