/* Loopscribe — dark, quiet, warm. The interface should disappear behind the ears. */

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  --bg: #0c1015;
  --panel: #10141a;
  --panel-2: #161b23;
  --line: #232a34;
  --fg: #e8eef6;
  --dim: #8b97a6;
  --ink: #ffb254;
  --live: #78dcff;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#app { height: 100dvh; display: flex; flex-direction: column; }

button {
  font: inherit; color: var(--fg);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; touch-action: manipulation; user-select: none;
}
button:hover { border-color: #35404e; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: default; }
button.big { padding: 9px 16px; font-weight: 600; }
button.mini { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
button.icon { width: 32px; padding: 5px 0; text-align: center; }
button.ghost { background: none; border: none; color: var(--dim); text-decoration: underline; }
button.tgl { color: var(--dim); }
button.tgl.on { color: var(--ink); border-color: rgba(255,178,84,0.45); }
#tapBtn.hit { background: var(--ink); color: #1a1206; }
.hint { color: var(--ink); border-color: rgba(255,178,84,0.45); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

input, select {
  font: inherit; color: var(--fg);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; outline: none;
}
input:focus, select:focus { border-color: rgba(255,178,84,0.5); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.dim { color: var(--dim); }
.spacer { flex: 1; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  position: relative; flex: none;
}
.logo { font-weight: 700; letter-spacing: 0.02em; }
.logo span { color: var(--ink); }
#title {
  flex: 1; min-width: 0; background: none; border-color: transparent;
  color: var(--dim); font-size: 13px;
}
#title:focus { color: var(--fg); border-color: var(--line); }
header.hide-title #title { visibility: hidden; }
#sharePop {
  position: absolute; right: 10px; top: 46px; z-index: 40;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 200px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
#sharePop button { background: none; border: none; text-align: left; padding: 9px 10px; border-radius: 6px; }
#sharePop button:hover { background: rgba(255,255,255,0.06); }
#sharePop hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- home ---------- */
#home { flex: 1; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px; }
.hero { max-width: 560px; text-align: center; }
.hero h1 { font-size: clamp(26px, 5vw, 38px); margin-bottom: 14px; }
.hero p { color: var(--dim); margin-bottom: 22px; }
.hero em { color: var(--ink); font-style: normal; }
.urlrow { display: flex; gap: 8px; margin-bottom: 10px; }
.urlrow input { flex: 1; padding: 12px 14px; font-size: 15px; }
.urlrow button { padding: 12px 22px; font-weight: 600; background: var(--ink); color: #1a1206; border: none; }
.fine { font-size: 12px; margin-top: 26px; }
#savedList { margin-top: 26px; text-align: left; }
.saved-h { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.saved-row { display: flex; gap: 6px; margin-bottom: 6px; }
.saved-open { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-del { flex: none; width: 36px; color: var(--dim); }

/* ---------- studio ---------- */
#studio { flex: 1; min-height: 0; display: flex; flex-direction: column; }

#videoWrap {
  flex: none; background: #000;
  height: min(30dvh, calc(56.25vw)); transition: height 0.25s ease;
  overflow: hidden;
}
#videoWrap.collapsed { height: 0; }
#videoWrap iframe, #yt { width: 100%; height: 100%; }
.yt-fail { color: var(--dim); display: grid; place-items: center; height: 100%; padding: 16px; text-align: center; }

#timelineWrap { flex: none; height: 88px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#timelineWrap canvas { display: block; touch-action: none; }

/* ---------- saved sections ---------- */
#marksRow {
  flex: none; display: flex; gap: 6px; align-items: center;
  padding: 6px 10px 0; overflow-x: auto; scrollbar-width: none;
}
#marksRow::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 6px 4px 12px; border-radius: 999px; font-size: 12px;
  color: var(--dim);
}
.chip.active { color: var(--ink); border-color: rgba(255,178,84,0.5); }
.chip.add { color: var(--live); border-style: dashed; padding: 4px 12px; }
.chip-x {
  width: 17px; height: 17px; line-height: 15px; text-align: center;
  border-radius: 50%; font-size: 12px; color: var(--dim);
}
.chip-x:hover { background: rgba(255,255,255,0.1); color: var(--fg); }
.chip-edit {
  width: 90px; padding: 1px 6px; font-size: 12px; border-radius: 999px;
  background: none; border-color: transparent;
}

#transport {
  flex: none; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 10px;
}
#timeRead { color: var(--dim); min-width: 52px; text-align: center; }
#bpmInp { width: 70px; text-align: center; }
#bpmInp::-webkit-inner-spin-button { display: none; }
#meterSel { padding: 7px 6px; }

/* ---------- chord lane ---------- */
#chordLane {
  flex: none; position: relative; height: 44px; margin: 0 0 1px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.lane-hint { color: var(--dim); font-size: 12px; line-height: 44px; padding-left: 46px; opacity: 0.7; }
.chord-cell {
  position: absolute; top: 0; bottom: 0;
  border-left: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-evenly;
  cursor: text; overflow: hidden;
}
.chord-cell:hover { background: rgba(255,255,255,0.03); }
.chord { font-size: 15px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.chord-input {
  width: 92%; padding: 4px 6px; text-align: center; font-size: 14px;
  background: var(--panel-2);
}

/* ---------- sketch ---------- */
#sketchBar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; font-size: 12px; background: var(--panel); border-top: 1px solid var(--line);
}
#recDot { width: 9px; height: 9px; border-radius: 50%; background: #3a4450; flex: none; }
#recDot.live { background: #ff5d5d; box-shadow: 0 0 8px rgba(255,93,93,0.7); animation: pulse 1.2s infinite; }

#rollWrap { flex: 1; min-height: 120px; border-top: 1px solid var(--line); }
#rollWrap canvas { display: block; touch-action: none; }
.ink { color: var(--ink); }

/* ---------- piano ---------- */
#pianoRow {
  flex: none; display: flex; align-items: stretch; gap: 4px;
  height: 96px; padding: 6px; background: var(--panel); border-top: 1px solid var(--line);
  position: relative;
}
#octDown, #octUp { flex: none; width: 30px; padding: 0; color: var(--dim); }
#piano { flex: 1; position: relative; touch-action: none; }
.pk { position: absolute; top: 0; bottom: 0; border-radius: 0 0 5px 5px; }
.pk.white { background: #e8eef6; border: 1px solid #9aa5b1; z-index: 1; }
.pk.black { background: #1c222b; border: 1px solid #000; height: 62%; z-index: 2; }
.pk.white.down { background: var(--ink); }
.pk.black.down { background: #b97722; }
.pk.white::after {
  content: attr(data-label); position: absolute; bottom: 3px; left: 0; right: 0;
  text-align: center; font-size: 9px; color: #6a7683;
}
#midiDot {
  position: absolute; right: 12px; top: -7px;
  width: 8px; height: 8px; border-radius: 50%; background: #3a4450;
}
#midiDot.on { background: #4cd977; box-shadow: 0 0 6px rgba(76,217,119,0.8); }

/* ---------- help ---------- */
#help {
  position: fixed; inset: 0; z-index: 50; background: rgba(5,8,12,0.72);
  display: grid; place-items: center; padding: 16px;
}
.help-card {
  position: relative; max-width: 620px; max-height: 86dvh; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 24px;
}
.help-card h2 { font-size: 15px; margin: 14px 0 8px; color: var(--ink); }
.help-card h2:first-of-type { margin-top: 0; }
.help-card ol { padding-left: 20px; }
.help-card li { margin-bottom: 8px; color: var(--dim); }
.help-card li b { color: var(--fg); }
.help-card table td { padding: 3px 14px 3px 0; color: var(--dim); }
.help-card table td.mono { color: var(--fg); white-space: nowrap; }
#helpClose { position: absolute; top: 10px; right: 10px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 116px; transform: translate(-50%, 12px);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 16px; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 60;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  #transport { gap: 5px; padding: 6px; }
  #transport button { padding: 8px 10px; }
  #timeRead { min-width: 46px; font-size: 12px; }
  #videoWrap { height: min(26dvh, 56.25vw); }
  #timelineWrap { height: 76px; }
  #pianoRow { height: 88px; }
  .logo { font-size: 13px; }
}
