:root {
  --bg: #0b0b0f;
  --panel: #131319;
  --panel2: #1a1a22;
  --panel3: #23232d;
  --line: #262631;
  --lane: #101016;
  --lane2: #0d0d12;
  --text: #f4f4f7;
  --muted: #9a9aab;
  --faint: #6b6b7b;
  --accent: #ff3355;
  --rec: #ff3355;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 14px;
  --hw: 104px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.32; cursor: default; }
:focus-visible { outline: 2px solid #8ab4ff; outline-offset: 2px; }
[hidden] { display: none !important; }
.ic { width: 22px; height: 22px; flex: none; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px;
  display: inline-grid; place-items: center; color: var(--text);
}
.icon-btn:active { background: var(--panel3); }

/* ---------------- HOME ---------------- */
#home { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.home-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -0.01em; }
.brand img { border-radius: 8px; }
.home-head-right { display: flex; align-items: center; gap: 4px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 4px 8px; border-radius: 99px; background: var(--panel); }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.status.on i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status.off i { background: var(--warn); }

.home-main { width: 100%; max-width: 560px; margin: 0 auto; padding: 0 16px calc(var(--safe-bottom) + 32px); }
.grab { padding: 18px 0 8px; display: flex; flex-direction: column; gap: 12px; }
.grab h1 { margin: 6px 0 8px; font-size: 34px; line-height: 1.05; letter-spacing: -0.03em; font-weight: 850; }

.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  height: 64px; border-radius: 18px; font-size: 18px; font-weight: 750;
  background: var(--panel2); width: 100%;
  transition: transform 0.08s ease;
}
.big-btn:active { transform: scale(0.98); }
.big-btn.primary { background: linear-gradient(180deg, #ff4766, #e8193f); color: #fff; box-shadow: 0 10px 30px -10px rgba(255, 51, 85, 0.65); }
.big-btn .ic { width: 24px; height: 24px; }

.url-form { display: flex; gap: 8px; }
.url-form input {
  flex: 1; min-width: 0; height: 50px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); padding: 0 14px; font-size: 16px;
}
.url-form input::placeholder { color: var(--faint); }
.url-go { width: 50px; height: 50px; border-radius: 14px; background: var(--panel2); display: grid; place-items: center; }

.ghost-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  color: var(--text); text-decoration: none; font-weight: 600;
}
.ghost-btn:active { background: var(--panel2); }
.ghost-btn.small { height: 38px; font-size: 14px; }
.ghost-btn .ic { width: 20px; height: 20px; }
.hint { margin: 2px 2px 0; color: var(--muted); font-size: 13px; }

.sessions { margin-top: 22px; }
.sessions-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sessions-head h2 { margin: 0; font-size: 17px; }
.chips { display: flex; gap: 6px; }
.chip { height: 34px; padding: 0 12px; border-radius: 99px; background: var(--panel2); font-size: 13px; font-weight: 600; color: var(--muted); }
.chip:active { background: var(--panel3); }

.project-list { display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--muted); font-size: 14px; padding: 24px 12px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.card {
  display: flex; align-items: center; gap: 12px; padding: 8px; padding-right: 2px;
  background: var(--panel); border-radius: var(--radius); text-align: left; width: 100%;
}
.card:active { background: var(--panel2); }
.card .thumb {
  width: 76px; height: 48px; border-radius: 9px; flex: none; background: #222 center/cover no-repeat;
  display: grid; place-items: center; color: rgba(255,255,255,0.6);
}
.card .thumb.blank { background: linear-gradient(135deg, #2a1830, #10202a); }
.card .info { flex: 1; min-width: 0; }
.card .t { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.card .more { width: 40px; height: 44px; display: grid; place-items: center; color: var(--muted); }

/* ---------------- STUDIO ---------------- */
#studio { background: var(--bg); }
.studio-head {
  display: flex; align-items: center; gap: 2px;
  padding: calc(var(--safe-top) + 4px) 6px 4px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.proj-name {
  flex: 1; min-width: 0; text-align: left; font-weight: 700; font-size: 16px; padding: 8px 6px; border-radius: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.proj-name:active { background: var(--panel3); }
.head-actions { display: flex; }

.timeline {
  flex: 1; min-height: 0; position: relative;
  display: grid; grid-template-columns: var(--hw) 1fr; grid-template-rows: 30px 1fr;
}
.tl-corner { grid-area: 1 / 1; background: var(--panel); border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.mini-btn { height: 26px; padding: 0 10px; border-radius: 8px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; }
.mini-btn .ic { width: 16px; height: 16px; }
.mini-btn:active { background: var(--panel3); }
.tl-headers { grid-area: 2 / 1; overflow: hidden; position: relative; background: var(--panel); border-right: 1px solid var(--line); }
.tl-headers-inner { will-change: transform; }
.tl-stage { grid-area: 1 / 2 / 3 / 3; position: relative; overflow: hidden; }
.tl-stage canvas { position: absolute; inset: 0; display: block; }
.tl-overlay { touch-action: none; }

.th {
  position: relative; border-bottom: 1px solid var(--line); padding: 6px 6px 6px 9px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.th::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--c); }
.th-name { display: flex; align-items: center; gap: 6px; text-align: left; min-width: 0; padding: 2px 0; font-size: 12.5px; font-weight: 650; }
.th-dot { display: none; }
.th-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.th-btns { display: flex; gap: 4px; }
.th-btns button, .th-beat {
  width: 28px; height: 28px; border-radius: 8px; background: var(--panel3); font-size: 11px; font-weight: 800;
  display: grid; place-items: center; color: var(--muted);
}
.th-btns .ic { width: 15px; height: 15px; }
.th-beat { background: transparent; color: var(--c); }
.th-arm.on { background: var(--rec); color: #fff; }
.th-m.on { background: #f59e0b; color: #111; }
.th-s.on { background: #3b82f6; color: #fff; }
.th-add {
  display: flex; align-items: center; gap: 6px; margin: 10px 8px; height: 38px; padding: 0 10px;
  border-radius: 10px; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; font-weight: 650;
}
.th-add .ic { width: 16px; height: 16px; }

.tap-to-play { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(11,11,15,0.55); padding: 24px; }
.tap-to-play .big-btn { max-width: 320px; }

.toolbar {
  display: flex; gap: 2px; overflow-x: auto; padding: 6px 6px; background: var(--panel);
  border-top: 1px solid var(--line); scrollbar-width: none; min-height: 64px;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool {
  flex: 1 0 auto; min-width: 56px; height: 52px; border-radius: 12px; padding: 0 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; font-weight: 650; color: var(--muted);
}
.tool .ic { width: 21px; height: 21px; color: var(--text); }
.tool:active:not(:disabled) { background: var(--panel3); }
.tool.danger .ic { color: #ff6b81; }
.tool-sep { width: 1px; background: var(--line); margin: 8px 2px; flex: none; }

.transport {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 8px 14px calc(var(--safe-bottom) + 10px); background: var(--panel2); border-top: 1px solid var(--line);
}
.time { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
#timeNow { font-size: 20px; font-weight: 750; letter-spacing: -0.01em; }
#timeTotal { font-size: 12px; color: var(--muted); }
.transport-btns { display: flex; align-items: center; gap: 14px; }
.t-btn { width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; background: var(--panel3); }
.t-btn .ic { width: 24px; height: 24px; }
.t-btn.play { width: 58px; height: 58px; background: var(--text); color: #111; }
.t-btn.play .ic { width: 26px; height: 26px; }
.t-btn.rec { width: 74px; height: 74px; background: #2b1218; border: 3px solid rgba(255,51,85,0.55); }
.rec-dot { width: 40px; height: 40px; border-radius: 50%; background: var(--rec); transition: all 0.18s ease; box-shadow: 0 0 18px rgba(255,51,85,0.55); }
.t-btn.rec.on { border-color: var(--rec); animation: recpulse 1.2s ease-in-out infinite; }
.t-btn.rec.on .rec-dot { width: 26px; height: 26px; border-radius: 7px; }
.t-btn.rec.ready { animation: readypulse 1.6s ease-in-out infinite; }
.t-btn:active { transform: scale(0.95); }
@keyframes recpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,51,85,0.5); } 50% { box-shadow: 0 0 0 10px rgba(255,51,85,0); } }
@keyframes readypulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,51,85,0.35); } 50% { box-shadow: 0 0 0 8px rgba(255,51,85,0); } }

.meter-wrap { justify-self: end; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.meter { width: 10px; height: 44px; border-radius: 5px; background: var(--panel3); position: relative; overflow: hidden; }
.meter i { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; background: linear-gradient(0deg, #34d399 0%, #34d399 60%, #fbbf24 80%, #ff3355 100%); background-size: 100% 44px; background-position: bottom; transition: height 0.05s linear; }
.meter-label { font-size: 9px; font-weight: 800; color: var(--faint); letter-spacing: 0.08em; }

body.recording .toolbar .tool, body.recording .studio-head .icon-btn, body.recording .th button { pointer-events: none; opacity: 0.35; }

/* ---------------- Loader ---------------- */
.loader { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(5,5,8,0.82); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 24px; }
.loader-card { width: 100%; max-width: 360px; background: var(--panel); border-radius: 22px; padding: 18px; display: flex; flex-direction: column; gap: 10px; align-items: stretch; text-align: center; box-shadow: 0 30px 60px -20px #000; }
.loader-thumb { position: relative; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: var(--panel3); }
.loader-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.loader-thumb img:not([src]), .loader-thumb img[src=""] { display: none; }
.loader-eq { position: absolute; inset: auto 0 0 0; height: 48px; display: flex; gap: 5px; align-items: flex-end; justify-content: center; padding-bottom: 10px; background: linear-gradient(transparent, rgba(0,0,0,0.6)); }
.loader-eq i { width: 6px; border-radius: 3px; background: #fff; animation: eq 0.9s ease-in-out infinite; }
.loader-eq i:nth-child(2) { animation-delay: -0.2s; } .loader-eq i:nth-child(3) { animation-delay: -0.45s; }
.loader-eq i:nth-child(4) { animation-delay: -0.1s; } .loader-eq i:nth-child(5) { animation-delay: -0.6s; }
@keyframes eq { 0%, 100% { height: 6px; } 50% { height: 26px; } }
.loader-title { font-weight: 750; font-size: 16px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.loader-stage { color: var(--muted); font-size: 13.5px; min-height: 19px; }
.progress { height: 6px; border-radius: 3px; background: var(--panel3); overflow: hidden; position: relative; }
.progress i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.15s; }
.progress.indeterminate i { width: 35%; animation: indet 1.1s ease-in-out infinite; }
@keyframes indet { 0% { left: -35%; } 100% { left: 100%; } }

/* ---------------- Sheets ---------------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.5); opacity: 0; transition: opacity 0.18s; }
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; max-height: 86dvh; overflow-y: auto;
  margin: 0 auto; max-width: 560px; background: var(--panel); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 18px); transform: translateY(100%); transition: transform 0.22s cubic-bezier(.2,.8,.2,1);
  border: 1px solid var(--line); border-bottom: 0;
}
.sheet.show { transform: none; }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--panel3); margin: 2px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-section { padding: 10px 0; border-top: 1px solid var(--line); }
.sheet-section:first-of-type { border-top: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.field label, .field .lbl { font-size: 13px; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; }
.field .val { color: var(--text); font-variant-numeric: tabular-nums; }
.field input[type=text], .field input[type=url], .field input[type=password] {
  height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 0 12px; font-size: 16px;
}
.field small { color: var(--faint); font-size: 12px; }
input[type=range] { width: 100%; height: 32px; accent-color: var(--accent); background: transparent; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.toggle-row .tl { display: flex; flex-direction: column; }
.toggle-row .tl b { font-weight: 600; font-size: 15px; }
.toggle-row .tl small { color: var(--faint); font-size: 12.5px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--panel3); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.menu-list { display: flex; flex-direction: column; }
.menu-item { display: flex; align-items: center; gap: 14px; padding: 13px 4px; text-align: left; font-size: 15.5px; font-weight: 550; border-radius: 10px; width: 100%; }
.menu-item:active { background: var(--panel2); }
.menu-item .ic { color: var(--muted); }
.menu-item small { display: block; color: var(--faint); font-size: 12.5px; font-weight: 500; }
.menu-item.danger { color: #ff6b81; }
.menu-item.danger .ic { color: #ff6b81; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn { flex: 1; height: 48px; border-radius: 13px; background: var(--panel3); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #3a1219; color: #ff6b81; }
.btn .ic { width: 20px; height: 20px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.45; }
.note code { background: var(--panel3); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 12px); transform: translate(-50%, -140%);
  z-index: 80; max-width: min(92vw, 460px); padding: 11px 16px; border-radius: 14px;
  background: #f4f4f7; color: #111; font-weight: 600; font-size: 14px; box-shadow: 0 12px 30px -10px #000;
  transition: transform 0.22s cubic-bezier(.2,.8,.2,1); pointer-events: none; text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: #ff3355; color: #fff; }

/* ---------------- Larger screens / landscape ---------------- */
@media (min-width: 760px) {
  :root { --hw: 150px; }
  .th-name { font-size: 13.5px; }
  .tool { min-width: 68px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .toolbar { min-height: 52px; padding: 3px 6px; }
  .tool { height: 44px; font-size: 0; gap: 0; }
  .transport { padding-top: 4px; padding-bottom: calc(var(--safe-bottom) + 4px); }
  .t-btn.rec { width: 58px; height: 58px; }
  .rec-dot { width: 30px; height: 30px; }
  .t-btn.play { width: 48px; height: 48px; }
  .grab h1 { font-size: 26px; }
}

.card-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; text-align: left; }

/* ---------------- Accounts ---------------- */
#auth { overflow-y: auto; }
.auth-wrap { width: 100%; max-width: 400px; margin: 0 auto; padding: calc(var(--safe-top) + 40px) 20px calc(var(--safe-bottom) + 32px); display: flex; flex-direction: column; gap: 14px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; font-weight: 850; font-size: 26px; letter-spacing: -0.02em; }
.auth-brand img { border-radius: 16px; }
.auth-tag { text-align: center; color: var(--muted); margin: 0 0 8px; line-height: 1.45; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel); border-radius: 14px; padding: 4px; }
.auth-tabs button { height: 40px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.auth-tabs button[aria-selected="true"] { background: var(--panel3); color: var(--text); }
.auth-form { display: flex; flex-direction: column; gap: 2px; }
.auth-form input { height: 50px; border-radius: 13px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 0 14px; font-size: 16px; }
.auth-form input:focus { border-color: #8ab4ff; outline: none; }
.auth-form .big-btn { margin-top: 10px; }
.auth-form .big-btn:disabled { opacity: 0.6; }
.auth-error { color: #ff6b81; font-size: 14px; font-weight: 600; min-height: 20px; margin: 4px 2px 0; }
.auth-foot { text-align: center; }
#auth[data-tab="login"] .signup-only, #auth[data-tab="signup"] .login-only { display: none; }

.avatar-btn { width: 36px; height: 36px; border-radius: 50%; margin-left: 4px; background: linear-gradient(135deg, #ff4766, #a78bfa); color: #fff; font-weight: 800; font-size: 15px; display: grid; place-items: center; }
.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: middle; }
.sync-dot.syncing { background: #60a5fa; animation: blink 1s infinite; }
.sync-dot.offline, .sync-dot.error { background: var(--warn); }
@keyframes blink { 50% { opacity: 0.3; } }
.acct-head { display: flex; align-items: center; gap: 12px; padding: 4px 0 10px; }
.acct-head .avatar-btn { width: 48px; height: 48px; font-size: 20px; margin: 0; }
.acct-head b { display: block; font-size: 16px; }
.acct-head small { color: var(--muted); }
.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 99px; background: var(--panel3); color: var(--muted); margin-left: 6px; vertical-align: middle; text-transform: uppercase; letter-spacing: 0.04em; }
.meterbar { height: 8px; border-radius: 4px; background: var(--panel3); overflow: hidden; margin-top: 6px; }
.meterbar i { display: block; height: 100%; background: linear-gradient(90deg, #34d399, #fbbf24); }
.member { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.member:first-child { border-top: 0; }
.member .mi { flex: 1; min-width: 0; }
.member .mi b { display: block; font-size: 14.5px; }
.member .mi small { color: var(--muted); font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .mbtn { height: 34px; padding: 0 10px; border-radius: 10px; background: var(--panel3); font-size: 12.5px; font-weight: 700; }
.member .mbtn.danger { color: #ff6b81; }
.code-box { font: 700 20px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.06em; padding: 14px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); text-align: center; -webkit-user-select: all; user-select: all; }
