/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:root {
  --bg:          #1c1c1e;
  --bg-card:     #2c2c2e;
  --bg-card2:    #3a3a3c;
  --bg-input:    #2c2c2e;
  --accent:      #3b82f6;
  --accent-dark: #2563eb;
  --text:        #ffffff;
  --text-muted:  #8e8e93;
  --border:      #38383a;
  --danger:      #ff3b30;
  --green:       #30d158;
  --radius:      14px;
  --radius-sm:   10px;
}

html, body {
  height: 100%;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  font-size: 17px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── App Shell ── */
#app {
  height: 100dvh;
  background: #000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  /* padding-bottom: env(safe-area-inset-bottom); */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ── Screens ── */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.screen.active { display: flex; }

/* Teleprompter mode — make safe-area zones black to match script bg */
#app.tp-active { background: #000; }

/* ════════════════════════════════
   HOME SCREEN
   ════════════════════════════════ */

.home-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 4px;
}

.home-topbar .btn-edit {
  background: var(--bg-card2);
  color: var(--text);
  border: none;
  border-radius: 20px;
  padding: 11px 20px;
  font-size: 16px;
  cursor: pointer;
}

.home-topbar .btn-edit.active-edit {
  color: var(--accent);
}

.home-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.home-topbar-right button {
  background: var(--bg-card2);
  border: none;
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.home-title {
  font-size: 28px;
  font-weight: 700;
  padding: 4px 16px 12px;
  letter-spacing: -0.4px;
}

/* ── Script Grid ── */
.scripts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 16px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.grid-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
  cursor: pointer;
  position: relative;
  overflow: visible;
  transition: opacity 0.15s;
}

.grid-card:active { opacity: 0.7; }

.grid-card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.grid-card-preview {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
}

/* New card */
.grid-card--new {
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--bg-card);
}

.grid-card--new .new-icon {
  font-size: 32px;
  font-weight: 300;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 2px;
}

.grid-card--new .new-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

/* Edit mode — delete badge */
.grid-card-delete-badge {
  display: none;
  position: absolute;
  top: -8px;
  left: -8px;
  width: 22px;
  height: 22px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid var(--bg);
  align-items: center;
  justify-content: center;
  z-index: 10;
  cursor: pointer;
  line-height: 1;
}

.edit-mode .grid-card-delete-badge { display: flex; }
.edit-mode .grid-card--new .grid-card-delete-badge { display: none; }

/* ── Home Search ── */
.home-search {
  padding: 4px 16px 12px;
}

.home-search-inner {
  background: var(--bg-card);
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
}

.home-search-inner span {
  color: var(--text-muted);
  font-size: 16px;
}

.home-search-inner input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
}

.home-search-inner input::placeholder { color: var(--text-muted); }

/* ════════════════════════════════
   TELEPROMPTER / SCRIPT VIEW
   ════════════════════════════════ */

/* Screen is the positioning context */
#screen-tp {
  position: relative;
  background: #000;
}

/* Text fills the entire screen */
.tp-scroll-area {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* 50vh top/bottom so the reading line is always screen centre */
  padding: 50vh 20px 50vh;
}

.tp-text {
  font-size: 32px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Top bar floats over the text */
.tp-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* DON'T REMOVE THIS COMMENT 
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  */
   padding: max(8px, 16px);
  background: linear-gradient(to bottom, rgba(0,0,0,0.9) 50%, transparent 100%);
  transition: opacity 0.4s ease;
}

.tp-topbar .btn-pill-sm {
  background: rgba(58,58,60,0.9);
  color: var(--text);
  border: none;
  border-radius: 20px;
  padding: 11px 20px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.tp-topbar .btn-pill-sm:active { opacity: 0.7; }

/* Bottom controls float over the text */
.tp-controls {
  position: absolute;
  bottom: -5px;
  left: 0;
  right: 0;
  z-index: 10;

  background: linear-gradient(to top, rgba(0,0,0,0.95) 100%, transparent 100%); 
  border-top: none;
  /* Don't remove this comment
  padding: 16px 16px max(12px, env(safe-area-inset-bottom)); */
  padding: max(8px, 16px);
  transition: opacity 0.4s ease;
}

.tp-controls-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.tp-speed-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tp-speed-track {
  flex: 1;
  height: 4px;
  background: var(--bg-card2);
  border-radius: 2px;
  position: relative;
  touch-action: none; /* allow drag without interference */
}

.tp-speed-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  background: var(--text);
  border-radius: 50%;
  cursor: pointer;
}

.tp-speed-num {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  min-width: 28px;
  text-align: right;
}

.tp-btn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.tp-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 26px;
  cursor: pointer;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}

.tp-btn:active { opacity: 0.6; }

.tp-btn-start {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
}

.tp-btn-start.playing {
  background: #ff9f0a;
}

.tp-btn-start:active { opacity: 0.85; }

/* ════════════════════════════════
   NEW SCRIPT MODAL
   ════════════════════════════════ */

.modal-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding-top: 120px;
}

.modal-overlay.open { display: flex; }

.modal-card {
  background: #2c2c2e;
  border-radius: 16px;
  padding: 20px 16px 16px;
  width: calc(100% - 48px);
  max-width: 340px;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.modal-input {
  width: 100%;
  background: #3a3a3c;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  margin-bottom: 14px;
}

.modal-input::placeholder { color: var(--text-muted); }

.modal-btns {
  display: flex;
  gap: 10px;
}

.modal-btn {
  flex: 1;
  background: #3a3a3c;
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 15px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

.modal-btn--confirm {
  font-weight: 600;
}

.modal-btn:active { opacity: 0.7; }

/* ════════════════════════════════
   EDITOR SCREEN
   ════════════════════════════════ */

.editor-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 16px 6px;
  background: #000;
  flex-shrink: 0;
}

.btn-done-pill {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 11px 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-done-pill:active { opacity: 0.85; }

.editor-textarea {
  flex: 1;
  background: #000;
  color: var(--text);
  border: none;
  outline: none;
  padding: 8px 20px 20px;
  font-size: 36px;
  font-weight: 500;
  line-height: 1.3;
  resize: none;
  font-family: inherit;
  -webkit-overflow-scrolling: touch;
}

.editor-textarea::placeholder { color: #444; }

/* ════════════════════════════════
   SETTINGS SCREEN
   ════════════════════════════════ */

.settings-topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 16px;
  position: relative;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-topbar h1 {
  font-size: 17px;
  font-weight: 600;
}

.settings-topbar .btn-done {
  position: absolute;
  right: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
}

.settings-section-label {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 4px 6px;
  margin-top: 20px;
}

.settings-section-label:first-child { margin-top: 0; }

.settings-group {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
}

.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--bg-card2); }

.settings-row-label { font-size: 16px; }

.settings-row-right {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 15px;
}

.settings-chevron {
  color: var(--text-muted);
  font-size: 14px;
}

/* Toggle switch */
.toggle {
  width: 51px;
  height: 31px;
  background: var(--bg-card2);
  border-radius: 16px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle.on { background: var(--green); }

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.toggle.on::after { transform: translateX(20px); }

/* ════════════════════════════════
   INPUT DEBUG
   ════════════════════════════════ */

.input-debug-scroll {
  background: var(--bg);
}

.input-debug-row {
  align-items: flex-start;
}

.input-debug-row--button {
  align-items: center;
}

.input-debug-copy {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.input-debug-meta {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.input-debug-pre {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border-radius: 12px;
  background: #111214;
  color: #cfe3ff;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
