:root {
  --purple: #b559f0;
  --purple-dark: #7d2fb8;
  --white: #ffffff;
  --sky: #6bb3d9;
  --shadow: 0 2px 6px rgba(0, 40, 80, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--sky);
  color: var(--white);
  font-family: "Arial Hebrew", "Segoe UI", Arial, Helvetica, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: url("assets/Background.png") center / cover no-repeat;
  box-shadow: 0 0 40px rgba(0, 0, 0, .25);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; animation: fade-in .3s ease; }
@keyframes fade-in { from { opacity: 0; } }

/* Splash */
#screen-splash { justify-content: center; background: #fff; padding: 0; }
.splash { width: 100%; height: 100%; object-fit: contain; }

/* Image buttons */
.img-btn {
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  width: min(78%, 300px);
  transition: transform .1s ease, filter .1s ease;
}
.img-btn img { display: block; width: 100%; height: auto; pointer-events: none; }
.img-btn.big { width: min(86%, 340px); }
.img-btn:active { transform: scale(.95); filter: brightness(.95); }
.img-btn:focus-visible, .text-btn:focus-visible, .back-btn:focus-visible {
  outline: 3px solid var(--white);
  outline-offset: 4px;
  border-radius: 12px;
}

.text-btn, .back-btn {
  border: 0;
  background: rgba(255, 255, 255, .9);
  color: var(--purple-dark);
  font: bold 20px/1 inherit;
  font-family: inherit;
  padding: 12px 32px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.text-btn:active, .back-btn:active { transform: scale(.96); }

/* Menu */
#screen-menu { justify-content: center; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 4vh; width: 100%; }

/* Rules / about */
.title-img { width: min(86%, 340px); margin-bottom: 8px; }
.card {
  flex: 1;
  overflow-y: auto;
  background: rgba(255, 255, 255, .93);
  color: #2a2a4a;
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 16px;
  font-size: 17px;
  line-height: 1.55;
  box-shadow: var(--shadow);
  -webkit-user-select: text;
  user-select: text;
}
.card p { margin: 0 0 10px; }
.card ol { margin: 0 0 10px; padding-inline-start: 22px; }
.card b { color: var(--purple-dark); }
.about { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.about p { margin: 10px 0; font-size: 26px; font-weight: bold; text-shadow: var(--shadow); }

/* Game */
#screen-game { justify-content: flex-start; gap: 0; }
.back-btn {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  font-size: 15px;
  padding: 7px 16px;
  z-index: 2;
}
.total {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  font-size: 15px;
  font-weight: bold;
  opacity: .9;
  direction: ltr;
}
.phase-img { width: min(100%, 360px); margin-top: 28px; }
.group-img { width: min(75%, 260px); margin-top: 4px; }

.timer {
  font-size: clamp(56px, 16vw, 76px);
  font-weight: bold;
  line-height: 1;
  margin-top: 1.5vh;
  direction: ltr;
  text-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.timer.low { color: #ffe14d; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

.note {
  position: relative;
  width: min(100%, 380px);
  margin-top: 1vh;
}
.note img { display: block; width: 100%; height: auto; }
.word {
  position: absolute;
  inset: 12% 8% 16%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--purple);
  font-weight: bold;
  font-size: clamp(24px, 9vw, 40px);
  line-height: 1.1;
  text-shadow: 1px 1px 0 rgba(90, 30, 140, .25);
}
.word.long { font-size: clamp(18px, 6.5vw, 30px); }
.word.pop { animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

.score-line { font-size: 24px; font-weight: bold; margin-top: 1vh; text-shadow: var(--shadow); }
.score-line b { display: inline-block; min-width: 1.5em; text-align: center; }

.bottom { margin-top: auto; width: 100%; display: flex; justify-content: center; }

/* Time-out screen */
#screen-timeout { justify-content: flex-start; gap: 1.5vh; }
.timeout-img { width: min(80%, 280px); margin-top: 1vh; }
.phase-done {
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  text-shadow: var(--shadow);
}
.scores {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  width: 100%;
  margin-top: 1vh;
}
.scores img { width: min(75%, 260px); }
.scores b { font-size: 30px; margin: 2px 0 10px; text-shadow: var(--shadow); }

/* Game over */
#screen-over { justify-content: center; gap: 2vh; }
.big-note .word { font-size: clamp(22px, 8vw, 36px); }

@media (max-height: 600px) {
  .phase-img { width: min(80%, 300px); margin-top: 22px; }
  .group-img { width: min(60%, 220px); }
  .timeout-img { width: min(55%, 200px); }
  .stack { gap: 2vh; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
  .img-btn { transition: none; }
  .timer.low, .word.pop { animation: none; }
}
