/* ===== לוח שנה מעומד — דפדוף בספר ===== */

:root {
  color-scheme: light;
  --bg: #ece4d6;
  --bg-2: #e2d7c4;
  --surface: #fffdf8;
  --surface-2: #f7f1e6;
  --ink: #2a2018;
  --ink-2: #6b5c4a;
  --ink-3: #9b8b76;
  --line: #d9cdb8;
  --accent: #7d1f2e;
  --accent-ink: #fff;
  --gold: #a8823c;
  --shadow-book: 0 24px 60px -18px rgba(52, 36, 18, .48), 0 4px 14px rgba(52, 36, 18, .18);
  --radius: 12px;
  --bar: rgba(255, 253, 248, .88);
  --font: "Heebo", "Segoe UI", "Arial Hebrew", system-ui, sans-serif;
  --serif: "Frank Ruhl Libre", "Times New Roman", serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14120f;
  --bg-2: #1b1815;
  --surface: #23201b;
  --surface-2: #2b271f;
  --ink: #ece3d3;
  --ink-2: #b6a893;
  --ink-3: #8a7d69;
  --line: #3b352c;
  --accent: #c2823a;
  --accent-ink: #1a1510;
  --gold: #c2823a;
  --shadow-book: 0 24px 70px -16px rgba(0, 0, 0, .8), 0 4px 14px rgba(0, 0, 0, .5);
  --bar: rgba(27, 24, 21, .9);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, var(--bg-2), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

button, select, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

/* ---------- סרגל עליון ---------- */

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bar);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  z-index: 30;
  position: relative;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-inline-end: 6px;
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
}

.brand b {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand span {
  color: var(--ink-3);
  font-size: 12px;
  white-space: nowrap;
}

.spacer { flex: 1 1 auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  color: var(--ink-2);
  font-size: 14px;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); color: var(--accent-ink); }
.btn svg { width: 18px; height: 18px; flex: none; }

.btn-label { display: inline; }

/* ---------- במה ---------- */

.stage-wrap {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  min-height: 0;
}

.stage {
  flex: 1 1 auto;
  position: relative;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 18px;
  scrollbar-width: thin;
  touch-action: pan-x pan-y;
}

.stage.zoomed { cursor: grab; }
.stage.zoomed.dragging { cursor: grabbing; }

.book {
  position: relative;
  transform-style: preserve-3d;
  perspective: 2400px;
  flex: none;
}

.slot {
  position: absolute;
  top: 0;
  height: 100%;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-book);
}

.slot canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.slot.right {
  right: 0;
  border-radius: var(--radius) 0 0 var(--radius);
}

.slot.left {
  left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.book.single .slot {
  border-radius: var(--radius);
}

/* גב הכריכה — צל בשדרה */
.spine {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 44px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 3;
  background: linear-gradient(90deg,
      rgba(0, 0, 0, 0) 0%,
      rgba(60, 40, 20, .16) 42%,
      rgba(60, 40, 20, .28) 50%,
      rgba(60, 40, 20, .16) 58%,
      rgba(0, 0, 0, 0) 100%);
}

.book.single .spine { display: none; }

/* ---------- הדף המתהפך ---------- */

.leaf {
  position: absolute;
  top: 0;
  height: 100%;
  transform-style: preserve-3d;
  z-index: 10;
  pointer-events: none;
  will-change: transform;
}

.leaf.hidden { display: none; }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-book);
}

.face canvas { display: block; width: 100%; height: 100%; }

.face.back { transform: rotateY(180deg); }

.face .shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.leaf.fwd .face.front { border-radius: 0 var(--radius) var(--radius) 0; }
.leaf.fwd .face.back  { border-radius: var(--radius) 0 0 var(--radius); }
.leaf.back-dir .face.front { border-radius: var(--radius) 0 0 var(--radius); }
.leaf.back-dir .face.back  { border-radius: 0 var(--radius) var(--radius) 0; }

/* ---------- סרגל תחתון ---------- */

.footbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bar);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  transition: background .15s, color .15s, transform .1s;
}

.nav-btn:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.nav-btn:active:not(:disabled) { transform: scale(.94); }
.nav-btn:disabled { opacity: .35; cursor: default; }
.nav-btn svg { width: 20px; height: 20px; }

.dayline {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  line-height: 1.25;
}

.dayline .heb {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dayline .sub {
  font-size: 12px;
  color: var(--ink-3);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dayline .today-chip {
  display: inline-block;
  margin-inline-start: 6px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  vertical-align: 2px;
}

.slider-wrap {
  flex: 0 0 auto;
  width: min(30vw, 260px);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagebox {
  flex: 0 0 auto;
  width: min(30vw, 260px);
  display: flex;
  align-items: center;
  justify-content: center;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  direction: rtl;
}

.pagenum {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-3);
  min-width: 62px;
  text-align: center;
}

/* ---------- חלוניות ---------- */

.sheet {
  position: absolute;
  top: 100%;
  left: 10px;
  margin-top: 6px;
  width: min(420px, calc(100vw - 20px));
  max-height: min(70dvh, 560px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 50px -12px rgba(40, 26, 10, .35);
  padding: 14px;
  z-index: 40;
}

.sheet[hidden] { display: none; }
.sheet h3 { margin: 0 0 10px; font-size: 14px; color: var(--ink-2); font-weight: 600; }
.sheet h3 + h3 { margin-top: 16px; }

.field {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.field input[type="date"],
.field input[type="search"],
.field select {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 0; }

.months {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  padding: 5px 11px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--ink-2);
}

.chip:hover { border-color: var(--gold); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }

.days-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 5px;
}

.dcell {
  height: 46px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  font-size: 14px;
  font-family: var(--serif);
  font-weight: 700;
}

.dcell small {
  font-family: var(--font);
  font-weight: 400;
  font-size: 10px;
  color: var(--ink-3);
}

.dcell:hover { border-color: var(--gold); }
.dcell.cur { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.dcell.cur small { color: inherit; opacity: .8; }
.dcell.today { box-shadow: inset 0 0 0 2px var(--gold); }

/* חיפוש */

.result {
  display: block;
  width: 100%;
  text-align: start;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  margin-bottom: 4px;
}

.result:hover { background: var(--surface-2); border-color: var(--line); }
.result b { display: block; font-size: 12.5px; color: var(--accent); margin-bottom: 2px; font-weight: 600; }
:root[data-theme="dark"] .result b { color: var(--gold); }
.result span { font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.result mark { background: rgba(168, 130, 60, .32); color: inherit; border-radius: 3px; padding: 0 1px; }

.muted { color: var(--ink-3); font-size: 13px; padding: 6px 2px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--ink-2);
  padding: 6px 0;
  cursor: pointer;
}

.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- מסך טעינה ---------- */

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  z-index: 50;
  text-align: center;
  padding: 20px;
}

.loading[hidden] { display: none; }

.spin {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading p { margin: 0; color: var(--ink-2); font-size: 14px; }
.loading .err { color: var(--accent); max-width: 34em; line-height: 1.6; }

.toast {
  position: fixed;
  bottom: 74px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  background: var(--ink);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 99px;
  font-size: 13.5px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.toast.show { opacity: .96; }

/* ---------- אזורי הקשה לדפדוף ---------- */

.tapzone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 5;
  border: none;
  background: transparent;
  padding: 0;
}

.tapzone.next { left: 0; cursor: w-resize; }
.tapzone.prev { right: 0; cursor: e-resize; }
.tapzone:disabled { cursor: default; }
.stage-wrap.zoomed .tapzone { display: none; }

/* ---------- חץ הסמן ---------- */

.cursor-arrow {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 8;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;      /* ממורכז על נקודת הסמן */
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .3));
  will-change: transform, opacity;
}

.cursor-arrow svg { width: 100%; height: 100%; display: block; }
.cursor-arrow.flip svg { transform: scaleX(-1); }   /* חץ שמאלה = קדימה */

.cursor-arrow.on { opacity: .95; }

.stage-wrap.hide-cursor .tapzone { cursor: none; }

/* ---------- רמז ראשוני ---------- */

.hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--ink) 92%, transparent);
  color: var(--bg);
  font-size: 13.5px;
  box-shadow: 0 10px 26px -8px rgba(0, 0, 0, .4);
  pointer-events: none;
  opacity: 0;
  transition: opacity .45s;
}

.hint svg { width: 19px; height: 19px; flex: none; }
.hint.show { opacity: .95; }
.hint[hidden] { display: none; }

@media (max-width: 660px) {
  .hint { font-size: 12.5px; padding: 8px 13px; top: 10px; }
}

/* במסכי מגע אין ריחוף — החץ לא רלוונטי */
@media (hover: none) {
  .cursor-arrow { display: none; }
}

/* ---------- רספונסיבי ---------- */

@media (max-width: 900px) {
  .btn-label { display: none; }
  .brand span { display: none; }
  .slider-wrap { display: none; }
  .pagebox { width: auto; }
}

@media (max-width: 660px) {
  .bar { padding: 6px 6px; gap: 1px; }
  .brand { display: none; }
  .btn { height: 34px; min-width: 34px; padding: 0 5px; }
  .btn svg { width: 17px; height: 17px; }
  .stage { padding: 10px; }
  .footbar { padding: 6px 8px; gap: 6px; }
  .dayline .heb { font-size: 15px; }
  .pagenum { font-size: 11px; min-width: 0; }
  .nav-btn { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  .leaf { transition: none !important; }
}
