:root {
  --bg: #12141c;
  --bg2: #191c27;
  --panel: #1f2331;
  --panel2: #2a2f42;
  --line: #343a52;
  --text: #eef0f7;
  --muted: #9ba2b9;
  --accent: #6d8bff;
  --accent2: #9a6dff;
  --good: #3ecf8e;
  --bad: #ff5d6c;
  --warn: #ffc857;
  --radius: 16px;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Google Sans", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overflow: hidden;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

#app {
  position: fixed;
  inset: 0;
  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);
}

.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- Menu ---------- */
.menu { overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 24px; }
.menu-head { display: flex; align-items: center; gap: 12px; margin: 4px 2px 18px; }
.menu-head h1 { font-size: 26px; margin: 0; letter-spacing: 0.2px; }
.menu-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.menu-head .sub .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.menu-head .sub.ready .dot { background: var(--good); }
.menu-head .grow { flex: 1; }
.logo { width: 48px; height: 48px; border-radius: 14px; flex: none; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 14px; border-radius: var(--radius);
  background: linear-gradient(160deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  text-align: start;
  transition: transform .12s ease, border-color .12s ease;
}
.card:active { transform: scale(0.97); border-color: var(--accent); }
.card svg { width: 54px; height: 54px; }
.card .name { font-weight: 700; font-size: 17px; }
.card .info { color: var(--muted); font-size: 12.5px; margin-top: -6px; }

.menu-foot { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: 14px;
}
.pill.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pill:active { transform: scale(0.97); }
.pill svg { width: 18px; height: 18px; }

/* ---------- Game screen ---------- */
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; min-height: 52px; flex: none;
}
.topbar h1 { font-size: 18px; margin: 0; margin-inline-start: 2px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--line);
}
.icon-btn:active { background: var(--panel2); transform: scale(0.94); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.badge { position: relative; }
.icon-btn .count {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:disabled { opacity: 0.35; }

.game-body { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.stage { flex: 1; min-height: 0; position: relative; }
.stage > canvas { position: absolute; left: 0; top: 0; touch-action: none; }

.hud { display: flex; justify-content: center; gap: 8px; padding: 2px 10px 6px; flex: none; flex-wrap: wrap; }
.chip {
  display: flex; flex-direction: column; align-items: center; min-width: 74px;
  padding: 5px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
}
.chip .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
.chip .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chip.wide { min-width: 120px; }

.levelbar { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 10px 6px; flex: none; }
.levelbar .lv { min-width: 110px; text-align: center; font-weight: 700; font-size: 17px; }
.levelbar .icon-btn { width: 36px; height: 36px; }
.hearts { display: flex; gap: 3px; margin-inline-start: 10px; }
.hearts svg { width: 20px; height: 20px; }

/* ---------- Modal & toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(6, 8, 14, 0.62);
  opacity: 0; transition: opacity .18s ease;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  width: min(380px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  padding: 22px 20px 18px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
  transform: translateY(14px) scale(0.97); transition: transform .2s cubic-bezier(.2,.9,.3,1.2);
}
.modal-backdrop.show .modal { transform: none; }
.modal h2 { margin: 0 0 10px; font-size: 22px; text-align: center; }
.modal-body { color: var(--muted); font-size: 15px; line-height: 1.45; }
.modal-body p { margin: 0 0 10px; }
.modal-body b, .modal-body strong { color: var(--text); }
.modal-body .big { font-size: 34px; font-weight: 800; color: var(--text); text-align: center; margin: 4px 0 6px; }
.modal-body ul { padding-inline-start: 20px; margin: 6px 0 10px; }
.modal-body li { margin-bottom: 5px; }
.modal-buttons { display: flex; gap: 10px; margin-top: 16px; }
.modal-buttons button {
  flex: 1; padding: 13px 10px; border-radius: 14px; font-weight: 700; font-size: 15.5px;
  background: var(--panel2); border: 1px solid var(--line);
}
.modal-buttons button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-buttons button:active { transform: scale(0.97); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text); }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--panel2); border: 1px solid var(--line); position: relative; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--good); border-color: var(--good); }
.switch.on::after { transform: translateX(20px); }

.toast {
  position: fixed; left: 50%; top: calc(70px + env(safe-area-inset-top)); z-index: 60;
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: #f4f5fa; color: #14161f; font-weight: 700; font-size: 15px;
  padding: 10px 18px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.35);
  transition: opacity .18s ease, transform .18s ease; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Blocks (Tetris) controls ---------- */
.padbar { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px 10px; flex: none; }
.padbar .grp { display: flex; gap: 8px; }
.padbtn {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; touch-action: none;
}
.padbtn svg { width: 26px; height: 26px; }
.padbtn.held { background: var(--panel2); border-color: var(--accent); transform: scale(0.94); }
/* Full size needs 402px (6 x 56 + 4 x 8 + 10 + 24); at 50px and 6px gaps the bar is 358px, so it fits 360. */
@media (max-width: 402px) { .padbtn { width: 50px; height: 52px; } .padbar .grp { gap: 6px; } }

/* ---------- Word game ---------- */
.wg { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.wg-mode { display: flex; justify-content: center; padding: 0 0 6px; flex: none; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { padding: 7px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); }
.wg-board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px 10px; }
.wg-board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 6px; }
.wg-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.wg-row.shake { animation: shake .45s; }
.tile {
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 6px;
  font-weight: 800; text-transform: uppercase; color: var(--text);
  background: transparent;
}
.tile.filled { border-color: #59607a; animation: pop .1s; }
.tile.correct { background: #3a9a5b; border-color: #3a9a5b; }
.tile.present { background: #c49b2b; border-color: #c49b2b; }
.tile.absent { background: #3a3f52; border-color: #3a3f52; }
.tile.flip-in { animation: flipIn .16s ease-in forwards; }
.tile.flip-out { animation: flipOut .16s ease-out forwards; }
.tile.bounce { animation: bounce .5s ease; }
.kb { flex: none; padding: 4px 4px 8px; display: flex; flex-direction: column; gap: 7px; }
.kb-row { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1; max-width: 44px; height: 54px; border-radius: 7px; background: #555b72;
  font-weight: 700; font-size: 15px; text-transform: uppercase; display: flex; align-items: center; justify-content: center;
}
.key.wide { max-width: 68px; flex: 1.5; font-size: 12px; }
.key.correct { background: #3a9a5b; }
.key.present { background: #c49b2b; }
.key.absent { background: #2c3040; color: #8088a3; }
.key:active { filter: brightness(1.25); }
.key svg { width: 22px; height: 22px; }
.dist { margin: 6px 0 2px; }
.dist-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 13px; }
.dist-row .bar { background: var(--panel2); color: #fff; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-align: right; min-width: 22px; }
.dist-row .bar.hi { background: #3a9a5b; }
.stats4 { display: flex; justify-content: space-around; text-align: center; margin: 4px 0 12px; }
.stats4 .n { font-size: 26px; font-weight: 800; color: var(--text); }
.stats4 .l { font-size: 11px; }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); } }
@keyframes flipIn { from { transform: rotateX(0); } to { transform: rotateX(90deg); } }
@keyframes flipOut { from { transform: rotateX(90deg); } to { transform: rotateX(0); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-22px); } 70% { transform: translateY(4px); } }

@media (prefers-reduced-motion: reduce) {
  .tile.filled, .wg-row.shake, .tile.bounce { animation: none; }
}

/* ---------- Right-to-left (Hebrew) ---------- */
/* Arrows that mean "back" or "previous/next" point the other way in Hebrew. */
[dir=rtl] .topbar .back svg, [dir=rtl] .levelbar .icon-btn svg { transform: scaleX(-1); }
/* Physical controls and the English word game keep left-to-right order. */
.padbar, .wg-board, .kb { direction: ltr; }
