/* Shared design tokens and components for both layouts. */

:root {
  --bg: #0f0f12;
  --panel: #18181d;
  --panel-2: #222229;
  --panel-3: #2c2c35;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #f4f4f6;
  --dim: #a3a3ad;
  --faint: #6e6e78;
  --accent: #ffc531;
  --accent-ink: #1d1600;
  --accent-soft: rgba(255, 197, 49, 0.16);
  --danger: #ff5a5f;
  --clip: #3557d6;
  --clip-2: #4a6cf0;
  --title: #8a56f0;
  --audio: #1f9d63;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body { overscroll-behavior: none; }
#app { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
img { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon svg { display: block; }

/* ---------- boot ---------- */
.boot { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }
.boot-logo, .brand-mark {
  width: 64px; height: 64px; border-radius: 18px;
  background: url("../icons/favicon.svg") center / cover no-repeat;
}
.boot-msg { color: var(--dim); max-width: 32em; }
.boot-logo { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.7; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 7px 14px; border-radius: 10px;
  border: 1px solid transparent; background: var(--panel-3); color: var(--text);
  font-weight: 600; white-space: nowrap; transition: background 0.15s, transform 0.08s;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:hover:not(:disabled) { background: #383843; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #ffd35c; }
.btn.ghost { background: transparent; border-color: var(--line-2); }
.btn.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost.danger { background: transparent; color: var(--danger); border-color: rgba(255, 90, 95, 0.4); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.big { min-height: 50px; font-size: 16px; border-radius: 14px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-row.end { justify-content: flex-end; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 6px; border-radius: 10px;
  border: 0; background: transparent; color: var(--text); touch-action: manipulation;
}
.icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.icon-btn.danger { color: var(--danger); }

/* ---------- form controls ---------- */
.panel { display: flex; flex-direction: column; gap: 10px; }
.panel-title { margin: 18px 0 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.field-label { font-size: 12px; font-weight: 600; color: var(--dim); margin-top: 4px; }
.hint { color: var(--faint); font-size: 12.5px; margin: 0; }
.hint.center { text-align: center; padding: 24px; }
.warn { color: #ffb4a8; background: rgba(255, 90, 95, 0.12); border-radius: var(--radius-s); padding: 10px 12px; margin: 8px 0; }

.sl { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; }
.sl-label { font-size: 13px; color: var(--dim); }
.sl-value { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.sl-range { grid-column: 1 / -1; width: 100%; }
.sl-marks { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 28px; background: transparent; margin: 0;
  touch-action: pan-y; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--panel-3); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--panel-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%;
  background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 0; }

.seg { display: inline-flex; flex-wrap: nowrap; gap: 2px; padding: 3px; border-radius: 11px; background: var(--panel-2); max-width: 100%; overflow-x: auto; }
.seg.wrap { flex-wrap: wrap; }
.seg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1 0 auto;
  min-height: 32px; padding: 4px 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--dim); font-weight: 600; font-size: 13px; touch-action: manipulation;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.on { background: var(--accent); color: var(--accent-ink); }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; -webkit-user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; width: 42px; height: 26px; border-radius: 13px; background: var(--panel-3); transition: background 0.15s; flex: none; }
.toggle-thumb { position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle input:checked + .toggle-track { background: #34c759; }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-row { display: flex; gap: 24px; flex-wrap: wrap; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.15); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.swatch-custom { width: 32px; height: 32px; padding: 0; border: 0; background: none; border-radius: 50%; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 30px; padding: 4px 11px; border-radius: 15px; border: 1px solid var(--line-2);
  background: transparent; color: var(--text); font-size: 12.5px; font-weight: 600; touch-action: manipulation;
}
.chip:hover { background: rgba(255, 255, 255, 0.06); }

.text-input, .title-text {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-s); border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text); font-size: 16px;
}
.title-text { resize: vertical; min-height: 72px; line-height: 1.35; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.kv span { color: var(--dim); }
.kv b { font-weight: 600; text-align: right; }

/* ---------- transitions, aspect cards ---------- */
.tr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.tr-option {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px;
  border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel-2);
  font-size: 11.5px; color: var(--dim); text-align: center; touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer;
}
.tr-option:hover { border-color: var(--line-2); color: var(--text); }
.tr-option.on { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.tr-glyph svg { border-radius: 4px; display: block; }

.aspect-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.aspect-card {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 4px;
  border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel-2);
}
.aspect-card.on { border-color: var(--accent); background: var(--accent-soft); }
.aspect-shape { display: block; border: 2px solid currentColor; border-radius: 3px; margin: 4px 0 6px; }
.aspect-label { font-size: 12px; font-weight: 600; }
.aspect-sub { font-size: 11px; color: var(--faint); }

/* ---------- trimmer ---------- */
.trim-track { position: relative; height: 64px; border-radius: 10px; overflow: hidden; background: #000; touch-action: none; }
.trim-strip { position: absolute; inset: 0; display: flex; }
.trim-strip img { flex: 1 1 0; min-width: 0; height: 100%; object-fit: cover; pointer-events: none; }
.trim-shade { position: absolute; top: 0; bottom: 0; background: rgba(0, 0, 0, 0.62); pointer-events: none; }
.trim-shade.left { left: 0; }
.trim-shade.right { right: 0; }
.trim-window { position: absolute; top: 0; bottom: 0; border: 3px solid var(--accent); border-left-width: 0; border-right-width: 0; cursor: grab; }
.trim-handle { position: absolute; top: -3px; bottom: -3px; width: 18px; background: var(--accent); display: flex; align-items: center; justify-content: center; cursor: ew-resize; touch-action: none; }
.trim-handle span { width: 3px; height: 22px; border-radius: 2px; background: rgba(0, 0, 0, 0.55); }
.trim-handle.in { left: -9px; border-radius: 8px 0 0 8px; }
.trim-handle.out { right: -9px; border-radius: 0 8px 8px 0; }
.trim-readout { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); }
.trim-readout b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- overlays ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0); transition: background 0.2s;
}
.backdrop.in { background: rgba(0, 0, 0, 0.55); }
.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; box-shadow: var(--shadow);
  transform: translateY(12px) scale(0.98); opacity: 0; transition: transform 0.2s, opacity 0.2s;
}
.modal.wide { width: min(760px, calc(100vw - 32px)); }
.modal.small { width: min(420px, calc(100vw - 32px)); }
.backdrop.in .modal { transform: none; opacity: 1; }
.modal-head, .sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px 20px; }
.modal-head h2, .sheet-head h2 { flex: 1; margin: 0; font-size: 17px; }
.modal-body { padding: 8px 20px 20px; overflow-y: auto; }
.confirm p { margin: 0 0 14px; color: var(--dim); }

.toasts { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: min(520px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px; white-space: pre-line;
  background: #2d2d36; border: 1px solid var(--line-2); box-shadow: var(--shadow); font-weight: 500;
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s;
}
.toast.in { opacity: 1; transform: none; }
.toast.error { background: #3a1d20; border-color: rgba(255, 90, 95, 0.5); }

.update-banner {
  position: fixed; z-index: 150; left: 50%; top: calc(12px + var(--safe-top)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 14px;
  background: #2a2412; border: 1px solid rgba(255, 197, 49, 0.45); box-shadow: var(--shadow); color: #ffe7a6;
}

.busy {
  position: fixed; z-index: 120; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 14px;
  background: #24242c; border: 1px solid var(--line-2); box-shadow: var(--shadow);
}
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Decoder <video> elements must be in the DOM (iOS) but never visible. */
.deck-host { position: fixed; left: 0; top: 0; width: 2px; height: 2px; overflow: hidden; opacity: 0.01; pointer-events: none; z-index: -1; }
.deck-host video { width: 2px; height: 2px; }

.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 300; pointer-events: none; padding: 6px 10px; border-radius: 8px;
  background: #2d2d36; border: 1px solid var(--line-2); box-shadow: var(--shadow); font-size: 12px; font-weight: 600; opacity: 0.9;
}
.drag-ghost.ok { border-color: var(--accent); }

/* ---------- export ---------- */
.export { display: flex; flex-direction: column; gap: 8px; }
.export-info { margin: 10px 0 4px; }
.progress { height: 10px; border-radius: 5px; background: var(--panel-3); overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.25s; }
.progress-label { font-variant-numeric: tabular-nums; font-weight: 600; }
.export-preview { width: 100%; max-height: 46dvh; border-radius: 12px; background: #000; }
.export-action { position: sticky; bottom: -20px; padding: 12px 0 4px; background: linear-gradient(transparent, var(--panel) 30%); }

/* ---------- projects ---------- */
.projects { display: flex; flex-direction: column; gap: 12px; }
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-card {
  display: flex; align-items: center; gap: 14px; padding: 8px; border-radius: 14px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer;
}
.project-card:hover { border-color: var(--line-2); }
.project-card.current { border-color: rgba(255, 197, 49, 0.5); }
.project-thumb { width: 96px; height: 56px; border-radius: 10px; background: #000; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--faint); flex: none; }
.project-thumb img { width: 100%; height: 100%; object-fit: cover; }
.project-meta { flex: 1; min-width: 0; text-align: left; }
.project-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-sub { color: var(--faint); font-size: 12.5px; margin-top: 2px; }
.project-menu { display: flex; gap: 2px; }

.settings .seg { width: 100%; }
.settings .diag-report {
  max-height: 180px; overflow: auto; margin: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--panel-2); color: var(--dim); font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; -webkit-touch-callout: default;
}
.update-status { display: block; margin-top: 8px; color: var(--dim); }

.preview-canvas { display: block; background: #000; }
.title-box { position: absolute; z-index: 2; border: 1.5px dashed var(--accent); border-radius: 4px; cursor: move; touch-action: none; }
.title-box::after { content: ""; position: absolute; inset: -12px; }
