:root {
  --bg: #05060f;
  --surface: rgba(16, 20, 44, 0.82);
  --surface-strong: rgba(22, 27, 58, 0.95);
  --border: rgba(140, 160, 255, 0.22);
  --text: #f2f4ff;
  --muted: #aab3dd;
  --accent: #ffb52e;
  --accent-text: #1a1206;
  --highlight: rgba(255, 181, 46, 0.25);
  --radius: 16px;
  --font: 'Rubik', 'Segoe UI', 'Arial Hebrew', Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
  /* בטלפון: בלי הגדלת דף בצביטה או בהקשה כפולה (בסצנה מתקרבים עם האצבעות), ובלי הגדלת טקסט אוטומטית */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

#scene, #scene canvas {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}
/* "עדשה": השוליים של התמונה כהים מעט, כמו בצילום במצלמה – מושך את העין למרכז */
#scene::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.42) 100%);
}

/* ---------- כפתורים ---------- */
.btn {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-strong); }
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }
.btn-primary:hover { background: #ffc657; }
.btn-icon { padding: 8px 12px; min-width: 42px; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-big { font-size: 18px; padding: 14px 26px; }

/* ---------- סרגל עליון ---------- */
.topbar {
  position: fixed;
  top: 0;
  inset-inline: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- הגדרות קול ---------- */
.settings {
  position: fixed;
  top: 64px;
  inset-inline-end: 16px;
  z-index: 20;
  width: min(300px, calc(100vw - 32px));
  padding: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
}
.settings[hidden] { display: none; }
.settings h2 { margin: 0 0 12px; font-size: 18px; }
.setting { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.setting > span:first-child { display: flex; justify-content: space-between; }
.setting output { color: var(--accent); font-variant-numeric: tabular-nums; }
.setting input { width: 100%; accent-color: var(--accent); }
.setting-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.settings-actions { display: flex; gap: 8px; }
.credit { margin: 12px 0 0; font-size: 11px; opacity: 0.6; }
.credit a { color: inherit; }
.voice-status { margin: 12px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---------- זמן ---------- */
.timebar {
  position: fixed;
  top: 64px;
  inset-inline-start: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  font-size: 13px;
}
.speed { display: flex; flex-direction: column; gap: 2px; color: var(--muted); }
.speed input { width: 140px; accent-color: var(--accent); }
.clock { display: flex; flex-direction: column; gap: 2px; min-width: 130px; }
#date-label { font-weight: 500; font-size: 14px; }
#speed-label { color: var(--muted); }

/* ---------- תוויות על כוכבי הלכת ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, 0);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: rgba(5, 6, 15, 0.55);
  border: 1px solid transparent;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.label:hover, .label.active { border-color: var(--accent); background: rgba(5, 6, 15, 0.8); }

/* ---------- בחירת כוכב לכת ---------- */
.chooser {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  overflow-x: auto;
  scrollbar-width: none;
}
.chooser::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 64px;
  padding: 8px 6px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.chip:hover { background: var(--surface-strong); }
.chip.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chip .ball-emoji { font-size: 20px; line-height: 22px; }
.chip .ball {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset -5px -4px 8px rgba(0, 0, 0, 0.45);
}

/* ---------- חלון מידע ---------- */
.panel {
  position: fixed;
  top: 64px;
  inset-inline-end: 16px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  animation: pop 0.25s ease-out;
}
.panel[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
.close {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.close:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.panel-head { display: flex; align-items: center; gap: 12px; padding-inline-end: 30px; }
.panel h2 { margin: 0; font-size: 26px; }
.subtitle { margin: 2px 0 0; color: var(--muted); }
.dot {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  box-shadow: inset -8px -6px 12px rgba(0, 0, 0, 0.45);
}
.listen { margin: 14px 0 6px; }
.live { margin: 6px 0 0; font-size: 14px; color: var(--accent); font-variant-numeric: tabular-nums; }
.live[hidden] { display: none; }
.narration { font-size: 17px; line-height: 1.7; margin: 8px 0; }
.narration span { border-radius: 6px; transition: background 0.2s; }
.narration span.speaking { background: var(--highlight); }
.fun {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 181, 46, 0.12);
  border: 1px solid rgba(255, 181, 46, 0.35);
  font-size: 15px;
  line-height: 1.5;
}
.fun:empty { display: none; }
.fun::before { content: 'הידעתם? '; font-weight: 700; color: var(--accent); }
.facts { margin: 12px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.facts:empty { display: none; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* ---------- אופק שואל אם להמשיך ---------- */
.ask {
  margin: 12px 0 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 181, 46, 0.14);
  border: 1px solid rgba(255, 181, 46, 0.5);
  animation: pop 0.25s ease-out;
}
.ask[hidden] { display: none; }
.ask p { margin: 0 0 10px; font-size: 17px; }
.ask-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- ירחים ---------- */
.moons { margin: 12px 0; }
.moons[hidden] { display: none; }
.moons h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); font-weight: 500; }
.moons-list { display: flex; flex-wrap: wrap; gap: 6px; }
.moons-list .btn { font-size: 14px; padding: 6px 12px; }
.label.motion-label { color: #cfe0ff; border-color: rgba(157, 184, 255, 0.6); pointer-events: none; }
.label.moon-label { font-size: 12px; padding: 1px 8px; color: #dfe4ff; }

/* ---------- מושגים ---------- */
.term {
  font: inherit;
  color: #ffd27a;
  background: none;
  border: 0;
  border-bottom: 2px dotted rgba(255, 181, 46, 0.8);
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 0;
}
.term:hover, .term:focus-visible { background: var(--highlight); outline: none; }
body.term-open #panel { visibility: hidden; }
.term-card { z-index: 3; border-color: rgba(255, 181, 46, 0.55); background: var(--surface-strong); }
.term-emoji { font-size: 34px; line-height: 1; }
.term-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.term-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 14px; }
.term-grid .btn { border-radius: 12px; text-align: start; white-space: normal; padding: 8px 10px; }
#term-list[hidden], #term-view[hidden] { display: none; }

/* ---------- סיור ---------- */
.tourbar {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
}
.tourbar[hidden] { display: none; }

/* ---------- מסך פתיחה ---------- */
.intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(5, 6, 15, 0.45), rgba(5, 6, 15, 0.9));
  z-index: 10;
}
.intro[hidden] { display: none; }
.intro-card {
  max-width: 480px;
  text-align: center;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  backdrop-filter: blur(12px);
}
.intro h2 { margin: 6px 0 10px; font-size: 30px; }
.intro p { color: var(--muted); font-size: 17px; line-height: 1.6; margin: 0 0 18px; }
.intro-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.voice-note {
  margin-top: 16px !important;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 120, 80, 0.12);
  border: 1px solid rgba(255, 120, 80, 0.4);
  font-size: 14px !important;
  color: var(--text) !important;
}
.hint { font-size: 14px !important; margin: 16px 0 0 !important; }

/* ---------- אופק המדריך ---------- */
.presenter {
  position: fixed;
  left: 0;
  top: 0;
  width: 300px;
  height: 330px;
  /* הגוף נעלם בהדרגה בתחתית, במקום להיחתך בקו ישר */
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 98%);
  mask-image: linear-gradient(to bottom, #000 72%, transparent 98%);
  pointer-events: none;
  z-index: 11;
  transition: transform 0.7s cubic-bezier(0.3, 1.25, 0.5, 1);
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.5));
}
.presenter[hidden] { display: none; }
.presenter canvas { display: block; }

/* ---------- טלפון ---------- */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 6px; padding: 8px 12px; }
  .brand { font-size: 17px; }
  .actions { flex-wrap: nowrap; gap: 6px; }
  .btn { font-size: 14px; padding: 7px 12px; }
  .timebar {
    top: auto;
    bottom: 84px;
    inset-inline: 12px;
    justify-content: space-between;
    padding: 6px 10px;
  }
  .speed input { width: 100px; }
  .clock { min-width: 0; }
  .panel {
    top: auto;
    bottom: 84px;
    inset-inline: 8px;
    width: auto;
    max-height: 36vh;
    padding: 12px 14px;
    z-index: 2;
  }
  .panel h2 { font-size: 22px; }
  .narration { font-size: 16px; }
  /* בזמן סיור: סרגל הסיור יורד לתחתית במקום בורר כוכבי הלכת, כדי לא להסתיר את מערכת השמש */
  .tourbar { bottom: max(12px, env(safe-area-inset-bottom)); gap: 6px; padding: 6px 8px; }
  body.touring .chooser { display: none; }
  body.touring .panel { bottom: 70px; }
  body.panel-open .timebar { display: none; }
  .chooser { justify-content: flex-start; }
  .chip { min-width: 58px; font-size: 12px; }
  .presenter { width: 150px; height: 135px; }
  .hide-phone { display: none; }
  /* בטלפון יש שישה כפתורים בשורה העליונה – מקטינים את כפתורי הסמלים כדי שכולם ייכנסו */
  .actions { gap: 4px; }
  .btn-icon { min-width: 36px; padding: 6px 8px; }
}
.settings-guide { display: block; margin-top: 12px; }

/* בחלונות ההסבר מותר רק לגלול למעלה ולמטה, בלי צביטה שמגדילה את כל הדף */
.panel, .settings, .intro { touch-action: pan-y; }

/* ---------- טלפון לרוחב (מסך רחב אבל נמוך) ---------- */
@media (max-height: 500px) and (min-width: 721px) {
  .topbar { padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); justify-content: flex-end; }
  .brand { display: none; }
  .actions { gap: 6px; }
  .btn { font-size: 13px; padding: 5px 10px; }
  .btn-icon { min-width: 34px; padding: 5px 8px; }
  .hide-phone { display: none; }
  .timebar { top: 6px; inset-inline-start: 10px; padding: 4px 8px; gap: 6px; font-size: 11px; }
  .speed span { display: none; }
  .speed input { width: 90px; }
  .clock { min-width: 0; }
  #date-label { font-size: 12px; }
  .panel {
    top: 48px;
    bottom: 64px;
    max-height: none;
    width: min(340px, 45vw);
    padding: 10px 14px;
  }
  .panel h2 { font-size: 19px; }
  .narration { font-size: 15px; line-height: 1.55; }
  .dot { width: 30px; height: 30px; }
  .chooser { padding: 4px 8px; padding-bottom: max(4px, env(safe-area-inset-bottom)); justify-content: flex-start; }
  .chip { min-width: 50px; padding: 4px 4px; gap: 2px; font-size: 11px; }
  .chip .ball { width: 16px; height: 16px; }
  .chip .ball-emoji { font-size: 15px; line-height: 16px; }
  .tourbar { bottom: 62px; left: auto; right: 10px; transform: none; padding: 4px 6px; font-size: 13px; }
  .presenter { width: 150px; height: 165px; }
  .intro-card { max-height: calc(100vh - 24px); overflow-y: auto; padding: 16px 18px; }
  .intro h2 { font-size: 22px; margin: 0 0 6px; }
  .intro p { font-size: 15px; margin-bottom: 10px; }
  .btn-big { font-size: 15px; padding: 9px 18px; }
  .settings { top: 48px; max-height: calc(100vh - 60px); overflow-y: auto; }
}

/* אפקטים של הפתיחה בסיור: כפתור שזוהר, ותאריך שמהבהב */
.btn.glow { animation: glow 1.1s ease-in-out infinite alternate; }
@keyframes glow {
  from { box-shadow: 0 0 0 0 rgba(255, 200, 80, 0); }
  to { box-shadow: 0 0 14px 4px rgba(255, 200, 80, 0.85); border-color: #ffc850; }
}
.flash { animation: flash 0.6s ease-in-out 3; }
@keyframes flash { 50% { color: #ffc850; text-shadow: 0 0 10px rgba(255, 200, 80, 0.9); } }

/* שביל החלב מבחוץ: "אנחנו כאן" ו"מרכז הגלקסיה" */
.label.milky-here { background: rgba(40, 120, 255, 0.45); border-color: rgba(140, 210, 255, 0.9); font-weight: 700; pointer-events: auto; cursor: pointer; }
.label.milky-centre { background: rgba(120, 80, 20, 0.45); border-color: rgba(255, 210, 140, 0.8); }

/* מעבר רך בין העברית לאנגלית: הדף נעלם בעדינות ונכנס בעדינות */
@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
body { animation: page-in 0.6s ease-out both; }
body.leaving { opacity: 0; transition: opacity 0.35s ease-in; }
@media (prefers-reduced-motion: reduce) { body { animation: none; } body.leaving { transition: none; } }

/* אפשרויות למפתחים בתוך ההגדרות (מוסתרות כברירת מחדל) */
.dev-settings { margin-top: 14px; padding-top: 12px; border-top: 1px dashed rgba(255, 255, 255, 0.2); }
.dev-settings h3 { margin: 0 0 10px; font-size: 15px; }
.dev-settings select { width: 100%; padding: 6px 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.08); color: inherit; border: 1px solid rgba(255, 255, 255, 0.2); font: inherit; }
.dev-settings select option { color: #000; }
.dev-note { font-size: 12px; opacity: 0.75; margin: 4px 0 10px; }
.dev-settings[hidden] { display: none; }

/* גרעין של סרט צילום: רעש עדין שקופץ למקום אחר כמה פעמים בשנייה */
.film-grain {
  position: fixed;
  inset: -64px;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  animation: grain-shift 0.5s steps(5) infinite;
}
@keyframes grain-shift {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-37px, 21px); }
  40% { transform: translate(19px, -43px); }
  60% { transform: translate(-11px, 33px); }
  80% { transform: translate(41px, 9px); }
  100% { transform: translate(0, 0); }
}
@media (prefers-reduced-motion: reduce) { .film-grain { animation: none; } }

/* "טסים בחלל": כפתור למעבר בין מהירות אמיתית למואטת, בתוך חלון ההסבר */
.motion-speed-btn { margin-top: 4px; }
.label.voyager-label { color: #eaf6ff; border-color: rgba(140, 220, 255, 0.7); }
.label.centre-label { color: #ffd9a8; border-color: rgba(255, 179, 71, 0.6); pointer-events: none; }
