/* ---------------------------------------------------------------
   ספריית אווטאר — dark ink base, one accent per book (nation).
   Reisinger Neta (Light/Regular/Medium/Bold) is self-hosted from
   /web/fonts. IBM Plex Mono carries numerals and timecodes only.
----------------------------------------------------------------*/
@font-face {
  font-family: 'Reisinger Neta';
  src: url('/fonts/Reisinger-Neta-Light.woff2') format('woff2'),
       url('/fonts/Reisinger-Neta-Light.woff') format('woff');
  font-weight: 300; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Reisinger Neta';
  src: url('/fonts/Reisinger-Neta-Regular.woff2') format('woff2'),
       url('/fonts/Reisinger-Neta-Regular.woff') format('woff');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Reisinger Neta';
  src: url('/fonts/Reisinger-Neta-Medium.woff2') format('woff2'),
       url('/fonts/Reisinger-Neta-Medium.woff') format('woff');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Reisinger Neta';
  src: url('/fonts/Reisinger-Neta-Bold.woff2') format('woff2'),
       url('/fonts/Reisinger-Neta-Bold.woff') format('woff');
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --ink:      #0C1216;
  --ink-2:    #131C21;
  --surface:  #1A252B;
  --line:     rgba(237, 230, 216, .10);
  --paper:    #EDE6D8;
  --muted:    #8FA0A8;

  --water:  #3E86C4;
  --earth:  #6FA24A;
  --fire:   #C4453A;
  --air:    #E8A33D;
  --spirit: #7C6BC4;

  --accent: var(--air);
  --spring: cubic-bezier(.22, 1.15, .36, 1);
  --dock-h: 68px;
  font-family: 'Noto Sans Hebrew', system-ui, sans-serif;
}

/* Reisinger Neta reads as a display face, not a body face — reserved
   for headings only. Everything else uses Noto Sans Hebrew. */
h1, h2, .book-card .t {
  font-family: 'Reisinger Neta', system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* Class-level display rules outrank the browser default for [hidden],
   so every overlay needs this to actually stay closed. */
[hidden] { display: none !important; }

html {
  background: var(--ink);
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(120% 60% at 50% 0%, #16232A 0%, var(--ink) 62%);
  color: var(--paper);
  min-height: 100dvh;
  padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom) + 20px);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.eyebrow {
  font-size: 11px; font-weight: 500; letter-spacing: .34em;
  color: var(--muted); text-transform: none;
}

/* ------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; padding: 26px 20px 14px; flex-wrap: wrap;
}
.brand h1 {
  margin: 2px 0 0; font-size: 30px; font-weight: 700; letter-spacing: -.01em;
}
.search { flex: 1 1 220px; max-width: 380px; }
.search input {
  width: 100%; padding: 11px 16px; border-radius: 999px;
  background: var(--ink-2); border: 1px solid var(--line);
  transition: border-color .25s, background .25s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--accent); background: var(--surface); outline: none; }

/* ------------------------------------------- series + book rail */
.series-switch { display: flex; gap: 8px; padding: 4px 20px 10px; }
.series-switch button {
  padding: 7px 14px; border-radius: 999px; font-size: 13px; color: var(--muted);
  border: 1px solid var(--line); transition: all .3s var(--spring);
}
.series-switch button.on { color: var(--ink); background: var(--paper); border-color: var(--paper); }

.rail {
  display: flex; gap: 10px; padding: 6px 20px 18px;
  overflow-x: auto; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }

.book-card {
  --c: var(--muted);
  flex: 0 0 auto; width: 132px; padding: 14px 14px 12px;
  border-radius: 18px; text-align: start;
  background: linear-gradient(160deg, color-mix(in oklab, var(--c) 22%, var(--ink-2)), var(--ink-2));
  border: 1px solid color-mix(in oklab, var(--c) 30%, transparent);
  transition: transform .4s var(--spring), border-color .3s;
}
.book-card:hover { transform: translateY(-3px); }
.book-card.on { border-color: var(--c); transform: translateY(-3px); }
.book-card svg { width: 30px; height: 30px; color: var(--c); display: block; }
.book-card .n {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px;
  color: var(--muted); margin-top: 12px;
}
.book-card .t { font-weight: 700; font-size: 17px; line-height: 1.15; }
.book-card .c { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* -------------------------------------------------------- grid */
.grid {
  display: grid; gap: 14px; padding: 0 20px;
  /* --card-min is set from the size control in the ניהול tab */
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min, 158px), 1fr));
}
.card {
  --c: var(--accent);
  text-align: start; border-radius: 16px; overflow: hidden;
  background: var(--ink-2); border: 1px solid var(--line);
  animation: rise .5s var(--spring) both;
  transition: transform .35s var(--spring), border-color .3s;
}
.card:hover { transform: translateY(-4px); border-color: color-mix(in oklab, var(--c) 45%, transparent); }
.card .thumb {
  position: relative; aspect-ratio: 16 / 9; background: #0A0F12;
  display: grid; place-items: center; overflow: hidden;
}
.card.book .thumb { aspect-ratio: 2 / 3; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .thumb .fallback { color: color-mix(in oklab, var(--c) 60%, var(--muted)); }
.card .thumb .fallback svg { width: 34px; height: 34px; }
.card .body { padding: 10px 12px 13px; }
.card .no {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--c);
}
.card .name {
  font-size: 14px; font-weight: 500; margin-top: 3px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { font-size: 11px; color: var(--muted); margin-top: 6px; font-family: 'IBM Plex Mono', monospace; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.empty {
  text-align: center; color: var(--muted); padding: 60px 30px; font-size: 14px; line-height: 1.7;
}

/* -------------------------------------------------------- dock */
.dock {
  position: fixed; inset-inline: 0; bottom: calc(12px + env(safe-area-inset-bottom));
  margin-inline: auto; width: max-content; display: flex; gap: 4px; padding: 5px;
  border-radius: 999px; z-index: 30;
  background: rgba(19, 28, 33, .82); backdrop-filter: blur(18px);
  border: 1px solid var(--line); box-shadow: 0 12px 34px rgba(0,0,0,.5);
}
.dock button {
  padding: 9px 16px; border-radius: 999px; font-size: 13px; color: var(--muted);
  transition: all .35s var(--spring);
}
.dock button.on { background: var(--paper); color: var(--ink); font-weight: 500; }

/* ------------------------------------------------------- sheet */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end;
  justify-content: center; background: rgba(6, 10, 12, .66); backdrop-filter: blur(3px);
  animation: fade .25s ease both;
}
.sheet {
  --c: var(--accent);
  width: min(560px, 100%); max-height: 88dvh; overflow-y: auto; overflow-x: hidden;
  background: var(--ink-2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0; padding: 0 0 24px;
  animation: slide .45s var(--spring) both;
}
@media (min-width: 720px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 24px; border-bottom: 1px solid var(--line); }
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes slide { from { transform: translateY(40px); opacity: 0 } to { transform: none; opacity: 1 } }

.sheet .hero { position: relative; aspect-ratio: 16/9; background: #0A0F12; }
.sheet .hero img { width: 100%; height: 100%; object-fit: cover; }
.sheet .hero::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to top, var(--ink-2), transparent 62%);
}
.sheet .pad { padding: 0 22px; overflow-wrap: break-word; word-break: break-word; min-width: 0; }
.sheet h2 { margin: 18px 0 4px; position: relative; font-size: 23px; font-weight: 700; }
.sheet .hero + .pad h2 { margin-top: -34px; }
.sheet .sub { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--c); }
.sheet p.desc { color: var(--muted); line-height: 1.75; font-size: 14px; margin: 14px 0 0; }
.actions { display: flex; gap: 10px; margin: 20px 0 0; flex-wrap: wrap; }
.actions button {
  padding: 12px 22px; border-radius: 999px; font-weight: 500; font-size: 14px;
  transition: transform .3s var(--spring), opacity .2s;
}
.actions button:active { transform: scale(.96); }
.actions button:disabled { opacity: .45; pointer-events: none; }
.btn-main { background: var(--c); color: #0C1216; }
.btn-ghost { border: 1px solid var(--line); color: var(--paper); }
.sheet .stat { font-size: 12px; color: var(--muted); margin-top: 14px; font-family: 'IBM Plex Mono', monospace; }

/* --------------------------------------------- player / reader */
.stage {
  position: fixed; inset: 0; z-index: 60; background: #05090B;
  display: flex; align-items: center; justify-content: center;
  animation: fade .2s ease both;
}
.stage video { width: 100%; height: 100%; max-height: 100dvh; background: #000; }
.stage-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); inset-inline-end: 14px;
  z-index: 10; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(12,18,22,.72); backdrop-filter: blur(10px); font-size: 15px;
}
.stage-title {
  position: absolute; top: calc(20px + env(safe-area-inset-top)); inset-inline-start: 18px;
  font-size: 14px; color: rgba(237,230,216,.8); pointer-events: none;
  text-shadow: 0 2px 10px #000;
}

/* subtitles, drawn by us — direction/alignment are just normal CSS
   here, unlike the browser's own caption box which ignores both.
   (No unicode-bidi override: that would tell the browser to guess
   direction from content again instead of respecting the dir we set
   in JS, which is exactly the bug that was undoing the fix.) */
.sub-overlay {
  position: absolute; bottom: 12%; left: 50%; transform: translateX(-50%);
  max-width: 88%; width: max-content; z-index: 6;
  text-align: center;
  font-size: var(--sub-size, clamp(16px, 2.6vw, 26px));
  line-height: var(--sub-line-height, 1.45);
  color: var(--sub-color, #fff);
  text-shadow: var(--sub-outline, 0 2px 6px rgba(0,0,0,.9), 0 0 3px rgba(0,0,0,.9));
  background: var(--sub-bg, transparent);
  padding: var(--sub-bg-pad, 0);
  border-radius: 6px;
  pointer-events: none;
}
.sub-toggle {
  position: absolute; top: calc(62px + env(safe-area-inset-top)); inset-inline-end: 14px; z-index: 7;
  padding: 6px 14px; border-radius: 999px; font-size: 12px;
  background: rgba(12,18,22,.6); backdrop-filter: blur(10px); color: rgba(237,230,216,.85);
  opacity: 0; transition: opacity .3s ease; pointer-events: none;
}
.stage.controls-visible .sub-toggle { opacity: 1; pointer-events: auto; }

.reader { flex-direction: column; background: #15181A; }
.reader-bar {
  position: relative; width: 100%; padding: 14px 62px; display: flex; gap: 12px;
  align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line);
  font-size: 13px; padding-top: calc(14px + env(safe-area-inset-top));
}
.reader-bar .stage-close { top: calc(8px + env(safe-area-inset-top)); }
.reader-pos { font-family: 'IBM Plex Mono', monospace; color: var(--muted); font-size: 12px; }
.reader-body {
  flex: 1; width: 100%; overflow: auto;
  background: radial-gradient(120% 100% at 50% 0%, #22282B 0%, #15181A 70%);
}
.reader-body canvas, .reader-body img {
  display: block; margin: 22px auto; max-width: min(920px, 100%);
  border-radius: 3px; box-shadow: 0 18px 44px rgba(0, 0, 0, .45);
  animation: page-in .35s var(--spring) both;
}
@keyframes page-in { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }

.reader-loading {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; color: var(--muted); font-size: 13px;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.reader-nav {
  display: flex; gap: 10px; padding: 12px; justify-content: center;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.reader-nav button {
  padding: 10px 26px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px;
  transition: border-color .25s, transform .25s var(--spring);
}
.reader-nav button:active { transform: scale(.95); }

/* ------------------------------------------------------- misc */
.toast {
  position: fixed; bottom: calc(var(--dock-h) + 28px); inset-inline: 0; margin-inline: auto;
  width: max-content; max-width: 82vw; z-index: 70;
  background: var(--surface); border: 1px solid var(--line); color: var(--paper);
  padding: 11px 20px; border-radius: 999px; font-size: 13px;
  animation: slide .4s var(--spring) both;
}

.settings-list { padding: 0 20px; display: grid; gap: 12px; max-width: 460px; }
.settings-list button {
  padding: 15px 20px; border-radius: 16px; background: var(--ink-2);
  border: 1px solid var(--line); text-align: start; font-size: 15px;
  transition: border-color .3s;
}
.settings-list button:hover { border-color: var(--accent); }
.settings-list small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ------------------------------------------------------ login */
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.login { display: grid; gap: 12px; width: min(320px, 100%); text-align: center; }
.login h1 { margin: 2px 0 18px; font-size: 32px; font-weight: 700; }
.login input {
  padding: 13px 18px; border-radius: 999px; text-align: center;
  background: var(--ink-2); border: 1px solid var(--line);
}
.login input:focus { border-color: var(--air); outline: none; }
.login button { padding: 13px; border-radius: 999px; background: var(--air); color: var(--ink); font-weight: 500; }
.login-err { color: var(--fire); font-size: 13px; margin: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* quality picker inside the item sheet, for episodes with more than
   one uploaded version (e.g. a compressed MP4 next to the original) */
.quality { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.quality button {
  padding: 7px 14px; border-radius: 999px; font-size: 12.5px;
  font-family: 'IBM Plex Mono', monospace; color: var(--muted);
  border: 1px solid var(--line); transition: all .3s var(--spring);
}
.quality button.on { color: var(--ink); background: var(--c); border-color: var(--c); }

/* card-size control in the ניהול tab */
.setting-group {
  padding: 15px 20px; border-radius: 16px;
  background: var(--ink-2); border: 1px solid var(--line);
}
.setting-title { font-size: 15px; display: block; margin-bottom: 12px; }
.size-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.size-picker button {
  padding: 8px 16px; border-radius: 999px; font-size: 13px; color: var(--muted);
  border: 1px solid var(--line); transition: all .3s var(--spring);
}
.size-picker button.on { color: var(--ink); background: var(--paper); border-color: var(--paper); }

/* prevents the background page from panning/scrolling behind an
   open sheet/player/reader — a touch starting on the modal could
   otherwise drag the page underneath it too */
body.scroll-locked { overflow: hidden; position: fixed; inset: 0; width: 100%; }

/* subtitle appearance controls in the ניהול tab */
.sub-style-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.sub-style-row:first-of-type { margin-top: 0; }
.sub-style-label { font-size: 12.5px; color: var(--muted); min-width: 68px; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-row button {
  padding: 6px 13px; border-radius: 999px; font-size: 12.5px; color: var(--muted);
  border: 1px solid var(--line); transition: all .3s var(--spring);
}
.pill-row button.on { color: var(--ink); background: var(--paper); border-color: var(--paper); }
.pill-row .swatch {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
  margin-inline-end: 6px; background: var(--sw); vertical-align: middle;
}
