:root {
  --bg: #07051a;
  --panel: rgba(18, 10, 40, 0.62);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f4ecff;
  --dim: #a99cc9;
  --pink: #ff4fd8;
  --cyan: #36e2ff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Gothic A1', system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#viz { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; }
#app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; gap: 14px; padding: 14px 18px; max-width: 1280px; margin: 0 auto; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font-family: ui-monospace, monospace; font-size: 0.85em; background: rgba(255,255,255,0.12); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }

/* ---------- 상단 ---------- */
#top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 10px 16px;
  backdrop-filter: blur(10px);
}
h1 { margin: 0 8px 0 0; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: 28px; letter-spacing: 1px; }
h1 span { color: var(--pink); text-shadow: 0 0 14px var(--pink); margin-left: 4px; }
.group { display: flex; align-items: center; gap: 8px; }
.group label { font-size: 13px; color: var(--dim); }
#top button, #top select {
  height: 38px; min-width: 38px; padding: 0 10px; border-radius: 11px;
  background: rgba(255,255,255,0.08); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
#top select option { background: #1a1035; }
#top button small { font-size: 12px; }
#top button:hover { background: rgba(255,255,255,0.16); }
#top button.big { width: 48px; height: 48px; border-radius: 50%; font-size: 20px; background: linear-gradient(135deg, #ff4fd8, #7a5cff); border: none; box-shadow: 0 0 18px rgba(255,79,216,0.5); }
#top button.big.on { background: linear-gradient(135deg, #36e2ff, #7a5cff); box-shadow: 0 0 22px rgba(54,226,255,0.6); }
#top button.rec.on, #recAudio.on { background: #ff3d5a !important; border-color: #ff3d5a; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.6; } }
#top button.mini { min-width: 28px; width: 28px; height: 28px; padding: 0; border-radius: 8px; }
.beat-counter { font-family: ui-monospace, monospace; font-size: 18px; width: 44px; text-align: center; color: var(--cyan); text-shadow: 0 0 10px var(--cyan); }
#bpmValue { font-family: ui-monospace, monospace; width: 34px; font-size: 18px; }
input[type=range] { accent-color: var(--pink); width: 120px; }
input[type=range].short { width: 80px; }

/* ---------- 패드 & 시퀀서 ---------- */
main { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 14px; align-items: start; }
#pads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pad {
  aspect-ratio: 1; border-radius: 16px; position: relative; overflow: hidden;
  background: linear-gradient(160deg, rgba(255,255,255,0.10), rgba(255,255,255,0.02)), var(--panel);
  border: 1px solid color-mix(in srgb, var(--c) 55%, transparent);
  box-shadow: inset 0 0 0 0 var(--c);
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; padding: 9px;
  backdrop-filter: blur(8px); touch-action: none;
  transition: transform 0.06s;
}
.pad kbd { font-size: 13px; color: var(--c); border-color: color-mix(in srgb, var(--c) 40%, transparent); }
.pad span { font-size: 12.5px; font-weight: 700; text-align: left; line-height: 1.2; }
.pad::after { content: ''; position: absolute; inset: 0; background: var(--c); opacity: 0; pointer-events: none; }
.pad.hit { animation: padhit 0.32s ease-out; }
.pad.hit::after { animation: padglow 0.32s ease-out; }
@keyframes padhit { 0% { transform: scale(0.93); box-shadow: 0 0 30px var(--c); } 100% { transform: scale(1); box-shadow: 0 0 0 transparent; } }
@keyframes padglow { 0% { opacity: 0.75; } 100% { opacity: 0; } }

#grid {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 10px;
  display: flex; flex-direction: column; gap: 4px; backdrop-filter: blur(10px); touch-action: none;
}
.row { display: grid; grid-template-columns: 86px repeat(16, 1fr); gap: 3px; align-items: center; }
.row.bass:first-of-type, .row[data-i="4"], .row[data-i="8"], .row[data-i="12"] { margin-top: 5px; }
.label {
  height: 100%; min-height: 22px; font-size: 11.5px; font-weight: 700; text-align: left; padding: 0 6px;
  background: none; border: none; border-left: 3px solid var(--c); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row.muted .label { opacity: 0.35; text-decoration: line-through; }
.row.muted .cell.on { opacity: 0.3; }
.cell { height: 22px; border-radius: 5px; background: rgba(255,255,255,0.06); cursor: pointer; transition: background 0.08s; }
.cell.beat { background: rgba(255,255,255,0.11); }
.cell:hover { background: rgba(255,255,255,0.2); }
.cell.on { background: var(--c); box-shadow: 0 0 8px color-mix(in srgb, var(--c) 70%, transparent); }
.cell.head { outline: 2px solid rgba(255,255,255,0.75); outline-offset: -1px; }
.cell.on.head { filter: brightness(1.5); box-shadow: 0 0 16px var(--c); }

/* ---------- 하단 FX ---------- */
#fx {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 10px 16px; backdrop-filter: blur(10px);
}
#fx input[type=range] { width: 160px; }
#fx .keys { margin: 0 0 0 auto; font-size: 12.5px; color: var(--dim); }

/* ---------- 안내 & 토스트 ---------- */
#intro {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 2; text-align: center;
  background: rgba(10, 5, 30, 0.8); border: 1px solid var(--pink); border-radius: 20px; padding: 18px 26px;
  box-shadow: 0 0 40px rgba(255,79,216,0.35); transition: opacity 0.5s; pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
#intro h2 { margin: 0 0 6px; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: 26px; }
#intro p { margin: 0; color: var(--dim); }
#intro.hidden { opacity: 0; }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: rgba(20, 10, 45, 0.92); border: 1px solid var(--pink); border-radius: 12px; padding: 9px 16px; font-size: 14px; animation: pop 0.3s ease-out; transition: opacity 0.4s, transform 0.4s; white-space: nowrap; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.95); } }

/* ---------- 반응형 ---------- */
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  #pads { max-width: 520px; width: 100%; margin: 0 auto; }
  #fx .keys { display: none; }
}
@media (max-width: 600px) {
  #app { padding: 10px; gap: 10px; }
  #top { padding: 8px 10px; gap: 8px 10px; }
  h1 { font-size: 22px; width: 100%; text-align: center; margin: 0; }
  .group { flex-wrap: wrap; }
  input[type=range] { width: 90px; }
  #grid { padding: 6px; }
  .row { grid-template-columns: 56px repeat(16, 1fr); gap: 2px; }
  .label { font-size: 10px; padding: 0 3px; }
  .cell { height: 18px; border-radius: 3px; }
  .pad span { font-size: 11px; }
  #fx input[type=range] { width: 110px; }
  .toast { white-space: normal; text-align: center; max-width: calc(100vw - 32px); }
}
