:root {
  --bg-top: #20264f;
  --bg-bottom: #2c2f5e;
  --card: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #f4f5ff;
  --text-dim: rgba(244, 245, 255, 0.66);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gap: 18px;
  --pad: 20px;
  --max-w: 560px;
  /* Set by JS from the game count: 2 columns (tiles ≈ 1/4) … 3 columns
     (tiles ≈ 1/9, the smallest). --tracks centers a not-yet-full row. */
  --cols: 2;
  --tracks: 1;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

/* Paint the twilight gradient on the root, fixed to the viewport, so it covers
   the whole screen — including the bottom safe-area / overscroll region — and
   no white ever shows below the content. Solid color is a hard fallback. */
html {
  background-color: var(--bg-bottom);
  background-image: linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
  background-repeat: no-repeat;
}

body {
  min-height: 100dvh;
  background: transparent;
  color: var(--text);
  font-family: "Baloo 2", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Baloo 2 has no Hebrew glyphs — use rounded Fredoka for Hebrew / RTL. */
:root[lang="he"] body,
:root[dir="rtl"] body {
  font-family: "Fredoka", "Baloo 2", system-ui, -apple-system, sans-serif;
}

.hub {
  max-width: var(--max-w);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(var(--safe-top) + var(--pad))
    var(--pad)
    calc(var(--safe-bottom) + var(--pad));
  display: flex;
  flex-direction: column;
  justify-content: safe center;
}

.game-grid {
  /* Square tile side = one column of the usable width, so N columns exactly
     fill the width. --cols drives the size; --tracks (= min(count, cols))
     keeps a partial row centered. */
  --cell: calc(
    (min(100vw, var(--max-w)) - 2 * var(--pad) - (var(--cols) - 1) * var(--gap))
    / var(--cols)
  );
  list-style: none;
  margin: 0 auto;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--tracks), var(--cell));
  gap: var(--gap);
  justify-content: center;
}

.game-tile {
  display: block;
  width: var(--cell);
  text-decoration: none;
  transition: transform 0.12s ease;
}

.game-tile:active { transform: scale(0.94); }

.game-icon {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20%;
  font-size: calc(var(--cell) * 0.42);
  line-height: 1;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.24);
}

.game-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hub-empty {
  text-align: center;
  color: var(--text-dim);
  margin-top: 40px;
}

/* In-app game player (full-screen iframe overlay). */
.player {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--bg-top);
}

.player[hidden] { display: none; }

html.playing, html.playing body { overflow: hidden; }

.player-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 6px) 12px 6px;
  background: var(--bg-top);
}

.player-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 8px 14px 8px 8px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.player-back:active { transform: scale(0.96); }

.player-back-arrow {
  font-size: 24px;
  line-height: 1;
  margin-top: -2px;
}

.player-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dim);
}

.player-frame {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  background: var(--bg-top);
}

/* Settings gear (menu screen) + overlay — shared design system. */
.hub-gear {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  right: calc(var(--safe-right, 0px) + 12px);
  z-index: 40;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
}
.hub-gear:active { transform: scale(0.94); }
html.playing .hub-gear { display: none; }

/* About / info button — mirrors the gear on the opposite top corner. */
.hub-info {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  left: calc(var(--safe-left, 0px) + 12px);
  z-index: 40;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
}
.hub-info:active { transform: scale(0.94); }
html.playing .hub-info { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
}
.overlay[hidden] { display: none; }

.scrim {
  position: absolute;
  inset: 0;
  background: rgba(16, 18, 41, 0.68);
  animation: fade 0.2s ease;
}

.panel {
  position: relative;
  width: min(360px, calc(100vw - 48px));
  background: rgb(51, 59, 107);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 26px;
  padding: 24px 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  animation: rise 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  text-align: center;
}
.panel h2 { margin: 0 0 6px; font-size: 28px; font-weight: 800; }
.panel-sub { margin: 0 0 18px; color: rgb(255, 204, 61); font-weight: 700; font-size: 16px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.row-label { font-size: 18px; font-weight: 600; }

.toggle {
  width: 56px;
  height: 32px;
  border-radius: 16px;
  border: none;
  background: rgba(255, 255, 255, 0.22);
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
}
.toggle.on { background: rgb(87, 199, 112); }
.toggle .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s ease;
}
.toggle.on .knob { left: 27px; }

.btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border: none;
  border-radius: 16px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: rgb(92, 107, 173); }
.btn.primary { background: rgb(87, 199, 112); }
/* Translucent action buttons (feedback / requests) — calm, not competing. */
.btn.tertiary {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 17px;
}
.btn.tertiary:active { background: rgba(255, 255, 255, 0.16); }

/* Settings "Requests & feedback" section. */
.settings-section {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.section-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  text-align: start;
  margin: 2px 2px 4px;
}
.settings-section .btn { margin-top: 10px; }

/* Segmented language chooser (shared kit). */
.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.1);
}
.seg-btn {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
.seg-btn.active { background: rgb(92, 107, 173); }
.seg-btn:active { transform: scale(0.96); }

/* About / info panel — wider, scrollable, start-aligned reading content. */
.info-panel {
  width: min(400px, calc(100vw - 40px));
  text-align: start;
}
.info-panel h2 { text-align: center; }
.info-body {
  max-height: min(56vh, 460px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 6px 0 2px;
}
.info-intro {
  margin: 0 0 16px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}
.info-h {
  margin: 6px 0 2px;
  font-size: 20px;
  font-weight: 800;
  color: rgb(255, 204, 61);
}
.info-sub2 {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-dim);
}
.info-device {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
}
.info-device-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.info-steps { margin: 0; padding-inline-start: 20px; }
.info-steps li { font-size: 15px; line-height: 1.55; margin: 3px 0; }

/* In-app feedback / request form. */
.feedback-text {
  width: 100%;
  min-height: 116px;
  resize: vertical;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  padding: 12px 14px;
  margin-top: 4px;
  text-align: start;
}
.feedback-text::placeholder { color: var(--text-dim); }
.feedback-text:focus { outline: none; border-color: rgba(255, 255, 255, 0.4); }
.feedback-error {
  margin: 8px 2px 0;
  font-size: 14px;
  font-weight: 600;
  color: rgb(237, 102, 107);
  text-align: start;
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 16px; }
.feedback-thanks {
  font-size: 22px;
  font-weight: 800;
  color: rgb(87, 199, 112);
  margin: 20px 0 6px;
}

/* RTL mirroring for pinned chrome. Gameplay/tiles stay orientation-neutral. */
:root[dir="rtl"] .hub-gear {
  right: auto;
  left: calc(var(--safe-left, 0px) + 12px);
}
:root[dir="rtl"] .hub-info {
  left: auto;
  right: calc(var(--safe-right, 0px) + 12px);
}
:root[dir="rtl"] .player-back-arrow { transform: scaleX(-1); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
