/* Layout: full-screen WebGL canvas, HUD pinned to the edges, modal cards centered over the scene.
   One deliberate look: Moshiach-flag yellow and royal blue over Brooklyn-dusk navy, brick red for danger. */
:root {
  --flag: #ffd21f;
  --flag-deep: #e8a900;
  --royal: #1f3fa0;
  --navy: #101a36;
  --navy-glass: rgba(16, 26, 54, 0.82);
  --brick: #b5442c;
  --cream: #fff6dc;
  --muted: #b9c3e0;
  --display: "Secular One", "Rubik", "Arial Hebrew", Arial, sans-serif;
  --body: "Rubik", "Arial Hebrew", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--navy);
  color: var(--cream);
  font-family: var(--body);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
#game { position: fixed; inset: 0; }
#game canvas { display: block; width: 100%; height: 100%; }
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top {
  position: absolute; inset: 0 0 auto 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 0 max(14px, env(safe-area-inset-left, 0px));
}
.hud-score {
  background: var(--navy-glass); border: 2px solid var(--flag); border-radius: 14px;
  padding: 6px 14px; min-width: 110px; position: relative;
}
.hud-score .lbl { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.num { font-family: var(--display); font-size: 28px; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--flag); }
.mult {
  position: absolute; top: -10px; left: -10px; background: var(--brick); color: var(--cream);
  font-family: var(--display); border-radius: 999px; padding: 2px 9px; font-size: 15px;
  animation: pulse .6s ease-in-out infinite alternate;
}

.progress { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.track {
  position: relative; flex: 1; min-width: 140px; height: 14px; border-radius: 999px;
  background: var(--navy-glass); border: 2px solid rgba(255,255,255,.35); overflow: visible;
}
#progFill { position: absolute; inset: 0 0 0 auto; width: 0%; border-radius: 999px; background: linear-gradient(270deg, var(--flag), var(--flag-deep)); }
#zoneTicks span {
  position: absolute; top: -3px; width: 2px; height: 16px; background: rgba(255,255,255,.55);
}
#zoneTicks em {
  position: absolute; top: 15px; transform: translateX(50%); font-style: normal; font-size: 10px;
  color: var(--cream); white-space: nowrap; text-shadow: 0 1px 3px #000;
}
#progRunner {
  position: absolute; top: 50%; right: 0%; width: 20px; height: 20px; margin-right: -10px; margin-top: -10px;
  border-radius: 50%; background: var(--royal); border: 3px solid var(--flag); box-shadow: 0 0 10px rgba(255,210,31,.8);
}
.goal-badge {
  font-family: var(--display); font-size: 18px; background: var(--brick); color: var(--cream);
  padding: 2px 10px; border-radius: 8px; border: 2px solid var(--cream);
}
.dist { width: 100%; text-align: center; font-size: 13px; margin-top: 16px; text-shadow: 0 1px 4px #000; font-variant-numeric: tabular-nums; }

.hud-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.lives { display: flex; gap: 4px; font-size: 24px; line-height: 1; filter: drop-shadow(0 1px 2px #000); }
.lives .heart { color: #ff4d6d; }
.lives .heart.lost { color: rgba(255,255,255,.25); }
.btns { display: flex; gap: 6px; }
.icon-btn {
  pointer-events: auto; width: 40px; height: 40px; border-radius: 12px; border: 2px solid var(--cream);
  background: var(--navy-glass); color: var(--cream); font-family: var(--display); font-size: 17px; cursor: pointer;
}
.icon-btn:focus-visible, .big-btn:focus-visible, .link-btn:focus-visible { outline: 3px solid var(--flag); outline-offset: 2px; }
.icon-btn.off { opacity: .5; text-decoration: line-through; }

.mitzvot {
  position: absolute; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px 10px; border-radius: 16px; background: var(--navy-glass);
  border: 1px solid rgba(255,255,255,.2); width: max-content; max-width: calc(100% - 24px); flex-wrap: wrap; justify-content: center;
}
.mz { display: flex; flex-direction: column; align-items: center; width: 50px; transition: transform .15s; }
.mz img { width: 38px; height: 38px; }
.mz b { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--flag); }
.mz.bump { transform: scale(1.3); }

.powers {
  position: absolute; top: calc(96px + env(safe-area-inset-top, 0px)); right: max(14px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 8px;
}
.pw {
  display: flex; align-items: center; gap: 8px; background: var(--navy-glass); border-radius: 12px;
  padding: 4px 10px 4px 6px; border: 2px solid var(--flag); font-size: 14px;
}
.pw img { width: 34px; height: 34px; }
.pw .bar { width: 70px; height: 6px; background: rgba(255,255,255,.2); border-radius: 3px; overflow: hidden; }
.pw .bar i { display: block; height: 100%; background: var(--flag); }

.simcha {
  position: absolute; left: max(14px, env(safe-area-inset-left, 0px)); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-family: var(--display); font-size: 14px;
  text-shadow: 0 1px 3px #000;
}
.simcha-bar {
  width: 16px; height: 150px; border-radius: 10px; background: var(--navy-glass); border: 2px solid var(--cream);
  position: relative; overflow: hidden;
}
#simchaFill { position: absolute; inset: auto 0 0 0; height: 0%; background: linear-gradient(0deg, var(--royal), #5aa0ff, var(--flag)); }
.simcha.full .simcha-bar { box-shadow: 0 0 16px var(--flag); border-color: var(--flag); }

.zone-banner {
  position: absolute; top: 28%; left: 50%; transform: translate(-50%, -20px); opacity: 0;
  font-family: var(--display); font-size: clamp(28px, 6vw, 54px); color: var(--cream);
  text-shadow: 0 3px 0 var(--royal), 0 6px 18px rgba(0,0,0,.6); white-space: nowrap; transition: opacity .4s, transform .4s;
}
.zone-banner.show { opacity: 1; transform: translate(-50%, 0); }
.zone-banner small { display: block; text-align: center; font-family: var(--body); font-size: .38em; color: var(--flag); }

#pops { position: absolute; inset: 0; overflow: hidden; }
.pop {
  position: absolute; transform: translate(-50%, -50%); font-family: var(--display); font-size: 20px; white-space: nowrap;
  color: var(--flag); text-shadow: 0 2px 0 var(--royal), 0 0 8px rgba(0,0,0,.5); animation: popUp 1s ease-out forwards;
}
.pop.big { font-size: 30px; color: var(--cream); }
.pop.bad { color: #ff8c7a; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(ellipse at center, rgba(16,26,54,.25), rgba(16,26,54,.75));
  overflow-y: auto;
}
.card {
  width: min(520px, 100%); background: var(--navy-glass); border: 3px solid var(--flag); border-radius: 24px;
  padding: 22px 24px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; gap: 12px; max-height: 100%; overflow-y: auto;
}
.card.small { width: min(400px, 100%); }
h1, h2 { font-family: var(--display); font-weight: 400; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(40px, 9vw, 64px); color: var(--flag); text-shadow: 0 4px 0 var(--royal); line-height: 1.05; }
h2 { font-size: clamp(30px, 7vw, 44px); color: var(--flag); text-shadow: 0 3px 0 var(--royal); }
.sub { margin: 0; color: var(--cream); line-height: 1.55; max-width: 44ch; }
.flag-chip {
  font-family: var(--display); background: var(--flag); color: var(--royal); padding: 2px 18px; border-radius: 6px;
  font-size: 18px; transform: rotate(-3deg); box-shadow: 0 3px 0 var(--flag-deep);
}
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 14px; color: var(--muted); width: 100%; }
.controls .touch { grid-column: 1 / -1; }
/* A touch screen without a mouse has no keyboard to explain: only the swipe line stays. */
@media (hover: none) and (pointer: coarse) {
  .controls > div:not(.touch) { display: none; }
  .controls .touch { color: var(--cream); }
}
kbd {
  display: inline-block; min-width: 24px; padding: 1px 6px; margin-inline-end: 3px; border-radius: 6px;
  background: var(--cream); color: var(--navy); font-family: var(--body); font-weight: 800; font-size: 13px;
  box-shadow: 0 2px 0 var(--muted);
}
.legend-title { font-family: var(--display); font-size: 16px; color: var(--flag); margin-top: 4px; }
.legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; width: 100%; }
.lg { display: flex; align-items: center; gap: 8px; text-align: right; font-size: 13px; background: rgba(255,255,255,.06); border-radius: 10px; padding: 4px 8px; }
.lg img { width: 36px; height: 36px; flex: none; }
.lg b { display: block; color: var(--cream); font-size: 14px; }
.lg span { color: var(--muted); }
.big-btn {
  font-family: var(--display); font-size: 24px; color: var(--royal); background: var(--flag);
  border: none; border-radius: 16px; padding: 10px 34px; cursor: pointer; box-shadow: 0 5px 0 var(--flag-deep);
  transition: transform .1s, box-shadow .1s; margin-top: 6px;
}
.big-btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--flag-deep); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--flag-deep); }
.link-btn { background: none; border: none; color: var(--muted); font-family: var(--body); font-size: 15px; cursor: pointer; text-decoration: underline; }
.best { font-size: 14px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.stat { background: rgba(255,255,255,.07); border-radius: 12px; padding: 8px 4px; }
.stat b { display: block; font-family: var(--display); font-size: 24px; color: var(--flag); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.win-mitzvot { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.win .card { border-color: var(--cream); }
.win-title { font-size: clamp(38px, 9vw, 60px); }

/* Character picker, wallet and shop */
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.pick-btn, .tab {
  display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  background: rgba(255,255,255,.06); color: var(--cream); border: 2px solid rgba(255,255,255,.25);
  border-radius: 14px; padding: 6px 10px; font-family: var(--display); font-size: 20px;
}
.pick-btn img { width: 56px; height: 56px; }
.pick-btn[aria-pressed="true"], .tab[aria-pressed="true"] { border-color: var(--flag); background: rgba(255,210,31,.16); color: var(--flag); }
.pick-btn:focus-visible, .tab:focus-visible, .ghost-btn:focus-visible, .buy-btn:focus-visible { outline: 3px solid var(--flag); outline-offset: 2px; }
.menu-row { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.ghost-btn {
  font-family: var(--display); font-size: 17px; color: var(--cream); background: var(--royal);
  border: 2px solid var(--flag); border-radius: 12px; padding: 6px 18px; cursor: pointer;
}
.wallet, .wallet-big { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; text-align: center; line-height: 1.5; }
.wallet b, .wallet-big b { color: var(--flag); font-family: var(--display); font-weight: 400; }
.wallet-big { font-size: 16px; }
.shop-card { width: min(640px, 100%); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: min(320px, 100%); }
.tab { font-size: 17px; padding: 4px 10px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; width: 100%; }
.shop-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.15); border-radius: 14px; padding: 8px 6px;
}
.shop-item.on { border-color: var(--flag); }
.shop-item img { width: 72px; height: 72px; }
.shop-item b { color: var(--cream); font-size: 15px; }
.shop-item span { color: var(--muted); font-size: 12px; min-height: 2.6em; }
.buy-btn {
  width: 100%; margin-top: 4px; font-family: var(--display); font-size: 15px; border-radius: 10px; padding: 5px 4px;
  cursor: pointer; border: 2px solid var(--flag); background: var(--flag); color: var(--royal); font-variant-numeric: tabular-nums;
}
.buy-btn.owned { background: transparent; color: var(--flag); }
.buy-btn.worn { background: var(--royal); color: var(--cream); }
.buy-btn:disabled { cursor: default; background: transparent; border-color: rgba(255,255,255,.25); color: var(--muted); font-family: var(--body); font-size: 12px; }
.levels-title { font-family: var(--display); font-size: 16px; color: var(--flag); }
.worlds { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 6px; width: 100%; }
.world-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; padding: 6px 4px;
  background: transparent; color: var(--muted); border: 2px solid rgba(255,255,255,.15); border-radius: 12px;
  font-family: var(--display); font-size: 15px; flex-wrap: wrap;
}
.world-btn .orb { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--c1), var(--c2)); }
.world-btn small { font-family: var(--body); font-size: 11px; width: 100%; text-align: center; }
.world-btn[aria-pressed="true"] { border-color: var(--flag); color: var(--flag); background: rgba(255,210,31,.12); }
.world-btn:focus-visible { outline: 3px solid var(--flag); outline-offset: 2px; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; width: 100%; }
.install-btn { font-size: 16px; }
.install-hint { margin: 0; font-size: 14px; line-height: 1.6; color: var(--cream); background: rgba(255,255,255,.07); border-radius: 10px; padding: 6px 12px; }
.install-hint b { color: var(--flag); }
/* Menu footer, copyright and the contact form */
.menu-footer { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.copyright { margin: 0; font-size: 11px; color: var(--muted); opacity: .8; }
.contact-form { width: 100%; display: flex; flex-direction: column; gap: 4px; text-align: right; margin: 0; }
.contact-form label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.contact-form input, .contact-form select, .contact-form textarea {
  font-family: var(--body); font-size: 16px; padding: 7px 10px; border-radius: 10px; width: 100%;
  border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: var(--cream);
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
.contact-form select option { color: #111; }
.contact-form textarea { resize: vertical; min-height: 90px; }
.contact-form input:focus-visible, .contact-form select:focus-visible, .contact-form textarea:focus-visible { outline: 3px solid var(--flag); outline-offset: 1px; border-color: var(--flag); }
.contact-form .big-btn { align-self: center; }
.contact-status { margin: 4px 0 0; min-height: 1.3em; font-size: 14px; text-align: center; color: var(--cream); }
.contact-status.ok { color: #8fe08f; }
.contact-status.err { color: #ff8c7a; }
.gear-line, .need-line { margin: 0; font-size: 14px; color: var(--cream); text-align: center; }
.gear-line .have { color: #8fe08f; }
.gear-line .miss { color: #ff8c7a; }
.need-line { background: rgba(181,68,44,.25); border: 1px solid var(--brick); border-radius: 10px; padding: 6px 10px; }
.need-line b { color: var(--flag); }
.level-btn.needs-gear small { color: #ff8c7a; }
.shop-item.needed { border: 2px solid var(--brick); box-shadow: 0 0 10px rgba(181,68,44,.6); }
.shop-cat { grid-column: 1 / -1; margin: 6px 0 0; font-family: var(--display); font-weight: 400; font-size: 17px; color: var(--flag); text-align: right; border-bottom: 1px solid rgba(255,210,31,.35); padding-bottom: 2px; }
.level-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; padding: 8px 4px;
  background: rgba(255,255,255,.06); color: var(--cream); border: 2px solid rgba(255,255,255,.2); border-radius: 14px;
  font-family: var(--display); font-size: 15px;
}
.level-btn .orb {
  width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--c1), var(--c2));
  box-shadow: 0 0 10px var(--c1);
}
.level-btn small { font-family: var(--body); font-size: 11px; color: var(--muted); }
.level-btn[aria-pressed="true"] { border-color: var(--flag); background: rgba(255,210,31,.16); color: var(--flag); }
.level-btn:disabled { cursor: default; opacity: .45; }
.level-btn:disabled .orb { filter: grayscale(1); box-shadow: none; }
.level-btn:focus-visible { outline: 3px solid var(--flag); outline-offset: 2px; }
/* Name entry and high-score board */
.name-form { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 0; }
.name-form label { font-family: var(--display); font-size: 15px; color: var(--flag); }
.name-row { display: flex; gap: 8px; width: min(320px, 100%); }
.name-row input {
  flex: 1; min-width: 0; font-family: var(--body); font-size: 17px; padding: 6px 10px; border-radius: 10px;
  border: 2px solid var(--flag); background: rgba(255,255,255,.08); color: var(--cream);
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
.name-row input::placeholder { color: var(--muted); }
.name-row input:focus-visible { outline: 3px solid var(--flag); outline-offset: 1px; }
.name-row input:disabled, .name-row button:disabled { opacity: .55; cursor: default; }
.saved { margin: 0; font-size: 14px; color: var(--cream); min-height: 1.2em; }
.saved b { color: var(--flag); }
.mini-board { list-style: none; margin: 0; padding: 0; width: min(320px, 100%); display: flex; flex-direction: column; gap: 2px; }
.mini-board li {
  display: grid; grid-template-columns: 2em 1fr auto; gap: 6px; align-items: center; padding: 3px 10px; border-radius: 8px;
  background: rgba(255,255,255,.05); font-size: 14px; font-variant-numeric: tabular-nums;
}
.mini-board li.me, .board-table tr.me td { background: rgba(255,210,31,.2); color: var(--flag); }
.mini-board .r { color: var(--muted); }
.board-tabs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.board-tabs .tab { font-size: 15px; padding: 3px 12px; }
.board-wrap { width: 100%; overflow-x: auto; }
.board-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.board-table th { color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px 6px; text-align: right; border-bottom: 1px solid rgba(255,255,255,.2); }
.board-table td { padding: 6px; text-align: right; border-bottom: 1px solid rgba(255,255,255,.08); }
.board-table td.sc { color: var(--flag); font-family: var(--display); }
.board-table .won { color: var(--flag); font-size: 12px; }
.board-table .empty { text-align: center; color: var(--muted); padding: 18px 6px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.bank { margin: 0; color: var(--cream); font-size: 14px; font-variant-numeric: tabular-nums; }
.bank b { color: var(--flag); }

.loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--navy); font-family: var(--display); font-size: 26px; color: var(--flag);
}

@keyframes popUp { 0% { opacity: 0; margin-top: 0; } 15% { opacity: 1; } 100% { opacity: 0; margin-top: -70px; } }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.15); } }

@media (min-width: 900px) {
  #menu, #shop, #board { justify-content: flex-start; padding-right: max(6vw, 16px); }
}
@media (max-width: 640px) {
  .hud-top { flex-wrap: wrap; row-gap: 6px; }
  .progress { order: 3; flex-basis: 100%; max-width: none; }
  .hud-score { min-width: 84px; padding: 4px 10px; }
  .num { font-size: 22px; }
  .mitzvot { flex-wrap: nowrap; gap: 2px; padding: 4px 6px; }
  .mz { width: 38px; }
  .mz img { width: 28px; height: 28px; }
  .mz b { font-size: 12px; }
  .simcha-bar { height: 100px; }
  .powers { top: calc(150px + env(safe-area-inset-top, 0px)); }
  #zoneTicks em { display: none; }
  .controls { grid-template-columns: 1fr; }
  .levels { grid-template-columns: repeat(2, 1fr); }
  .worlds { grid-template-columns: repeat(3, 1fr); }
}
/* A phone held sideways: little height, so the HUD shrinks and stays clear of the runner. */
@media (max-height: 520px) {
  .hud-score { min-width: 84px; padding: 3px 10px; }
  .num { font-size: 20px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .lives { font-size: 19px; }
  .mitzvot { flex-wrap: nowrap; gap: 2px; padding: 3px 6px; bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .mz { width: 36px; }
  .mz img { width: 24px; height: 24px; }
  .mz b { font-size: 11px; }
  .simcha-bar { height: 80px; }
  .simcha { font-size: 12px; }
  .powers { top: calc(64px + env(safe-area-inset-top, 0px)); }
  .pw img { width: 26px; height: 26px; }
  .zone-banner { top: 22%; }
  .card { padding: 14px 18px; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .mult { animation: none; }
  .zone-banner { transition: none; }
}
