:root {
  --bg: #1b1b1d;
  --panel: #2a2a2d;
  --tile: #3a3a3e;
  --tile-hi: #48484d;
  --text: #e8e8ea;
  --dim: #8d8d93;
  --on: #5dff6a;
  --accent: #f4f05a;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  touch-action: manipulation; /* no double-tap zoom */
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; letter-spacing: inherit; cursor: pointer; }

.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen.active { display: flex; }

/* ---------- Home ---------- */
.home-inner {
  margin: auto;
  padding: 24px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}
.wordmark {
  margin: 0;
  font-size: clamp(56px, 18vw, 120px);
  line-height: 0.9;
  letter-spacing: -0.02em;
  text-shadow: -4px 0 #ff2bd6, 4px 0 #19e8ff;
}
.big-btn {
  display: inline-block;
  padding: 18px 36px;
  background: var(--accent);
  color: #111;
  border-radius: 12px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
.big-btn.ghost { background: transparent; color: var(--text); border: 1px solid #555; font-family: inherit; }
.fine { color: var(--dim); line-height: 1.6; margin: 0; }

/* ---------- Shared bars ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  min-height: 48px;
}
.icon-btn {
  background: none;
  border: 0;
  font-size: 26px;
  width: 44px;
  height: 44px;
  line-height: 1;
}
.pill {
  background: var(--tile);
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 11px;
}
.pill.on { background: var(--accent); color: #111; }
.format, .top-right { display: flex; gap: 6px; }

/* Full-screen view: hide the bars and panel, keep gestures on the image. */
.exit-full { display: none; }
#editor.full .topbar, #editor.full .panel { display: none; }
#editor.full .stage { padding: 0; }
#editor.full .stage canvas { border-radius: 0; }
#editor.full .badge { top: 60px; }
#editor.full .exit-full {
  display: block;
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  padding: 10px 16px;
}

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  touch-action: none;
}
.stage canvas, .stage img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  display: block;
}
.stage img { -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }
.badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  padding: 6px 0 4px;
  margin-top: 8px;
}
.grab { width: 36px; height: 4px; border-radius: 2px; background: #555; margin: 0 auto 8px; }

.slider-row { padding: 6px 28px 10px; }
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  touch-action: none;
  background: transparent;
  margin: 0;
}
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: #666; }
input[type=range]::-moz-range-track { height: 1px; background: #666; }
/* Wide invisible thumb with a thin white bar drawn in the middle: easy to grab with a thumb. */
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 32px;
  margin-top: -16px;
  background: linear-gradient(90deg, transparent 12px, #fff 12px, #fff 16px, transparent 16px);
  border: 0;
}
input[type=range]::-moz-range-thumb { width: 4px; height: 28px; background: #fff; border: 0; border-radius: 2px; }

.opt-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 0 16px;
  min-height: 40px;
}
.opt-row:empty { display: none; }
.opt {
  flex: 0 1 150px;
  background: var(--tile);
  border: 0;
  border-radius: 8px;
  padding: 11px 8px;
  font-size: 12px;
}
.opt.on { color: var(--on); }
.opt.primary { background: var(--accent); color: #111; font-weight: 700; }

.hint { text-align: center; color: var(--dim); font-size: 11px; margin: 8px 16px; min-height: 1em; }

.strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 16px 8px;
  scrollbar-width: none;
}
.strip::-webkit-scrollbar { display: none; }
.fx {
  flex: 0 0 auto;
  width: 72px;
  height: 64px;
  background: var(--tile);
  border: 0;
  border-radius: 8px;
  text-align: left;
  padding: 8px;
  font-size: 11px;
  display: flex;
  align-items: flex-start;
}
.fx.on { color: var(--on); background: var(--tile-hi); }

.bottombar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 0 12px;
  gap: 6px;
}
.bottom-right { display: flex; align-items: center; gap: 2px; min-width: 0; }
.layer-info { color: var(--dim); font-size: 11px; white-space: nowrap; }

/* Video recording: REC / END, hold-to-extend, and the clip so far. */
.rec-row { display: flex; gap: 6px; align-items: center; }
.rec-row .pill { padding: 8px 11px; white-space: nowrap; }
.pill.rec.live { background: #c9302a; color: #fff; }
.pill.rec.live.capturing { background: #ff3b30; box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.45); }
.pill.extend { touch-action: none; -webkit-touch-callout: none; }
.pill.extend.on { background: var(--accent); color: #111; }
.stage video { max-width: 100%; max-height: 100%; border-radius: 6px; display: block; }
.next { font-size: 34px; }

.result-panel { padding: 12px 0 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #000;
  border: 1px solid #444;
  padding: 10px 16px;
  border-radius: 10px;
  max-width: calc(100% - 32px);
  text-align: center;
  z-index: 10;
}
