/* Framewave: the page around the canvas (preview on top, timeline at the bottom, the
   transport bar between them). Tokens and components are Tailwave's. */

/* ---- Tokens ------------------------------------------------------------- */

:root {
  color-scheme: light;
  --bg: #eef0f6;
  --surface: #ffffff;
  --surface-2: #f5f6fa;
  --surface-3: #e5e8f0;
  --hover: rgba(15, 23, 42, 0.05);
  --press: rgba(15, 23, 42, 0.09);
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.15);
  --text: #0f172a;
  --text-2: #4f5a70;
  --text-3: #636978;
  --accent-a: #0891b2;
  --accent-b: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.1);
  --on-accent: #ffffff;
  --focus: rgba(124, 58, 237, 0.5);
  --ok: #047b56;
  --warn: #a35905;
  --danger: #dc2626;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.05);
  --shadow-2: 0 2px 6px rgba(15, 23, 42, 0.08), 0 24px 48px rgba(15, 23, 42, 0.14);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  /* Must match View::kTimeline and View::kTransport (src/view/view.h). */
  --timeline: 168px;
  --transport: 60px;
  --bar: 52px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0c11;
    --surface: #12151c;
    --surface-2: #171b24;
    --surface-3: #242a37;
    --hover: rgba(255, 255, 255, 0.05);
    --press: rgba(255, 255, 255, 0.09);
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.13);
    --text: #e9ecf3;
    --text-2: #a0a8bc;
    --text-3: #848b9c;
    --accent-a: #22d3ee;
    --accent-b: #a78bfa;
    --accent-soft: rgba(167, 139, 250, 0.14);
    --on-accent: #0a0c11;
    --focus: rgba(167, 139, 250, 0.6);
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.4), 0 28px 56px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0c11;
  --surface: #12151c;
  --surface-2: #171b24;
  --surface-3: #242a37;
  --hover: rgba(255, 255, 255, 0.05);
  --press: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text: #e9ecf3;
  --text-2: #a0a8bc;
  --text-3: #848b9c;
  --accent-a: #22d3ee;
  --accent-b: #a78bfa;
  --accent-soft: rgba(167, 139, 250, 0.14);
  --on-accent: #0a0c11;
  --focus: rgba(167, 139, 250, 0.6);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.4), 0 28px 56px rgba(0, 0, 0, 0.5);
}

/* ---- Base --------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

button, select, input { font: inherit; color: inherit; }
input { user-select: text; -webkit-user-select: text; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

svg.i {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Layout ------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-rows: var(--bar) 1fr;
  grid-template-columns: minmax(0, 1fr); /* never wider than the window */
  height: 100%;
}

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 15px;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand img { display: block; border-radius: 7px; }

.file {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text-2);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file small {
  margin-left: 10px;
  color: var(--text-3);
  font-weight: 400;
}

.bar-end { display: flex; align-items: center; gap: 6px; }

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.app[data-screen="start"] #canvas,
.app[data-screen="start"] .transport,
.app[data-screen="boot"] .transport { visibility: hidden; }

/* ---- Buttons ------------------------------------------------------------ */

.icon-btn, .tool {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.icon-btn:hover:not(:disabled), .tool:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-btn:active:not(:disabled), .tool:active:not(:disabled) { background: var(--press); }
.tool:disabled { color: var(--text-3); opacity: 0.45; cursor: default; }

.tool.play {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}

.tool.play:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: var(--on-accent);
  filter: brightness(1.08);
}

.tool.mark { color: var(--accent-b); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, filter 0.12s, transform 0.08s;
}

.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  filter: brightness(1.08);
}

/* Not yet usable: a plain button with a readable label, not a faded gradient. */
.btn.primary:disabled {
  opacity: 1;
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  box-shadow: none;
}

.btn.ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn.big { height: 46px; padding: 0 22px; border-radius: 12px; font-size: 14.5px; }

/* ---- Start screen -------------------------------------------------------- */

.start {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(700px 400px at 20% 10%, color-mix(in srgb, var(--accent-b) 10%, transparent), transparent 70%),
    radial-gradient(700px 400px at 85% 90%, color-mix(in srgb, var(--accent-a) 9%, transparent), transparent 70%),
    var(--bg);
}

.app:not([data-screen="start"]) .start { display: none; }

.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 520px;
  text-align: center;
}

.start-logo { border-radius: 16px; box-shadow: var(--shadow-1); }
.start h1 { margin: 6px 0 0; font-size: 30px; letter-spacing: -0.025em; }
.start-lead { margin: 0 0 8px; color: var(--text-2); font-size: 15px; line-height: 1.55; }
.hint { margin: 0; color: var(--text-3); font-size: 12.5px; }

.recent { width: 100%; margin-top: 18px; text-align: left; }
.recent h2 { margin: 0 0 6px; color: var(--text-3); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }
.recent ul { margin: 0; padding: 0; list-style: none; }

.recent button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  margin-bottom: 6px;
}

.recent button:hover { border-color: var(--border-strong); background: var(--surface-2); }
.recent small { color: var(--text-3); }

body.dragging .stage::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px dashed var(--accent-b);
  border-radius: 16px;
  background: var(--accent-soft);
  pointer-events: none;
}

/* ---- Loading, notice ----------------------------------------------------- */

.loading {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: var(--text-2);
}

.spin {
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent-a);
  border-right-color: var(--accent-b);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.notice {
  position: absolute;
  left: 50%;
  bottom: calc(var(--timeline) + var(--transport) + 16px);
  z-index: 4;
  max-width: min(620px, calc(100% - 32px));
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border));
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: var(--text-2);
  text-align: center;
}

.notice.instead {
  top: calc((100% - var(--timeline) - var(--transport)) / 2);
  bottom: auto;
  transform: translate(-50%, -50%);
  padding: 18px 22px;
  font-size: 14px;
  border-color: var(--border-strong);
}

/* ---- Transport ------------------------------------------------------------ */

.transport {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--timeline);
  height: var(--transport);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
  scrollbar-width: none;
}

.transport::-webkit-scrollbar { display: none; }
.transport > * { flex-shrink: 0; }

.group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}

.group:last-child { border-right: 0; }

.clock {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
  font: 600 15px var(--mono);
  font-variant-numeric: tabular-nums;
}

.clock .of, .clock #timeAll { color: var(--text-3); font-size: 12.5px; font-weight: 500; }

.cut { gap: 6px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 1px;
  color: var(--text-3);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.time-input {
  width: 108px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font: 12.5px var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
}

.time-input:focus { border-color: var(--accent-b); outline: none; background: var(--surface); }
.time-input.bad { border-color: var(--danger); }

.vol {
  width: 84px;
  accent-color: var(--accent-b);
  cursor: pointer;
}

.length {
  min-width: 70px;
  color: var(--text-2);
  font: 12.5px var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ---- Dialogs ------------------------------------------------------------ */

.dialog {
  width: min(520px, 100vw - 32px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
}

.dialog[open] { animation: pop 0.16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.99); } }
.dialog::backdrop { background: rgba(5, 7, 12, 0.45); backdrop-filter: blur(2px); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0 22px;
}

.dialog-head h2 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 22px 20px;
}

.dialog-body p { margin: 0; color: var(--text-2); }

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 18px 18px;
}

.seg {
  display: flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
}

.seg input { position: absolute; opacity: 0; pointer-events: none; }

.seg label {
  flex: 1;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.seg label:hover { color: var(--text); }
.seg input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.seg input:focus-visible + label { outline: 2px solid var(--focus); }
.seg input:disabled + label { opacity: 0.4; cursor: default; }

.explain { min-height: 40px; line-height: 1.5; }
.explain b { color: var(--text); }
.explain .warn { color: var(--warn); }

.row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 12px;
}

.label { color: var(--text-2); font-weight: 600; }

/* (not input[type="text"]: the release build's minified page drops that default) */
.row select, .row input:not([type="checkbox"]) {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-2);
}

.check { display: flex; align-items: center; gap: 8px; color: var(--text-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent-b); }
.note { color: var(--text-3) !important; font-size: 12.5px; min-height: 18px; }

.progress {
  height: 10px;
  overflow: hidden;
  border-radius: 5px;
  background: var(--surface-3);
}

.progress i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b), var(--accent-a));
  background-size: 200% 100%;
  animation: sheen 1.4s linear infinite;
  transition: width 0.15s;
}

@keyframes sheen { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.done-line { display: flex; align-items: center; gap: 10px; color: var(--text) !important; font-size: 15px; font-weight: 600; }
.done-line svg.i { color: var(--ok); width: 22px; height: 22px; }

.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 5px 0; border-bottom: 1px solid var(--border); color: var(--text-2); }
.keys td:last-child { text-align: right; }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font: 11.5px var(--mono);
  text-align: center;
}

.crash-details {
  max-height: 200px;
  margin: 8px 0 0;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-2);
  font: 11.5px/1.5 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}

/* ---- Tooltip and toasts ------------------------------------------------- */

.tip {
  position: fixed;
  z-index: 60;
  max-width: 280px;
  padding: 5px 9px;
  border-radius: 7px;
  background: #0f172a;
  color: #e9ecf3;
  font-size: 12px;
  pointer-events: none;
  box-shadow: var(--shadow-1);
}

.tip kbd { margin-left: 6px; border-color: rgba(255, 255, 255, 0.2); background: rgba(255, 255, 255, 0.08); color: #e9ecf3; }

.toasts {
  position: fixed;
  right: 16px;
  top: calc(var(--bar) + 12px);
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}

.toast.leaving { opacity: 0; transform: translateY(-6px); transition: opacity 0.2s, transform 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
.toast .dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--accent-a); }
.toast.ok .dot { background: var(--ok); }
.toast.warn .dot { background: var(--warn); }
.toast.error .dot { background: var(--danger); }
.toast .btn { height: 28px; padding: 0 10px; margin-left: 4px; }

/* ---- Narrow windows and touch -------------------------------------------- */

@media (max-width: 760px) {
  .bar { gap: 8px; padding: 0 8px 0 10px; }
  .bar .label, .brand b, .file small { display: none; }
  .bar .btn { padding: 0 10px; }
  .time-input { width: 96px; }
}

/* Phones: the transport on two rows (playback, then the cut), the rest scrolls. */
@media (max-width: 640px) {
  :root { --transport: 104px; --timeline: 168px; }
  .transport {
    flex-wrap: wrap;
    align-content: center;
    row-gap: 4px;
    column-gap: 8px;
    padding: 4px 8px;
    overflow-x: hidden;
  }
  .transport .group { padding-right: 4px; border-right: 0; }
  /* A phone's own buttons do the volume; pinch zooms the timeline. */
  .transport [data-cmd="home"], .transport [data-cmd="end"], .transport [data-cmd="redo"],
  .transport [data-cmd^="view."], .transport .group:has(#volume) { display: none; }
  .clock { border-right: 0; padding-right: 4px; font-size: 14px; }
  .clock .of, .clock #timeAll { display: none; }
  .cut { order: 9; width: 100%; justify-content: space-between; }
  .field span { display: none; }
  .time-input { width: 92px; }
  #keysBtn { display: none; }
}

@media (pointer: coarse) {
  .icon-btn, .tool { width: 42px; height: 42px; }
  .btn { height: 42px; }
  .seg label { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .spin, .progress i { animation: none; }
  .dialog[open], .toast { animation: none; }
}
