/* 휴대폰 피아노 & 비트 메이커 — 스튜디오 믹서 UI (다크/라이트) */

:root {
  --bg: #0a0b12;
  --bg-glow: #1b1d36;
  --card: rgba(255, 255, 255, .05);
  --card-2: rgba(255, 255, 255, .035);
  --brd: rgba(255, 255, 255, .10);
  --txt: #eef1ff;
  --dim: #99a2c4;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --hot: #ff4d6d;
  --step: rgba(255, 255, 255, .07);
  --step-beat: rgba(255, 255, 255, .13);
  --key-white: #f8f9ff;
  --key-white-2: #dde1f2;
  --key-black: #141626;
  --key-label: #737b99;
  --dock-bg: rgba(10, 11, 18, .93);
  --shadow: 0 12px 32px rgba(0, 0, 0, .5);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Malgun Gothic", system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: #eceef7;
  --bg-glow: #ffffff;
  --card: #ffffff;
  --card-2: #f3f5fc;
  --brd: rgba(20, 26, 60, .11);
  --txt: #14172a;
  --dim: #5c6484;
  --step: rgba(20, 26, 60, .07);
  --step-beat: rgba(20, 26, 60, .13);
  --key-white: #ffffff;
  --key-white-2: #e6e9f6;
  --key-black: #232741;
  --key-label: #8a90ab;
  --dock-bg: rgba(255, 255, 255, .95);
  --shadow: 0 12px 26px rgba(26, 32, 80, .14);
}

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

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(8px + env(safe-area-inset-top)) 0 calc(92px + env(safe-area-inset-bottom));
  font-family: var(--font);
  color: var(--txt);
  background:
    radial-gradient(120% 70% at 50% -10%, var(--bg-glow) 0%, var(--bg) 58%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .022) 0 1px, transparent 1px 22px);
  opacity: .9;
}

[data-theme="light"] body::before { opacity: .5; }

.app {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 10px;
}

/* ── 헤더 ─────────────────────────────────── */
.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.logo {
  font-size: 22px;
  filter: drop-shadow(0 2px 8px rgba(139, 92, 246, .55));
}

.titles { min-width: 0; }

.titles h1 {
  margin: 0;
  font-size: 15px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.titles p {
  margin: 2px 0 0;
  font-size: 9.5px;
  color: var(--dim);
  letter-spacing: .1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ver {
  flex: 0 0 auto;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .4px;
  color: var(--accent-2);
  border: 1px solid rgba(34, 211, 238, .38);
  border-radius: 99px;
  padding: 2px 6px;
  text-transform: uppercase;
}

.tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.vol {
  flex: 0 0 auto;
  width: 62px;
  height: 26px;
}

.icon {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  border: 1px solid var(--brd);
  background: var(--card-2);
  color: var(--txt);
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
}

.icon:active { transform: scale(.94); }

/* ── 카드 ─────────────────────────────────── */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--brd);
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

[data-theme="dark"] .card {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, 0) 60%);
}

.sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.sec-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -.2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status {
  font-size: 10px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status.on { color: var(--accent-2); }

/* ── 트랜스포트 ───────────────────────────── */
.transport {
  display: grid;
  grid-template-columns: 84px 1fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: 52px;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, .22);
  background: linear-gradient(160deg, var(--accent), #5b8bff);
  color: #fff;
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .2px;
  box-shadow: 0 6px 18px rgba(120, 92, 246, .45);
  padding: 0;
}

.play .pi { font-size: 15px; line-height: 1; }

.play:active { transform: scale(.97); }

.play.on {
  background: linear-gradient(160deg, #ff6b81, var(--hot));
  box-shadow: 0 6px 18px rgba(255, 77, 109, .45);
}

.dial {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  background: var(--card-2);
  border: 1px solid var(--brd);
  border-radius: 13px;
  padding: 6px 9px;
  min-width: 0;
}

.dial-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
}

.dial-top span {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .6px;
  color: var(--dim);
  text-transform: uppercase;
}

.dial-top output {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--txt);
  letter-spacing: -.5px;
}

/* ── 슬라이더 ─────────────────────────────── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  background: transparent;
  margin: 0;
  padding: 0;
}

.dial input[type="range"] { width: 100%; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: .75;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0, 0, 0, .12);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: #fff;
}

/* ── 칩 ───────────────────────────────────── */
.presets,
.instrs {
  display: grid;
  gap: 5px;
  margin-top: 9px;
}

.presets { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.instrs { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 0; margin-bottom: 8px; }

.chip {
  height: 30px;
  padding: 0 2px;
  border-radius: 9px;
  border: 1px solid var(--brd);
  background: var(--card-2);
  color: var(--dim);
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: -.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip:active { transform: scale(.96); }

.chip[aria-pressed="true"],
.chip.active {
  color: #fff;
  border-color: rgba(255, 255, 255, .26);
  background: linear-gradient(160deg, var(--accent), #4f7dff);
  box-shadow: 0 4px 12px rgba(120, 92, 246, .35);
}

.chip.ghost {
  color: var(--hot);
  border-color: rgba(255, 77, 109, .35);
  background: rgba(255, 77, 109, .08);
}

.chip.tiny {
  height: 26px;
  min-width: 40px;
  padding: 0 7px;
  font-size: 10px;
  border-radius: 8px;
}

/* ── 16스텝 그리드 ─────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 40px repeat(16, minmax(0, 1fr));
  gap: 3px 2px;
  margin-top: 10px;
  touch-action: none;
}

.ruler {
  height: 11px;
  font-size: 8.5px;
  line-height: 11px;
  text-align: center;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.ruler.beat { color: var(--accent-2); font-weight: 700; }

.corner { height: 11px; }

.trk {
  height: 28px;
  padding: 0 1px;
  border-radius: 7px;
  border: 1px solid var(--brd);
  background: var(--card-2);
  color: var(--dim);
  font-family: var(--font);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: -.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
}

.trk:active { color: var(--txt); background: rgba(139, 92, 246, .22); }

.step {
  height: 28px;
  width: 100%;
  padding: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--step);
  position: relative;
  transition: background .08s, box-shadow .08s;
}

.step.beat { background: var(--step-beat); }

.step.on {
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  border-color: rgba(255, 255, 255, .3);
  box-shadow: 0 0 10px rgba(139, 92, 246, .5), inset 0 1px 0 rgba(255, 255, 255, .35);
}

.step.now { box-shadow: 0 0 0 2px rgba(255, 255, 255, .55) inset; }

.step.now.on { box-shadow: 0 0 14px rgba(34, 211, 238, .85), inset 0 0 0 2px rgba(255, 255, 255, .6); }

.tip {
  margin: 9px 0 0;
  font-size: 9.5px;
  line-height: 1.45;
  color: var(--dim);
}

/* ── 건반 ─────────────────────────────────── */
.octctl {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mini {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--brd);
  background: var(--card-2);
  color: var(--txt);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
}

.mini:disabled { opacity: .32; }

.octlabel {
  height: 26px;
  min-width: 62px;
  padding: 0 6px;
  border-radius: 8px;
  border: 1px solid var(--brd);
  background: var(--card-2);
  color: var(--txt);
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
}

.nbadge {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  min-width: 26px;
}

.keys {
  position: relative;
  height: 158px;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, #06070e, #0b0d1a);
  box-shadow: inset 0 6px 14px rgba(0, 0, 0, .6), 0 2px 0 rgba(255, 255, 255, .06);
  touch-action: none;
}

[data-theme="light"] .keys {
  background: linear-gradient(180deg, #cfd4e8, #aeb4cf);
}

.key {
  position: absolute;
  top: 0;
  padding: 0;
  border: 0;
  border-radius: 0 0 6px 6px;
  font-family: var(--font);
  transition: background .05s, transform .05s;
  touch-action: none;
}

.key.white {
  height: 100%;
  background: linear-gradient(180deg, var(--key-white) 0%, var(--key-white-2) 92%, #c9cee4 100%);
  border-right: 1px solid rgba(0, 0, 0, .28);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .07);
}

.key.white.on {
  background: linear-gradient(180deg, #c4b5fd, #7c5cff);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18), 0 0 16px rgba(139, 92, 246, .7);
}

.key.black {
  height: 52%;
  z-index: 3;
  background: linear-gradient(180deg, #33384f 0%, var(--key-black) 70%, #05060c 100%);
  box-shadow: 0 4px 8px rgba(0, 0, 0, .65), inset 0 -3px 0 rgba(255, 255, 255, .07);
  border-radius: 0 0 5px 5px;
}

.key.black.on {
  background: linear-gradient(180deg, #a78bfa, #22d3ee);
  box-shadow: 0 0 14px rgba(34, 211, 238, .75);
}

.key .kl {
  position: absolute;
  bottom: 7px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 8.5px;
  font-weight: 700;
  color: var(--key-label);
  pointer-events: none;
}

.key.white.on .kl { color: #fff; }

/* ── 안내 / 푸터 ──────────────────────────── */
.help {
  margin: 0 2px 8px;
  font-size: 10.5px;
  color: var(--dim);
  border: 1px solid var(--brd);
  border-radius: 12px;
  background: var(--card-2);
  padding: 8px 11px;
}

.help summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--txt);
  font-size: 11px;
  list-style: none;
}

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

.help summary::before { content: "▸ "; color: var(--accent-2); }

.help[open] summary::before { content: "▾ "; }

.help ul {
  margin: 7px 0 2px;
  padding-left: 15px;
  line-height: 1.55;
}

.help li { margin-bottom: 4px; }

.help code {
  font-size: 9.5px;
  background: rgba(139, 92, 246, .16);
  border-radius: 4px;
  padding: 0 3px;
}

.foot {
  margin: 2px 0 6px;
  text-align: center;
  font-size: 9px;
  color: var(--dim);
  opacity: .75;
}

/* ── 하단 독 (녹음) ───────────────────────── */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  background: var(--dock-bg);
  border-top: 1px solid var(--brd);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -8px 26px rgba(0, 0, 0, .35);
}

.rec {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 106px;
  height: 44px;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: linear-gradient(160deg, #2a2d45, #1a1c2c);
  color: #fff;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -.2px;
  padding: 0 12px;
}

[data-theme="light"] .rec {
  background: linear-gradient(160deg, #ffffff, #eef0fa);
  color: var(--txt);
  border-color: var(--brd);
}

.rec .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--hot);
  box-shadow: 0 0 8px rgba(255, 77, 109, .8);
}

.rec.on {
  background: linear-gradient(160deg, #ff5d78, #ff8a5c);
  color: #fff;
  border-color: rgba(255, 255, 255, .3);
}

.rec.on .dot {
  background: #fff;
  border-radius: 2px;
  box-shadow: none;
  animation: blip 1s ease-in-out infinite;
}

@keyframes blip {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.recinfo {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.recinfo b {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .5px;
}

.recinfo small {
  font-size: 9.5px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 13px;
  border-radius: 13px;
  border: 1px solid rgba(34, 211, 238, .45);
  background: rgba(34, 211, 238, .12);
  color: #9ff0ff;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
}

[data-theme="light"] .save { color: #0a7d94; }

.save:disabled { opacity: .38; border-color: var(--brd); background: var(--card-2); color: var(--dim); }

.save:active:not(:disabled) { transform: scale(.96); }

body.recording .clock { color: var(--hot); }

/* ── 토스트 ───────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: 86vw;
  padding: 9px 14px;
  border-radius: 11px;
  background: rgba(20, 22, 38, .95);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, .16);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 40;
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 좁은 아이폰(390px): 제목이 잘리지 않도록 밀도를 낮춘다 */
@media (max-width: 430px) {
  .hdr { gap: 6px; }
  .brand { gap: 6px; }
  .tools { gap: 5px; }
  .titles p { display: none; }
  .titles h1 { font-size: 13.5px; letter-spacing: -.4px; }
  .vol { width: 50px; }
  .ver { display: none; }
  .logo { font-size: 20px; }
}

@media (min-width: 430px) {
  .grid { grid-template-columns: 46px repeat(16, minmax(0, 1fr)); }
  .trk { font-size: 10px; }
  .step, .trk { height: 32px; }
  .keys { height: 176px; }
  .brand .titles h1 { font-size: 16px; }
}

@media (max-height: 720px) {
  .keys { height: 132px; }
  .step, .trk { height: 25px; }
}
