/* falling UI — warm, restrained Claude-style aesthetic. No build step. */

:root {
  --bg: #f5f4ee;
  --surface: #fffdf9;
  --surface-2: #faf8f2;
  --ink: #1f1e1c;
  --ink-2: #57534e;
  --ink-3: #8a847c;
  --line: #e7e3da;
  --line-2: #d9d4c8;
  --accent: #c45f3c;
  --accent-ink: #fff;
  --accent-soft: #f3e1d8;
  --ok: #4f7a52;
  --err: #b3402f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 30, 28, 0.04), 0 6px 24px rgba(31, 30, 28, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1916;
    --surface: #232220;
    --surface-2: #2a2825;
    --ink: #f3f1ec;
    --ink-2: #c6c1b8;
    --ink-3: #8f897f;
    --line: #34322e;
    --line-2: #413e39;
    --accent: #e07a55;
    --accent-soft: #3a2c25;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); font-size: 0.85em; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  max-width: 1180px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(160deg, var(--accent), #e6a07c);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  position: relative; flex: none;
}
.logo::after {
  content: ""; position: absolute; left: 9px; top: 7px;
  width: 5px; height: 14px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 8px 4px 0 rgba(255, 255, 255, 0.7), 16px -1px 0 rgba(255, 255, 255, 0.85);
}
h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
.tagline { margin: 0; color: var(--ink-3); font-size: 0.82rem; }
.badge {
  font-family: var(--mono); font-size: 0.72rem; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 999px;
}

/* Layout */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 20px;
  max-width: 1180px;
  margin: 8px auto 0;
  padding: 0 28px;
}
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); margin: 0 0 12px; }
.card h2.mt { margin-top: 22px; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.label { font-size: 0.85rem; color: var(--ink-2); font-weight: 550; }
.label em { font-style: normal; color: var(--ink-3); font-weight: 400; }

input[type="file"], input[type="number"], select {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  padding: 9px 11px;
  width: 100%;
}
input[type="number"], select { height: 40px; }
input[type="file"] { padding: 8px; font-size: 0.85rem; }
input[type="file"]::file-selector-button {
  font: inherit; font-size: 0.82rem;
  margin-right: 10px; padding: 6px 11px;
  border: 1px solid var(--line-2); border-radius: 7px;
  background: var(--surface); color: var(--ink); cursor: pointer;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

/* Info "?" affordance with an accessible tooltip (native `title` is set as a
   fallback in app.js, so help shows even if this CSS bubble is unavailable). */
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 4px; vertical-align: middle;
  border: 1px solid var(--line-2); border-radius: 50%;
  color: var(--ink-3); font-size: 10px; font-weight: 700; font-style: normal;
  cursor: help; position: relative; user-select: none;
}
.info:hover, .info:focus-visible { color: var(--accent); border-color: var(--accent); outline: none; }
.info::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: calc(100% + 7px); z-index: 20;
  width: max-content; max-width: 230px;
  background: var(--ink); color: var(--bg);
  font: 400 0.75rem/1.4 var(--font); text-align: left; white-space: normal;
  padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-3px);
  transition: opacity .12s ease, transform .12s ease; pointer-events: none;
}
.info:hover::after, .info:focus::after { opacity: 1; visibility: visible; transform: translateY(0); }

/* Live theme/renderer preview */
.preview {
  position: relative; margin: 14px 0 0; padding: 0;
  border-radius: 11px; overflow: hidden; border: 1px solid var(--line);
  background: var(--surface-2); aspect-ratio: 16 / 9;
}
.preview img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  background: #000; opacity: 0; transition: opacity .2s ease;
}
.preview img.loaded { opacity: 1; }
.preview-cap {
  position: absolute; left: 8px; bottom: 8px;
  font-size: 0.68rem; letter-spacing: 0.04em; text-transform: uppercase;
  color: #fff; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(2px);
  padding: 3px 8px; border-radius: 999px; pointer-events: none;
}

.advanced { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 4px; }
.advanced summary {
  cursor: pointer; font-size: 0.85rem; color: var(--ink-2);
  padding: 12px 0 6px; font-weight: 550; list-style-position: inside;
}
.checks { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 0.85rem; color: var(--ink-2); }
.check input { width: auto; }

/* Buttons */
.primary, .ghost {
  font: inherit; font-weight: 600; font-size: 0.95rem;
  border-radius: 10px; padding: 11px 18px; cursor: pointer;
  border: 1px solid transparent; text-decoration: none; display: inline-block; text-align: center;
}
.primary { background: var(--accent); color: var(--accent-ink); width: 100%; margin-top: 18px; }
.primary:hover { filter: brightness(1.05); }
.primary:disabled { background: var(--line-2); color: var(--ink-3); cursor: not-allowed; }
.ghost { background: transparent; border-color: var(--line-2); color: var(--ink); }
.ghost:hover { background: var(--surface-2); }
.hint { font-size: 0.8rem; color: var(--ink-3); margin: 10px 0 0; text-align: center; }

/* Output */
.output { display: flex; flex-direction: column; }
.placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--ink-3); text-align: center;
  border: 1.5px dashed var(--line-2); border-radius: 12px; padding: 48px 20px; min-height: 280px;
}
.placeholder-icon {
  width: 46px; height: 46px; border-radius: 11px;
  background: var(--accent-soft);
  position: relative;
}
.placeholder-icon::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 0; height: 0; border-left: 14px solid var(--accent);
  border-top: 9px solid transparent; border-bottom: 9px solid transparent;
  left: 4px;
}

.progress { padding: 8px 2px; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
#phase { font-weight: 600; }
.bar { height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #e6a07c);
  border-radius: 999px; transition: width 0.25s ease;
}
.sub { color: var(--ink-3); margin: 8px 0 0; }

#result video {
  width: 100%; border-radius: 12px; background: #000;
  border: 1px solid var(--line); display: block;
}
.result-actions { display: flex; gap: 10px; margin-top: 14px; }
.result-actions .primary { margin-top: 0; }

.error {
  background: color-mix(in srgb, var(--err) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--err) 35%, var(--line));
  color: var(--err); border-radius: 10px; padding: 12px 14px; font-size: 0.88rem;
  white-space: pre-wrap; word-break: break-word;
}

/* MIDI source mode tab toggle */
.source-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--ink-2);
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab:hover { background: var(--surface); color: var(--ink); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(31, 30, 28, 0.08); }

/* Notice (e.g. "Web MIDI not supported") */
.notice {
  font-size: 0.85rem;
  color: var(--err);
  background: color-mix(in srgb, var(--err) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--err) 30%, var(--line));
  border-radius: 9px;
  padding: 10px 14px;
  margin-bottom: 12px;
}

/* Record / Stop button pair */
.rec-controls { display: flex; gap: 10px; margin-bottom: 12px; }
.rec-btn {
  flex: 1;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 9px;
  padding: 10px 16px;
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.rec-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#recStart:not(:disabled) { border-color: var(--accent); color: var(--accent); }
#recStart:not(:disabled):hover { background: var(--accent-soft); }
#recStop:not(:disabled) { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#recStop:not(:disabled):hover { filter: brightness(1.05); }

/* Live stats bar */
.rec-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--ink-2);
}
.stat-item { display: flex; align-items: center; gap: 6px; }
.stat-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); flex: none; }
.stat-dot.live { background: var(--err); animation: rec-pulse 1s infinite; }
@keyframes rec-pulse { 50% { opacity: 0.3; } }

/* Download .mid action row */
.rec-actions { display: flex; gap: 10px; margin-top: 4px; }
.rec-actions .ghost { flex: 1; }
.ghost.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.ghost.danger:hover { background: color-mix(in srgb, var(--err) 8%, var(--surface)); }
#recAudioLabel { font-family: var(--mono); font-size: 0.8rem; }

/* Additional download chips below the rendered video */
.result-downloads { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.dl-chip { font-size: 0.82rem; padding: 7px 14px; border-radius: 8px; text-decoration: none; }

.foot { text-align: center; color: var(--ink-3); font-size: 0.78rem; padding: 28px; }
