:root {
  --bg:         #0b0b0b;
  --surface:    #141414;
  --border:     #242424;
  --cell-bg:    #1a1a1a;
  --cell-hover: #212121;
  --text:       #f0f0f0;
  --muted:      #464646;
  --score:      #f0aa3a;
  --cell:       52px;
  --gap:        3px;
  --pad:        8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 48px;
}

/* ── Header ─────────────────────────────────────────── */

header {
  width: 100%;
  max-width: 560px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 26px 20px 0;
}

h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
}

.lang-switcher {
  display: flex;
  gap: 1px;
}

.lang-switcher a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  transition: color 0.12s;
}

.lang-switcher a:hover        { color: var(--text); }
.lang-switcher a.active       { color: var(--text); background: var(--surface); }

/* ── Layout ─────────────────────────────────────────── */

main {
  width: 100%;
  max-width: 560px;
  padding: 18px 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* ── Info bar ────────────────────────────────────────── */

.game-info {
  width: 100%;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.info-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 20px;
  border-right: 1px solid var(--border);
  min-width: 72px;
}

.info-block .label {
  font-size: 0.6rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.info-block .val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--score);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.info-block.next-block {
  flex: 1;
  border-right: 1px solid var(--border);
}

#next-balls {
  display: flex;
  gap: 8px;
  align-items: center;
  height: 1.5rem;
}

.mini-ball {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0,0,0,0.55);
}

.mini-ball::after {
  content: '';
  position: absolute;
  top: 10%; left: 15%;
  width: 38%; height: 28%;
  background: rgba(255,255,255,0.42);
  border-radius: 50%;
  transform: rotate(-30deg);
}

#new-game {
  background: var(--text);
  color: var(--bg);
  border: none;
  padding: 0 20px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background 0.12s;
}

#new-game:hover  { background: #d4d4d4; }
#new-game:active { background: #aaaaaa; }

/* ── Grid ────────────────────────────────────────────── */

#grid {
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  gap: var(--gap);
  background: var(--surface);
  padding: var(--pad);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.cell {
  width: var(--cell);
  height: var(--cell);
  background: var(--cell-bg);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s;
}

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

.cell.no-path { animation: no-path 0.38s ease; }

@keyframes no-path {
  0%, 100% { background: var(--cell-bg); }
  45%       { background: #2e1111; }
}

/* ── Ball ────────────────────────────────────────────── */

.ball {
  width: 76%;
  height: 76%;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  box-shadow:
    0 5px 14px rgba(0,0,0,0.6),
    inset 0 -3px 7px rgba(0,0,0,0.3);
  transition: transform 0.1s;
}

/* soft shading layer */
.ball::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%,
    rgba(255,255,255,0.14) 0%,
    transparent 62%);
  pointer-events: none;
}

/* specular spot */
.ball::after {
  content: '';
  position: absolute;
  top: 10%; left: 16%;
  width: 34%; height: 24%;
  background: rgba(255,255,255,0.52);
  border-radius: 50%;
  transform: rotate(-32deg);
  pointer-events: none;
}

.ball:hover { transform: scale(1.08); }

.ball.selected {
  animation: float 0.72s ease-in-out infinite;
  box-shadow:
    0 5px 14px rgba(0,0,0,0.6),
    0 0 0 2px rgba(255,255,255,0.65),
    inset 0 -3px 7px rgba(0,0,0,0.3);
}

@keyframes float {
  0%, 100% { transform: translateY(0)    scale(1);    }
  50%       { transform: translateY(-5px) scale(1.05); }
}

.ball.new { animation: pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* ── Hint ────────────────────────────────────────────── */

.hint {
  color: var(--muted);
  font-size: 0.74rem;
  text-align: center;
}

/* ── Game over ───────────────────────────────────────── */

#game-over {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 0.18s ease;
}

#game-over.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 52px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: modal-in 0.22s ease;
}

@keyframes modal-in {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: none;             opacity: 1; }
}

.modal h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.modal p       { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.modal strong  { display: block; color: var(--score); font-size: 2rem;
                 font-weight: 700; margin: 6px 0; font-variant-numeric: tabular-nums; }

#restart {
  background: var(--text);
  color: var(--bg);
  border: none;
  padding: 12px 32px;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.12s;
}

#restart:hover { background: #d4d4d4; }

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 560px) {
  main { padding: 14px 12px 0; }
  header { padding: 20px 12px 0; }
}

@media (max-width: 480px) {
  :root { --cell: 36px; --gap: 2px; --pad: 5px; }
  h1 { font-size: 1.15rem; }
  .modal { padding: 32px 24px; }

  /* Two-row info bar */
  .game-info { flex-wrap: wrap; }

  /* Row 1: Score + Best */
  .info-block:nth-child(1),
  .info-block:nth-child(2) {
    flex: 1 0 50%;
    min-width: 0;
    border-bottom: 1px solid var(--border);
  }
  .info-block:nth-child(2) { border-right: none; }

  /* Row 2: Next + Button */
  .info-block.next-block {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
  }
}

@media (max-width: 380px) {
  :root { --cell: 31px; }
}
