@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; font-family: "Geist", -apple-system, BlinkMacSystemFont, system-ui, sans-serif; }

:root {
  --glass: rgba(16, 16, 18, 0.62);
  --glass-strong: rgba(14, 14, 16, 0.78);
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.14);
  --fg: #fff;
  --fg60: rgba(255,255,255,0.60);
  --fg36: rgba(255,255,255,0.36);
  --fg18: rgba(255,255,255,0.18);
  --red: oklch(0.64 0.22 25);
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

#camera {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 0;
  transform: scaleX(-1);
}

/* ─── Script Overlay ─── */
#text-overlay {
  position: fixed; z-index: 10;
  top: 40px; left: 50%; transform: translateX(-50%);
  width: 82%; max-width: 340px; height: 180px;
  border-radius: 20px;
  background: var(--glass);
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10), 0 12px 40px rgba(0,0,0,0.4);
  overflow: hidden;
  touch-action: none; cursor: grab;
  display: flex; flex-direction: column;
}


/* fade masks */
#text-overlay::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 36px;
  background: linear-gradient(to top, rgba(16,16,18,0.9), transparent);
  pointer-events: none; z-index: 2;
}

#script-content {
  padding: 0 18px; color: var(--fg); font-size: 20px;
  line-height: 1.32; white-space: pre-wrap;
  overflow-y: auto; overflow-x: hidden;
  height: 100%; text-align: center; letter-spacing: -0.2px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#script-content::-webkit-scrollbar { display: none; }

#script-content .spacer-top { height: 30%; min-height: 50px; flex-shrink: 0; }
#script-content .spacer-bottom { height: 70%; min-height: 100px; flex-shrink: 0; }

#script-content .line {
  opacity: 0.28; transition: all 0.2s ease; font-weight: 500;
  padding: 3px 0;
}
#script-content .line.active {
  opacity: 1; font-weight: 600; font-size: 1.15em;
  text-shadow: 0 2px 10px rgba(0,0,0,0.6);
}
#script-content .line.near { opacity: 0.55; }

/* progress rail */
#progress-rail {
  position: absolute; top: 8px; left: 14px; right: 14px;
  height: 2px; border-radius: 1px; background: rgba(255,255,255,0.08); z-index: 3;
}
#progress-fill {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0%;
  background: var(--red); border-radius: 1px; box-shadow: 0 0 6px var(--red);
  transition: width 0.3s ease;
}


/* ─── Countdown ─── */
#countdown {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.25);
}
#countdown .countdown-circle {
  width: 180px; height: 180px; border-radius: 50%;
  background: rgba(20,20,22,0.55);
  backdrop-filter: blur(32px) saturate(140%);
  -webkit-backdrop-filter: blur(32px) saturate(140%);
  box-shadow: inset 0 0 0 1px var(--stroke-strong), 0 20px 60px rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  font-size: 120px; font-weight: 600; color: #fff;
  letter-spacing: -4px; font-variant-numeric: tabular-nums;
  animation: countdown-pop 0.5s ease-out;
}

/* ─── Toolbar ─── */
#controls {
  position: fixed; left: 12px; right: 12px; bottom: 28px;
  border-radius: 28px;
  background: var(--glass-strong);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  box-shadow: inset 0 0 0 1px var(--stroke), 0 12px 40px rgba(0,0,0,0.5);
  padding: 14px;
  z-index: 30;
}

#speed-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 12px;
  border-bottom: 1px solid var(--stroke);
  margin-bottom: 12px;
}

#action-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px;
}

#controls button {
  width: 40px; height: 40px; border-radius: 10px;
  border: none; background: transparent; color: var(--fg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
}
#controls button:active { background: rgba(255,255,255,0.08); }

#speed-slider {
  flex: 1; height: 3px; -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.10); border-radius: 2px; outline: none;
}
#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 9px;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
}
#speed-value {
  font-family: var(--mono); font-size: 11px; color: var(--fg60);
  min-width: 36px; text-align: right; font-variant-numeric: tabular-nums;
}

/* Record button — large, red */
#btn-record {
  width: 58px !important; height: 58px !important; border-radius: 29px !important;
  border: 2px solid rgba(255,255,255,0.85) !important;
  background: transparent !important; padding: 0 !important;
}
#btn-record .rec-dot {
  width: 44px; height: 44px; border-radius: 22px;
  background: var(--red); box-shadow: 0 0 12px var(--red);
  transition: all 0.2s ease;
}
body.recording #btn-record .rec-dot {
  width: 18px; height: 18px; border-radius: 4px;
  animation: rec-pulse 1.4s ease-in-out infinite;
}

/* ─── Recording state ─── */
#rec-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 40;
  box-shadow: inset 0 0 0 2px var(--red), inset 0 0 60px rgba(220, 60, 50, 0.35);
  animation: rec-glow 2.2s ease-in-out infinite;
  display: none;
}
body.recording #rec-glow { display: block; }

#rec-badge {
  position: fixed; top: auto; bottom: 116px; left: 20px; z-index: 41;
  display: none; align-items: center; gap: 8px;
  padding: 7px 12px 7px 10px; border-radius: 100px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: inset 0 0 0 1px var(--stroke);
  font-family: var(--mono); font-size: 12px; color: #fff;
  letter-spacing: 0.5px; font-variant-numeric: tabular-nums;
}
body.recording #rec-badge { display: flex; }
#rec-badge .dot {
  width: 8px; height: 8px; border-radius: 4px;
  background: var(--red); box-shadow: 0 0 8px var(--red);
  animation: rec-pulse 1.4s ease-in-out infinite;
}

/* ─── Modals (bottom sheets) ─── */
.modal {
  position: fixed; inset: 0; z-index: 200; display: flex;
  flex-direction: column; justify-content: flex-end;
}
.modal.hidden { display: none !important; }

.modal-scrim {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}

.modal-sheet {
  position: relative; z-index: 1;
  background: rgba(14, 14, 16, 0.92);
  backdrop-filter: blur(32px) saturate(160%);
  -webkit-backdrop-filter: blur(32px) saturate(160%);
  border-top-left-radius: 26px; border-top-right-radius: 26px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 -20px 60px rgba(0,0,0,0.5);
  color: #fff; max-height: 80vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

.sheet-grabber {
  display: flex; justify-content: center; padding: 8px 0 4px;
}
.sheet-grabber::after {
  content: ''; width: 36px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.18);
}

.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px 16px;
}
.sheet-header h2 {
  font-size: 19px; font-weight: 600; letter-spacing: -0.3px; margin: 0;
}
.sheet-close {
  width: 32px; height: 32px; border-radius: 16px; border: none;
  background: rgba(255,255,255,0.08); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.sheet-body { padding: 0 20px 28px; }

/* Form elements in sheets */
.sheet-body textarea {
  width: 100%; min-height: 160px; border-radius: 14px;
  background: rgba(255,255,255,0.04);
  box-shadow: inset 0 0 0 1px var(--stroke);
  border: none; padding: 14px; font-size: 15px; line-height: 1.45;
  color: var(--fg); font-family: inherit; resize: none;
}
.sheet-body textarea:focus { outline: none; box-shadow: inset 0 0 0 1px var(--stroke-strong); }

.sheet-label {
  font-size: 11px; font-weight: 600; color: var(--fg60);
  text-transform: uppercase; letter-spacing: 1.4px;
  margin-bottom: 8px; display: block;
}

.sheet-divider {
  display: flex; align-items: center; gap: 12px; margin: 20px 0;
}
.sheet-divider::before, .sheet-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--stroke);
}
.sheet-divider span {
  font-size: 11px; color: var(--fg36); font-family: var(--mono); letter-spacing: 1px;
}

.sheet-btn {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 14px 16px; border-radius: 14px; border: none;
  background: rgba(255,255,255,0.04); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  color: #fff; font-family: inherit; text-align: left; cursor: pointer;
  margin-bottom: 10px;
}
.sheet-btn:active { background: rgba(255,255,255,0.08); }
.sheet-btn .icon-wrap {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,0.06);
  display: flex; align-items: center; justify-content: center;
}
.sheet-btn .btn-text { flex: 1; }
.sheet-btn .btn-text .title { font-size: 15px; font-weight: 500; }
.sheet-btn .btn-text .hint { font-size: 12px; color: var(--fg60); margin-top: 2px; }

.sheet-primary {
  width: 100%; height: 52px; border-radius: 14px; border: none;
  background: #fff; color: #000; font-family: inherit;
  font-size: 16px; font-weight: 600; letter-spacing: -0.2px; cursor: pointer;
  margin-top: 12px;
}

/* Settings sliders */
.setting-slider { margin-bottom: 22px; }
.setting-slider .slider-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.setting-slider .slider-header label { font-size: 14px; font-weight: 500; color: #fff; }
.setting-slider .slider-header span { font-family: var(--mono); font-size: 13px; color: var(--fg60); font-variant-numeric: tabular-nums; }
.setting-slider input[type="range"] {
  width: 100%; height: 3px; -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.10); border-radius: 2px; outline: none;
}
.setting-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 11px;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.4); cursor: pointer;
}

/* Toggle */
.setting-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border: none; background: transparent; color: #fff;
  font-family: inherit; cursor: pointer; text-align: left; width: 100%;
}
.setting-toggle .toggle-label { font-size: 14px; font-weight: 500; }
.setting-toggle .toggle-hint { font-size: 12px; color: var(--fg60); margin-top: 2px; }
.toggle-track {
  width: 44px; height: 26px; border-radius: 13px; padding: 2px;
  background: rgba(255,255,255,0.14); display: flex; align-items: center;
  transition: all 0.18s ease;
}
.toggle-track.on { background: #fff; justify-content: flex-end; }
.toggle-thumb {
  width: 22px; height: 22px; border-radius: 11px;
  background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.toggle-track.on .toggle-thumb { background: #000; }

/* Recordings list */
.recording-item {
  display: flex; align-items: center; gap: 12px; padding: 10px;
  background: rgba(255,255,255,0.04); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  border-radius: 14px; margin-bottom: 8px;
}
.rec-title { font-size: 14px; font-weight: 500; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-date { font-size: 12px; color: var(--fg60); margin-top: 3px; font-family: var(--mono); letter-spacing: 0.2px; }
.rec-actions button {
  width: 36px; height: 36px; border-radius: 18px; border: none;
  background: rgba(255,255,255,0.06); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.rec-actions button:active { background: rgba(255,255,255,0.12); }

/* ─── Drag handle (top of overlay) ─── */
#drag-handle {
  position: relative; z-index: 6;
  height: 28px; cursor: grab;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
#drag-handle:active { cursor: grabbing; }
#drag-handle .handle-bar {
  width: 40px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.35);
}

/* ─── Eye marker (camera lens target) ─── */
#eye-marker {
  position: fixed; z-index: 15;
  top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  touch-action: none; cursor: grab;
}
#eye-marker:active { cursor: grabbing; }
#eye-marker .eye-ring {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--red);
  box-shadow: 0 0 10px var(--red), inset 0 0 4px rgba(220,60,50,0.3);
}
#eye-marker .eye-ring::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--red);
}
#eye-marker .eye-label {
  font-family: var(--mono); font-size: 8px; letter-spacing: 1.5px;
  color: var(--red); opacity: 0.7;
}

/* ─── Reading line indicator (right side of overlay) ─── */
#reading-line {
  position: absolute; right: 0; top: 15%; z-index: 5;
  width: 3px; height: 22px; border-radius: 2px;
  background: rgba(255,255,255,0.7);
  box-shadow: 0 0 6px rgba(255,255,255,0.3);
}
@media (orientation: landscape) {
  #reading-line { top: 50%; transform: translateY(-50%); }
}

/* ─── Resize handle ─── */
#resize-handle {
  position: absolute; right: 6px; bottom: 6px;
  width: 24px; height: 24px; z-index: 5;
  cursor: nwse-resize; touch-action: none;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.5;
}

/* ─── Landscape mode ─── */
@media (orientation: landscape) {
  #controls {
    position: fixed; top: 10px; right: 10px; bottom: 10px;
    left: auto; width: auto;
    border-radius: 28px; padding: 14px;
    display: flex; flex-direction: row; align-items: stretch;
    gap: 0;
  }

  /* Action buttons: left column, vertical */
  #action-row {
    order: 1;
    flex-direction: column; gap: 6px; padding: 0 10px 0 4px;
    justify-content: center;
    border-right: 1px solid var(--stroke);
  }

  /* Speed controls: right column, vertical */
  #speed-row {
    order: 2;
    flex-direction: column; gap: 4px;
    padding: 0 4px 0 10px;
    border-bottom: none; margin-bottom: 0;
    align-items: center; justify-content: center;
  }

  #speed-slider {
    -webkit-appearance: slider-vertical; appearance: slider-vertical;
    width: 3px; height: 70px; flex: none;
    writing-mode: vertical-lr; direction: rtl;
  }
  #speed-slider::-webkit-slider-thumb {
    width: 16px; height: 16px; border-radius: 8px;
  }

  #speed-row #btn-speed-down, #speed-row #btn-speed-up {
    width: 36px; height: 30px;
  }

  #speed-value { font-size: 10px; min-width: auto; text-align: center; }

  #btn-record {
    width: 52px !important; height: 52px !important; border-radius: 26px !important;
  }
  #btn-record .rec-dot { width: 38px; height: 38px; border-radius: 19px; }
  body.recording #btn-record .rec-dot { width: 16px; height: 16px; border-radius: 3px; }

  #text-overlay {
    top: 50%; left: 40px; right: auto;
    transform: translateY(-50%);
    width: 55%; max-width: 500px; height: 180px;
  }

  #rec-badge {
    top: 14px; bottom: auto; left: 50%; transform: translateX(-50%);
  }

  /* Modals become side sheets in landscape */
  .modal { flex-direction: row; justify-content: flex-end; }
  .modal-sheet {
    border-top-left-radius: 22px; border-bottom-left-radius: 22px;
    border-top-right-radius: 0; border-bottom-right-radius: 0;
    max-height: 100vh; width: 340px; height: 100%;
  }
  .sheet-grabber { display: none; }
}

/* ─── Animations ─── */
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes rec-glow {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--red), inset 0 0 60px rgba(220, 60, 50, 0.30); }
  50% { box-shadow: inset 0 0 0 2px var(--red), inset 0 0 80px rgba(220, 60, 50, 0.55); }
}
@keyframes countdown-pop {
  0% { transform: scale(0.6); opacity: 0; }
  40% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.hidden { display: none !important; }
