:root {
  --bg:               #f2f2f7;
  --accent:           #f0589e;
  --accent-light:     rgba(240, 88, 158, 0.07);
  --accent-medium:    rgba(240, 88, 158, 0.16);
  --glass:            rgba(255, 255, 255, 0.75);
  --glass-border:     rgba(255, 255, 255, 0.90);
  --cell-bg:          #ffffff;
  --cell-given-bg:    #ffffff;
  --cell-given-color: #505050;
  --cell-user-color:  #1a1a1a;
  --cell-error-bg:    #fff0f3;
  --cell-error-color: #e02020;
  --box-separator:    #8c8c8c;
  --cell-separator:   #dedede;
  --text-primary:     #1a1a1a;
  --text-muted:       #9a9a9a;
  --life-color:       #e05252;
  --hint-color:       #d97706;
}

[data-theme="dark"] {
  --bg:               #1c1c1e;
  --accent:           #f0589e;
  --accent-light:     rgba(240, 88, 158, 0.10);
  --accent-medium:    rgba(240, 88, 158, 0.22);
  --glass:            rgba(255, 255, 255, 0.07);
  --glass-border:     rgba(255, 255, 255, 0.11);
  --cell-bg:          #2c2c2e;
  --cell-given-bg:    #242426;
  --cell-given-color: #f0f0f0;
  --cell-user-color:  #f0f0f0;
  --cell-error-bg:    #3d1520;
  --cell-error-color: #ff6080;
  --box-separator:    rgba(255, 255, 255, 0.18);
  --cell-separator:   rgba(255, 255, 255, 0.07);
  --text-primary:     #f0f0f0;
  --text-muted:       #6e6e72;
  --life-color:       #e05252;
  --hint-color:       #fbbf24;
}

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

html {
  height: -webkit-fill-available;
  height: 100%;
}

body {
  height: -webkit-fill-available;
  height: 100%;
  min-height: -webkit-fill-available;
  min-height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  font-family: 'Inter', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 430px;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.25s;
}

/* ─── LAYOUT ─── */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
}

/* ─── HEADER ─── */
.header {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0 6px;
  flex-shrink: 0;
}

.btn-icon {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.15s;
}
.btn-icon:active { background: var(--accent-light); }

.header-center {
  text-align: center;
}

.header-date {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.header-timer {
  font-size: 20px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ─── STATS ROW ─── */
.stats-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 4px 2px 8px;
  flex-shrink: 0;
}

.hints-display { justify-content: flex-end; }

.lives { display: flex; gap: 6px; align-items: center; }
.life-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--life-color);
  transition: background 0.2s;
}
.life-dot.lost { background: var(--cell-separator); }

.difficulty-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hints-display { display: flex; gap: 6px; align-items: center; }
.hint-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--hint-color);
  transition: background 0.2s;
}
.hint-dot.used { background: var(--cell-separator); }

/* ─── GRID WRAP (glass panel) ─── */
.grid-wrap {
  flex-shrink: 0;
  width: min(calc(100vw - 32px), calc(var(--vh, 1vh) * 100 - 210px), 400px);
  margin: 0 auto;
  position: relative;
  padding: 0;
  border-radius: 20px;
  background:
    radial-gradient(ellipse at 28% 22%, rgba(255,255,255,0.28) 0%, transparent 55%),
    linear-gradient(140deg, rgba(228,222,213,0.85) 0%, rgba(210,203,193,0.95) 100%);
  box-shadow: 0 6px 24px rgba(0,0,0,0.09), 0 1px 4px rgba(0,0,0,0.06);
}

/* Glass border shimmer */
.grid-wrap::before {
  content: "";
  border-radius: 20px;
  pointer-events: none;
  background: linear-gradient(160deg, rgba(255,255,255,0.65) 0%, rgba(255,255,255,0) 45%, rgba(255,255,255,0.18) 100%);
  padding: 1px;
  position: absolute;
  inset: 0;
  -webkit-mask-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);
  mask-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);
  -webkit-mask-clip: content-box, border-box;
  mask-clip: content-box, border-box;
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

/* ─── GRID ─── */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  aspect-ratio: 1;
  gap: 2px;
  padding: 2px;
  background: var(--box-separator);
  border-radius: 20px;
}

.box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0;
  background: var(--cell-bg);
}

.box .cell {
  border-right: 1px solid var(--cell-separator);
  border-bottom: 1px solid var(--cell-separator);
}
.box .cell:nth-child(3n)    { border-right: none; }
.box .cell:nth-child(7),
.box .cell:nth-child(8),
.box .cell:nth-child(9)     { border-bottom: none; }

/* Скругление угловых боксов (без overflow:hidden — не обрезает анимацию) */
.box:nth-child(1) { border-top-left-radius:     18px; }
.box:nth-child(3) { border-top-right-radius:    18px; }
.box:nth-child(7) { border-bottom-left-radius:  18px; }
.box:nth-child(9) { border-bottom-right-radius: 18px; }

/* Скругление угловых ячеек — чтобы их фон тоже был rounded */
.box:nth-child(1) .cell:nth-child(1) { border-top-left-radius:     16px; }
.box:nth-child(3) .cell:nth-child(3) { border-top-right-radius:    16px; }
.box:nth-child(7) .cell:nth-child(7) { border-bottom-left-radius:  16px; }
.box:nth-child(9) .cell:nth-child(9) { border-bottom-right-radius: 16px; }

.cell {
  background: var(--cell-bg);
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(14px, 5.6vw, 26px);
  font-weight: 600;
  color: var(--cell-user-color);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
  position: relative;
  overflow: hidden;
}

.cell-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease;
}

.cell.given {
  background: var(--cell-given-bg);
  color: var(--cell-given-color);
  cursor: default;
}

.cell.highlighted    { background: var(--accent-light); }
.cell.highlighted-num { background: var(--accent-medium); }

@keyframes cell-popin {
  0%   { opacity: 0; transform: scale(0.7);  }
  33%  { opacity: 1; transform: scale(1.3);  }
  66%  { transform: scale(0.8);  }
  100% { transform: scale(1);    }
}
.cell.popin,
.cell.ripple,
.cell.bounce { background: var(--cell-bg) !important; }

.cell.popin .cell-inner {
  animation: cell-popin .3s ease-out;
  background: var(--accent-medium);
}

@keyframes cell-bounce {
  0%   { transform: scale(1);   }
  30%  { transform: scale(1.3); }
  65%  { transform: scale(0.8); }
  100% { transform: scale(1);   }
}
.cell.bounce .cell-inner {
  animation: cell-bounce .5s ease-out;
  background: var(--accent-light);
}

@keyframes cell-ripple {
  0%   { transform: scale(1);    }
  30%  { transform: scale(1.3);  }
  65%  { transform: scale(0.8);  }
  100% { transform: scale(1);    }
}
.cell.ripple .cell-inner {
  animation: cell-ripple .5s ease-out;
  background: var(--accent-medium);
}

.cell.selected {
  background: var(--accent-light) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell.error {
  background: var(--cell-error-bg) !important;
  color: var(--cell-error-color) !important;
}

/* ─── SPACER ─── */
.spacer { flex: 1; }

/* ─── NUMPAD ─── */
.numpad {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 14px 0 4px;
}

.numpad-row {
  display: flex;
  gap: 7px;
  justify-content: center;
}

.num-btn {
  width: clamp(48px, 13.5vw, 62px);
  height: clamp(48px, 13.5vw, 62px);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  background: var(--glass);
  font-family: 'Inter', sans-serif;
  font-size: clamp(17px, 5vw, 26px);
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, border-color 0.1s, color 0.1s, transform 0.08s;
  position: relative;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

/* Glass border shimmer */
.num-btn::before {
  content: "";
  border-radius: 14px;
  pointer-events: none;
  background: linear-gradient(rgba(255,255,255,0.55) 0%, rgba(255,255,255,0) 55%);
  padding: 1px;
  position: absolute;
  inset: 0;
  -webkit-mask-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);
  mask-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);
  -webkit-mask-clip: content-box, border-box;
  mask-clip: content-box, border-box;
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.num-btn:active { transform: scale(0.92); }

.num-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.num-btn.done {
  opacity: 0.25;
  cursor: default;
}

.num-btn.notes-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ─── NOTES GRID ─── */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
}

.note-digit {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 500;
  color: var(--accent);
  line-height: 1;
}
.note-digit.dim {
  opacity: 0.35;
}

/* ─── CONTROLS ─── */
.controls {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 8px 20px;
}

.ctrl-btn {
  width: 52px;
  height: 52px;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  background: var(--glass);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.1s, transform 0.08s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  position: relative;
}

.ctrl-btn::before {
  content: "";
  border-radius: 50%;
  pointer-events: none;
  background: linear-gradient(rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 55%);
  padding: 1px;
  position: absolute;
  inset: 0;
  -webkit-mask-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);
  mask-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);
  -webkit-mask-clip: content-box, border-box;
  mask-clip: content-box, border-box;
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.ctrl-btn:active { transform: scale(0.91); }

/* ─── CONFETTI (canvas, см. showConfetti в JS) ─── */

/* ─── RESULT OVERLAY ─── */
@property --g {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 80%;
}

.screen.result-shown {
  filter: blur(3px);
  transition: filter 0.3s ease;
}

.result-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  --g: 80%;
  background: linear-gradient(to bottom,
    transparent                    var(--g),
    rgba(255,255,255,0.1)          calc(var(--g) + 3%),
    rgba(255,255,255,0.4)          calc(var(--g) + 7%),
    rgba(255,255,255,0.75)         calc(var(--g) + 10%),
    #fff                           calc(var(--g) + 20%)
  );
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: --g 1s cubic-bezier(0.32, 0.72, 0, 1), opacity 1s ease;
  padding: 0 16px 56px;
}
.result-overlay.visible {
  --g: 0%;
  opacity: 1;
  pointer-events: all;
}

.result-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* Каждый элемент карточки — скрыт и сдвинут вниз */
.result-date,
.result-time,
.result-perfect,
.result-difficulty,
.result-stats,
.result-percentile {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Появление со stagger */
.result-overlay.visible .result-date       { opacity: 1; transform: none; transition-delay: 1.0s; }
.result-overlay.visible .result-time       { opacity: 1; transform: none; transition-delay: 1.2s; }
.result-overlay.visible .result-perfect    { opacity: 1; transform: none; transition-delay: 1.4s; }
.result-overlay.visible .result-difficulty { opacity: 1; transform: none; transition-delay: 1.6s; }
.result-overlay.visible .result-stats      { opacity: 1; transform: none; transition-delay: 1.8s; }
.result-overlay.visible .result-percentile { opacity: 1; transform: none; transition-delay: 2.0s; }
.result-overlay.visible .result-actions    { opacity: 1; transform: none; transition-delay: 2.2s; }

.result-actions {
  position: absolute;
  bottom: 40px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.32, 0.72, 0, 1);
}

.result-btn-share {
  flex: 1;
  height: 52px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
  transition: transform 0.12s, opacity 0.12s;
}
.result-btn-share:active { opacity: 0.85; transform: scale(0.97); }

.result-btn-next {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  background: transparent;
  border: 1.5px solid var(--cell-separator);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s, background 0.12s;
}
.result-btn-next:active { background: var(--accent-light); transform: scale(0.93); }

.result-card::before {
  display: none;
}

.result-date {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.result-time {
  font-size: 54px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: 10px;
}

.result-perfect {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  min-height: 16px;
  margin-bottom: 4px;
}

.result-difficulty {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 24px;
}

.result-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px 8px;
  padding-top: 20px;
  margin-bottom: 20px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.stat-label {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  line-height: 1.2;
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.result-percentile {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ─── HOME OVERLAY (поверх игры, едет сверху вниз) ─── */
.home-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  --g: 0%;
  background: linear-gradient(to bottom,
    transparent                    var(--g),
    rgba(255,255,255,0.1)          calc(var(--g) + 3%),
    rgba(255,255,255,0.4)          calc(var(--g) + 7%),
    rgba(255,255,255,0.75)         calc(var(--g) + 10%),
    #fff                           calc(var(--g) + 20%)
  );
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 16px 56px;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-100%);
  transition: transform 0.55s cubic-bezier(0.32, 0.72, 0, 1), opacity 1s ease, --g 1s cubic-bezier(0.32, 0.72, 0, 1);
}

.home-overlay.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}


.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 400px;
}

/* Stagger-появление */
.home-logo,
.home-date,
.home-streak,
.home-players,
.home-btn-play {
  opacity: 0;
  transition: opacity 0.45s ease;
}

.home-overlay.visible .home-logo     { opacity: 1; transition-delay: 0.45s; }
.home-overlay.visible .home-date     { opacity: 1; transition-delay: 0.6s; }
.home-overlay.visible .home-streak   { opacity: 1; transition-delay: 0.75s; }
.home-overlay.visible .home-players  { opacity: 1; transition-delay: 0.9s; }
.home-overlay.visible .home-btn-play { opacity: 1; transition-delay: 1.05s; }

.home-logo {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 32px;
}

.home-date {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.home-streak {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 16px;
}

.home-streak-num {
  font-size: 54px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.home-streak-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.home-players {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 28px;
}

.home-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34c759;
  flex-shrink: 0;
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.home-players-text {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}

.home-btn-play {
  width: 100%;
  height: 52px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s, opacity 0.12s;
}

.home-btn-play:active {
  transform: scale(0.97);
  opacity: 0.88;
}
