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

body {
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  background-color: #1b5e20;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 80px,
      rgba(0,0,0,0.07) 80px,
      rgba(0,0,0,0.07) 160px
    );
}

.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.hidden { display: none !important; }

/* ── Setup Screen ── */
.setup-card {
  background: #2e7d32;
  border: 2px solid #4caf50;
  border-radius: 20px;
  padding: 40px 36px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.logo { font-size: 3.5rem; margin-bottom: 8px; }
h1 { font-size: 2.4rem; font-weight: 800; letter-spacing: 2px; color: #fff; }
.subtitle { color: #a5d6a7; font-size: 1rem; letter-spacing: 3px; text-transform: uppercase; margin-bottom: 32px; }

.player-inputs {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}

.player-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.player-field label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #a5d6a7;
  font-weight: 700;
}

.player-field input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 2px solid #4caf50;
  background: #1b5e20;
  color: #fff;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.player-field input::placeholder { color: #66bb6a; }
.player-field input:focus { border-color: #81c784; box-shadow: 0 0 0 3px rgba(76,175,80,0.3); }

.field-error {
  font-size: 0.78rem;
  color: #ffcc80;
  min-height: 1em;
}

.saved-names {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.name-chip {
  background: #1b5e20;
  border: 1px solid #66bb6a;
  color: #c8e6c9;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.name-chip:hover { background: #388e3c; color: #fff; }

.vs-badge {
  font-size: 0.85rem;
  font-weight: 800;
  color: #fff;
  background: #388e3c;
  border: 2px solid #4caf50;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 28px;
  flex-shrink: 0;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  background: #43a047;
  color: #fff;
  border: 2px solid #66bb6a;
  border-radius: 10px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: #4caf50; transform: scale(1.02); }

/* ── Game Screen ── */
.game-layout {
  display: flex;
  gap: 32px;
  align-items: flex-start;
  width: 100%;
  max-width: 860px;
}

.game-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Match header */
.match-header {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #2e7d32;
  border: 2px solid #4caf50;
  border-radius: 14px;
  padding: 12px 20px;
  width: 100%;
}

.player-tag {
  flex: 1;
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
  color: #c8e6c9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.match-score {
  font-size: 1.8rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 4px;
  flex-shrink: 0;
}

/* Status */
.status {
  font-size: 1.1rem;
  font-weight: 600;
  color: #a5d6a7;
  min-height: 1.5em;
  text-align: center;
  transition: color 0.2s;
}
.status.goal { color: #69f0ae; font-size: 1.4rem; font-weight: 800; }
.status.draw { color: #ffe082; }

/* Board */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #4caf50;
  border: 3px solid #fff;
  border-radius: 4px;
  padding: 6px;
}

.cell {
  width: 100px;
  height: 100px;
  background: #2e7d32;
  border: 2px dashed rgba(255,255,255,0.4);
  border-radius: 4px;
  font-size: 2.6rem;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s, transform 0.1s;
}
.cell:hover:not(:disabled) { background: #388e3c; transform: scale(1.05); }
.cell:disabled { cursor: default; }
.cell.x { color: #ffffff; }
.cell.o { color: #ffe082; }
.cell.winning {
  background: #43a047;
  border: 2px solid #69f0ae;
  box-shadow: 0 0 18px rgba(105,240,174,0.5);
}

/* Stats row */
.match-stats { display: flex; gap: 24px; }
.stat-item { text-align: center; }
.stat-val { display: block; font-size: 1.6rem; font-weight: 800; color: #fff; }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: #a5d6a7; }

/* Buttons */
.btn-row { display: flex; gap: 12px; }
.btn-secondary {
  padding: 9px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  background: #2e7d32;
  color: #c8e6c9;
  border: 2px solid #4caf50;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-secondary:hover { background: #388e3c; color: #fff; transform: scale(1.03); }

/* ── Leaderboard ── */
.leaderboard-panel {
  flex: 1;
  background: #2e7d32;
  border: 2px solid #4caf50;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.leaderboard-panel h2 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #a5d6a7;
  margin-bottom: 16px;
  text-align: center;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.leaderboard-table th {
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: #a5d6a7;
  padding: 6px 8px;
  border-bottom: 1px solid #4caf50;
  text-align: left;
}
.leaderboard-table th:not(:nth-child(2)) { text-align: center; }

.leaderboard-table td {
  padding: 8px 8px;
  border-bottom: 1px solid rgba(76,175,80,0.25);
  color: #e8f5e9;
}
.leaderboard-table td:not(:nth-child(2)) { text-align: center; }

.leaderboard-table tbody tr:first-child td { color: #ffe082; font-weight: 700; }
.leaderboard-table tbody tr:nth-child(2) td { color: #e0e0e0; }
.leaderboard-table tbody tr:nth-child(3) td { color: #ffcc80; }

.leaderboard-table tr.active-player td { background: rgba(105,240,174,0.1); }

.lb-hint {
  margin-top: 12px;
  font-size: 0.72rem;
  color: #81c784;
  text-align: center;
}

/* Responsive */
@media (max-width: 700px) {
  .game-layout { flex-direction: column; align-items: center; }
  .cell { width: 88px; height: 88px; }
  .leaderboard-panel { width: 100%; max-width: 340px; }
}
