/* 180+ Mini App — brand palette from the logo:
   violet #3F2B9A → deep indigo #1A1040 → azure #065DA7, silver #F0F0F0 */

:root {
  --bg-1: #1a1040;
  --bg-2: #2a1b6b;
  --accent-1: #3f2b9a;
  --accent-2: #065da7;
  --azure: #1e90ff;
  --text: #f0f0f0;
  --text-dim: #b9b3d9;
  --card: rgba(255, 255, 255, 0.07);
  --card-border: rgba(255, 255, 255, 0.13);
  --good: #2ecc71;
  --bad: #ff5e6c;
  --radius: 18px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 55%, #0c2f63 130%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 90px; }

/* ---------- loader ---------- */
.loader-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80vh; }
.hex-loader { font-size: 64px; animation: spin 1.6s ease-in-out infinite; color: var(--azure); }
.loader-text { font-size: 28px; font-weight: 800; letter-spacing: 4px; margin-top: 8px; }
@keyframes spin { 50% { transform: rotate(180deg) scale(1.15); } }

/* ---------- generic ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.btn {
  display: block; width: 100%;
  border: none; border-radius: var(--radius);
  padding: 16px; margin-bottom: 10px;
  font-size: 17px; font-weight: 700; color: #fff;
  background: linear-gradient(100deg, var(--accent-1), var(--accent-2));
  box-shadow: 0 6px 22px rgba(63, 43, 154, 0.45);
  cursor: pointer; transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--card); border: 1px solid var(--card-border); box-shadow: none; }
.btn.small { padding: 11px; font-size: 15px; margin-bottom: 8px; }

.title { font-size: 22px; font-weight: 800; margin: 6px 0 14px; }
.subtitle { color: var(--text-dim); font-size: 14px; margin-bottom: 14px; }

.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar .back { background: var(--card); border: 1px solid var(--card-border); color: var(--text);
  border-radius: 12px; padding: 8px 14px; font-size: 15px; cursor: pointer; }
.topbar .grow { flex: 1; font-weight: 800; font-size: 17px; text-align: center; }

/* ---------- home ---------- */
.hero { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.hero .hex { width: 52px; height: 52px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 17px; }
.hex-logo { width: 56px; height: 56px; border-radius: 16px; display: block;
  box-shadow: 0 6px 20px rgba(63, 43, 154, .5); }
.hex-loader-img { width: 84px; height: 84px; border-radius: 22px;
  animation: pulse 1.4s ease-in-out infinite; box-shadow: 0 10px 36px rgba(6, 93, 167, .5); }
@keyframes pulse { 50% { transform: scale(1.09); } }
.hero h1 { font-size: 20px; }
.hero p { color: var(--text-dim); font-size: 13px; }

.subjects { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.subject-chip { padding: 9px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--card); border: 1px solid var(--card-border); color: var(--text-dim); cursor: pointer; }
.subject-chip.active { background: linear-gradient(100deg, var(--accent-1), var(--accent-2));
  color: #fff; border-color: transparent; }

.mode-card { position: relative; overflow: hidden; cursor: pointer; }
.mode-card h3 { font-size: 18px; margin-bottom: 4px; }
.mode-card p { color: var(--text-dim); font-size: 13px; }
.mode-card .emoji { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 34px; opacity: .85; }

/* ---------- list buttons ---------- */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid3 .btn { margin-bottom: 0; padding: 14px 8px; }

/* ---------- player ---------- */
.progress-wrap { height: 7px; border-radius: 999px; background: rgba(255,255,255,.12); margin-bottom: 10px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-1), var(--azure)); transition: width .25s; }
.player-meta { display: flex; justify-content: space-between; align-items: center;
  color: var(--text-dim); font-size: 14px; margin-bottom: 10px; }
.player-meta b { color: var(--text); }

.q-images img { width: 100%; border-radius: 14px; margin-bottom: 8px; background: #fff; display: block; }

.answers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0; }
.answers.cols-4 { grid-template-columns: repeat(4, 1fr); }
.answers.cols-6 { grid-template-columns: repeat(6, 1fr); }
.answers.cols-7 { grid-template-columns: repeat(7, 1fr); }
.answers.cols-8 { grid-template-columns: repeat(8, 1fr); }
.ans-btn { padding: 14px 0; border-radius: 14px; border: 1px solid var(--card-border);
  background: var(--card); color: var(--text); font-size: 17px; font-weight: 700; cursor: pointer; }
.ans-btn.selected { background: linear-gradient(100deg, var(--accent-1), var(--accent-2)); border-color: transparent; }
.ans-btn.dim { opacity: .45; }

.match-pairs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.pair-tag { background: var(--card); border: 1px solid var(--card-border); border-radius: 10px;
  padding: 6px 10px; font-size: 14px; font-weight: 700; }
.match-hint { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }

.short-input { width: 100%; padding: 14px; border-radius: 14px; border: 1px solid var(--card-border);
  background: rgba(0,0,0,.25); color: var(--text); font-size: 17px; margin: 12px 0; outline: none; }
.short-input:focus { border-color: var(--azure); }

.player-nav { display: flex; gap: 8px; margin-top: 6px; }
.player-nav .btn { margin-bottom: 0; }
.player-nav .nav-cnt { flex: 1.4; }
.player-nav .nav-arr { flex: 1; }

.nav-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 12px 0; }
.nav-cell { padding: 12px 0; text-align: center; border-radius: 12px; font-weight: 700; cursor: pointer;
  background: var(--card); border: 1px solid var(--card-border); }
.nav-cell.answered { background: linear-gradient(100deg, var(--accent-1), var(--accent-2)); border-color: transparent; }
.nav-cell.current { outline: 2px solid var(--azure); }

/* ---------- results ---------- */
.score-hero { text-align: center; padding: 26px 16px; }
.score-hero .nmt { font-size: 56px; font-weight: 900;
  background: linear-gradient(100deg, #9d8cff, var(--azure));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.score-hero .sub { color: var(--text-dim); margin-top: 4px; }
.dots { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-top: 14px; }
.dot { width: 13px; height: 13px; border-radius: 50%; }
.dot.g { background: var(--good); } .dot.b { background: var(--bad); } .dot.n { background: rgba(255,255,255,.2); }

.review-item { border-left: 4px solid var(--bad); }
.review-item.ok { border-left-color: var(--good); }
.review-item .rev-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 6px; }
.review-item .rev-answers { font-size: 14px; color: var(--text-dim); margin-bottom: 6px; }
.review-item .rev-answers b { color: var(--text); }
.review-item img { width: 100%; border-radius: 12px; margin-top: 8px; background: #fff; }
.expl { white-space: pre-wrap; font-size: 14px; background: rgba(0,0,0,.25); border-radius: 12px; padding: 12px; margin-top: 8px; }
.link-btn { background: none; border: none; color: var(--azure); font-size: 14px; font-weight: 700; cursor: pointer; padding: 6px 0; }

.fade-in { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

/* ---------- cascading picker ---------- */
.picker { padding-bottom: 8px; }
.lvl-label { font-size: 12px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-dim); margin: 10px 2px 8px; }
/* всі варіанти видно одразу — переносимо рядками, без горизонтального скролу */
.lvl-row { display: flex; gap: 8px; flex-wrap: wrap; padding-bottom: 6px; }
.subject-chip.wide { padding: 9px 18px; }
.lvl-hint { color: var(--text-dim); font-size: 14px; padding: 6px 2px; }
.lvl-anim:not([hidden]) { animation: slideIn .3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } }
.picker .btn { margin-top: 10px; margin-bottom: 6px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.row2 .card { margin-bottom: 0; min-width: 0; }
.row2 .mode-card h3 { font-size: 16px; }
.row2 .mode-card p { font-size: 12px; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(8, 4, 28, .96);
  display: flex; flex-direction: column; animation: fade .2s ease; }
.lb-close { position: absolute; top: 14px; right: 14px; z-index: 101;
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--card-border);
  background: var(--card); color: var(--text); font-size: 18px; cursor: pointer; }
.lb-stage { flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; }
.lb-stage img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff;
  transition: transform .06s linear; transform-origin: center; user-select: none; }
.q-images img, .review-item img { cursor: zoom-in; }

/* ---------- random verdict ---------- */
.verdict-ok { border-left: 4px solid var(--good); }
.verdict-bad { border-left: 4px solid var(--bad); }

/* ---------- stats ---------- */
.stat-big { text-align: center; padding: 18px 8px; }
.stat-big .num { font-size: 34px; font-weight: 900;
  background: linear-gradient(100deg, #9d8cff, var(--azure));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-big .cap { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.stat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 9px 2px; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,.07);
  overflow-wrap: anywhere; }
.stat-row:last-child { border-bottom: none; }
.stat-row.dim { color: var(--text-dim); }
.stat-row span:first-child { flex-shrink: 0; max-width: 55%; }
.stat-row span:last-child { text-align: right; white-space: nowrap; }
.stat-big { min-width: 0; }
.stat-big .num { font-size: clamp(22px, 8vw, 34px); overflow: hidden; text-overflow: ellipsis; }

/* ---------- admin ---------- */
.admin-q { display: flex; align-items: center; gap: 10px; padding: 10px 2px;
  border-bottom: 1px solid rgba(255,255,255,.07); cursor: pointer; }
.admin-q:last-child { border-bottom: none; }
.admin-q .qn { font-weight: 800; min-width: 34px; }
.admin-q .qmeta { flex: 1; font-size: 13px; color: var(--text-dim); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.admin-q .qmeta b { color: var(--text); }
.field-label { font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-dim); margin: 12px 2px 6px; }
.field { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--card-border);
  background: rgba(0,0,0,.25); color: var(--text); font-size: 15px; outline: none; font-family: inherit; }
textarea.field { min-height: 110px; resize: vertical; }
.btn.danger { background: linear-gradient(100deg, #8e2436, #c0392b); box-shadow: 0 6px 22px rgba(192,57,43,.35); }
.sess-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.sess-actions .btn { margin-bottom: 0; }

/* ---------- партіал-мітки, match single-level, calc ---------- */
.dot.y { background: #f1c40f; }
.review-item.part { border-left-color: #f1c40f; }
.pair-tag.hot { border-color: var(--azure); color: #fff; box-shadow: 0 0 0 1px var(--azure); }
select.field { appearance: none; -webkit-appearance: none; }
.score-hero .nmt .of { font-size: 26px; color: var(--text-dim); -webkit-text-fill-color: var(--text-dim); }

/* ---------- swipe anim + hint ---------- */
.slide-l { animation: slideL .22s ease; }
.slide-r { animation: slideR .22s ease; }
@keyframes slideL { from { opacity: .4; transform: translateX(60px); } }
@keyframes slideR { from { opacity: .4; transform: translateX(-60px); } }
.swipe-hint { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: linear-gradient(100deg, rgba(63,43,154,.45), rgba(6,93,167,.45));
  border: 1px solid var(--card-border); border-radius: 14px;
  padding: 10px 12px; margin-bottom: 10px; font-size: 14px; font-weight: 600; }
.hint-x { background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 2px 6px; }

/* ---------- fullscreen safe area (Telegram Bot API 8+) ---------- */
#app {
  padding-top: calc(16px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
}
body { touch-action: pan-y; }

/* ---------- довідкові матеріали ---------- */
.mats-overlay { position: fixed; inset: 0; z-index: 90; overflow-y: auto;
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
  padding: calc(14px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 14px 30px; }
.mats-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.mats-head .hint-x { font-size: 22px; }
.mats-body img { width: 100%; border-radius: 12px; margin-bottom: 10px; background: #fff; cursor: zoom-in; }
