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

:root {
  --app-h: 100dvh;
  --app-w: 100vw;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Vazirmatn', system-ui, sans-serif;
  background: #0b0d12; color: #e6e7ea;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
a { color: #7ea7ff; text-decoration: none; }
.muted { color: #8a90a0; }
.small { font-size: 12px; }
.center { text-align: center; }

/* ---------- Login ---------- */
.login-bg {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at top, #1a2240, #0b0d12);
  padding: 20px;
}
.lic-card {
  width: 100%; max-width: 380px;
  background: #14171f; border: 1px solid #232735; border-radius: 14px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.lic-card h1 { margin: 0; font-size: 18px; text-align: center; }
.lic-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.lic-card input {
  background: #0b0d12; border: 1px solid #2c3142; color: #fff;
  padding: 12px 14px; border-radius: 10px; font: inherit; letter-spacing: 1px;
}
.lic-card input:focus { outline: 2px solid #4a6dd0; }
.btn { background:#4a6dd0; color:#fff; border:0; padding:12px 16px; border-radius:10px; cursor:pointer; font:inherit; }
.btn:hover { background: #5a7de0; }
.flash { padding: 10px 14px; border-radius: 8px; }
.flash-error { background: #3b1d22; color: #ffb8c0; border: 1px solid #5b2a30; }
.dev-block { background: #0b0d12; border: 1px dashed #2c3142; padding: 12px; border-radius: 10px; display:flex; flex-direction:column; gap: 8px; }

/* ---------- Player layout ---------- */
.player-page {
  height: 100vh;
  height: 100dvh;
  height: var(--app-h);
  overflow: hidden;
}
body.lock-scroll { overflow: hidden; touch-action: none; }
.player-shell {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: 100vh;
  height: 100dvh;
  height: var(--app-h);
}
.player-pane { display: flex; flex-direction: column; min-width: 0; }
.player-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid #232735;
}

/* video-wrap is the iframe container */
.video-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
.video-wrap iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  max-width: none;
  border: 0;
  background: #000;
  display: none;
}
.video-wrap.has-video iframe {
  display: block;
}
.placeholder {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #b9bdca;
  pointer-events: none;
  background:
    radial-gradient(circle at center, rgba(74,109,208,0.08), transparent 60%),
    linear-gradient(180deg, #11151f, #0b0d12);
}
.video-wrap.has-video .placeholder {
  display: none;
}
.ph-inner {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 20px;
}
.ph-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(74,109,208,0.15);
  border: 2px solid rgba(74,109,208,0.4);
  display: flex; align-items: center; justify-content: center;
  color: #7ea7ff; font-size: 26px;
  padding-right: 4px; /* visually center the play triangle */
}
.ph-title { font-size: 16px; color: #e6e7ea; font-weight: 500; }
.ph-sub { font-size: 13px; color: #8a90a0; }

/* watermark above iframe — only shown when video is playing */
.wm {
  position: fixed;
  top: 0; left: 0;
  color: rgba(255,255,255,0.45);
  font-size: 14px;
  text-shadow: 0 0 6px rgba(0,0,0,0.7);
  pointer-events: none;
  transition: top 1s linear, left 1s linear, opacity .3s;
  letter-spacing: 0.5px;
  background: rgba(0,0,0,0.15);
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 9999;
  opacity: 0;
}
body.is-playing .wm { opacity: 0.75; }

/* loader */
.loader-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: rgba(11, 13, 18, 0.92);
  z-index: 50;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.loader-overlay.active {
  display: flex;
}
.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: #4a6dd0;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner-text {
  color: #8a90a0;
  font-size: 13px;
}

/* fullscreen button */
.fs-btn {
  position: absolute;
  top: 14px; left: 14px;
  z-index: 200;
  background: rgba(74,109,208,0.92);
  color: #fff;
  border: 0;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  transition: background .2s, transform .15s, box-shadow .2s;
}
.fs-btn .fs-ico { font-size: 15px; }
.fs-btn .fs-txt { font-weight: 600; letter-spacing: 0.2px; }
.fs-btn:hover, .fs-btn:focus { background: #5a7de0; outline: none; box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.fs-btn:active { transform: scale(0.96); }
.fs-btn.is-on { background: rgba(220,68,80,0.92); }
.fs-btn.is-on:hover, .fs-btn.is-on:focus { background: #e0556a; }

/* rotate hint shown only in mobile portrait fullscreen */
.rotate-hint {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 250;
  display: none;
  text-align: center;
  max-width: 80%;
}
.rotate-hint.show { display: block; }

/* fullscreen state — uses inset for RTL safety */
.video-wrap.in-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  width: var(--app-w);
  height: 100vh;
  height: 100dvh;
  height: var(--app-h);
  z-index: 9999;
  background: #000;
}
.video-wrap.in-fullscreen iframe {
  width: 100%;
  height: 100%;
}
.video-wrap.in-fullscreen .fs-btn {
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  padding: 10px 16px;
  font-size: 14px;
}
.video-wrap.in-fullscreen .fs-btn .fs-ico { font-size: 16px; }

.now-playing { padding: 10px 16px; margin: 0; font-size: 14px; color: #b9bdca; border-top: 1px solid #232735; }

/* TOC */
.toc-pane {
  background: #14171f; border-right: 1px solid #232735;
  display: flex; flex-direction: column;
  height: 100vh;
  height: 100dvh;
  height: var(--app-h);
}
.toc-header { padding: 14px 16px; border-bottom: 1px solid #232735; display: flex; justify-content: space-between; align-items: center; }
.toc { overflow-y: auto; padding: 8px 0; flex: 1; }

.ps-sec { border-bottom: 1px solid #1c2030; }
.ps-sec > summary {
  list-style: none; cursor: pointer;
  padding: 12px 18px; display: flex; justify-content: space-between; align-items: center;
  background: #14171f; font-weight: 500;
}
.ps-sec > summary::-webkit-details-marker { display: none; }
.ps-sec > summary:hover { background: #1a1e29; }
.ps-sec[open] > summary .chev { transform: rotate(90deg); }
.chev { color: #7ea7ff; transition: transform .2s; }
.ps-body { padding: 4px 8px 8px 18px; display: flex; flex-direction: column; gap: 2px; }
.ep-btn {
  display: flex; align-items: center; gap: 10px;
  background: transparent; color: #cdd1da; border: 0; text-align: right;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit;
}
.ep-btn:hover { background: #1c2030; }
.ep-btn.active { background: #2a3454; color: #fff; }
.ep-btn .dot { width: 6px; height: 6px; border-radius: 50%; background: #4a6dd0; }
.ep-btn .t { flex: 1; }
.ep-btn .d { color: #8a90a0; font-size: 12px; }

.link-btn { background:none; border:0; color:#7ea7ff; cursor:pointer; font:inherit; }

.toc-toggle, .mobile-only { display: none; }
.desktop-only { display: inline-block; }

/* mobile player */
@media (max-width: 820px) {
  body.is-playing .player-header {
    display: none;
  }
  body.is-playing .now-playing {
    display: none;
  }
  .player-shell {
    display: flex; flex-direction: column;
    height: 100vh;
    height: 100dvh;
    height: var(--app-h);
    overflow: hidden;
  }
  .player-pane {
    flex: 1 1 auto;
    display: flex; flex-direction: column;
    min-height: 0;
  }
  .video-wrap {
    flex: none;
    aspect-ratio: 16 / 9;
    width: 100%;
    min-height: 0;
    height: auto;
    max-height: none;
  }
  .video-wrap.in-fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw;
    width: var(--app-w);
    height: 100vh;
    height: 100dvh;
    height: var(--app-h);
    max-height: none;
    aspect-ratio: auto;
  }
  .video-wrap {
    min-height: 180px;
  }
  .toc-pane {
    position: fixed; top: 0; right: 0; bottom: 0; left: auto;
    width: 86%; max-width: 360px;
    transform: translateX(100%); transition: transform .25s;
    z-index: 20;
    height: 100vh;
    height: 100dvh;
    height: var(--app-h);
    border-right: 0; border-left: 1px solid #232735;
  }
  .toc-pane.open { transform: translateX(0); }
  .toc-toggle {
    display: inline-block; position: fixed; bottom: 18px; left: 18px;
    background: #4a6dd0; color: #fff; border: 0;
    padding: 12px 18px; border-radius: 999px;
    z-index: 21; cursor: pointer; font: inherit;
    box-shadow: 0 4px 16px rgba(74,109,208,0.4);
  }
  body.is-playing .toc-toggle {
    top: 10px;
    right: 10px;
    bottom: auto;
    left: auto;
    padding: 7px 12px;
    z-index: 200;
    opacity: 1;
    font-size: 12px;
    background: rgba(74,109,208,0.92);
    box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  }
  .mobile-only { display: inline-block; }
  .desktop-only { display: none; }
  .now-playing { padding: 8px 12px; font-size: 12px; }
  .player-header { padding: 10px 12px; font-size: 13px; }
  .ph-icon { width: 52px; height: 52px; font-size: 22px; }
  .ph-title { font-size: 15px; }
  .ph-sub { font-size: 12px; }
  .lic-card { padding: 18px; max-width: 100%; border-radius: 12px; }
  .lic-card h1 { font-size: 16px; }
  /* fs button — distinct pill so users find it easily */
  .fs-btn {
    top: 10px; left: 10px;
    padding: 7px 12px;
    font-size: 12px;
  }
  .fs-btn .fs-ico { font-size: 14px; }
  .toc-toggle:focus,
  .toc-toggle:hover { opacity: .9; }
  body.is-playing .wm {
    font-size: 12px;
    padding: 3px 8px;
    background: rgba(0,0,0,0.22);
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  body.is-playing .player-shell {
    display: flex;
    flex-direction: column;
    height: var(--app-h);
    overflow: hidden;
  }
  body.is-playing .player-pane {
    flex: 1 1 auto;
    min-height: 0;
  }
  body.is-playing .player-header,
  body.is-playing .now-playing {
    display: none;
  }
  body.is-playing .video-wrap {
    flex: 1 1 auto;
    aspect-ratio: auto;
    height: var(--app-h);
    min-height: 0;
    max-height: none;
  }
  body.is-playing .toc-pane {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: auto;
    width: 86%; max-width: 360px;
    height: var(--app-h);
    transform: translateX(100%);
    z-index: 20;
    border-right: 0;
    border-left: 1px solid #232735;
  }
  body.is-playing .toc-pane.open {
    transform: translateX(0);
  }
  body.is-playing .toc-toggle {
    display: inline-block;
    position: fixed;
    top: 10px;
    right: 10px;
    left: auto;
    bottom: auto;
    padding: 7px 12px;
    z-index: 200;
    opacity: 1;
    font-size: 12px;
    background: rgba(74,109,208,0.92);
    box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  }
  body.is-playing .fs-btn {
    top: 10px;
    left: 10px;
    padding: 7px 12px;
  }
}

@media (max-width: 480px) {
  .login-bg { padding: 12px; }
  .lic-card { padding: 16px; }
}
