:root{
  --bg: #0b1020;
  --panel: rgba(255,255,255,.06);
  --panel-2: rgba(255,255,255,.10);
  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.66);
  --border: rgba(255,255,255,.12);
  --shadow: rgba(0,0,0,.42);

  --tile: rgba(255,255,255,.06);
  --tile-border: rgba(255,255,255,.14);
  --tile-front: rgba(255,255,255,.18);

  --key: rgba(255,255,255,.07);
  --key-border: rgba(255,255,255,.14);

  --correct: #35c96f;
  --present: #f4c84a;
  --absent: #2b3146;

  --error: #ff4d6d;

  --radius: 18px;
  --radius-sm: 14px;
  --gap: 8px;

  --tileSize: clamp(48px, 6.5vmin, 62px);
  --keyH: clamp(32px, 4.5vmin, 40px);
}

*{ box-sizing: border-box; }
html, body, #app {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(900px 520px at 55% -12%, rgba(92,122,255,.30), transparent 58%),
    radial-gradient(760px 440px at 85% 0%, rgba(75,223,255,.14), transparent 62%),
    radial-gradient(540px 340px at 10% 18%, rgba(255,120,205,.10), transparent 55%),
    linear-gradient(180deg, rgba(255,255,255,.03), transparent 22%),
    var(--bg);
  color: var(--text);
}

.wrap{
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
  box-sizing: border-box;
  overflow: hidden;
}

.contentWrap{
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.app{
  width: min(520px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#appRoot{
  opacity: 0;
  transition: opacity .12s ease;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar{
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-right{
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-btn{
  padding: 8px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  color: rgba(255,255,255,.65);
  cursor: pointer;
  border-radius: 10px;
  transition: color .12s ease, background .12s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-btn:hover{
  color: var(--text);
  background: rgba(255,255,255,.10);
}

.brand{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  pointer-events: none;
  width: min(320px, calc(100% - 120px));
}
.brand .title{
  font-weight: 700;
  letter-spacing: .5px;
  font-size: 16px;
  line-height: 1.1;
  color: var(--text);
}
.game-num{
  color: rgba(255,255,255,.60);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-top: 3px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  transition: color .2s ease;
}
.game-num--won{
  color: #35c96f;
  font-size: 13px;
}
.game-num--lost{
  color: var(--error);
  font-size: 13px;
}

/* ── Кнопки модалок ── */
.modal-actions{
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.modal-btn{
  flex: 1;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  border: none;
  transition: transform .06s ease, background .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.modal-btn:active{ transform: scale(.97); }
.modal-btn--primary{
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.95);
  border: 1px solid rgba(255,255,255,.22);
}
.modal-btn--primary:hover{ background: rgba(255,255,255,.20); }
.modal-btn--ghost{
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.7);
  border: 1px solid rgba(255,255,255,.10);
}
.modal-btn--ghost:hover{ background: rgba(255,255,255,.10); }

.actions{
  display: flex;
  gap: 6px;
  align-items: center;
}
.btn{
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  transition: background .12s ease, transform .06s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn:hover{
  background: rgba(255,255,255,.08);
}
.btn:active{
  transform: scale(.95);
}
.btn--ghost{
  background: transparent;
}
.btn:disabled{
  opacity: .45;
  cursor: not-allowed;
}
.btn--icon{
  padding: 6px;
  font-size: 18px;
}

.panel{
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 16px;
  backdrop-filter: blur(10px);
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: fit-content;
  margin: 0 auto;
}

.attempts{
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 6px;
  letter-spacing: .3px;
}
.error{
  color: var(--error);
  font-size: 12px;
  display: none;
  text-align: center;
}
.error.error--show{
  display: block;
}

.board{
  display: grid;
  grid-template-rows: repeat(6, var(--tileSize));
  gap: var(--gap);
  padding: 4px 2px 6px;
  flex: 0 0 auto;
  width: fit-content;
  margin: 0 auto;
  overflow: hidden;
}
.row{
  display: grid;
  grid-template-columns: repeat(5, var(--tileSize));
  gap: var(--gap);
  min-height: 0;
}

.tile{
  position: relative;
  width: 100%;
  height: var(--tileSize);
  perspective: 700px;
  user-select: none;
}
.tile__inner{
  width: 100%;
  height: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.03);
  transform-style: preserve-3d;
  transition: transform 330ms cubic-bezier(.2,.9,.2,1);
}
.tile__face{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 30px;
  letter-spacing: .2px;
  backface-visibility: hidden;
  border-radius: 12px;
}
.tile__front{
  background: transparent;
  color: rgba(255,255,255,.40);
}
.tile__back{
  background: rgba(255,255,255,.04);
  transform: rotateX(180deg);
}

.tile--filled .tile__front{
  color: rgba(255,255,255,.94);
}

.tile--flipped .tile__inner{
  transform: rotateX(180deg);
}

.tile--correct .tile__back{
  background: rgba(53,201,111,.85);
  border: 1px solid rgba(53,201,111,.95);
  color: rgba(255,255,255,.96);
}
.tile--present .tile__back{
  background: rgba(244,200,74,.88);
  border: 1px solid rgba(244,200,74,.96);
  color: rgba(255,255,255,.96);
}
.tile--absent .tile__back{
  background: rgba(15, 18, 32, .98);
  border: 1px solid rgba(255,255,255,.05);
  color: rgba(255,255,255,.30);
}

.keyboard{
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px 8px;
  background: linear-gradient(to top, rgba(11,16,32,.95) 60%, transparent);
}
.kbdRow{
  display: grid;
  gap: 4px;
  grid-auto-rows: var(--keyH);
}
.kbdRow--r1{ grid-template-columns: repeat(9, 1fr); }
.kbdRow--r2{ grid-template-columns: repeat(10, 1fr); }
.kbdRow--r3{ grid-template-columns: repeat(10, 1fr); }
.kbdRow--r4{ grid-template-columns: 1fr 1fr; gap: 6px; }

.key{
  border-radius: 12px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  height: var(--keyH);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  font-weight: 750;
  font-size: clamp(13px, 2.0vmin, 18px);
  color: rgba(255,255,255,.88);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .06s ease, background .12s ease, border-color .12s ease;
  min-width: 0;
  flex: 1;
}
.key:hover{ background: rgba(255,255,255,.075); border-color: rgba(255,255,255,.14); }
.key:active{ transform: scale(.98); }
.key--enter, .key--bksp{
  font-size: 14px;
}
.key--small{ font-size: 16px; }
.key--disabled{
  opacity: .55;
  cursor: not-allowed;
}

.key--correct{
  background: rgba(53,201,111,.30);
  border-color: rgba(53,201,111,.78);
}
.key--present{
  background: rgba(244,200,74,.28);
  border-color: rgba(244,200,74,.78);
}
.key--absent{
  background: rgba(15, 18, 32, .95);
  border-color: rgba(255,255,255,.05);
  color: rgba(255,255,255,.25);
  opacity: 1;
}

.shake{
  animation: shake .35s ease-in-out;
}
@keyframes shake{
  0%{ transform: translateX(0); }
  25%{ transform: translateX(-6px); }
  50%{ transform: translateX(6px); }
  75%{ transform: translateX(-4px); }
  100%{ transform: translateX(0); }
}

.overlay{
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,.58);
  z-index: 10;
}
.overlay--open{
  display: flex;
}

.modal{
  width: min(440px, 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(15, 18, 32, .96);
  box-shadow: 0 26px 90px rgba(0,0,0,.60);
  padding: 18px;
  backdrop-filter: blur(12px);
}
.modal h2{
  margin: 0 0 8px;
  font-size: 22px;
}
.modal p{
  margin: 0 0 10px;
  color: var(--muted);
}
.modal .word{
  font-weight: 1000;
  letter-spacing: 2px;
  font-size: 18px;
  margin: 10px 0 14px;
}
.statsGrid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 14px;
}
.stat{
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  padding: 10px;
}
.stat .k{
  color: var(--muted);
  font-size: 11px;
}
.stat .v{
  font-weight: 1000;
  font-size: 16px;
  margin-top: 4px;
}

.footerNote{
  color: rgba(255,255,255,.55);
  font-size: 11px;
  line-height: 1.35;
  margin-top: 6px;
}

@media (max-width: 420px){
  .wrap{ padding: 12px; }
  .app{ width: min(420px, 100%); gap: 10px; }
  .panel{ padding: 14px; }
  :root{ --gap: 8px; }
  .key{ padding: 11px 0; border-radius: 12px; }
}


/* Bounce-анимация победы */
@keyframes bounce {
  0%   { transform: translateY(0); }
  30%  { transform: translateY(-18px) scale(1.08); }
  60%  { transform: translateY(-6px); }
  80%  { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}
.tile--bounce .tile__inner {
  animation: bounce 0.55s cubic-bezier(.36,.07,.19,.97) both;
}

/* Таймер в оверлее */
.timerEl {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 14px;
  font-variant-numeric: tabular-nums;
}

/* ── FAQ ── */
.btn--icon{
  padding: 10px 12px;
  font-size: 16px;
}
.faqSub{
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
}
.faqList{
  margin: 0 0 16px 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}
.faqExTitle{
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 12px;
}
.faqExampleRow{
  margin-bottom: 16px;
}
.faqExampleTiles{
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}
.faqExampleDesc{
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  line-height: 1.4;
}
.faqExampleDesc strong{
  color: var(--text);
  font-weight: 600;
}
.faqTile{
  width: 36px; height: 36px;
  flex-shrink: 0;
  perspective: 500px;
}
.faqTile__inner{
  width: 100%; height: 100%;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 16px;
  background: rgba(255,255,255,.04);
  transform-style: preserve-3d;
  transition: transform 800ms cubic-bezier(.2,.9,.2,1);
}
.faqTile__face{
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  backface-visibility: hidden;
  border-radius: 6px;
  font-weight: 900; font-size: 16px;
}
.faqTile__front{
  color: var(--text);
}
.faqTile__back{
  transform: rotateX(180deg);
  color: #fff;
}
.faqTile--flipped .faqTile__inner{
  transform: rotateX(180deg);
}
.faqTile--correct .faqTile__inner{ background: rgba(53,201,111,.30); border-color: rgba(53,201,111,.78); }
.faqTile--present .faqTile__inner{ background: rgba(244,200,74,.28); border-color: rgba(244,200,74,.78); }
.faqTile--absent .faqTile__inner{ background: rgba(43,49,70,.85); border-color: rgba(255,255,255,.12); }
.faqTile--absent .faqTile__back{ color: rgba(255,255,255,.86); }

/* ── Таблица лидеров ── */
.leadersLoading{
  color: var(--muted);
  font-size: 13px;
  margin: 12px 0;
}
.leadersTable{
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
  max-height: 320px;
  overflow-y: auto;
}
.leaderRow{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
}
.leaderRow--top{
  background: rgba(255,255,255,.07);
  border-color: rgba(255,255,255,.14);
}
.leaderRank{
  width: 28px;
  text-align: center;
  font-size: 16px;
  flex-shrink: 0;
}
.leaderName{
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leaderWins{
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── Таб-бар навигация ── */
.tabbar{
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 12px;
  gap: 8px;
  flex: 0 0 auto;
}

.tab{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s ease;
  min-width: 70px;
}

.tab:hover{
  color: var(--text);
  background: rgba(255,255,255,.04);
}

.tab--active{
  color: var(--text);
  background: rgba(255,255,255,.08);
}

.tab__icon{
  font-size: 22px;
  line-height: 1;
}

.tab__label{
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}

/* Экраны контента */
.tab-content{
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.screen-stack{
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-items: center;
}

.screen-stack .panel{
  width: 100%;
  max-width: 520px;
}

.gameArea{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  padding-bottom: 180px;
}

.tab-content--active{
  display: flex;
}

/* Профиль */
.profile-header{
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  background: rgba(255,255,255,.04);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.08);
}

.profile-avatar{
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  overflow: hidden;
}

.profile-avatar img{
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-info{
  flex: 1;
}

.profile-name{
  font-weight: 700;
  font-size: 16px;
}

.profile-id{
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.achievements-grid{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.achievement{
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  opacity: .5;
}

.achievement--unlocked{
  opacity: 1;
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.16);
}

/* Турниры */
.tournament-card{
  padding: 14px;
  background: rgba(255,255,255,.04);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.08);
}

.tournament-card + .tournament-card{
  margin-top: 10px;
}

.tournament-title{
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 6px;
}

.tournament-meta{
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 12px;
}

/* Placeholder экраны */
.screen-placeholder{
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 14px;
}

.screen-placeholder__icon{
  font-size: 48px;
  margin-bottom: 12px;
  opacity: .5;
}

/* ── Дуэль ── */
.duel-scoreboard{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: rgba(255,255,255,.04);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.08);
  margin-bottom: 12px;
}

.duel-player{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.duel-player__name{
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.duel-player__score{
  font-size: 24px;
  font-weight: 1000;
  color: var(--text);
}

.duel-timer{
  font-size: 18px;
  font-weight: 700;
  color: var(--correct);
  font-variant-numeric: tabular-nums;
}

.duel-timer.duel-timer--low{
  color: var(--error);
}

.duel-vs{
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  padding: 0 8px;
}

.countdownEl{
  animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse{
  0%, 100%{ transform: scale(1); opacity: 1; }
  50%{ transform: scale(1.1); opacity: 0.8; }
}