/* ============================================================
   Gil is getting old: The Game — comic style
   Palette anchored to the illustrations: ink, cream, comic red,
   sunny yellow, peach skin tone.
   ============================================================ */
:root {
  --ink: #1d1d1d;
  --paper: #fff6e5;
  --card: #ffffff;
  --red: #e0362c;
  --yellow: #ffc93c;
  --peach: #f7a96e;
  --green: #2f9e44;
  --blue: #4d9de0;
  /* soft comic tints — pastel fills that keep ink text readable */
  --yellow-soft: #ffe9b3;
  --peach-soft: #ffdcc2;
  --blue-soft: #cfe8ff;
  --green-soft: #d5f2dd;
  --pink-soft: #ffd7d2;
  --purple-soft: #e8dcff;
  --border-w: 3px;
  --radius: 16px;
  --shadow: 4px 4px 0 var(--ink);
  --font-display: 'Fredoka', 'Rubik', sans-serif;
  --font-body: 'Rubik', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--paper);
  /* comic halftone dots behind the app card on desktop — two-tone pop print */
  background-image:
    radial-gradient(rgba(224, 54, 44, 0.10) 2px, transparent 2px),
    radial-gradient(rgba(77, 157, 224, 0.12) 2px, transparent 2px);
  background-size: 22px 22px, 22px 22px;
  background-position: 0 0, 11px 11px;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 480px;
  margin-inline: auto;
  background: var(--paper);
  overflow: hidden;
}

/* Desktop: frame the game like a phone card */
@media (min-width: 600px) {
  body { display: grid; place-items: center; }
  .app {
    height: min(820px, calc(100dvh - 48px));
    border: var(--border-w) solid var(--ink);
    border-radius: 24px;
    box-shadow: 8px 8px 0 var(--ink);
  }
}

/* ---------------- screens ---------------- */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.screen.active { display: flex; }

.screen-footer {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  justify-content: center;
}

/* ---------------- buttons ---------------- */
.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--yellow);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 24px;
  min-height: 48px;
  cursor: pointer;
  transition: transform 150ms ease-out, box-shadow 150ms ease-out;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }
.btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }

.btn-primary { background: var(--red); color: #fff; }
.btn-secondary { background: var(--card); }
.btn-big {
  font-size: 1.35rem;
  padding: 14px 44px;
  border-radius: 999px;
}

/* ---------------- banner ---------------- */
.banner {
  margin-top: 12px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink);
}
.banner a {
  color: var(--red);
  font-weight: 700;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}
.banner a:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---------------- welcome ---------------- */
/* Background illustration slot: when ready, add here e.g.
   #screen-welcome { background: url('img/welcome-bg.png') center/cover no-repeat; } */
#screen-welcome { justify-content: space-between; }

/* slow-spinning comic sunburst behind the title */
#screen-welcome::before {
  content: '';
  position: absolute;
  inset: -45%;
  background: repeating-conic-gradient(
    rgba(255, 201, 60, 0.22) 0deg 9deg,
    transparent 9deg 24deg
  );
  animation: sunSpin 80s linear infinite;
  pointer-events: none;
}
#screen-welcome > * { position: relative; }

/* ghost language toggle */
#screen-welcome .lang-toggle {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  inset-inline-end: 20px;
  z-index: 1;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
  min-width: 44px;
  cursor: pointer;
  opacity: 0.55;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: opacity 150ms ease-out;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#screen-welcome .lang-toggle:hover { opacity: 1; }
#screen-welcome .lang-toggle:active { opacity: 1; }
#screen-welcome .lang-toggle:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

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

.welcome-center {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 96px;
}

.welcome-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
[dir="rtl"] .welcome-hero { gap: 14px; }

.welcome-art {
  width: min(26vw, 110px);
  height: auto;
  flex-shrink: 0;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}
.logo-line {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.3rem, 10.5vw, 3.3rem);
  line-height: 1.05;
  white-space: pre-line;
  text-transform: uppercase;
  max-width: 9ch;
  /* comic sticker effect */
  color: var(--paper);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  filter: drop-shadow(4px 4px 0 var(--ink));
}
/* Hebrew title is shorter — let it be bigger */
[dir="rtl"] .logo-line {
  font-size: clamp(2.9rem, 13.5vw, 4.2rem);
}
.logo-badge {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 6px 20px;
  transform: rotate(-3deg);
}

/* ---------------- story ---------------- */
#screen-story { justify-content: center; }
.story-text {
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 1.05rem;
  line-height: 1.55;
  max-width: 42ch;
  margin: auto auto 0;
}
.story-text p:first-child {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--red);
}
.story-text em {
  font-style: italic;
  font-weight: 500;
  background: var(--yellow-soft);
  border-radius: 6px;
  padding: 0 4px;
}
.story-text strong {
  /* hand-highlighter sweep under the mission line */
  background: linear-gradient(transparent 52%, var(--yellow) 52%, var(--yellow) 94%, transparent 94%);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  padding: 0 2px;
}
.story-art {
  display: block;
  margin: 16px auto 0;
  max-height: 22dvh;
  max-width: 70%;
  object-fit: contain;
}

/* ---------------- rules ---------------- */
.rules-head { text-align: center; margin-bottom: 12px; }
.rules-head h2 {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.8rem;
  text-transform: uppercase;
  background: linear-gradient(transparent 55%, var(--blue-soft) 55%, var(--blue-soft) 96%, transparent 96%);
  padding: 0 6px;
}
.rules-hint { font-size: 0.9rem; opacity: 0.75; margin-top: 2px; }

.rules-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
  padding: 2px;
}
.rule {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 9px 12px;
}
.rule .problem { font-weight: 500; font-size: 0.95rem; }
.rule .arrow { margin-inline-start: auto; opacity: 0.45; flex-shrink: 0; }
[dir="rtl"] .rule .arrow { transform: scaleX(-1); }
.rule .supplement {
  min-width: 8.4em;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}
/* Each supplement owns one color — same in the cheat sheet and in the
   game buttons, so players can memorize by color too. */
.sup-poor-vision      { --sup: #e9f1a1; } /* Vitamin A — lime zest */
.sup-fatigue          { --sup: #ffd7d2; } /* Vitamin B12 — blood pink */
.sup-damaged-skin     { --sup: #ffbe76; } /* Vitamin C — citrus orange */
.sup-low-immunity     { --sup: #ffe9b3; } /* Vitamin D — pale sunshine */
.sup-balance-problems { --sup: #d5f2dd; } /* Vitamin E — mint green */
.sup-anemia           { --sup: #d8dee9; } /* Iron — steel gray */
.sup-weak-bones       { --sup: #ffffff; } /* Calcium — milk white */
.sup-rapid-heartbeat  { --sup: #e8dcff; } /* Magnesium — lavender */
.sup-joint-pain       { --sup: #a8e6e2; } /* Omega 3 — ocean aqua */
.sup-hair-loss        { --sup: #cfe4ff; } /* Zinc — baby blue */

.rule .supplement { background: var(--sup, var(--yellow)); }

/* Desktop phone-card is capped at 820px — tighten rows so all 10 fit */
@media (min-width: 600px) and (max-height: 940px) {
  .rules-list { gap: 5px; }
  .rule { padding: 5px 12px; }
}

/* Short screens: compact the rules rows so all 10 fit without scrolling */
@media (max-height: 720px) {
  .rules-head h2 { font-size: 1.5rem; }
  .rules-list { gap: 4px; }
  .rule { padding: 6px 10px; border-radius: 10px; }
  .rule .problem, .rule .supplement { font-size: 0.85rem; }
}

/* ---------------- game ---------------- */
#screen-game { gap: 10px; }

.hud {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.hud-round {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hud-clock {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  min-width: 4ch;
  text-align: end;
}
.hud-clock.low { color: var(--red); }

.timerbar {
  height: 12px;
  border: var(--border-w) solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  overflow: hidden;
}
.timerbar-fill {
  height: 100%;
  background: var(--red);
  transform-origin: left center;
  transform: scaleX(1);
}
[dir="rtl"] .timerbar-fill { transform-origin: right center; }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.issue-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 7vw, 2rem);
  text-transform: uppercase;
  text-align: center;
}
.issue-img {
  flex: 1;
  min-height: 0;
  max-height: 30dvh;
  max-width: 80%;
  object-fit: contain;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.choice {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--card);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 54px;
  padding: 8px;
  cursor: pointer;
  transition: transform 120ms ease-out, box-shadow 120ms ease-out, background 120ms ease-out;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.choice { background: var(--sup, var(--card)); }
.choice:active,
.choice.picked { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.choice:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }
.choices.locked .choice { pointer-events: none; opacity: 0.6; }
.choices.locked .choice.picked { opacity: 1; }

/* ---------------- overlays ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay[hidden] { display: none; }

.countdown { background: var(--paper); overflow: hidden; }
.countdown::before {
  content: '';
  position: absolute;
  inset: -50%;
  background: repeating-conic-gradient(
    rgba(255, 201, 60, 0.4) 0deg 10deg,
    transparent 10deg 24deg
  );
  animation: sunSpin 40s linear infinite;
  pointer-events: none;
}
/* soft paper halo so the rays don't clutter the number */
.countdown::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, var(--paper) 0%, var(--paper) 16%, transparent 52%);
  pointer-events: none;
}
.countdown-num { position: relative; z-index: 1; }
.countdown-num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 9rem;
  color: var(--red);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  /* drop-shadow (not text-shadow): renders a solid black copy on mobile */
  filter: drop-shadow(6px 6px 0 var(--ink));
  /* compensate for the shadow's rightward ink mass (physical, shadow ignores dir) */
  margin-left: -6px;
  animation: countPop 900ms ease-out;
}
@keyframes countPop {
  0% { transform: scale(0.3); opacity: 0; }
  35% { transform: scale(1.15); opacity: 1; }
  55% { transform: scale(1); }
  100% { transform: scale(1); opacity: 1; }
}

.result { background: rgba(29, 29, 29, 0.45); }
.pow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 4px solid var(--ink);
  border-radius: 20px;
  box-shadow: 6px 6px 0 var(--ink);
  padding: 26px 40px;
  transform: rotate(-3deg);
  animation: powIn 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes powIn {
  from { transform: rotate(-3deg) scale(0.4); opacity: 0; }
  to { transform: rotate(-3deg) scale(1); opacity: 1; }
}
.pow-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.2rem;
  text-transform: uppercase;
}
.pow-months {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
}
.pow.correct .pow-label { color: var(--green); }
.pow.wrong .pow-label, .pow.timeout .pow-label { color: var(--red); }

/* ---------------- end ---------------- */
#screen-end { justify-content: space-between; }
.end-center {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}
.end-subtitle {
  font-size: 1rem;
  font-weight: 500;
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 4px 16px;
  transform: rotate(-2deg);
}
.end-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.4rem, 6.5vw, 1.9rem);
  line-height: 1.25;
  max-width: 20ch;
}
.end-img {
  max-height: 26dvh;
  max-width: 60%;
  object-fit: contain;
}
.end-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* ---------------- motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
