:root {
  --bg: #17082b;
  --bg-2: #3b1577;
  --card: #ffffff;
  --card-ink: #1b1035;
  --ink: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --accent: #ff6b35;
  --accent-2: #ffd166;
  --mint: #06d6a0;
  --pink: #ef476f;
  --sky: #4cc9f0;
  --glass: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.14);
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  color: var(--ink);
  text-align: start; /* הכיוון (ימין-לשמאל או שמאל-לימין) מגיע מ-dir של הדף, לפי השפה */
  background-color: var(--bg);
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font-family: inherit; touch-action: manipulation; }

.screen {
  display: none;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 8px 0 2px; }
/* כפתור החלפת השפה, בפינה של מסך הפתיחה */
.hero { position: relative; }
.lang-btn {
  position: absolute; top: 0; inset-inline-end: 0;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--glass-border); background: var(--glass); color: var(--ink);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.lang-btn:active { transform: scale(0.96); }
.hero .logo { font-size: 64px; line-height: 1; display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.hero h1 { margin: 6px 0 4px; font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
.hero .sub { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.4; }
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-8px) rotate(4deg); }
}

/* ---------- cards ---------- */
.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.card h2 { margin: 0 0 10px; font-size: 17px; font-weight: 700; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; line-height: 1.5; }
.hint-inline { color: var(--muted); font-size: 13px; font-weight: 400; }
.footer-note { color: var(--muted); font-size: 13px; line-height: 1.5; text-align: center; margin: 4px 0 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }

input[type="text"], input[type="url"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
input[dir="ltr"] { text-align: left; }
input::placeholder { color: rgba(255, 255, 255, 0.45); }
input:focus { border-color: var(--accent-2); }

/* ---------- chips & segmented ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.center { justify-content: center; }
.chips:empty { display: none; }
.chip {
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.chip.on { background: var(--accent); border-color: var(--accent); }
.chip:active { transform: scale(0.95); }
.chip .x { opacity: 0.75; margin-inline-start: 8px; font-weight: 800; }
.chip.player { background: rgba(76, 201, 240, 0.18); border-color: rgba(76, 201, 240, 0.4); }
.chip.big { font-size: 20px; padding: 14px 22px; }
.chip.playing { animation: chip-pulse 0.5s ease-in-out infinite alternate; }
@keyframes chip-pulse { from { transform: scale(1); } to { transform: scale(1.07); } }
#sp-login { margin-bottom: 10px; }
#sp-status { margin: 0 0 10px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent-2); font: inherit; text-decoration: underline; cursor: pointer; }

.seg { display: flex; background: rgba(0, 0, 0, 0.28); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 4px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.seg button.on { background: #fff; color: var(--card-ink); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
.seg.grid-2 { display: grid; grid-template-columns: 1fr 1fr; }
.src-panel { margin-top: 12px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  width: 100%;
  transition: transform 0.08s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--pink)); }
.btn-xl { padding: 20px; font-size: 22px; border-radius: 20px; }
.btn-ghost { background: rgba(255, 255, 255, 0.1); border: 1px solid var(--glass-border); }
.btn-ghost.dark { background: #f1eef8; color: var(--card-ink); border-color: #e4def2; }
.btn-small { padding: 12px 16px; font-size: 15px; width: auto; flex: 0 0 auto; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- settings ---------- */
details.card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 17px;
  font-weight: 700;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '▾'; color: var(--muted); font-size: 18px; transition: transform 0.2s; }
details.card[open] > summary { margin-bottom: 10px; }
details.card[open] > summary::after { transform: rotate(180deg); }
.icon-spacer { width: 42px; height: 42px; flex: 0 0 auto; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .hero .logo, .parcel, .parcel.still, .parcel-wrap.arrive, .hand, .eq i, .task-card { animation: none !important; }
}
.setting { margin: 10px 0; }
.setting label { display: block; font-size: 15px; margin-bottom: 6px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-size: 15px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; flex: 0 0 auto; }
.error {
  color: #ffd0d0;
  background: rgba(239, 71, 111, 0.22);
  border: 1px solid rgba(239, 71, 111, 0.45);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin: 0;
}
.install { display: flex; align-items: center; gap: 12px; }
.install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.install-text span { color: var(--muted); font-size: 13px; line-height: 1.4; }

/* ---------- game ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; }
.icon-btn {
  border: 0;
  background: var(--glass);
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
#round-label, .top-title { font-weight: 700; color: var(--muted); }
.me-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--glass);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex: 0 0 auto;
}
.me-badge.hidden { display: flex !important; visibility: hidden; }
.center { text-align: center; }

/* ---------- lobby ---------- */
#join-code { text-align: center; letter-spacing: 14px; font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; padding: 16px 12px; }
#join-code::placeholder { color: rgba(255, 255, 255, 0.35); }

/* ---------- מסך הבית: שתי בחירות בלבד ---------- */
.home-top { display: flex; justify-content: flex-end; }
.home-hero { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.home-hero .logo { font-size: 96px; }
.home-hero h1 { font-size: 40px; }
.home-actions { display: flex; flex-direction: column; gap: 12px; }
.choice {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 88px; padding: 14px 18px;
  border-radius: var(--radius); border: 1px solid var(--glass-border); background: var(--glass); color: var(--ink);
  font-family: inherit; text-align: start; cursor: pointer;
}
.choice:active { transform: scale(0.98); }
.choice-host { background: linear-gradient(135deg, var(--accent), var(--pink)); border-color: transparent; }
.choice-icon { font-size: 34px; line-height: 1; }
.choice-text { display: flex; flex-direction: column; gap: 3px; }
.choice-text b { font-size: 20px; font-weight: 800; }
.choice-text small { font-size: 14px; color: rgba(255, 255, 255, 0.85); }

/* ---------- מסך ההצטרפות ---------- */
.join-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 14px; text-align: center; }
.join-body .logo { font-size: 72px; }
.join-body .lead { margin: 0; }
/* כפתור החזרה מצביע ימינה בעברית ושמאלה באנגלית */
[dir="ltr"] .flip { transform: scaleX(-1); }
.lang-btn { position: static; }
.lobby-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; text-align: center; }
.lobby-body .lead { margin: 0; }
.code-box { background: var(--glass); border: 2px dashed var(--glass-border); border-radius: var(--radius); padding: 16px 12px 12px; }
.code-label { color: var(--muted); font-size: 14px; }
.code {
  font-size: 68px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 10px;
  margin-inline-start: 10px;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  -webkit-user-select: text;
  user-select: text;
}
span.chip { cursor: default; }

/* ---------- parcel: drag, fling, arrive ---------- */
.parcel-wrap { display: inline-block; transition: opacity 0.2s; }
.parcel-wrap.grab { touch-action: none; cursor: grab; }
/* כל אזור "החבילה בתנועה" תופס את האצבע, כדי שהחלקה למעלה או למטה לא תגלול את הדף */
#st-passing { touch-action: none; }
#st-passing.active { min-height: 56vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.parcel-wrap.dragging { cursor: grabbing; }
.parcel-wrap.dragging .parcel { animation-play-state: paused; }
.parcel-wrap.flying { transition: transform 0.35s ease-in, opacity 0.3s ease-in; }
.parcel-wrap.away { opacity: 0.22; transform: scale(0.55); }
.parcel-wrap.away .parcel { animation: none; }
.parcel-wrap.arrive { animation: arrive 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes arrive {
  from { transform: translateY(-55vh) scale(0.3) rotate(-40deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.stage { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 50vh; }
.state { display: none; width: 100%; text-align: center; }
.state.active { display: block; }
.lead { color: var(--muted); font-size: 16px; line-height: 1.5; margin: 0 0 16px; }

.parcel {
  font-size: 120px;
  line-height: 1;
  display: inline-block;
  animation: toss 0.9s ease-in-out infinite;
  filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.4));
}
.parcel.still { animation: bob 2.4s ease-in-out infinite; }
@keyframes toss {
  0%, 100% { transform: translateY(0) rotate(-12deg); }
  50% { transform: translateY(-36px) rotate(12deg); }
}
#st-passing h2, #st-ready h2 { font-size: 32px; margin: 14px 0 8px; }
.eq { display: flex; gap: 6px; justify-content: center; height: 40px; align-items: flex-end; margin-top: 10px; }
.eq i { width: 8px; height: 10px; border-radius: 4px; background: var(--accent-2); animation: eq 0.55s ease-in-out infinite alternate; }
.eq i:nth-child(2) { animation-delay: 0.1s; background: var(--mint); }
.eq i:nth-child(3) { animation-delay: 0.2s; background: var(--sky); }
.eq i:nth-child(4) { animation-delay: 0.05s; background: var(--pink); }
.eq i:nth-child(5) { animation-delay: 0.25s; background: var(--accent); }
.eq i:nth-child(6) { animation-delay: 0.15s; background: var(--mint); }
.eq i:nth-child(7) { animation-delay: 0.3s; background: var(--accent-2); }
@keyframes eq { from { height: 8px; } to { height: 40px; } }
.hint-box {
  margin: 14px auto 0;
  color: #fff;
  background: rgba(255, 209, 102, 0.18);
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 360px;
}

.hand { font-size: 110px; line-height: 1; display: inline-block; animation: shake 0.45s ease-in-out infinite; }
@keyframes shake {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(12deg); }
}
#st-stop h2 { font-size: 46px; margin: 4px 0 10px; color: var(--accent-2); letter-spacing: 1px; }

.task-card {
  background: var(--card);
  color: var(--card-ink);
  border-radius: 26px;
  padding: 22px 18px 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.task-for { font-size: 15px; font-weight: 700; color: var(--pink); margin-bottom: 6px; }
.task-emoji { font-size: 64px; line-height: 1.1; }
.task-text { font-size: clamp(20px, 5.6vw, 26px); font-weight: 700; line-height: 1.35; margin: 12px 0 12px; }
.task-cat { display: inline-block; font-size: 12px; font-weight: 700; color: #7a6f93; background: #f1eef8; border-radius: 999px; padding: 4px 10px; }
.task-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.task-actions .row { align-items: stretch; } /* שני הכפתורים באותו גובה, גם כשטקסט נשבר לשתי שורות */

.player-dock { margin-top: auto; padding-top: 10px; }
#embed-host iframe { width: 100%; border: 0; border-radius: 14px; display: block; }
#embed-host audio { width: 100%; display: block; }
#dock-info { color: var(--muted); font-size: 13px; text-align: center; margin-top: 6px; min-height: 1em; }

#flash { position: fixed; inset: 0; background: var(--accent-2); opacity: 0; pointer-events: none; z-index: 50; }
#flash.go { animation: flash 0.7s ease-out; }
@keyframes flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; width: 100%; height: 100%; display: none; }

.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 39; }
.sheet {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  background: #fff;
  color: var(--card-ink);
  border-radius: 26px 26px 0 0;
  padding: 18px 20px calc(24px + env(safe-area-inset-bottom));
  z-index: 40;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
  max-height: 70vh;
  overflow: auto;
  max-width: 560px;
  margin: 0 auto;
}
.sheet h3 { margin: 0 0 12px; font-size: 20px; }
.sheet-text { margin: 0 0 16px; color: #5d5375; font-size: 15px; line-height: 1.5; }
.sheet .leaderboard li { background: #f1eef8; }

.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--glass);
  margin-bottom: 8px;
  font-size: 18px;
  font-weight: 600;
}
.leaderboard li .pts { font-weight: 800; color: var(--accent-2); }
.sheet .leaderboard li .pts { color: var(--accent); }
.leaderboard li.empty { justify-content: center; color: var(--muted); font-size: 15px; font-weight: 400; }

@media (max-height: 640px) {
  .parcel, .hand { font-size: 84px; }
  .stage { min-height: 40vh; }
}
