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

:root {
  --dark:   #07101a;
  --card:   #0d1c2b;
  --rail:   #6b3a1f;
  --felt:   #1a6b3c;
  --accent: #f5c518;
  --red:    #e84040;
  --txt:    #e8eaf0;
  --muted:  #6a85a0;
  --radius: 14px;
  --shadow: 0 12px 48px rgba(0,0,0,.7);
}

html, body {
  height: 100%; overflow: hidden;
  background: var(--dark);
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--txt);
}

.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ── Buttons ── */
.btn {
  border: none; border-radius: 10px;
  font-family: inherit; font-weight: 700;
  font-size: .85rem; letter-spacing: .05em;
  cursor: pointer; padding: 11px 24px;
  transition: transform .15s ease, box-shadow .15s ease, opacity .2s;
  user-select: none; outline: none;
}
.btn:active { transform: translateY(2px) scale(.97) !important; }
.btn:focus-visible { box-shadow: 0 0 0 3px rgba(245,197,24,.55); }
.btn.primary {
  background: linear-gradient(135deg, #f5c518 0%, #d4a000 100%);
  color: #0a0a00;
  box-shadow: 0 4px 18px rgba(245,197,24,.45);
}
.btn.primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(245,197,24,.65); }
.btn.primary:disabled { opacity: .4; cursor: not-allowed; transform: none !important; box-shadow: none; }
.btn.secondary {
  background: rgba(255,255,255,.06);
  color: var(--txt);
  border: 1.5px solid rgba(255,255,255,.12);
}
.btn.secondary:hover { background: rgba(255,255,255,.11); border-color: rgba(255,255,255,.22); transform: translateY(-1px); }
.btn.large { padding: 15px 40px; font-size: 1rem; border-radius: 12px; }
.accent { color: var(--accent); }

/* ══════════════════════ SPLASH ══════════════════════ */
#splash {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 40%, #0a1f35 0%, #050d16 60%, #000 100%);
  transition: opacity .6s ease, transform .6s ease;
  z-index: 50;
}
#splash.exit { opacity: 0; transform: scale(1.04); pointer-events: none; }
#intro-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#splash-content {
  position: relative; z-index: 2; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  animation: fadeUp .9s cubic-bezier(.22,1,.36,1) both;
}
#splash-badge {
  font-size: .65rem; font-weight: 800; letter-spacing: .25em;
  color: var(--accent); text-transform: uppercase;
  border: 1.5px solid rgba(245,197,24,.4); border-radius: 30px; padding: 5px 16px;
  background: rgba(245,197,24,.08);
  animation: fadeUp .9s .1s cubic-bezier(.22,1,.36,1) both;
}
#splash-title {
  font-size: clamp(3.5rem, 10vw, 6.5rem); font-weight: 900; line-height: .95;
  letter-spacing: -.02em;
  text-shadow: 0 0 60px rgba(245,197,24,.3), 0 4px 24px rgba(0,0,0,.6);
  animation: fadeUp .9s .2s cubic-bezier(.22,1,.36,1) both;
}
#splash-sub {
  font-size: clamp(.9rem, 2.5vw, 1.15rem); color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase; font-weight: 500;
  animation: fadeUp .9s .3s cubic-bezier(.22,1,.36,1) both;
}
#btn-enter {
  animation: fadeUp .9s .45s cubic-bezier(.22,1,.36,1) both;
  display: flex; align-items: center; gap: 10px; font-size: 1.05rem;
}
.pulse { animation: fadeUp .9s .45s cubic-bezier(.22,1,.36,1) both, pulse 2.4s 1.4s ease-in-out infinite; }
#splash-balls-row {
  position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; z-index: 2;
  animation: fadeUp .9s .6s cubic-bezier(.22,1,.36,1) both;
}
#splash-balls-row .mini-ball {
  width: 22px; height: 22px; border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  border: 1.5px solid rgba(255,255,255,.18);
}

#x-badge {
  position: absolute;
  top: 20px; right: 20px;
  z-index: 10;
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.55);
  border: 1.5px solid rgba(255,255,255,.14);
  border-radius: 30px;
  padding: 8px 16px 8px 12px;
  color: #fff;
  text-decoration: none;
  font-size: .82rem; font-weight: 700; letter-spacing: .03em;
  backdrop-filter: blur(10px);
  transition: background .2s, border-color .2s, transform .15s;
  animation: fadeUp .9s .7s cubic-bezier(.22,1,.36,1) both;
}
#x-badge:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.35);
  transform: translateY(-2px);
}
#x-icon {
  width: 16px; height: 16px;
  color: #fff; flex-shrink: 0;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%,100% { box-shadow: 0 4px 18px rgba(245,197,24,.45); }
  50%      { box-shadow: 0 4px 40px rgba(245,197,24,.85), 0 0 0 8px rgba(245,197,24,.12); }
}

/* ══════════════════════ GUIDE ══════════════════════ */
#guide { background: var(--dark); overflow-y: auto; z-index: 40; }
#guide.slide-in  { animation: slideInRight .45s cubic-bezier(.22,1,.36,1) both; }
#guide.slide-out { animation: slideOutLeft .35s cubic-bezier(.55,0,1,.45) both; }
@keyframes slideInRight { from { opacity:0; transform:translateX(60px); } to { opacity:1; transform:none; } }
@keyframes slideOutLeft  { from { opacity:1; transform:none; } to { opacity:0; transform:translateX(-60px); } }

#guide-inner {
  max-width: 900px; margin: 0 auto;
  padding: 40px 24px 60px;
  display: flex; flex-direction: column; gap: 28px;
}
#guide-header { text-align: center; }
.guide-8ball {
  width: 72px; height: 72px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #2a2a2a, #000);
  border: 3px solid rgba(255,255,255,.1);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 900; color: #fff;
  box-shadow: 0 0 40px rgba(255,255,255,.08), 0 8px 32px rgba(0,0,0,.6);
  margin-bottom: 16px; position: relative;
}
.guide-8ball::after {
  content: ''; position: absolute; top: 10px; left: 14px;
  width: 20px; height: 12px; border-radius: 50%;
  background: rgba(255,255,255,.15); transform: rotate(-30deg);
}
#guide-header h2 { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 800; letter-spacing: -.01em; }
.guide-lead { color: var(--muted); margin-top: 8px; font-size: .95rem; }

#guide-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 14px;
}
.gcard {
  background: var(--card); border: 1px solid rgba(255,255,255,.07);
  border-radius: var(--radius); padding: 22px;
  display: flex; flex-direction: column; gap: 10px;
  animation: cardIn .5s calc(var(--d) + 100ms) cubic-bezier(.22,1,.36,1) both;
  transition: border-color .2s, transform .2s;
}
.gcard:hover { border-color: rgba(245,197,24,.35); transform: translateY(-3px); }
.gcard-icon { font-size: 1.7rem; }
.gcard h3 { font-size: .95rem; font-weight: 700; color: var(--accent); }
.gcard p  { font-size: .85rem; color: var(--muted); line-height: 1.6; }
.gcard strong { color: var(--txt); }
.gcard em { color: var(--red); font-style: normal; }
@keyframes cardIn { from { opacity:0; transform:translateY(24px); } to { opacity:1; transform:none; } }

#guide-controls {
  background: var(--card); border: 1px solid rgba(255,255,255,.07);
  border-radius: var(--radius); padding: 20px;
  display: flex; flex-direction: column; gap: 11px;
}
.ctrl-row { display: flex; align-items: center; gap: 14px; }
kbd {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  border-radius: 6px; padding: 5px 12px;
  font-size: .76rem; font-weight: 600; color: var(--accent);
  white-space: nowrap; font-family: inherit;
}
.ctrl-row span { color: var(--muted); font-size: .86rem; }

/* ── Mode selector ── */
#mode-section {
  background: var(--card); border: 1px solid rgba(255,255,255,.07);
  border-radius: var(--radius); padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
}
#mode-label, #diff-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted);
}
#mode-btns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.mode-btn {
  background: rgba(255,255,255,.04); border: 2px solid rgba(255,255,255,.1);
  border-radius: 12px; padding: 18px 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color .2s, background .2s, transform .15s;
  color: var(--txt); font-family: inherit;
}
.mode-btn:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.22); transform: translateY(-2px); }
.mode-btn.active { border-color: var(--accent); background: rgba(245,197,24,.08); }
.mode-icon { font-size: 2rem; }
.mode-name { font-weight: 700; font-size: .9rem; }
.mode-desc { font-size: .75rem; color: var(--muted); }

#diff-section { display: flex; flex-direction: column; gap: 10px; }
#diff-btns { display: flex; gap: 8px; }
.diff-btn {
  flex: 1; border: 1.5px solid rgba(255,255,255,.1);
  border-radius: 8px; padding: 9px 12px;
  background: rgba(255,255,255,.04); color: var(--muted);
  font-family: inherit; font-weight: 600; font-size: .82rem;
  cursor: pointer; transition: border-color .2s, background .2s, color .2s;
}
.diff-btn:hover { background: rgba(255,255,255,.08); color: var(--txt); }
.diff-btn.active { border-color: var(--accent); background: rgba(245,197,24,.1); color: var(--accent); }

#guide-actions {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}

/* ══════════════════════ GAME ══════════════════════ */
#game-screen {
  display: flex; flex-direction: column;
  height: 100vh; padding: 8px; gap: 8px; z-index: 30;
}
#game-screen.slide-in { animation: slideInRight .4s cubic-bezier(.22,1,.36,1) both; }

#ui-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-shrink: 0; height: 64px;
}
.player-card {
  background: var(--card); border: 2px solid transparent;
  border-radius: var(--radius); padding: 8px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 140px; transition: border-color .25s, box-shadow .25s;
}
.player-card.active { border-color: var(--accent); box-shadow: 0 0 18px rgba(245,197,24,.35); }
.player-name { font-weight: 700; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.player-balls { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; min-height: 14px; }
.player-balls .dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.3);
  display: inline-block; transition: background .3s, opacity .3s;
}
.player-type { font-size: .68rem; color: var(--accent); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }

#status-center { text-align: center; flex: 1; }
#turn-label { font-size: .95rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
#foul-msg { font-size: .72rem; color: var(--red); font-weight: 600; min-height: 16px; }

#canvas-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 0; position: relative;
}
#pool {
  display: block; border-radius: 10px; cursor: crosshair;
  box-shadow: 0 0 0 7px #5c2e0d, 0 0 0 12px #3a1c06, 0 20px 80px rgba(0,0,0,.8);
  touch-action: none;
}

#ai-thinking {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(10,20,32,.92); border: 1px solid rgba(245,197,24,.3);
  border-radius: 30px; padding: 8px 22px;
  font-size: .82rem; font-weight: 600; color: var(--accent);
  letter-spacing: .06em;
  animation: aiPulse 1s ease-in-out infinite;
  backdrop-filter: blur(6px);
}
@keyframes aiPulse { 0%,100%{opacity:.7} 50%{opacity:1} }

#ui-bottom {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; flex-shrink: 0; height: 54px;
}
#power-wrap { display: flex; align-items: center; gap: 8px; }
.lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
#power-bar {
  width: 160px; height: 12px; background: rgba(255,255,255,.08);
  border-radius: 6px; overflow: hidden; border: 1px solid rgba(255,255,255,.1);
}
#power-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #4caf50 0%, #f5c518 60%, #e84040 100%);
  border-radius: 6px; transition: width .04s linear;
}
#power-pct { font-size: .8rem; font-weight: 700; color: var(--accent); min-width: 36px; }

/* ══════════════════════ WIN OVERLAY ══════════════════════ */
#win-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.78);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
#win-overlay.hidden { display: none; }
#win-box {
  background: var(--card); border: 1px solid rgba(255,255,255,.09);
  border-radius: 22px; padding: 40px 56px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  box-shadow: var(--shadow); animation: popIn .35s cubic-bezier(.34,1.56,.64,1) both;
}
#win-canvas { border-radius: 12px; }
#win-title { font-size: 2rem; font-weight: 900; color: var(--accent); letter-spacing: -.01em; }
#win-sub   { color: var(--muted); font-size: .95rem; }
.win-btns  { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
@keyframes popIn { from { transform:scale(.75); opacity:0; } to { transform:scale(1); opacity:1; } }

/* ══════════════════════ RESPONSIVE ══════════════════════ */
@media (max-width: 520px) {
  #ui-top { height: auto; flex-wrap: wrap; }
  .player-card { min-width: 110px; padding: 6px 10px; }
  #power-bar { width: 100px; }
  #ui-bottom { gap: 8px; height: auto; flex-wrap: wrap; padding-bottom: 4px; }
  .btn { padding: 9px 16px; font-size: .8rem; }
  #guide-inner { padding: 24px 14px 48px; }
  #win-box { padding: 32px 24px; }
  #mode-btns { grid-template-columns: 1fr 1fr; }
}
