:root {
  --bg: #0d0b1f;
  --bg-2: #17133a;
  --panel: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f1ff;
  --muted: #a49fc8;
  --chips: #3ba7ff;
  --mult: #ff4f6d;
  --good: #3ee39a;
  --bad: #ff4f6d;
  --gold: #ffc94a;
  --rare: #b46bff;
  --card: #fbf6ea;
  --card-ink: #231c3d;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: "Rubik", system-ui, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

#app {
  position: relative;
  width: 100%; max-width: 480px; height: 100dvh; margin: 0 auto;
  background: radial-gradient(120% 70% at 50% 0%, #2a1f6b 0%, var(--bg-2) 45%, var(--bg) 100%);
  overflow: hidden;
}

.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  padding: 18px 16px calc(18px + var(--safe-b));
  gap: 14px;
  overflow-y: auto;
}
.screen.active { display: flex; }

/* ---------- common ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.btn { padding: 14px 18px; border-radius: 14px; font-weight: 800; letter-spacing: .06em; transition: transform .08s; }
.btn:active { transform: scale(.96); }
.btn-primary { background: linear-gradient(180deg, #ff6a86, #e83a5f); box-shadow: 0 5px 0 #a5203f; }
.btn-primary:active { box-shadow: 0 1px 0 #a5203f; transform: translateY(4px); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-big { font-size: 20px; padding: 18px; }
.error { color: var(--bad); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }
.icon-btn { position: absolute; top: 16px; right: 74px; font-size: 20px; opacity: .8; }

/* ---------- login ---------- */
#screen-login { justify-content: center; align-items: stretch; text-align: center; }
.logo { font-weight: 900; font-size: clamp(38px, 12vw, 56px); line-height: .95; letter-spacing: -.02em; display: flex; flex-direction: column; }
.logo-break { color: var(--text); }
.logo-through { background: linear-gradient(90deg, var(--chips), var(--rare), var(--mult)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--muted); margin: 4px 0 18px; }
.login-cards { position: relative; height: 150px; margin-bottom: 10px; }
.mini-card {
  position: absolute; left: 50%; top: 10px; width: 86px; height: 120px; margin-left: -43px;
  border-radius: 12px; background: var(--card); color: var(--card-ink);
  display: grid; place-items: center; font-weight: 900; font-size: 26px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.mini-card.c1 { transform: translateX(-70px) rotate(-14deg); }
.mini-card.c3 { transform: translateX(70px) rotate(14deg); }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#username {
  padding: 15px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0,0,0,.3);
  color: var(--text); font: inherit; font-size: 18px; text-align: center; outline: none;
}
#username:focus { border-color: var(--rare); }

/* ---------- hub ---------- */
.hub-top { display: flex; justify-content: space-between; align-items: center; }
.hub-name { font-size: 24px; font-weight: 800; }
.hub-sub { color: var(--muted); }
.level-badge {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  font-weight: 900; font-size: 20px; background: linear-gradient(135deg, var(--rare), var(--chips));
  box-shadow: 0 0 24px rgba(180,107,255,.5);
}
.matrix-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.tag { flex: 0 0 76px; font-size: 11px; font-weight: 800; text-transform: uppercase; padding: 5px 0; text-align: center; border-radius: 8px; }
.tag-grammar { background: rgba(59,167,255,.18); color: var(--chips); }
.tag-trap { background: rgba(255,79,109,.18); color: var(--mult); }
.tag-vocab { background: rgba(255,201,74,.16); color: var(--gold); }
.tag-mastered { background: rgba(62,227,154,.16); color: var(--good); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; padding: 5px 8px; border-radius: 8px; background: rgba(255,255,255,.08); }
.chip.empty { opacity: .45; font-style: italic; }
.trophies { display: flex; flex-wrap: wrap; gap: 8px; }
.trophy { display: flex; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 10px; background: rgba(255,201,74,.12); font-size: 13px; }
.trophy.locked { filter: grayscale(1); opacity: .35; }
.hub-actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.ad-banner {
  display: flex; gap: 10px; align-items: center; justify-content: center;
  padding: 12px; border-radius: 14px; border: 1px dashed rgba(255,201,74,.5);
  background: rgba(255,201,74,.07); color: var(--gold); font-size: 14px;
}

/* ---------- game ---------- */
.game-top { display: flex; justify-content: space-between; align-items: center; }
.blind-name { font-weight: 900; font-size: 20px; }
.blind-target { color: var(--muted); }
.blind-target b { color: var(--gold); }
.score-box { text-align: right; }
.score-label { font-size: 11px; letter-spacing: .15em; color: var(--muted); }
.score-value { font-size: 34px; font-weight: 900; line-height: 1; display: inline-block; }
.progress { height: 8px; background: rgba(255,255,255,.08); border-radius: 8px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--chips), var(--good)); border-radius: 8px; }

.hud { display: flex; justify-content: center; align-items: center; gap: 10px; }
.hud-chips, .hud-mult {
  min-width: 96px; padding: 8px 14px; border-radius: 14px; text-align: center;
  display: flex; flex-direction: column; font-weight: 900; font-size: 28px; line-height: 1;
}
.hud small { font-size: 10px; letter-spacing: .12em; font-weight: 600; opacity: .8; margin-top: 2px; }
.hud-chips { background: var(--chips); box-shadow: 0 4px 0 #1b6cb3; }
.hud-mult { background: var(--mult); box-shadow: 0 4px 0 #a5203f; }
.hud-x { font-size: 26px; font-weight: 900; color: var(--muted); }

.pips { display: flex; justify-content: center; gap: 8px; }
.pip { width: 26px; height: 6px; border-radius: 4px; background: rgba(255,255,255,.15); }
.pip.current { background: var(--text); }
.pip.ok { background: var(--good); }
.pip.fail { background: var(--bad); }
.pip.rare { box-shadow: 0 0 0 2px var(--rare); }
.pip.legendary { box-shadow: 0 0 0 2px var(--gold); }

.card-stage { perspective: 1200px; display: flex; justify-content: center; flex: 1 1 auto; min-height: 210px; align-items: center; }
.card { width: min(86%, 340px); aspect-ratio: 5 / 3.6; position: relative; }
.card-inner { position: absolute; inset: 0; transform-style: preserve-3d; }
.card-face {
  position: absolute; inset: 0; border-radius: 20px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
}
.card-back {
  background: repeating-linear-gradient(45deg, #3b2d8f 0 12px, #2c2170 12px 24px);
  border: 6px solid var(--card); display: grid; place-items: center;
}
.back-pattern { font-weight: 900; font-size: 64px; color: var(--card); opacity: .9; }
.card-front {
  transform: rotateY(180deg); background: var(--card); color: var(--card-ink);
  padding: 16px 18px; display: flex; flex-direction: column; border: 3px solid transparent;
}
.card-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 800; letter-spacing: .1em; }
.card-type { padding: 3px 8px; border-radius: 6px; background: var(--card-ink); color: var(--card); }
.card-level { opacity: .6; }
.card-rarity { font-size: 12px; font-weight: 900; letter-spacing: .14em; min-height: 16px; margin-top: 6px; }
.card-prompt { font-size: clamp(18px, 5.2vw, 22px); font-weight: 600; margin: auto 0; line-height: 1.3; }
.card-topic { font-size: 11px; opacity: .55; text-transform: uppercase; letter-spacing: .08em; }

.card.rare .card-front { border-color: var(--rare); background: linear-gradient(160deg, #fff 0%, #f1e4ff 55%, #e3f3ff 100%); }
.card.rare .card-rarity { color: var(--rare); }
.card.legendary .card-front { border-color: var(--gold); background: linear-gradient(160deg, #fffaf0 0%, #ffe9b0 60%, #ffd36b 100%); }
.card.legendary .card-rarity { color: #b07800; }
.card.rare .card-face.card-front, .card.legendary .card-face.card-front { animation: glow 1.6s ease-in-out infinite alternate; }
.card.rare { --glow: rgba(180,107,255,.75); }
.card.legendary { --glow: rgba(255,201,74,.85); }
@keyframes glow { from { box-shadow: 0 0 12px var(--glow), 0 16px 40px rgba(0,0,0,.45); } to { box-shadow: 0 0 36px var(--glow), 0 16px 40px rgba(0,0,0,.45); } }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option {
  padding: 14px 10px; border-radius: 14px; background: rgba(255,255,255,.09); border: 1px solid var(--line);
  font-weight: 600; font-size: 15px; min-height: 56px; box-shadow: 0 4px 0 rgba(0,0,0,.35);
}
.option:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.option.correct { background: var(--good); color: #062a1a; border-color: transparent; }
.option.wrong { background: var(--bad); border-color: transparent; }
.option:disabled { cursor: default; }

.feedback {
  position: absolute; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b));
  padding: 16px; border-radius: 20px; background: #1d1747; border: 1px solid var(--line);
  box-shadow: 0 -10px 40px rgba(0,0,0,.5); display: none; flex-direction: column; gap: 8px; z-index: 5;
}
.feedback.show { display: flex; }
.fb-title { font-size: 22px; font-weight: 900; }
.feedback.good .fb-title { color: var(--good); }
.feedback.bad .fb-title { color: var(--bad); }
.fb-gain { font-weight: 800; color: var(--gold); }
.fb-expl { margin: 0; color: var(--muted); line-height: 1.4; }
.source-tag { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--muted); opacity: .5; }

/* ---------- result ---------- */
#screen-result { justify-content: center; text-align: center; }
.result-title { font-size: 34px; font-weight: 900; }
.result-title.win { color: var(--good); }
.result-title.lose { color: var(--bad); }
.result-score { font-size: 64px; font-weight: 900; }
.result-score small { font-size: 22px; color: var(--muted); }
.result-level { color: var(--gold); font-weight: 800; min-height: 1.2em; }
.result-list, .result-trophies { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; background: rgba(13,11,31,.88); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px; z-index: 20; }
.overlay.show { display: flex; }
.loader-cards { position: relative; width: 70px; height: 96px; }
.loader-cards div { position: absolute; inset: 0; border-radius: 10px; background: repeating-linear-gradient(45deg, #3b2d8f 0 8px, #2c2170 8px 16px); border: 3px solid var(--card); }
#loader-text { color: var(--muted); }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 30; }
#toast {
  position: absolute; left: 50%; top: -80px; z-index: 40;
  background: #2a2160; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: 90%; text-align: center; pointer-events: none;
}
.float-score { position: absolute; font-weight: 900; font-size: 28px; color: var(--gold); pointer-events: none; z-index: 10; text-shadow: 0 3px 0 rgba(0,0,0,.4); }

@media (prefers-reduced-motion: reduce) {
  .card.rare .card-face.card-front, .card.legendary .card-face.card-front { animation: none; }
}
