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

[hidden] { display: none !important; }

:root {
  --ui-bg: #111318;
  --ui-panel: #1a1d24;
  --ui-border: #2a2f3a;
  --ui-text: #e8eaf0;
  --ui-muted: #8b92a3;
  --accent: #4f8cff;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--ui-bg);
  color: var(--ui-text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, select, input { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-panel);
  cursor: pointer;
}
.btn:hover { border-color: var(--ui-muted); }
.btn-ghost { background: transparent; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 10px 20px;
}
.btn-primary:hover { filter: brightness(1.1); }

/* ============ EDITOR ============ */
.editor {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.editor-header,
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--ui-border);
}
.editor-footer { border-bottom: 0; border-top: 1px solid var(--ui-border); }
.editor-header h1 { margin: 0; font-size: 18px; }
.home-link { color: inherit; text-decoration: none; }
.home-link span { font-weight: 400; color: var(--ui-muted); }
.footer-info { display: flex; flex-direction: column; gap: 2px; }
.credit { font-size: 12px; color: var(--ui-muted); }
.header-actions { display: flex; gap: 8px; }
#stats { color: var(--ui-muted); }

.editor-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: 0;
}

#script {
  width: 100%;
  height: 100%;
  resize: none;
  padding: 24px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ui-text);
  font-size: 18px;
  line-height: 1.6;
}
#script.flash { animation: flash 0.6s; }
@keyframes flash { 50% { background: rgba(255, 80, 80, 0.15); } }

.settings {
  overflow-y: auto;
  padding: 12px 16px 24px;
  border-left: 1px solid var(--ui-border);
  background: var(--ui-panel);
}

fieldset {
  border: 0;
  border-bottom: 1px solid var(--ui-border);
  margin: 0;
  padding: 12px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
legend {
  float: left;
  width: 100%;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ui-muted);
}
fieldset label { display: flex; flex-direction: column; gap: 4px; }
fieldset label output { float: right; color: var(--ui-muted); }
fieldset label.check { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
fieldset .row { display: flex; gap: 10px; }
fieldset .row label { flex: 1; }

input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="color"] { width: 100%; height: 32px; padding: 0; border: 1px solid var(--ui-border); border-radius: 6px; background: none; }
input[type="file"] { font-size: 12px; color: var(--ui-muted); }
select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
}
.hint { margin: 0; font-size: 12px; color: var(--ui-muted); }

.shortcuts dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 12px;
}
.shortcuts dt { color: var(--ui-text); font-family: ui-monospace, Menlo, monospace; }
.shortcuts dd { margin: 0; color: var(--ui-muted); }

/* ============ PROMPTER ============ */
.prompter {
  --font-size: 56px;
  --line-height: 1.5;
  --width: 70%;
  --font: system-ui, sans-serif;
  --align: left;
  --text-color: #fff;
  --dim: 0.4;
  --guide-pos: 35;

  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  user-select: none;
}
.prompter.idle { cursor: none; }

.bg, .dim { position: absolute; inset: 0; }
.bg img, .bg video { width: 100%; height: 100%; object-fit: cover; }
#bgCam { transform: scaleX(-1); }
.dim { background: rgba(0, 0, 0, var(--dim)); pointer-events: none; }

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
}
.stage.dragging { cursor: grabbing; }

.text {
  width: var(--width);
  margin: 0 auto;
  padding-top: calc(var(--guide-pos) * 1vh);
  padding-bottom: calc((100 - var(--guide-pos)) * 1vh);
  font-family: var(--font);
  font-size: var(--font-size);
  line-height: var(--line-height);
  text-align: var(--align);
  color: var(--text-color);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  will-change: transform;
}
.text p { margin: 0 0 0.8em; }

.guide {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--guide-pos) * 1%);
  height: calc(var(--font-size) * var(--line-height));
  background: rgba(255, 255, 255, 0.07);
  border-top: 2px solid rgba(79, 140, 255, 0.7);
  border-bottom: 2px solid rgba(79, 140, 255, 0.7);
  pointer-events: none;
}
.guide::before {
  content: "▶";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 28px;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 30vh;
  font-weight: 800;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.progress {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
}
#progressBar { height: 100%; width: 0; background: var(--accent); }

.controls {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(20, 22, 28, 0.85);
  backdrop-filter: blur(10px);
  transition: opacity 0.3s, transform 0.3s;
}
.prompter.idle .controls {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
  pointer-events: none;
}
.controls button {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
}
.controls button:hover { background: rgba(255, 255, 255, 0.1); }
.controls button.on { color: var(--accent); }
.controls button.play { background: var(--accent); min-width: 48px; }
.controls .label {
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--ui-muted);
}
.controls .sep { width: 1px; height: 22px; margin: 0 4px; background: rgba(255, 255, 255, 0.15); }

.controls button.rec { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
.controls button.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: #e5484d; }
.controls button.rec.recording { background: rgba(229, 72, 77, 0.2); color: #ff8f92; }
.controls button.rec.recording .dot { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

.self-view {
  position: absolute;
  right: 20px;
  bottom: 90px;
  width: 220px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  transform: scaleX(-1);
  pointer-events: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
}
.modal-card {
  width: min(640px, 92vw);
  padding: 20px;
  border-radius: 14px;
  border: 1px solid var(--ui-border);
  background: var(--ui-panel);
}
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
.rec-preview video { width: 100%; max-height: 60vh; border-radius: 8px; background: #000; }
.rec-preview audio { width: 100%; }
.modal-card .hint { margin: 10px 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions a { text-decoration: none; }

.toast {
  position: fixed;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  z-index: 10;
  padding: 10px 16px;
  border-radius: 8px;
  background: #2b2f3a;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
