:root {
  --teal-900: #134e4a;
  --teal-700: #0f766e;
  --teal-500: #14b8a6;
  --teal-300: #5eead4;
  --magenta-700: #a21caf;
  --magenta-500: #d946ef;
  --magenta-300: #f0abfc;
  --ink: #1e293b;
  --paper: #f0fdfa;
  --card: #ffffff;
  --shadow: 0 8px 24px rgba(19, 78, 74, 0.18);
  --radius: 20px;
  --font: "Segoe UI", Tahoma, system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: linear-gradient(160deg, var(--paper) 0%, #fce7f3 45%, var(--teal-300) 100%);
  color: var(--ink);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 3px solid var(--teal-500);
}

.logo {
  margin: 0;
  flex: 1;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  line-height: 1.2;
}

.logo .en {
  display: block;
  font-size: 0.75em;
  font-weight: 600;
  color: var(--magenta-700);
  direction: ltr;
  text-align: start;
}

.icon-btn {
  border: none;
  background: var(--teal-500);
  color: #fff;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.icon-btn:active {
  transform: scale(0.96);
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-width: 55vw;
  justify-content: flex-end;
}

.score-chip {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  direction: ltr;
}

.score-chip.lead {
  outline: 3px solid var(--magenta-500);
}

#view-root {
  flex: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hero {
  text-align: center;
  padding: 0.5rem;
}

.hero h2 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.4rem, 5vw, 2rem);
  color: var(--teal-900);
}

.hero p {
  margin: 0;
  opacity: 0.85;
}

.hero .en {
  direction: ltr;
  display: block;
  font-size: 0.9em;
}

.char-row {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.5rem 0;
}

.char-badge {
  width: 64px;
  text-align: center;
  font-size: 0.7rem;
}

.char-badge svg {
  width: 56px;
  height: 56px;
  display: block;
  margin: 0 auto 0.25rem;
}

.section-title {
  margin: 0;
  font-size: 1.1rem;
  color: var(--magenta-700);
}

.section-title .en {
  font-weight: normal;
  font-size: 0.85em;
  color: var(--ink);
  direction: ltr;
  display: inline;
}

.btn-grid {
  display: grid;
  gap: 0.75rem;
}

.btn-grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.btn-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.big-btn {
  border: none;
  border-radius: var(--radius);
  padding: 1.1rem 1rem;
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  min-height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: transform 0.1s;
}

.big-btn .en {
  font-size: 0.75em;
  font-weight: 600;
  direction: ltr;
  opacity: 0.9;
}

.big-btn:active {
  transform: scale(0.97);
}

.big-btn.teal {
  background: linear-gradient(180deg, var(--teal-300), var(--teal-500));
  color: var(--teal-900);
}

.big-btn.magenta {
  background: linear-gradient(180deg, var(--magenta-300), var(--magenta-500));
  color: #fff;
}

.big-btn.ghost {
  background: var(--card);
  border: 3px solid var(--teal-500);
  color: var(--teal-900);
}

.big-btn.selected {
  outline: 4px solid var(--magenta-500);
}

.game-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border: none;
  border-inline-end: 6px solid var(--teal-500);
  text-align: start;
  cursor: pointer;
  width: 100%;
  font: inherit;
}

.game-card h3 {
  margin: 0 0 0.35rem;
  color: var(--teal-900);
}

.game-card p {
  margin: 0;
  font-size: 0.9rem;
}

.game-card .en {
  direction: ltr;
  display: block;
  font-size: 0.85em;
  margin-top: 0.25rem;
}

.game-card:active {
  transform: scale(0.99);
}

.action-bar {
  display: flex;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

.action-bar .big-btn {
  flex: 1;
}

.status-banner {
  text-align: center;
  padding: 1rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 800;
}

.status-banner .en {
  display: block;
  font-size: 0.65em;
  font-weight: 600;
  direction: ltr;
}

.status-banner.wait {
  background: var(--teal-900);
  color: var(--teal-300);
}

.status-banner.go {
  background: var(--magenta-500);
  color: #fff;
  animation: pulse 0.4s ease infinite alternate;
}

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.02);
  }
}

.split-arena {
  flex: 1;
  display: grid;
  gap: 4px;
  min-height: 50dvh;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.split-arena.p2 {
  grid-template-columns: 1fr 1fr;
}

.split-arena.p3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.split-arena.p4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.player-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  position: relative;
  touch-action: none;
}

.player-zone .zone-label {
  font-weight: 800;
  font-size: clamp(0.85rem, 3vw, 1.1rem);
  margin-bottom: 0.25rem;
}

.player-zone .zone-score {
  font-size: 2rem;
  font-weight: 900;
}

.player-zone.tap-target {
  cursor: pointer;
}

.player-zone.tap-target:active,
.player-zone.tap-target.active-flash {
  filter: brightness(1.15);
}

.player-zone.winner-flash {
  animation: winFlash 0.5s ease 3;
}

@keyframes winFlash {
  50% {
    box-shadow: inset 0 0 0 8px #fff;
  }
}

.player-zone.foul {
  animation: shake 0.35s ease;
  background: #fecaca !important;
}

@keyframes shake {
  25% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-4px);
  }
}

.p1-bg {
  background: linear-gradient(145deg, #99f6e4, #2dd4bf);
}
.p2-bg {
  background: linear-gradient(145deg, #f5d0fe, #e879f9);
}
.p3-bg {
  background: linear-gradient(145deg, #fde68a, #fbbf24);
}
.p4-bg {
  background: linear-gradient(145deg, #bfdbfe, #60a5fa);
}

.color-pad-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 140px;
  margin-top: 0.35rem;
}

.color-pad {
  aspect-ratio: 1;
  border: none;
  border-radius: 12px;
  min-height: 44px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15);
}

.color-pad:active {
  transform: scale(0.95);
}

.simon-center {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--ink);
  min-height: 72px;
}

.simon-light {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  opacity: 0.35;
  transition: opacity 0.15s, transform 0.15s;
}

.simon-light.lit {
  opacity: 1;
  transform: scale(1.08);
  box-shadow: 0 0 20px currentColor;
}

.c-red {
  background: #ef4444;
  color: #ef4444;
}
.c-green {
  background: #22c55e;
  color: #22c55e;
}
.c-blue {
  background: #3b82f6;
  color: #3b82f6;
}
.c-yellow {
  background: #eab308;
  color: #eab308;
}

.quiz-word {
  font-size: clamp(2rem, 10vw, 3.5rem);
  font-weight: 900;
  padding: 1rem;
  border-radius: var(--radius);
  background: #fff;
  text-align: center;
  direction: ltr;
}

.buzzer-btn {
  width: 100%;
  flex: 1;
  min-height: 100px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.5rem;
  font-weight: 900;
  color: #fff;
  box-shadow: var(--shadow);
}

.foot-note {
  text-align: center;
  padding: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

.foot-note .en {
  direction: ltr;
  display: block;
}

/* Language toggle: hide one language based on html.lang-en */
html.lang-en .he { display: none !important; }
html:not(.lang-en) .en { display: none !important; }

html.lang-en { direction: ltr; }
html.lang-en .game-card { border-inline-end: 6px solid var(--teal-500); }
html.lang-en .score-strip { justify-content: flex-start; }

.lang-toggle {
  border: none;
  background: rgba(255, 255, 255, 0.6);
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.install-banner {
  display: none;
  text-align: center;
  padding: 0.5rem;
}

.install-banner.show {
  display: block;
}

@media (orientation: landscape) and (max-height: 500px) {
  .hero {
    display: none;
  }
  #view-root {
    padding: 0.5rem;
  }
}
