:root {
  --panel-glass: rgba(30, 41, 59, 0.55);
  --panel-a: linear-gradient(135deg, #1d4ed8, #38bdf8);
  --panel-b: linear-gradient(135deg, #db2777, #f472b6);
  --accent: #38bdf8;
  --accent-2: #6366f1;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --win: #4ade80;
  --radius: 18px;
  --border: rgba(255, 255, 255, 0.08);
  --bg-a: #0f172a;
  --bg-b: #1e1b4b;
  --bg-c: #312e81;
}

@media (prefers-color-scheme: light) {
  :root {
    --panel-glass: rgba(255, 255, 255, 0.6);
    --panel-a: linear-gradient(135deg, #bfdbfe, #60a5fa);
    --panel-b: linear-gradient(135deg, #fbcfe8, #f472b6);
    --text: #0f172a;
    --muted: #475569;
    --border: rgba(15, 23, 42, 0.08);
    --bg-a: #e0e7ff;
    --bg-b: #f1f5f9;
    --bg-c: #fce7f3;
  }
}

* {
  box-sizing: border-box;
}

@keyframes bgShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(120deg, var(--bg-a), var(--bg-b), var(--bg-c), var(--bg-a));
  background-size: 400% 400%;
  animation: bgShift 18s ease infinite;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

@keyframes viewEnter {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.view-enter {
  animation: viewEnter 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

h1 {
  margin: 0 0 4px;
  text-align: center;
}

.logo {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2), #f472b6);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: bgShift 6s ease infinite;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  margin: 0 0 16px;
}

.suits {
  display: flex;
  justify-content: center;
  gap: 18px;
  font-size: 1.6rem;
  margin-bottom: 8px;
  opacity: 0.55;
}

.suits span {
  display: inline-block;
  animation: float 3.6s ease-in-out infinite;
}

.suits span:nth-child(1) { animation-delay: 0s; color: #f1f5f9; }
.suits span:nth-child(2) { animation-delay: 0.3s; color: #f472b6; }
.suits span:nth-child(3) { animation-delay: 0.6s; color: #f472b6; }
.suits span:nth-child(4) { animation-delay: 0.9s; color: #f1f5f9; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.card {
  background: var(--panel-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin: auto 0;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.setup form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 360px;
  margin: 0 auto;
}

.setup label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="text"],
input[type="number"] {
  font-size: 1.1rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  transition: border-color 0.2s ease, transform 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  transform: translateY(-1px);
}

.btn {
  font-size: 1rem;
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  will-change: transform;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0) scale(0.96);
}

.btn.primary {
  background: linear-gradient(135deg, #22d3ee, var(--accent-2));
  color: #0b1120;
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.45);
}

.btn.secondary {
  background: transparent;
  border: 1px solid var(--muted);
  color: var(--text);
}

.btn.secondary:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn.undo {
  background: linear-gradient(135deg, #f87171, #ef4444);
  color: white;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  display: block;
  box-shadow: 0 10px 25px rgba(239, 68, 68, 0.4);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .scoreboard {
    grid-template-columns: 1fr;
  }
}

.team-panel {
  border-radius: var(--radius);
  padding: 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
}

.team-a {
  background: var(--panel-a);
}

.team-b {
  background: var(--panel-b);
}

.team-panel h2 {
  margin: 0;
  font-size: 1.2rem;
  word-break: break-word;
  color: #0b1120;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.score {
  font-size: 3.8rem;
  font-weight: 800;
  line-height: 1;
  color: #0b1120;
}

@keyframes scoreBump {
  0% { transform: scale(1); }
  35% { transform: scale(1.28); }
  60% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

.score-bump {
  animation: scoreBump 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.btn.quick {
  background: rgba(11, 17, 32, 0.85);
  color: #f1f5f9;
  flex: 1 1 auto;
  min-width: 48px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.custom-form {
  display: flex;
  gap: 8px;
}

.custom-form input {
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(11, 17, 32, 0.15);
}

.custom-form .btn.add-custom {
  background: rgba(11, 17, 32, 0.85);
  color: #f1f5f9;
}

.controls {
  text-align: center;
}

.history {
  background: var(--panel-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.history ul {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

@keyframes historyIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.history li {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  animation: historyIn 0.3s ease both;
  border-left: 3px solid transparent;
}

.history-item.team-a {
  background: rgba(56, 189, 248, 0.14);
  border-left-color: #38bdf8;
}

.history-item.team-b {
  background: rgba(244, 114, 182, 0.14);
  border-left-color: #f472b6;
}

.history .empty {
  color: var(--muted);
  text-align: center;
  margin: 0;
}

.gameover {
  text-align: center;
  position: relative;
  z-index: 1;
}

@keyframes winnerPop {
  0% { opacity: 0; transform: scale(0.5); }
  60% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}

.winner-banner {
  color: var(--win);
  font-size: 2.2rem;
  text-shadow: 0 0 24px rgba(74, 222, 128, 0.55);
  animation: winnerPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.final-score {
  font-size: 1.3rem;
  color: var(--muted);
  margin-bottom: 24px;
}

.gameover-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 360px;
  margin: 0 auto;
}

.gameover-actions .btn.undo {
  background: transparent;
  border: 1px solid #ef4444;
  color: #ef4444;
  box-shadow: none;
}

.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.confetti {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  transform: rotate(var(--rotate));
  animation-name: confettiFall;
  animation-timing-function: ease-in;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(var(--rotate)); opacity: 1; }
  100% { transform: translateY(105vh) rotate(calc(var(--rotate) + 360deg)); opacity: 0; }
}

.storage-warning {
  background: #f59e0b;
  color: #1c1917;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin: 0;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
