:root {
  --bg: #08111f;
  --surface: rgba(15, 23, 42, 0.9);
  --surface-strong: #0f172a;
  --surface-soft: #13213a;
  --border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --gold: #fbbf24;
  --green: #34d399;
  --red: #f87171;
  --blue: #60a5fa;
  --shadow: rgba(8, 17, 31, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(96, 165, 250, 0.2), transparent 35%),
    linear-gradient(180deg, #0b1220 0%, var(--bg) 100%);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  width: min(100%, 540px);
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.topbar,
.setup-card,
.summary-card,
.history-card,
.team-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 14px 30px var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  margin-bottom: 1rem;
}

.setup-card {
  padding: 1rem;
  margin-bottom: 1rem;
}

.setup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.setup-header h2 {
  margin: 0;
}

.section-label-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.7rem;
}

.section-label-row h3 {
  margin: 0;
  font-size: 1rem;
}

.section-badge {
  display: inline-grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background: rgba(251, 191, 36, 0.2);
  color: var(--gold);
  font-weight: 800;
  font-size: 0.76rem;
}

.primary-button {
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  color: #111827;
  border-radius: 12px;
  padding: 0.72rem 0.9rem;
  font-weight: 800;
}

.match-control-row {
  margin: 0 0 1rem;
}

.match-control-row .primary-button {
  width: 100%;
  min-height: 3rem;
  font-size: 1rem;
}

.setup-grid {
  margin-bottom: 0.7rem;
}

.setup-grid label span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin-bottom: 0.45rem;
}

.setup-grid select,
.player-entry-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.65);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
  font-size: 1rem;
}

.player-entry-list {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.player-entry-item {
  display: grid;
  grid-template-columns: 2.2rem minmax(0, 1fr);
  gap: 0.55rem;
  align-items: center;
}

.player-entry-index {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(96, 165, 250, 0.18);
  color: var(--blue);
  font-weight: 700;
}

.player-entry-input {
  min-height: 2.8rem;
  border: 1px solid rgba(96, 165, 250, 0.35);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.06);
}

.team-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.team-slot {
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem;
}

.team-slot h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.team-slot-name-label {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 800;
}

.team-slot-name-input {
  margin: 0.55rem 0 0.7rem;
  padding: 0.62rem 0.7rem;
  font-size: 0.92rem;
}

.team-slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.team-slot-label {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.secondary-button {
  width: 100%;
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid rgba(96, 165, 250, 0.4);
  border-radius: 12px;
  background: rgba(96, 165, 250, 0.12);
  color: var(--text);
  font-weight: 800;
}

.team-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  min-height: 2.5rem;
}

.team-list li {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  color: var(--text);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 700;
}

.eyebrow.subtle {
  color: var(--muted);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  margin-top: 0.2rem;
}

.ghost-button {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  font-weight: 700;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.scoreboard.three-teams {
  grid-template-columns: repeat(3, 1fr);
}

.team-panel {
  padding: 0.9rem;
}

.team-a {
  border-top: 4px solid var(--blue);
}

.team-b {
  border-top: 4px solid var(--red);
}

.team-c {
  border-top: 4px solid var(--green);
}

.team-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.team-meta {
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

.team-name-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.65);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  margin-bottom: 0.8rem;
}

.score-wrap {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.3rem;
  margin: 0.2rem 0 0.9rem;
}

.score {
  font-size: clamp(2.1rem, 7vw, 3.5rem);
  font-weight: 800;
  line-height: 1;
}

.score-wrap small {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.score-button {
  background: rgba(96, 165, 250, 0.12);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.3rem;
  font-size: 1rem;
  font-weight: 800;
}

.team-b .score-button {
  background: rgba(248, 113, 113, 0.1);
}

.score-button.highlight {
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  color: #111827;
  border-color: rgba(251, 191, 36, 0.8);
}

.summary-card {
  margin-top: 1rem;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.summary-card h2 {
  font-size: 1.1rem;
  margin-top: 0.25rem;
}

.rule-summary {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.35rem;
  line-height: 1.4;
}

.history-card {
  margin-top: 1rem;
  padding: 1rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.history-header h3 {
  font-size: 1.05rem;
}

#roundCounter {
  color: var(--muted);
  font-size: 0.8rem;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
}

.history-item strong {
  display: block;
  font-size: 0.94rem;
}

.history-item span {
  color: var(--muted);
  font-size: 0.72rem;
}

.history-points {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--green);
}

.saved-matches-card {
  margin-top: 1rem;
}

.saved-matches-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.saved-match-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.3rem 0;
}

.saved-match-item {
  align-items: flex-start;
}

.saved-match-item strong {
  color: var(--text);
}

.saved-match-item small {
  display: block;
  margin-top: 0.22rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.score-celebration {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(3, 7, 18, 0.78);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.score-celebration.is-visible {
  opacity: 1;
}

.score-celebration-card {
  position: relative;
  width: min(82vw, 21rem);
  padding: 2rem 1.5rem 1.6rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 24px;
  background: rgba(15, 23, 42, 0.92);
  text-align: center;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.55);
  animation: score-card-in 300ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.score-character {
  font-size: 5.5rem;
  line-height: 1;
  animation: score-character-motion 900ms ease-in-out infinite alternate;
}

.score-prop {
  position: absolute;
  top: 4.1rem;
  left: calc(50% + 1.7rem);
  font-size: 2.2rem;
  animation: score-prop-motion 900ms ease-in-out infinite alternate;
}

.score-celebration-card p {
  margin-top: 1rem;
  color: var(--gold);
  font-size: 2.8rem;
  font-weight: 900;
  line-height: 1;
}

.score-celebration-card span {
  display: block;
  margin-top: 0.45rem;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
}

.score-celebration[data-points="2"] .score-character { animation-name: swim-motion; }
.score-celebration[data-points="2"] .score-prop {
  top: 3rem;
  left: calc(50% + 2.2rem);
  font-size: 1.4rem;
  animation-name: bubble-motion;
}
.score-celebration[data-points="3"] .score-character { animation-name: salmon-jump; }
.score-celebration[data-points="3"] .score-prop {
  top: 5rem;
  left: calc(50% - 2.8rem);
  font-size: 2.5rem;
  animation-name: splash-motion;
}

.salmon-illustration {
  position: relative;
  display: inline-block;
  width: 8.2rem;
  height: 5.2rem;
  transform: rotate(-18deg);
  animation: salmon-jump 700ms ease-in-out infinite;
}

.salmon-body {
  position: absolute;
  top: 1.15rem;
  left: 1.3rem;
  width: 5.7rem;
  height: 3.3rem;
  border-radius: 58% 48% 50% 46%;
  background: linear-gradient(145deg, #fb7185 0%, #f97316 48%, #be123c 100%);
  box-shadow: inset 0 -0.45rem 0 rgba(127, 29, 29, 0.28), 0 0.35rem 0.8rem rgba(249, 115, 22, 0.35);
}

.salmon-body::before,
.salmon-body::after {
  content: '';
  position: absolute;
  width: 1.6rem;
  height: 0.65rem;
  border-radius: 100% 0 100% 0;
  background: #fb923c;
}

.salmon-body::before {
  top: -0.35rem;
  left: 2.3rem;
  transform: rotate(-20deg);
}

.salmon-body::after {
  bottom: -0.3rem;
  left: 2.8rem;
  transform: rotate(18deg);
}

.salmon-eye {
  position: absolute;
  top: 0.55rem;
  right: 0.85rem;
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 0.2rem #111827;
}

.salmon-stripe {
  position: absolute;
  top: 0.2rem;
  left: 1.35rem;
  width: 2.5rem;
  height: 2.8rem;
  border-left: 0.18rem solid rgba(255, 255, 255, 0.42);
  border-right: 0.18rem solid rgba(255, 255, 255, 0.28);
  transform: skewY(-22deg);
}

.salmon-fin {
  position: absolute;
  top: 0.15rem;
  left: 1.9rem;
  width: 1.4rem;
  height: 0.8rem;
  border-radius: 100% 0;
  background: #e11d48;
  transform: rotate(-22deg);
}

.salmon-tail {
  position: absolute;
  top: 1.3rem;
  left: 0.25rem;
  width: 2.1rem;
  height: 3rem;
  border-radius: 70% 0 70% 0;
  background: linear-gradient(135deg, #fb7185, #be123c);
  transform: rotate(-25deg) skewY(8deg);
}

@keyframes score-card-in {
  from { transform: scale(0.72) translateY(1rem); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes score-character-motion {
  from { transform: translateY(0) rotate(-5deg); }
  to { transform: translateY(-0.55rem) rotate(5deg); }
}

@keyframes score-prop-motion {
  from { transform: translate(0, 0) rotate(-15deg); }
  to { transform: translate(0.35rem, -0.65rem) rotate(15deg); }
}

@keyframes swim-motion {
  from { transform: translateX(-1.2rem) rotate(-4deg); }
  to { transform: translateX(1.2rem) rotate(4deg); }
}

@keyframes bubble-motion {
  from { transform: translateY(0) scale(0.8); opacity: 0.5; }
  to { transform: translateY(-1.4rem) scale(1.2); opacity: 1; }
}

@keyframes salmon-jump {
  0%, 100% { transform: translateY(0) rotate(-10deg); }
  50% { transform: translateY(-2.2rem) rotate(12deg); }
}

@keyframes splash-motion {
  from { transform: scale(0.7) translateY(0); opacity: 0.5; }
  to { transform: scale(1.15) translateY(0.35rem); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .score-celebration { transition: none; }
  .score-celebration-card,
  .score-character,
  .score-prop { animation: none; }
}

.win-celebration {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: rgba(3, 7, 18, 0.94);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.win-celebration.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.fireworks-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.celebration-content {
  position: relative;
  z-index: 1;
  width: min(90vw, 30rem);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text);
  text-shadow: 0 3px 20px rgba(0, 0, 0, 0.6);
  animation: celebration-pop 500ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.celebration-content h2 {
  margin-top: 0.35rem;
  color: #fff;
  font-size: clamp(2.2rem, 10vw, 4.8rem);
  line-height: 0.98;
}

.celebration-content > p:not(.eyebrow) {
  margin-top: 0.8rem;
  color: #fde68a;
  font-size: 1.35rem;
  font-weight: 800;
}

.celebration-button {
  margin-top: 2rem;
  padding: 0.85rem 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 800;
}

@keyframes celebration-pop {
  from { transform: scale(0.75); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .win-celebration { transition: none; }
  .celebration-content { animation: none; }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 0.7rem;
  }

  .topbar,
  .summary-card,
  .history-card,
  .team-panel {
    border-radius: 16px;
  }

  .scoreboard {
    grid-template-columns: 1fr;
  }

  .summary-card {
    align-items: flex-start;
    flex-direction: column;
  }
}
