/* ============================================================
   Kawashima Mini App — светлая Apple-дизайн-система
   ============================================================ */
:root {
  --bg:        #f2f2f7;   /* systemGroupedBackground */
  --bg-2:      #eaeaf0;
  --surface:   #ffffff;
  --surface-2: #f7f7fa;
  --text:      #1c1c1e;
  --text-2:    #6b6b70;
  --muted:     #a1a1a8;
  --hairline:  rgba(60,60,67,0.10);

  --accent:    #007aff;   /* systemBlue */
  --accent-2:  #5e9bff;
  --indigo:    #5856d6;
  --purple:    #7d5bed;
  --green:     #34c759;
  --red:       #ff3b30;
  --orange:    #ff9f0a;
  --pink:      #ff5a8a;
  --teal:      #30c1b6;

  --r-lg: 26px;
  --r-md: 20px;
  --r-sm: 14px;

  --shadow-sm: 0 1px 2px rgba(17,17,26,.04);
  --shadow-md: 0 2px 6px rgba(17,17,26,.05), 0 12px 30px rgba(17,17,26,.06);
  --shadow-lg: 0 8px 20px rgba(17,17,26,.08), 0 30px 60px rgba(17,17,26,.10);

  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);

  --ease: cubic-bezier(.22,.61,.36,1);
  --spring: cubic-bezier(.34,1.56,.64,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

#app { max-width: 520px; margin: 0 auto; min-height: 100%; }
.view {
  padding: calc(var(--sat) + 14px) 18px calc(var(--sab) + 28px);
  min-height: 100vh;
  animation: viewIn .42s var(--ease);
}
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

/* ---------- типографика ---------- */
h1 { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--muted); }
.t2 { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- шапка ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 18px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  box-shadow: var(--shadow-sm); flex: 0 0 auto;
}
.topbar .hi { font-size: 13px; color: var(--muted); line-height: 1.2; }
.topbar .nm { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.pill-pro {
  font-size: 12px; font-weight: 700; padding: 6px 11px; border-radius: 999px;
  background: linear-gradient(135deg, #ffd15c, #ff8a3d); color: #5a3200;
}

/* ---------- карточки ---------- */
.card {
  background: var(--surface); border-radius: var(--r-md);
  box-shadow: var(--shadow-md); padding: 18px;
}
.section-title { font-size: 15px; font-weight: 700; color: var(--text-2); margin: 22px 4px 12px; letter-spacing: -.01em; }

/* ---------- HERO: возраст мозга ---------- */
.hero {
  position: relative; overflow: hidden; color: #fff;
  border-radius: var(--r-lg); padding: 22px;
  background: linear-gradient(135deg, #6a7bff 0%, #7d5bed 55%, #9d5cff 100%);
  box-shadow: 0 12px 30px rgba(109,91,237,.35);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -50px;
  width: 190px; height: 190px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.35), rgba(255,255,255,0) 70%);
}
.hero .label { font-size: 14px; font-weight: 600; opacity: .92; }
.hero .big { font-size: 68px; font-weight: 800; line-height: 1; letter-spacing: -.03em; margin: 6px 0 2px; }
.hero .big small { font-size: 22px; font-weight: 700; opacity: .8; }
.hero .sub { font-size: 13px; opacity: .9; max-width: 78%; }
.hero .brain { position: absolute; right: 18px; bottom: 12px; font-size: 52px; filter: drop-shadow(0 6px 12px rgba(0,0,0,.2)); }

/* ---------- статы ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-top: 12px; }
.stat {
  background: var(--surface); border-radius: var(--r-sm); padding: 14px 10px;
  text-align: center; box-shadow: var(--shadow-sm);
}
.stat .ic { font-size: 20px; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.stat .l { font-size: 11px; color: var(--muted); font-weight: 600; margin-top: 1px; }

/* ---------- кнопки ---------- */
.btn {
  width: 100%; padding: 16px; border-radius: var(--r-sm);
  font-size: 17px; font-weight: 700; letter-spacing: -.01em;
  transition: transform .12s var(--spring), box-shadow .2s, opacity .2s;
}
.btn:active { transform: scale(.965); }
.btn-primary { color: #fff; background: linear-gradient(135deg, var(--accent), #3d8bff); box-shadow: 0 8px 20px rgba(0,122,255,.28); }
.btn-secondary { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.btn-ghost { background: var(--surface-2); color: var(--text-2); }
.btn-lg { padding: 18px; font-size: 18px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- вертикальный список режимов по 7 системам ---------- */
.modes-list { display: flex; flex-direction: column; gap: 8px; }
.sys-head { display: flex; align-items: center; gap: 8px; margin: 18px 2px 8px; font-size: 13px;
  font-weight: 700; color: var(--text-2); letter-spacing: .01em; }
.sys-head:first-child { margin-top: 4px; }
.sys-dot { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; color: #fff; }
.sys-count { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 700;
  background: var(--surface-2); padding: 2px 9px; border-radius: 999px; }
.mode-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border-radius: 16px; padding: 13px 14px; box-shadow: var(--shadow-sm);
  transition: transform .12s var(--spring), box-shadow .2s;
}
.mode-row:active { transform: scale(.98); box-shadow: var(--shadow-md); }
.mode-row.locked { opacity: .6; }
.row-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-size: 20px; color: #fff; flex: 0 0 auto; }
.row-txt { flex: 1; min-width: 0; }
.row-t { font-size: 16px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-d { font-size: 12.5px; color: var(--text-2); line-height: 1.35; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-go { font-size: 22px; color: var(--muted); flex: 0 0 auto; font-weight: 300; }

/* ---------- CTA-карточка чекапа ---------- */
.cta {
  display: flex; align-items: center; gap: 14px; text-align: left;
  border-radius: var(--r-md); padding: 18px; width: 100%;
  background: linear-gradient(135deg, #0fb8a6, #10a3d6); color: #fff;
  box-shadow: 0 10px 24px rgba(16,163,214,.28); transition: transform .12s var(--spring);
}
.cta:active { transform: scale(.98); }
.cta .em { font-size: 30px; }
.cta .tt { font-size: 17px; font-weight: 700; }
.cta .ds { font-size: 12.5px; opacity: .92; margin-top: 2px; }
.cta .go { margin-left: auto; font-size: 22px; opacity: .9; }

/* ============================================================
   ИГРА
   ============================================================ */
.game-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm);
            display: grid; place-items: center; font-size: 18px; transition: transform .12s var(--spring); }
.icon-btn:active { transform: scale(.9); }
.game-head .title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.game-head .timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-2);
                    background: var(--surface); padding: 8px 12px; border-radius: 999px; box-shadow: var(--shadow-sm); font-size: 14px; }

.progress { height: 6px; background: var(--bg-2); border-radius: 999px; overflow: hidden; margin-bottom: 22px; }
.progress > i { display: block; height: 100%; width: 0;
                background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: 999px;
                transition: width .4s var(--ease); }

.qwrap { min-height: 44vh; display: flex; flex-direction: column; justify-content: center; }
.qcard {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-md);
  padding: 40px 20px; text-align: center; margin-bottom: 20px;
  animation: qpop .35s var(--spring);
}
@keyframes qpop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.qcard .prompt { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.qcard .q { font-size: 40px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; white-space: pre-line; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  padding: 20px; border-radius: var(--r-md); font-size: 22px; font-weight: 700;
  background: var(--surface); box-shadow: var(--shadow-sm); color: var(--text);
  transition: transform .1s var(--spring), background .18s, color .18s, box-shadow .2s;
}
.choice:active { transform: scale(.96); }
.choice.ok  { background: var(--green); color: #fff; box-shadow: 0 8px 20px rgba(52,199,89,.35); }
.choice.bad { background: var(--red);   color: #fff; box-shadow: 0 8px 20px rgba(255,59,48,.30); animation: shake .3s; }
.choice.dim { opacity: .45; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }

.livebar { display: flex; justify-content: center; gap: 18px; margin-top: 18px; font-size: 13px; color: var(--muted); font-weight: 600; }
.livebar b { color: var(--text); }

/* ============================================================
   РЕЗУЛЬТАТ
   ============================================================ */
.result { text-align: center; padding-top: 8px; animation: viewIn .5s var(--ease); }
.result .cap { font-size: 15px; color: var(--text-2); font-weight: 600; }
.ach-banner { display: inline-block; margin-top: 10px; padding: 8px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 700; color: #7a4b00;
  background: linear-gradient(135deg, #ffe08a, #ffb347); box-shadow: 0 6px 16px rgba(255,160,60,.30);
  animation: qpop .5s var(--spring); }
.ring-wrap { position: relative; width: 200px; height: 200px; margin: 18px auto 8px; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-wrap .inner { position: absolute; inset: 0; display: grid; place-items: center; flex-direction: column; }
.ring-wrap .num { font-size: 60px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.ring-wrap .unit { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.res-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0 24px; }
.res-stats .card { padding: 16px; }
.res-stats .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.res-stats .l { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* ============================================================ ПРАВИЛА */
.rules { text-align: center; padding-top: 12px; }
.rules-icon { width: 72px; height: 72px; border-radius: 22px; margin: 0 auto 16px; display: grid;
  place-items: center; font-size: 34px; color: #fff; box-shadow: var(--shadow-md); }
.rules h1 { font-size: 24px; margin-bottom: 14px; }
.rules-text { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
  padding: 18px; text-align: left; font-size: 15px; line-height: 1.5; color: var(--text-2);
  margin-bottom: 22px; }

/* ============================================================ ШУЛЬТЕ */
.sch-target { text-align: center; font-size: 17px; color: var(--text-2); font-weight: 600; margin-bottom: 16px; }
.sch-target b { color: var(--accent); font-size: 22px; }
.sch-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.sch-cell {
  aspect-ratio: 1; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm);
  font-size: 18px; font-weight: 700; color: var(--text);
  transition: transform .1s var(--spring), background .2s, color .2s, opacity .2s;
}
.sch-cell:active { transform: scale(.92); }
.sch-cell.done { background: var(--green); color: #fff; opacity: .55; box-shadow: none; }
.sch-cell.shake { animation: shake .3s; background: var(--red); color: #fff; }

/* ============================================================ КОРСИ */
/* width задан ЯВНО: пустые клетки + колонки 1fr иначе схлопывают грид в ноль ширины */
.corsi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  width: min(80vw, 300px); margin: 18px auto 0; }
.corsi-cell {
  aspect-ratio: 1; min-height: 72px; border-radius: 16px; background: #dde3ef;
  box-shadow: inset 0 1px 2px rgba(60,60,90,.10), inset 0 -1px 1px rgba(255,255,255,.6);
  transition: transform .12s var(--spring), background .18s, box-shadow .2s;
}
.corsi-cell.tappable:active { transform: scale(.94); }
.corsi-cell.lit { background: linear-gradient(135deg, #6a7bff, #9d5cff); box-shadow: 0 8px 20px rgba(125,91,237,.4); transform: scale(1.04); }
.corsi-cell.hit { background: var(--green); box-shadow: 0 6px 16px rgba(52,199,89,.35); }
.corsi-cell.miss { background: var(--red); box-shadow: 0 6px 16px rgba(255,59,48,.3); animation: shake .3s; }

/* flash число (память) + слово (струп) */
.q.flash { animation: flashIn .3s var(--spring); font-variant-numeric: tabular-nums; letter-spacing: .06em; }
@keyframes flashIn { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: none; } }
.stroop-word { font-size: 46px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }

/* символьные ряды (матрицы / «одинаково?») — компактнее и с ровным шагом */
.q.q-syms { font-size: 30px; line-height: 1.5; letter-spacing: .1em; }

/* «Найди лишнее» — крупные плитки */
.qcard.soft { padding: 24px 16px; }
.odd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.odd-tile {
  aspect-ratio: 1.4; border-radius: 16px; background: var(--surface-2); font-size: 40px;
  display: grid; place-items: center; box-shadow: var(--shadow-sm);
  transition: transform .1s var(--spring), background .2s, box-shadow .2s;
}
.odd-tile:active { transform: scale(.95); }
.odd-tile.ok  { background: var(--green); box-shadow: 0 8px 20px rgba(52,199,89,.35); }
.odd-tile.bad { background: var(--red); animation: shake .3s; }
.odd-tile.dim { opacity: .4; }

/* «Шифр» — легенда символ→цифра чипами */
.code-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }
.code-chip { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-size: 20px; font-weight: 700; }
.q.code-q { font-size: 40px; }

/* ============================================================ ЧЕКАП / ПРОФИЛЬ */
.avatar { cursor: pointer; }
.ck-badge { display: inline-block; font-size: 12px; font-weight: 700; color: var(--teal);
  background: rgba(48,193,182,.14); padding: 6px 14px; border-radius: 999px; margin-bottom: 14px; }
.ck-instr { font-size: 15px; color: var(--text-2); margin: -6px 0 18px; }
.ck-dots { display: flex; justify-content: center; gap: 7px; margin-bottom: 22px; }
.ck-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--bg-2); transition: all .2s; }
.ck-dots span.done { background: var(--teal); }
.ck-dots span.cur { background: var(--teal); transform: scale(1.5); }
.ck-radar { display: grid; place-items: center; padding: 10px 6px; }
.ck-pro { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
  padding: 16px; text-align: left; margin-top: 4px; }
.ck-line { font-size: 14.5px; line-height: 1.5; }
.ach-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.ach-chip { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-sm);
  padding: 10px 13px; font-size: 13px; font-weight: 600; }

/* ============================================================ ДУЭЛИ */
.btn-duel { background: linear-gradient(135deg, #ff7a59, #ff3b7f); color: #fff; box-shadow: 0 8px 20px rgba(255,60,120,.28); }
.duel-invite { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
  padding: 18px; font-size: 15px; line-height: 1.5; color: var(--text-2); margin-bottom: 22px; }
.duel-verdict { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 18px; }
.duel-vs { display: flex; align-items: center; justify-content: center; gap: 20px; }
.duel-side { text-align: center; }
.ds-v { font-size: 44px; font-weight: 800; letter-spacing: -.03em; }
.ds-l { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.duel-mid { font-size: 30px; font-weight: 700; color: var(--muted); }

/* ============================================================ РЕЙТИНГ / ЛИГА */
.lb-me { margin: 4px 0 14px; text-align: center; font-size: 15px; color: var(--text-2); }
.lb-me b { color: var(--text); font-size: 17px; }
.lb-list { display: flex; flex-direction: column; gap: 6px; }
.lb-row { display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow-sm); }
.lb-row.me { background: linear-gradient(135deg, #eaf3ff, #f3ecff); box-shadow: 0 4px 14px rgba(0,122,255,.14); }
.lb-row.promo { border-left: 3px solid var(--green); }
.lb-row.releg { border-left: 3px solid var(--red); }
.lb-rank { width: 30px; text-align: center; font-weight: 800; font-size: 16px; color: var(--text-2); }
.lb-rank.top { font-size: 20px; }
.lb-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-you { font-size: 11px; font-weight: 700; color: var(--accent); background: rgba(0,122,255,.12); padding: 2px 7px; border-radius: 999px; }
.lb-elo { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
.league-legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.zdot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.zdot.promo { background: var(--green); } .zdot.releg { background: var(--red); }

/* ---------- лоадер / ошибка ---------- */
.loader { min-height: 90vh; display: grid; place-items: center; }
.spinner { width: 40px; height: 40px; border-radius: 50%;
           border: 4px solid var(--hairline); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.err { text-align: center; padding-top: 30vh; color: var(--text-2); }
.err .em { font-size: 44px; }
