@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(10, 10, 12, 0.85);
  --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);
  --red: oklch(0.64 0.22 25);
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

/* ─── Lens dot (draggable) ─── */
#lens-dot {
  position: fixed; z-index: 50;
  top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  touch-action: none; cursor: grab;
}
#lens-dot:active { cursor: grabbing; }
#lens-dot .dot-ring {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--red);
  box-shadow: 0 0 12px var(--red);
  position: relative;
}
#lens-dot .dot-ring::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--red);
}
#lens-dot .dot-label {
  font-family: var(--mono); font-size: 7px; letter-spacing: 1.5px;
  color: var(--red); opacity: 0.8;
}

/* ─── Script Overlay ─── */
#text-overlay {
  position: fixed; z-index: 10;
  top: 36px; left: 4%; width: 92%; height: 55%;
  border-radius: 16px;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10);
  overflow: visible;
  touch-action: none;
  display: flex; flex-direction: column;
}

#drag-handle {
  height: 24px; cursor: grab; display: flex;
  align-items: center; justify-content: center;
  touch-action: none; flex-shrink: 0;
}
#drag-handle:active { cursor: grabbing; }
#drag-handle .handle-bar {
  width: 36px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.3);
}

#script-content {
  padding: 0 14px; color: var(--fg); font-size: 22px;
  line-height: 1.4; white-space: pre-wrap;
  overflow-y: auto; overflow-x: hidden;
  flex: 1; min-height: 0;
  text-align: center; letter-spacing: -0.2px;
  scrollbar-width: none;
}
#script-content::-webkit-scrollbar { display: none; }

#script-content .spacer-top { display: block; height: 40px; }
#script-content .spacer-bottom { display: block; height: 120px; }
#script-content .line { padding: 3px 6px; opacity: 1; font-weight: 500; }

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

/* ─── Countdown ─── */
#countdown {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5);
}
#countdown .countdown-circle {
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(20,20,22,0.8);
  box-shadow: inset 0 0 0 1px var(--stroke-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: 80px; font-weight: 600; color: #fff;
  animation: countdown-pop 0.5s ease-out;
}

/* ─── Toolbar ─── */
#controls {
  position: fixed; left: 4%; right: 4%; bottom: 10px;
  border-radius: 20px;
  background: rgba(10, 10, 12, 0.92);
  box-shadow: inset 0 0 0 1px var(--stroke);
  padding: 10px;
  z-index: 30;
}

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

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

#controls button {
  width: 38px; height: 38px; 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: 28px; -webkit-appearance: none; appearance: none;
  background: transparent; outline: none;
}
#speed-slider::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px; background: rgba(255,255,255,0.10);
}
#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 10px;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  margin-top: -9px;
}
#speed-value {
  font-family: var(--mono); font-size: 10px; color: var(--fg60);
  min-width: 32px; text-align: right;
}

/* Start button — highlighted */
#btn-start {
  background: rgba(255,255,255,0.1) !important;
  border-radius: 50% !important;
  width: 44px !important; height: 44px !important;
}

/* ─── Modals ─── */
.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.5); }
.modal-sheet {
  position: relative; z-index: 1;
  background: rgba(14, 14, 16, 0.95);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  color: #fff; max-height: 80vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}
.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: 10px 16px 12px; }
.sheet-header h2 { font-size: 17px; font-weight: 600; margin: 0; }
.sheet-close { width: 30px; height: 30px; border-radius: 15px; 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 16px 20px; }
.sheet-body textarea { width: 100%; min-height: 120px; border-radius: 12px; background: rgba(255,255,255,0.04); box-shadow: inset 0 0 0 1px var(--stroke); border: none; padding: 12px; font-size: 14px; line-height: 1.4; 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: 10px; font-weight: 600; color: var(--fg60); text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 6px; display: block; }
.sheet-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.sheet-divider::before, .sheet-divider::after { content: ''; flex: 1; height: 1px; background: var(--stroke); }
.sheet-divider span { font-size: 10px; color: var(--fg36); font-family: var(--mono); }
.sheet-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 12px; 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: 8px; }
.sheet-btn:active { background: rgba(255,255,255,0.08); }
.sheet-btn .icon-wrap { width: 32px; height: 32px; border-radius: 8px; 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: 14px; font-weight: 500; }
.sheet-btn .btn-text .hint { font-size: 11px; color: var(--fg60); margin-top: 1px; }
.sheet-primary { width: 100%; height: 46px; border-radius: 12px; border: none; background: #fff; color: #000; font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 10px; }

/* Settings */
.setting-slider { margin-bottom: 18px; }
.setting-slider .slider-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.setting-slider .slider-header label { font-size: 13px; font-weight: 500; color: #fff; }
.setting-slider .slider-header span { font-family: var(--mono); font-size: 12px; color: var(--fg60); }
.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: 20px; height: 20px; border-radius: 10px; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.4); }
.setting-toggle { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border: none; background: transparent; color: #fff; font-family: inherit; cursor: pointer; text-align: left; width: 100%; }
.setting-toggle .toggle-label { font-size: 13px; font-weight: 500; }
.setting-toggle .toggle-hint { font-size: 11px; color: var(--fg60); margin-top: 1px; }
.toggle-track { width: 40px; height: 24px; border-radius: 12px; 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: 20px; height: 20px; border-radius: 10px; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.3); }
.toggle-track.on .toggle-thumb { background: #000; }

/* ─── Landscape ─── */
@media (orientation: landscape) {
  #controls {
    position: fixed; top: 8px; right: 8px; bottom: 8px;
    left: auto; width: auto;
    border-radius: 20px; padding: 10px;
    display: flex; flex-direction: row; align-items: stretch;
  }
  #action-row { order: 1; flex-direction: column; gap: 4px; padding: 0 8px 0 2px; justify-content: center; border-right: 1px solid var(--stroke); }
  #speed-row { order: 2; flex-direction: column; gap: 4px; padding: 0 2px 0 8px; border-bottom: none; margin-bottom: 0; align-items: center; justify-content: center; }
  #speed-slider { -webkit-appearance: slider-vertical; appearance: slider-vertical; width: 3px; height: 60px; flex: none; writing-mode: vertical-lr; direction: rtl; }
  #speed-slider::-webkit-slider-thumb { width: 16px; height: 16px; border-radius: 8px; margin-top: 0; }
  #speed-value { font-size: 9px; }
  #text-overlay { top: 8px; left: 4%; width: 60%; height: 85%; }
  .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; max-height: 100vh; width: 300px; height: 100%; }
  .sheet-grabber { display: none; }
}

/* ─── Animations ─── */
@keyframes countdown-pop { 0% { transform: scale(0.6); opacity: 0; } 40% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
.hidden { display: none !important; }
