/* ===========================================================
   Tele.MohsenRashidi.art — design tokens
   Palette: broadcast control-room dark, tally-red accent.
   Type: Vazirmatn (Persian/Latin) for content, JetBrains Mono
   for HUD/timecode-style numeric readouts.
   Signature: viewfinder reading-band reticle + tally status pill.
   =========================================================== */

@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Variable.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn Fallback';
  src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn Fallback';
  src: url('/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/JetBrainsMono-Variable.woff2') format('woff2-variations');
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --bg-stage: #000000;
  --bg-deck: #131316;
  --bg-panel: #1c1d21;
  --bg-panel-2: #232429;
  --hairline: #2c2d33;
  --text-primary: #f5f5f4;
  --text-secondary: #9a9ba3;
  --text-dim: #5c5d66;
  --accent-tally: #ff3b3b;
  --accent-amber: #f5a623;
  --accent-green: #35d07f;
  --focus-ring: #4f8cff;
  --font-fa: 'Vazirmatn', 'Vazirmatn Fallback', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--text-primary);
  font-family: var(--font-fa);
  overscroll-behavior: none;
}

body { height: 100dvh; overflow: hidden; }

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}
input, textarea {
  font-family: inherit;
  color: inherit;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ===================== PIN GATE ===================== */
.pin-gate {
  position: fixed; inset: 0; z-index: 500;
  background: var(--bg-stage);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.pin-card {
  width: 100%; max-width: 360px;
  text-align: center;
}
.pin-logo {
  font-family: var(--font-mono);
  font-size: 22px; letter-spacing: 2px;
  color: var(--text-primary); margin-bottom: 8px;
}
.pin-logo span { color: var(--accent-tally); }
.pin-card p { color: var(--text-secondary); margin: 8px 0 20px; }
.pin-input {
  width: 100%; padding: 14px; font-size: 22px; text-align: center;
  letter-spacing: 6px; background: var(--bg-panel); border: 1px solid var(--hairline);
  border-radius: 10px; margin-bottom: 16px;
}
.pin-input:focus { outline: none; border-color: var(--focus-ring); }
.pin-error { color: var(--accent-tally); font-size: 13px; margin-top: 12px; }

/* ===================== APP SHELL ===================== */
.app { height: 100%; }

.shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-deck);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg-deck);
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.brand {
  font-family: var(--font-mono);
  font-weight: 700; font-size: 16px; letter-spacing: 1.5px;
  color: var(--text-primary);
}
.brand span { color: var(--accent-tally); }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-panel);
  color: var(--text-secondary);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { background: var(--bg-panel-2); color: var(--text-primary); }

.editor-main {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 16px; gap: 10px;
}
.doc-title-input {
  background: none; border: none; border-bottom: 1px solid var(--hairline);
  padding: 8px 2px; font-size: 17px; font-weight: 600;
  color: var(--text-primary);
}
.doc-title-input:focus { outline: none; border-color: var(--focus-ring); }
.doc-title-input::placeholder { color: var(--text-dim); }

.editor-textarea {
  flex: 1; min-height: 0; resize: none;
  background: var(--bg-panel); border: 1px solid var(--hairline);
  border-radius: 12px; padding: 14px; font-size: 17px; line-height: 1.8;
}
.editor-textarea:focus { outline: none; border-color: var(--focus-ring); }
.editor-textarea::placeholder { color: var(--text-dim); }

.editor-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--text-dim); padding: 0 2px;
}
.save-state { transition: color .2s; }
.save-state.dirty { color: var(--accent-amber); }
.save-state.saved { color: var(--accent-green); }

.editor-footer {
  flex-shrink: 0;
  display: flex; gap: 8px;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--bg-deck); border-top: 1px solid var(--hairline);
}
.btn {
  flex: 1; padding: 13px 10px; border-radius: 10px;
  font-size: 14px; font-weight: 600; text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
.btn-ghost { background: none; color: var(--text-secondary); flex: 0.8; }
.btn-ghost:active { color: var(--text-primary); }
.btn-outline { background: var(--bg-panel); color: var(--text-primary); border: 1px solid var(--hairline); flex: 0.9; }
.btn-outline:active { background: var(--bg-panel-2); }
.btn-start {
  flex: 1.4; background: var(--accent-tally); color: #fff;
}
.btn-start:active { background: #e02f2f; }
.play-icon { width: 14px; height: 14px; }
.btn-primary { width: 100%; background: var(--accent-tally); color: #fff; border-radius: 10px; padding: 13px; font-weight: 700; }

/* ===================== SHEETS (documents / settings) ===================== */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; max-height: 82vh;
  background: var(--bg-deck);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--hairline);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; background: var(--hairline); border-radius: 2px; margin: 10px auto; flex-shrink: 0; }
.sheet-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 18px 14px; flex-shrink: 0; border-bottom: 1px solid var(--hairline);
}
.sheet-header h2 { font-size: 16px; margin: 0; }
.sheet-close { width: 32px; height: 32px; font-size: 14px; }

/* documents list */
.docs-list { overflow-y: auto; padding: 8px 12px 20px; }
.docs-empty { text-align: center; color: var(--text-dim); padding: 40px 0; font-size: 14px; }
.doc-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 12px; border-radius: 12px; margin-bottom: 4px;
}
.doc-item:active { background: var(--bg-panel); }
.doc-item-main { flex: 1; min-width: 0; cursor: pointer; }
.doc-item-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-item-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; font-family: var(--font-mono); }
.doc-item-del { width: 34px; height: 34px; border-radius: 8px; color: var(--text-dim); flex-shrink: 0; font-size: 16px; }
.doc-item-del:active { color: var(--accent-tally); background: rgba(255,59,59,.1); }

/* settings */
.settings-body { overflow-y: auto; padding: 6px 18px 24px; }
.setting-row { padding: 14px 0; border-bottom: 1px solid var(--hairline); }
.setting-row label { display: block; font-size: 14px; color: var(--text-secondary); margin-bottom: 10px; }
.setting-control { display: flex; align-items: center; gap: 12px; }
.setting-val { min-width: 42px; text-align: center; font-size: 13px; color: var(--text-primary); background: var(--bg-panel); border-radius: 6px; padding: 3px 6px; }

input[type=range] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--hairline); border-radius: 2px; outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-tally); border: 2px solid #fff; cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-tally); border: 2px solid #fff; cursor: pointer;
}

.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row label { margin-bottom: 0; }
.switch { width: 46px; height: 26px; background: var(--bg-panel-2); border-radius: 13px; position: relative; flex-shrink: 0; transition: background .15s; }
.switch[aria-checked="true"] { background: var(--accent-tally); }
.switch-knob { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch[aria-checked="true"] .switch-knob { transform: translateX(-20px); }

.segmented { display: flex; gap: 6px; }
.segmented button { flex: 1; padding: 9px 4px; background: var(--bg-panel); border-radius: 8px; font-size: 12.5px; color: var(--text-secondary); }
.segmented button.active { background: var(--accent-tally); color: #fff; }

.swatches { display: flex; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--hairline); }
.swatch.active { border-color: var(--accent-tally); box-shadow: 0 0 0 2px rgba(255,59,59,.25); }

/* ===================== PROMPTER STAGE ===================== */
.stage {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg-stage);
  overflow: hidden;
}

.stage-mirror {
  position: absolute; inset: 0;
  transition: transform .15s ease;
}
.stage-viewport {
  position: absolute; inset: 0;
  overflow-y: scroll;
  scrollbar-width: none;
}
.stage-viewport::-webkit-scrollbar { display: none; }

.stage-pad-top { height: 42vh; }
.stage-pad-bottom { height: 70vh; }

.stage-text {
  font-family: var(--font-fa);
  font-size: 40px;
  line-height: 1.6;
  color: var(--text-primary);
  width: 90%;
  margin: 0 auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  padding: 0 4px;
}

/* reticle: reading-band guide, always screen-normal (never mirrored) */
.reticle {
  position: absolute; inset: 0; z-index: 120;
  pointer-events: none;
}
.reticle-line {
  position: absolute; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,59,59,.55) 12%, rgba(255,59,59,.55) 88%, transparent);
}
.reticle-top { top: 42vh; }
.reticle-bottom { top: calc(42vh + 15vh); }
.reticle .tick {
  position: absolute; top: -4px; width: 1px; height: 9px; background: rgba(255,59,59,.7);
}
.reticle-line .tick:nth-child(1) { left: 6%; }
.reticle-line .tick:nth-child(2) { right: 6%; }

.status-pill {
  position: absolute; top: calc(14px + var(--safe-top)); right: calc(16px + var(--safe-right));
  z-index: 130;
  display: flex; align-items: center; gap: 7px;
  background: rgba(28,29,33,.82); backdrop-filter: blur(6px);
  border: 1px solid var(--hairline);
  border-radius: 20px; padding: 7px 13px;
  font-size: 12px; color: var(--text-secondary);
  transition: opacity .2s;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.status-pill.live .dot { background: var(--accent-tally); box-shadow: 0 0 0 0 rgba(255,59,59,.6); animation: pulse 1.4s infinite; }
.status-pill .sep { color: var(--text-dim); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,59,59,.55); }
  70% { box-shadow: 0 0 0 7px rgba(255,59,59,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,59,59,0); }
}

.countdown-overlay {
  position: absolute; inset: 0; z-index: 140;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
}
.countdown-num {
  font-family: var(--font-mono); font-size: 120px; font-weight: 700;
  color: var(--accent-tally);
}

.stage-tap-zone { position: absolute; inset: 0; z-index: 110; }

.stage-controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 130;
  padding: 10px calc(14px + var(--safe-left)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-right));
  background: linear-gradient(to top, rgba(0,0,0,.88) 0%, rgba(0,0,0,.6) 60%, transparent 100%);
  transition: transform .2s ease, opacity .2s ease;
}
.controls-row { display: flex; align-items: center; justify-content: center; gap: 10px; }
.controls-row-primary { margin-bottom: 10px; }

.stage-btn {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,255,255,.08); color: var(--text-primary);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,.1);
}
.stage-btn svg { width: 20px; height: 20px; }
.stage-btn:active { background: rgba(255,255,255,.18); }
.stage-btn-play {
  width: 60px; height: 60px; background: var(--accent-tally); border-color: transparent;
}
.stage-btn-play svg { width: 24px; height: 24px; }
.stage-btn-play.is-playing svg { width: 18px; height: 18px; }

.controls-row-sliders { gap: 8px; }
.mini-slider {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px; padding: 7px 10px; flex: 1;
  justify-content: center;
}
.mini-label { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.mini-btn { width: 22px; height: 22px; border-radius: 6px; background: rgba(255,255,255,.1); font-size: 15px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.mini-btn:active { background: rgba(255,255,255,.22); }
.mini-val { min-width: 26px; text-align: center; font-size: 12.5px; }
.mini-toggle { color: var(--text-secondary); }
.mini-toggle.active { color: var(--accent-tally); background: rgba(255,59,59,.12); border-color: rgba(255,59,59,.3); }

.stage-hint {
  position: absolute; bottom: calc(10px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 130; font-size: 11.5px; color: var(--text-dim);
  background: rgba(19,19,22,.7); padding: 5px 12px; border-radius: 20px;
  pointer-events: none; transition: opacity .25s;
}

.chrome-hidden .status-pill,
.chrome-hidden .stage-controls,
.chrome-hidden .reticle {
  opacity: 0; pointer-events: none;
}
.chrome-hidden .stage-controls { transform: translateY(20px); }

/* ===================== LANDSCAPE ADJUSTMENTS ===================== */
@media (orientation: landscape) {
  .stage-pad-top { height: 30vh; }
  .reticle-top { top: 30vh; }
  .reticle-bottom { top: calc(30vh + 22vh); }
  .stage-text { width: 76%; }
  .controls-row-primary { margin-bottom: 8px; }
  .stage-btn { width: 40px; height: 40px; }
  .stage-btn-play { width: 52px; height: 52px; }
  .editor-footer { padding-top: 8px; padding-bottom: calc(8px + var(--safe-bottom)); }
}

@media (max-width: 380px) {
  .brand { font-size: 14px; }
  .btn { font-size: 13px; padding: 12px 6px; }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .status-pill.live .dot { animation: none; }
  .sheet { animation: none; }
}
