:root {
  --bg1: #16123a;
  --bg2: #0b1024;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-hover: rgba(255, 255, 255, 0.11);
  --line: rgba(255, 255, 255, 0.14);
  --glass: rgba(255, 255, 255, 0.32);
  --text: #eef0ff;
  --muted: #a9abd0;
  --accent: #a78bfa;
  --accent2: #22d3ee;
  --good: #86efac;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  min-height: 100vh;
  background-color: var(--bg2);
  background-image:
    radial-gradient(1100px 560px at 50% -12%, #2d2470 0%, transparent 62%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 18px; letter-spacing: -0.01em; color: var(--text); text-decoration: none; border-radius: 10px; }
.brand .back { color: var(--muted); margin-left: -4px; }
.brand:hover .back { color: var(--text); }
.logo { display: block; border-radius: 8px; }
.hud { display: flex; gap: 6px; }
.pill {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.pill b { color: var(--text); font-variant-numeric: tabular-nums; }
.icons { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: opacity 0.2s, background 0.2s;
}
.icon-btn:hover { background: var(--panel-hover); }
.icon-btn[aria-pressed="false"] { opacity: 0.45; }

@media (max-width: 420px) {
  .brand-name { display: none; }
}

/* ---------- Board ---------- */
.game {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.board {
  --ball: 40px;
  --gap: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--ball) * 0.7);
  padding: 34px 0 20px;
  min-height: 300px;
}
.row { display: flex; gap: var(--gap); justify-content: center; align-items: flex-end; }

.tube {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: calc(var(--ball) + 14px);
  height: calc(var(--ball) * 4 + 12px + 30px);
  padding: 0 0 5px;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02) 45%, rgba(255,255,255,0.09));
  border: 3px solid var(--glass);
  border-top: 0;
  border-radius: 4px 4px calc(var(--ball) * 0.6 + 6px) calc(var(--ball) * 0.6 + 6px);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.2s, box-shadow 0.2s;
}
.tube::before {
  content: "";
  position: absolute;
  top: -3px; left: -7px; right: -7px;
  height: 6px;
  border-radius: 4px;
  background: var(--glass);
  transition: background 0.2s;
}
.tube:focus-visible { outline: 2px solid var(--accent2); outline-offset: 5px; }
.tube.selected {
  transform: translateY(-16px);
  border-color: var(--accent);
  box-shadow: 0 12px 26px -10px rgba(167, 139, 250, 0.75);
}
.tube.selected::before { background: var(--accent); }
.tube.done { border-color: rgba(134, 239, 172, 0.7); }
.tube.done::before { background: rgba(134, 239, 172, 0.85); }
.tube.pop { animation: pop 0.42s ease; }
.tube.shake { animation: shake 0.32s ease; }
.tube.hint-from { border-color: var(--accent2); animation: glow-from 0.8s ease-in-out 3; }
.tube.hint-to { border-color: #fde047; animation: glow-to 0.8s ease-in-out 3; }

@keyframes pop { 40% { transform: scale(1.07); } }
@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
@keyframes glow-from { 50% { box-shadow: 0 0 0 6px rgba(34, 211, 238, 0.35); transform: translateY(-8px); } }
@keyframes glow-to { 50% { box-shadow: 0 0 0 6px rgba(253, 224, 71, 0.35); } }

.ball {
  flex: none;
  width: var(--ball);
  height: var(--ball);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 34% 28%, rgba(255,255,255,0.85) 0 8%, rgba(255,255,255,0.22) 22%, transparent 42%),
    var(--c);
  box-shadow: inset 0 -5px 9px rgba(0, 0, 0, 0.28), 0 2px 4px rgba(0, 0, 0, 0.25);
  color: rgba(0, 0, 0, 0.55);
  font-size: calc(var(--ball) * 0.42);
  font-weight: 700;
  line-height: 1;
}
.ball.fly { position: fixed; margin: 0; z-index: 50; pointer-events: none; }

/* ---------- Controls ---------- */
.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 460px;
  margin: 0 auto;
  padding: 4px 0 16px;
}
.ctrl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}
.ctrl:hover { background: var(--panel-hover); }
.ctrl:active { transform: scale(0.96); }

/* ---------- Ads ---------- */
.ad-slot { max-width: 728px; margin: 8px auto; padding: 0 16px; min-height: 90px; }
.ad-slot:empty { display: none; }

/* ---------- Article ---------- */
.info { max-width: 720px; margin: 28px auto 0; padding: 0 16px; color: var(--muted); line-height: 1.65; font-size: 15px; }
.info h1 { color: var(--text); font-size: 24px; line-height: 1.25; margin: 0 0 10px; }
.info h2 { color: var(--text); font-size: 19px; margin: 28px 0 8px; }
.info h3 { color: var(--text); font-size: 16px; margin: 18px 0 4px; }
.info strong { color: var(--text); }
.info kbd {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
}
.foot { max-width: 720px; margin: 36px auto 0; padding: 16px 16px 28px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.foot p { margin: 0 0 8px; }
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--text); }
.foot-links { display: flex; flex-wrap: wrap; gap: 14px; }

/* ---------- Modal / toast / confetti ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(5, 6, 20, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.card {
  width: min(320px, calc(100vw - 32px));
  padding: 26px 22px 22px;
  text-align: center;
  background: #1d1946;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
  animation: rise 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card h2 { margin: 6px 0 4px; font-size: 22px; }
.card p { margin: 0 0 18px; color: var(--muted); }
.trophy { font-size: 40px; color: #fde047; line-height: 1; text-shadow: 0 4px 18px rgba(253, 224, 71, 0.5); }
.primary {
  width: 100%;
  padding: 13px 20px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #a78bfa, #22d3ee);
  color: #0b1024;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.primary:active { transform: scale(0.98); }
@keyframes rise { from { transform: translateY(16px) scale(0.96); opacity: 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #262058;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 65; }

@media (prefers-reduced-motion: reduce) {
  .tube, .toast, .icon-btn { transition: none; }
  .tube.pop, .tube.shake, .card { animation: none; }
}
.more { max-width: 720px; margin: 28px auto 0; padding: 0 16px; }
.more h2 { font-size: 17px; margin: 0 0 10px; }
.more-list { display: flex; flex-wrap: wrap; gap: 8px; }
.more-list a { color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.more-list a:hover { background: var(--panel-hover); }
