/* style.css — «Самоцветы» design tokens + screen styles (ported from the handoff). */

:root {
  --bg1: oklch(0.97 0.018 72);
  --bg2: oklch(0.93 0.03 58);
  --ink: oklch(0.36 0.035 50);
  --muted: oklch(0.58 0.03 55);
  --board1: oklch(0.88 0.035 70);
  --board2: oklch(0.83 0.045 58);
  --accent: #ef7a52;
  --accent-hi: color-mix(in oklab, var(--accent), white 16%);
  --accent-lo: color-mix(in oklab, var(--accent), black 24%);
}

* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #efe7df;
  font-family: 'Nunito', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
input { user-select: text; -webkit-user-select: text; }
button { -webkit-appearance: none; font-family: inherit; }

/* phone-shaped column, fills the viewport (no device bezel, per the handoff) */
.app {
  position: relative;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  height: 100dvh;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
}
#root { height: 100%; }

/* ── keyframes (verbatim from the prototype) ─────────────────────────────── */
@keyframes spark {
  from { transform: translate(-50%, -50%); opacity: 1; }
  to   { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2); opacity: 0; }
}
@keyframes selPulse {
  0%, 100% { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent); }
  50%      { box-shadow: 0 0 0 3px #fff, 0 0 0 7px var(--accent), 0 0 14px var(--accent); }
}
@keyframes flashPop {
  0%   { transform: scale(0.4) translateY(8px); opacity: 0; }
  25%  { transform: scale(1.12) translateY(0); opacity: 1; }
  70%  { transform: scale(1) translateY(0); opacity: 1; }
  100% { transform: scale(0.9) translateY(-24px); opacity: 0; }
}

/* ── shared big button ───────────────────────────────────────────────────── */
.btn-big {
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 21px;
  border: none; border-radius: 18px; padding: 16px 22px; width: 100%;
  cursor: pointer; transition: transform .12s, filter .12s;
}
.btn-big:disabled { opacity: .45; cursor: not-allowed; }
.btn-big.primary {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent)); color: #fff;
  box-shadow: 0 6px 0 var(--accent-lo), 0 10px 18px rgba(200,90,60,0.3);
}
.btn-big.ghost {
  background: rgba(255,255,255,0.7); color: var(--ink);
  box-shadow: 0 3px 0 rgba(140,90,50,0.12);
}
.btn-big:active:not(:disabled) { transform: translateY(3px); }

/* ── 1. Welcome ──────────────────────────────────────────────────────────── */
.welcome-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 30px;
  padding: 40px 28px 28px; height: 100%; justify-content: center;
}
.title { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 42px; color: var(--ink); margin: 0; line-height: 1; }
.subtitle { font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 16px; color: var(--muted); margin: 6px 0 0; letter-spacing: 0.5px; }
.field-label { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 14px; color: var(--ink); }
.input {
  font-family: 'Fredoka', sans-serif; font-weight: 500; font-size: 22px; color: var(--ink);
  background: rgba(255,255,255,0.85); border: 2px solid rgba(140,90,50,0.14); border-radius: 16px;
  padding: 14px 16px; outline: none; width: 100%;
}
.recent-chip {
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 14px; color: var(--muted);
  background: rgba(255,255,255,0.6); border: 1px solid rgba(140,90,50,0.14); border-radius: 999px;
  padding: 7px 14px; cursor: pointer;
}
.footnote { font-family: 'Nunito', sans-serif; font-size: 12.5px; line-height: 1.5; color: var(--muted); text-align: center; margin: 0; }
.sound-toggle {
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 13px; color: var(--muted);
  background: rgba(255,255,255,0.6); border: 1px solid rgba(140,90,50,0.14); border-radius: 999px;
  padding: 6px 14px; cursor: pointer;
}

/* ── 2. Mode select ──────────────────────────────────────────────────────── */
.mode-wrap { display: flex; flex-direction: column; padding: 46px 20px 22px; height: 100%; overflow-y: auto; }
.greet { font-family: 'Nunito', sans-serif; font-size: 15px; font-weight: 700; color: var(--muted); }
.greet b { color: var(--ink); }
.h2 { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 32px; color: var(--ink); margin: 2px 0 18px; line-height: 1; }
.section-label { font-family: 'Nunito', sans-serif; font-size: 12px; font-weight: 800; letter-spacing: 1.4px; color: var(--muted); margin: 18px 0 10px; }
.mech-card {
  display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer; width: 100%;
  background: rgba(255,255,255,0.55); border: 2px solid transparent; border-radius: 20px; padding: 14px 16px;
  transition: border-color .15s, background .15s;
}
.mech-card.on { background: rgba(255,255,255,0.95); border-color: var(--accent); box-shadow: 0 6px 16px rgba(200,90,60,0.14); }
.mech-mini { width: 46px; height: 46px; border-radius: 12px; background: var(--board1); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; padding: 3px; flex-shrink: 0; }
.mech-text { flex: 1; text-align: left; }
.mech-title { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 19px; color: var(--ink); }
.mech-sub { font-family: 'Nunito', sans-serif; font-size: 12.5px; line-height: 1.35; color: var(--muted); margin-top: 2px; }
.mech-board { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.radio { width: 22px; height: 22px; border-radius: 999px; border: 2px solid rgba(140,90,50,0.25); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.radio.on { border-color: var(--accent); }
.radio-dot { width: 11px; height: 11px; border-radius: 999px; background: var(--accent); }
.seg { display: flex; gap: 8px; background: rgba(255,255,255,0.45); border-radius: 16px; padding: 5px; }
.seg-btn { flex: 1; font-family: 'Fredoka', sans-serif; font-weight: 500; font-size: 15px; color: var(--muted); background: transparent; border: none; border-radius: 12px; padding: 11px 6px; cursor: pointer; transition: all .15s; }
.seg-btn.on { background: #fff; color: var(--ink); box-shadow: 0 3px 8px rgba(140,90,50,0.12); }
.mode-actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 16px; }

/* ── 3. Results + leaderboard ────────────────────────────────────────────── */
.result-wrap { display: flex; flex-direction: column; padding: 44px 18px 22px; height: 100%; overflow-y: auto; }
.result-card { background: linear-gradient(165deg, var(--accent-hi), var(--accent)); border-radius: 24px; padding: 22px 20px 20px; text-align: center; color: #fff; box-shadow: 0 12px 26px rgba(200,90,60,0.28); }
.result-top { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 14px; letter-spacing: 1px; opacity: 0.9; }
.result-score { font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 56px; line-height: 1; margin-top: 4px; text-shadow: 0 2px 0 rgba(150,50,30,0.3); }
.result-score-label { font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 14px; opacity: 0.9; }
.stat-row { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 16px; background: rgba(255,255,255,0.18); border-radius: 14px; padding: 10px 6px; }
.stat { flex: 1; }
.stat-n { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 20px; }
.stat-l { font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 11px; opacity: 0.85; margin-top: 1px; }
.stat-sep { width: 1px; height: 28px; background: rgba(255,255,255,0.3); }
.rank-badge { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 13px; margin-top: 14px; background: rgba(255,255,255,0.22); border-radius: 999px; padding: 7px 12px; display: inline-block; }
.lb-label { font-family: 'Nunito', sans-serif; font-size: 12px; font-weight: 800; letter-spacing: 1.4px; color: var(--muted); margin: 20px 0 10px; }
.tab-row { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 12.5px; color: var(--muted); background: rgba(255,255,255,0.5); border: none; border-radius: 10px; padding: 8px 4px; cursor: pointer; }
.tab.on { background: var(--ink); color: #fff; }
.lb-list { display: flex; flex-direction: column; gap: 5px; }
.lb-empty { font-family: 'Nunito', sans-serif; font-size: 13px; color: var(--muted); text-align: center; padding: 16px; }
.lb-row { display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,0.6); border-radius: 12px; padding: 11px 14px; }
.lb-row.me { background: rgba(255,255,255,1); box-shadow: 0 0 0 2px var(--accent); }
.lb-rank { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 16px; color: var(--muted); width: 20px; text-align: center; }
.lb-rank.gold { color: var(--accent); }
.lb-name { flex: 1; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 15px; color: var(--ink); }
.lb-score { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 17px; color: var(--ink); }
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ── 4. Game board ───────────────────────────────────────────────────────── */
.game-wrap { display: flex; flex-direction: column; height: 100%; padding: 50px 18px 0; }
.hud { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 4px; }
.score-label { font-family: 'Nunito', sans-serif; font-size: 12px; font-weight: 800; letter-spacing: 1.5px; color: var(--muted); }
.score { font-family: 'Fredoka', sans-serif; font-size: 40px; font-weight: 600; line-height: 1; color: var(--ink); }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.timer { font-family: 'Fredoka', sans-serif; font-size: 26px; font-weight: 600; display: flex; align-items: center; gap: 5px; color: var(--ink); }
.timer.low { color: #e8425f; }
.timer-icon { font-size: 18px; }
.end-btn { font-family: 'Nunito', sans-serif; font-size: 13px; font-weight: 800; color: var(--muted); background: rgba(255,255,255,0.6); border: 1px solid rgba(140,90,50,0.15); border-radius: 999px; padding: 5px 13px; cursor: pointer; }
.chips { display: flex; gap: 7px; margin-top: 12px; flex-wrap: wrap; }
.chip { font-family: 'Nunito', sans-serif; font-size: 12.5px; font-weight: 800; color: var(--muted); background: rgba(255,255,255,0.55); border-radius: 999px; padding: 5px 11px; }
.chip.dim { opacity: 0.45; }
.board-outer { margin-top: 16px; display: flex; flex-direction: column; align-items: center; }
.board { position: relative; border-radius: 22px; overflow: hidden; background: linear-gradient(160deg, var(--board1), var(--board2)); box-shadow: inset 0 2px 10px rgba(120,70,30,0.18), 0 10px 26px rgba(120,70,30,0.16); }
.board.mine { background: linear-gradient(160deg, #3a322b, #221c17); box-shadow: inset 0 2px 14px rgba(0,0,0,0.55), 0 10px 26px rgba(0,0,0,0.3); }
.cell-sub { position: absolute; }
.sel-ring { position: absolute; box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent); z-index: 4; pointer-events: none; animation: selPulse 1s ease-in-out infinite; }
.gem-cell { position: absolute; left: 0; top: 0; display: flex; align-items: center; justify-content: center; transition: transform .28s cubic-bezier(.5,0,.3,1); z-index: 2; cursor: pointer; touch-action: none; }
.gem-cell.held { z-index: 9; filter: drop-shadow(0 6px 10px rgba(60,30,10,.35)); }
.flash { position: absolute; left: 0; right: 0; top: 38%; text-align: center; z-index: 12; pointer-events: none; animation: flashPop .65s ease-out forwards; }
.flash-gain { font-family: 'Fredoka', sans-serif; font-size: 46px; font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(120,40,60,.55), 0 0 18px rgba(255,255,255,.6); }
.flash-combo { font-family: 'Fredoka', sans-serif; font-size: 22px; font-weight: 600; color: #fff5d6; text-shadow: 0 2px 6px rgba(120,40,60,.5); margin-top: 2px; }
.pd-bar-track { margin-top: 14px; width: 100%; max-width: 336px; height: 28px; border-radius: 999px; position: relative; background: rgba(255,255,255,0.55); overflow: hidden; display: flex; align-items: center; }
.pd-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; transition: width .05s linear, background .2s; }
.pd-bar-label { position: relative; width: 100%; text-align: center; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 13px; color: var(--ink); z-index: 1; }
.hint { margin-top: auto; margin-bottom: 14px; font-family: 'Nunito', sans-serif; font-size: 13px; line-height: 1.4; color: var(--muted); text-align: center; padding: 0 6px; }

/* ── 5. «2048» tiles (glossy gem faces + number overlay) ─────────────────── */
.mode-note { font-family: 'Nunito', sans-serif; font-size: 13px; line-height: 1.4; color: var(--muted); background: rgba(255,255,255,0.45); border-radius: 14px; padding: 12px 14px; margin-top: 12px; }
.tile { position: absolute; left: 0; top: 0; display: flex; align-items: center; justify-content: center; transition: transform .12s cubic-bezier(.5,0,.3,1); z-index: 2; touch-action: none; }
.tile-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 3; pointer-events: none; font-family: 'Fredoka', sans-serif; font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(120,40,60,.5), 0 0 10px rgba(255,255,255,.45); }
@keyframes tileSpawn { 0% { transform: scale(.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes tilePop   { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }
.tile-face.spawn  { animation: tileSpawn .18s ease-out; }
.tile-face.merged { animation: tilePop .2s ease; }

/* ── 5b. «Память» cards (gem faces, 3D flip) ──────────────────────────────── */
/* Grani pereklyuchayutsya po opacity (ne backface-visibility): vlozhennyy gem ot
   createGemVisual imeet sobstvennyy transform i «prosvechivaet» skvoz' obratnuyu
   storonu. Opacity menyaetsya s zaderzhkoy .17s — rovno na seredine flipa (rebrom). */
.mem-board { display: grid; gap: 8px; justify-content: center; perspective: 800px; padding: 4px; }
.card { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.card-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .34s cubic-bezier(.4,0,.2,1); }
.card.up .card-inner, .card.matched .card-inner { transform: rotateY(180deg); }
.card-back, .card-face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; border-radius: 30%; transition: opacity 0s linear .17s; }
.card-back { opacity: 1; background: linear-gradient(160deg, var(--board1), var(--board2)); box-shadow: inset 0 2px 8px rgba(120,70,30,0.18), 0 4px 10px rgba(120,70,30,0.14); font-size: 24px; color: rgba(255,255,255,0.55); text-shadow: 0 1px 2px rgba(120,70,30,0.3); }
.card-face { opacity: 0; transform: rotateY(180deg); }
.card.up .card-back, .card.matched .card-back { opacity: 0; }
.card.up .card-face, .card.matched .card-face { opacity: 1; }
.card.matched { cursor: default; }
.card.matched .card-face { animation: cardMatch .3s ease; }
.card.matched .card-inner { box-shadow: 0 0 0 2px var(--accent), 0 6px 14px rgba(200,90,60,0.22); border-radius: 30%; }
@keyframes cardMatch { 0% { transform: rotateY(180deg) scale(1); } 50% { transform: rotateY(180deg) scale(1.16); } 100% { transform: rotateY(180deg) scale(1); } }

/* ── 6. co-op weekly goal + player level ─────────────────────────────────── */
.goal-card { width: 100%; background: rgba(255,255,255,0.6); border: 1px solid rgba(140,90,50,0.12); border-radius: 18px; padding: 14px 16px; display: flex; flex-direction: column; gap: 9px; }
.goal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.goal-title { font-family: 'Nunito', sans-serif; font-size: 12px; font-weight: 800; letter-spacing: 1.2px; color: var(--muted); }
.goal-amount { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 16px; color: var(--ink); }
.goal-bar { width: 100%; height: 14px; border-radius: 999px; background: rgba(140,90,50,0.12); overflow: hidden; }
.goal-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent-hi), var(--accent)); transition: width .5s cubic-bezier(.4,0,.2,1); }
.goal-fill.done { background: linear-gradient(90deg, oklch(0.78 0.16 145), oklch(0.66 0.17 150)); }
.goal-note { font-family: 'Nunito', sans-serif; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.goal-note.done { color: oklch(0.55 0.15 150); }
.goal-contribs { display: flex; flex-wrap: wrap; gap: 6px; }
.goal-contrib { font-family: 'Nunito', sans-serif; font-size: 12px; font-weight: 800; color: var(--muted); background: rgba(255,255,255,0.7); border-radius: 999px; padding: 4px 10px; }
.goal-contrib.me { color: #fff; background: var(--accent); }

.level-chip { width: 100%; background: rgba(255,255,255,0.6); border: 1px solid rgba(140,90,50,0.12); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 7px; }
.level-row { display: flex; align-items: center; gap: 8px; }
.level-n { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 16px; color: var(--accent-lo); }
.level-title { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 15px; color: var(--ink); flex: 1; }
.level-up-tag { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 11px; color: #fff; background: var(--accent); border-radius: 999px; padding: 3px 9px; }
.level-mini { width: 100%; height: 8px; border-radius: 999px; background: rgba(140,90,50,0.12); overflow: hidden; }
.level-mini-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent-hi), var(--accent)); transition: width .5s cubic-bezier(.4,0,.2,1); }
.level-sub { font-family: 'Nunito', sans-serif; font-size: 12px; font-weight: 700; color: var(--muted); }
.level-chip.level-up { animation: levelPop .5s ease; box-shadow: 0 0 0 2px var(--accent); }
@keyframes levelPop { 0% { transform: scale(0.92); } 45% { transform: scale(1.05); } 100% { transform: scale(1); } }
