:root {
  --bg: #0c0d10;
  --card: #16181d;
  --line: #2a2d35;
  --text: #f3f4f6;
  --muted: #9aa3af;
  --gold: #e8b923;
  --red: #e23d3d;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif; }
body { overflow: hidden; }
.hidden { display: none !important; }
.page { position: fixed; inset: 0; }

.page-edit {
  display: flex;
  flex-direction: column;
  padding: calc(16px + var(--safe-t)) 16px calc(88px + var(--safe-b));
  gap: 12px;
}
.edit-head h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: 0.04em; }
.edit-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
#scriptInput {
  flex: 1;
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  line-height: 1.7;
  outline: none;
}
.edit-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  font-size: 12px;
  color: var(--muted);
}
.edit-settings label { display: flex; flex-direction: column; gap: 4px; }
.edit-settings span { color: var(--gold); }
.edit-settings input[type="range"] { width: 100%; accent-color: var(--gold); }
.edit-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  padding: 10px 16px calc(12px + var(--safe-b));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.btn {
  flex: 1;
  height: 46px;
  border: 0;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--gold); color: #111; }
.btn.ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.danger { color: #ffb4b4; border-color: #e23d3d; background: #2a1515; }

.page-shoot { background: #000; }
#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  background: #000;
  pointer-events: none;
}
#look {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  background: #000;
  pointer-events: none;
}
#stage {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.board {
  position: absolute;
  z-index: 2;
  overflow: hidden;
  border: 2px solid rgba(232, 185, 35, 0.9);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.46);
  touch-action: none;
  transform-origin: center center;
}
.board.turned { transform: rotate(90deg); }
.edge { position: absolute; z-index: 3; touch-action: none; }
.edge.n, .edge.s { left: 0; right: 0; height: 28px; }
.edge.n { top: 0; cursor: ns-resize; }
.edge.s { bottom: 0; cursor: ns-resize; }
.edge.w, .edge.e { top: 28px; bottom: 28px; width: 28px; }
.edge.w { left: 0; cursor: ew-resize; }
.edge.e { right: 0; cursor: ew-resize; }
.board-handle {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: rgba(255,255,255,0.72);
  background: rgba(0,0,0,0.28);
  cursor: grab;
  user-select: none;
}
.script-view {
  height: calc(100% - 28px);
  overflow: hidden;
  padding: 8px 16px 16px;
  color: var(--gold);
  line-height: 1.55;
  font-weight: 600;
  touch-action: none;
  user-select: none;
}
.board-edit {
  width: 100%;
  height: calc(100% - 28px);
  border: 0;
  resize: none;
  background: transparent;
  color: var(--gold);
  font-weight: 600;
  line-height: 1.55;
  padding: 8px 16px 16px;
  outline: none;
}
.script-view::-webkit-scrollbar { display: none; }
.script-view p { margin: 0 0 10px; }
.script-view p.current { border-radius: 6px; }
.script-view span.read { color: rgba(255,255,255,0.38); }
.script-view span.hot {
  color: #1a1403;
  background: #e8b923;
  border-radius: 3px;
}
.script-view p.past { opacity: 0.55; }
.script-view mark {
  background: transparent;
  color: #ff8a3d;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.script-lib { display: flex; flex-direction: column; gap: 6px; max-height: 148px; }
.lib-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.lib-head .btn { flex: none; width: auto; height: 32px; padding: 0 14px; font-size: 13px; }
.lib-list { overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.lib-item { display: flex; gap: 8px; align-items: center; }
.lib-open {
  flex: 1;
  text-align: left;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.lib-del { border: 0; background: transparent; color: #ffb4b4; font-size: 13px; padding: 6px; }
.lib-empty { margin: 0; color: var(--muted); font-size: 12px; }
.shoot-top {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.shoot-top .icon-btn { pointer-events: auto; flex: none; width: auto; }
.rec-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--red);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  padding: 8px 16px;
  border-radius: 999px;
  letter-spacing: 0.14em;
  box-shadow: 0 0 0 3px rgba(255, 70, 70, 0.45);
}
.rec-badge i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  animation: recblink 1s steps(1) infinite;
}
@keyframes recblink { 50% { opacity: 0.15; } }

.shoot-dock {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 4;
  padding: 8px 10px calc(10px + var(--safe-b));
  background: linear-gradient(transparent, rgba(0,0,0,0.72));
}
.preset-row, .dock-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.preset-row button, .icon-btn {
  flex: 1;
  height: 38px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(20,20,24,0.72);
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
  padding: 0 2px;
}
.preset-row button.on { border-color: var(--gold); color: var(--gold); }
.rec-btn {
  width: 56px;
  height: 38px;
  flex: 0 0 56px;
  border: 0;
  border-radius: 19px;
  background: var(--red);
  color: #fff;
  font-weight: 700;
}
.rec-btn.on {
  background: var(--red);
  color: #fff;
  box-shadow: 0 0 0 3px #fff;
}
.dock-sliders {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 6px;
  color: rgba(255,255,255,0.8);
  font-size: 11px;
}
.dock-sliders label { display: flex; flex-direction: column; gap: 2px; }
.dock-sliders span { color: var(--gold); }
.dock-sliders input { width: 100%; accent-color: var(--gold); }
#btnMic { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-shoot.rec-compact #btnFontDown,
.page-shoot.rec-compact #btnFontUp,
.page-shoot.rec-compact #btnOrient,
.page-shoot.rec-compact .dock-row:nth-child(2) { display: none; }
.page-shoot.rec-compact .dock-row { justify-content: center; }
.page-shoot.rec-compact #btnPause,
.page-shoot.rec-compact #btnRec { flex: 0 0 96px; }
.page-shoot.rec-compact #btnEditScript { flex: 0 0 72px; }
.hint { margin: 0; text-align: center; color: rgba(255,255,255,0.62); font-size: 11px; }

.count-mask {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  font-size: 88px;
  font-weight: 800;
  color: #fff;
}

.result-sheet {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: rgba(8, 8, 10, 0.94);
}
#resultVideo {
  flex: 1;
  width: 100%;
  background: #000;
  border-radius: 12px;
  object-fit: contain;
}
.result-actions { display: flex; gap: 10px; }
.result-sheet .hint { color: rgba(255,255,255,0.72); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28%;
  transform: translateX(-50%);
  z-index: 9;
  background: rgba(12,13,16,0.92);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
}

@media (orientation: landscape) {
  .script-view { font-size: inherit; }
  .shoot-dock { padding-left: 24px; padding-right: 24px; }
  .edit-settings { grid-template-columns: 1fr 1fr 1fr 1fr; }
}
