:root {
  --ink: #f6f1ea;
  --muted: #b9b2a8;
  --accent: #e5484d;
  --glass: rgba(18, 16, 20, 0.62);
  /* נדרסים על ידי ערכת הנושא (themes.js) */
  --accent-ink: #ffffff;
  --frame: #faf8f4;
  --intro-bg: rgba(40, 18, 24, 0.85);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0e0e12;
  color: var(--ink);
  font-family: Inter, Assistant, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- intro ---------- */
.overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, var(--intro-bg), rgba(8, 8, 10, 0.96));
  z-index: 10;
  transition: opacity 0.9s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.intro-card { text-align: center; max-width: 420px; }
.intro-heart {
  font-size: 44px; color: var(--accent);
  animation: beat 1.4s ease-in-out infinite;
}
@keyframes beat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.18); }
  30% { transform: scale(1); }
  45% { transform: scale(1.12); }
}
.intro-card h1 {
  font-family: Fraunces, 'Frank Ruhl Libre', Georgia, serif;
  font-weight: 600;
  font-size: clamp(30px, 8vw, 44px);
  margin: 12px 0 8px;
  letter-spacing: -0.01em;
}
.intro-card p { color: var(--muted); font-size: 17px; margin: 0 0 28px; }

#enter-btn {
  font: 500 16px Inter, Assistant, sans-serif;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  padding: 14px 40px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s;
}
#enter-btn:active { transform: scale(0.96); }
#enter-btn:disabled { opacity: 0.5; cursor: default; }

#code {
  display: block;
  width: min(240px, 100%);
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: 500 18px Inter, Assistant, sans-serif;
  text-align: center;
  letter-spacing: 0.15em;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
#code:focus { border-color: var(--accent); }
#code.shake { animation: shake 0.4s ease; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.intro-card #code-hint { font-size: 14px; margin: 10px 0 0; }
.intro-card #code-error { color: #ff8a8d; font-size: 14px; margin: 6px 0 18px; min-height: 1.3em; }
.intro-card .hint { font-size: 13px; margin: 22px 0 0; opacity: 0.7; }
#hint-touch { display: none; }
@media (pointer: coarse) {
  #hint-desktop { display: none; }
  #hint-touch { display: block; }
}

/* ---------- caption ---------- */
.caption {
  position: fixed;
  left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  max-width: min(86vw, 460px);
  padding: 14px 22px;
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 5;
}
.caption.show { opacity: 1; transform: translate(-50%, 0); }
#caption-text { font-family: Fraunces, 'Frank Ruhl Libre', Georgia, serif; font-size: 21px; }
#caption-date { font-size: 13px; color: var(--muted); margin-top: 4px; }
#caption-date:empty { display: none; }

/* ---------- finale ---------- */
.finale {
  position: fixed;
  left: 50%; top: 18%;
  transform: translate(-50%, -10px) scale(0.96);
  padding: 18px 28px;
  border-radius: 18px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-family: Fraunces, 'Frank Ruhl Libre', Georgia, serif;
  font-size: clamp(20px, 5vw, 28px);
  text-align: center;
  max-width: 88vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease, transform 0.8s ease;
  z-index: 6;
}
.finale.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: center;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.6s ease;
}
body.playing #hud { opacity: 1; }
#progress { font-size: 13px; color: var(--muted); letter-spacing: 0.04em; }
.hud-buttons { display: flex; gap: 10px; }
.round {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--glass);
  color: var(--ink);
  font-size: 19px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.round.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------- joystick (touch only) ---------- */
#joystick {
  position: fixed;
  left: calc(28px + env(safe-area-inset-left));
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  display: none;
  z-index: 4;
}
#knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}
@media (pointer: coarse) {
  body.playing #joystick { display: block; }
  .caption { bottom: calc(170px + env(safe-area-inset-bottom)); }
}

/* ---------- large photo viewer ---------- */
.viewer {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 70px 16px calc(40px + env(safe-area-inset-bottom));
  background: rgba(8, 7, 10, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  z-index: 3;
  cursor: pointer;
}
.viewer.show { opacity: 1; visibility: visible; transition: opacity 0.35s ease; }
.viewer figure {
  margin: 0;
  display: flex; flex-direction: column; align-items: center;
  transform: scale(0.88) translateY(12px);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.viewer.show figure { transform: none; }
.viewer img {
  display: block;
  max-width: min(88vw, 1100px);
  max-height: calc(100vh - 210px);
  max-height: calc(100dvh - 210px);
  border: 10px solid var(--frame);
  border-radius: 4px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.viewer figcaption { text-align: center; margin-top: 16px; }
#viewer-text { font-family: Fraunces, 'Frank Ruhl Libre', Georgia, serif; font-size: clamp(20px, 4.5vw, 28px); }
#viewer-date { font-size: 14px; color: var(--muted); margin-top: 4px; }
#viewer-date:empty { display: none; }
.viewer img { -webkit-user-drag: none; pointer-events: none; }
@media (pointer: coarse) and (orientation: portrait) {
  .viewer { padding-bottom: calc(170px + env(safe-area-inset-bottom)); }
  .viewer img { max-height: calc(100dvh - 330px); }
}

/* טלפון לרוחב: הג'ויסטיק בצד, אז התמונה והכיתוב יכולים לתפוס את כל הגובה */
@media (pointer: coarse) and (orientation: landscape) {
  .caption { bottom: calc(16px + env(safe-area-inset-bottom)); max-width: min(52vw, 460px); }
  #joystick { width: 104px; height: 104px; bottom: calc(18px + env(safe-area-inset-bottom)); }
  .viewer { padding: 12px 140px calc(12px + env(safe-area-inset-bottom)); }
  .viewer img { max-width: 100%; max-height: calc(100dvh - 100px); border-width: 6px; }
  .viewer figcaption { margin-top: 8px; }
  #viewer-text { font-size: 19px; }
  #hud { top: calc(10px + env(safe-area-inset-top)); left: calc(16px + env(safe-area-inset-left)); right: calc(16px + env(safe-area-inset-right)); }
  .finale { top: 12%; }
}
