:root {
  --bg: #f5f7fa;
  --card: #fff;
  --line: #e1e8ed;
  --text: #0f1419;
  --muted: #6b7280;
  --green: #10b981;
  --blue: #2563eb;
  --yellow: #f59e0b;
  --red: #ef4444;
  --shadow: 0 10px 30px rgba(15, 20, 25, .08);
  --shadow-sm: 0 4px 12px rgba(15, 20, 25, .05);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

/* Topbar */
.topbar {
  min-height: 68px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

@media (max-width: 640px) {
  .topbar {
    min-height: 56px;
    padding: 0 16px;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-weight: 900;
  color: var(--text);
  transition: transform 0.2s ease;
}

.brand:hover {
  transform: scale(1.05);
}

.brand img {
  height: 44px;
  width: 44px;
  object-fit: contain;
}

.brand span {
  font-size: 1.3rem;
  background: linear-gradient(135deg, var(--green), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.topbar nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

.topbar nav a {
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.topbar nav a:hover {
  background: var(--bg);
  color: var(--green);
}

@media (max-width: 768px) {
  .topbar nav a {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .topbar nav {
    gap: 2px;
  }
}

/* Main content */
.page {
  width: min(1200px, calc(100% - 32px));
  margin: 28px auto 56px;
}

@media (max-width: 768px) {
  .page {
    width: calc(100% - 24px);
    margin: 20px auto 40px;
  }
}

/* Auth pages */
.auth-card {
  width: min(100%, 440px);
  margin: 48px auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

@media (max-width: 640px) {
  .auth-card {
    margin: 24px auto;
    padding: 24px;
    border-radius: 16px;
  }
}

.auth-card h1, .hero h1 {
  margin: 0 0 8px;
  font-size: 1.8rem;
  color: var(--text);
}

.auth-card h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text);
}

.auth-card p, .hero p, .card p {
  color: var(--muted);
  line-height: 1.6;
  margin: 8px 0;
}

.form {
  display: grid;
  gap: 16px;
}

.form label {
  display: grid;
  gap: 8px;
}

.form span, label span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  padding: 12px 14px;
  font: inherit;
  transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
  min-height: 100px;
  resize: vertical;
  font-family: inherit;
}

button, .primary, .secondary {
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s ease;
  font-size: 0.95rem;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.primary {
  background: linear-gradient(135deg, var(--green), #059669);
  color: #fff;
  font-weight: 700;
}

.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
}

.secondary {
  background: var(--bg);
  color: var(--blue);
  border: 1px solid var(--line);
}

.secondary:hover {
  background: rgba(37, 99, 235, 0.05);
  border-color: var(--blue);
}

.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.auth-links a {
  color: var(--blue);
  font-weight: 700;
  font-size: 0.9rem;
  transition: color 0.2s ease;
}

.auth-links a:hover {
  color: #1d4ed8;
  text-decoration: underline;
}

/* Flash messages */
.flash {
  padding: 14px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-weight: 700;
  border-left: 4px solid;
}

.flash.danger {
  background: #fee2e2;
  color: #991b1b;
  border-left-color: var(--red);
}

.flash.success {
  background: #dcfce7;
  color: #166534;
  border-left-color: var(--green);
}

/* Guest shell (login page) */
.guest-shell {
  background: linear-gradient(135deg, #064e3b 0%, #1e3a8a 50%, #7c2d12 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.guest-shell .topbar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
}

.login-stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 40px;
  align-items: center;
  padding: 40px 60px;
}

@media (max-width: 1024px) {
  .login-stage {
    grid-template-columns: 1fr;
    padding: 30px 20px;
    gap: 30px;
  }
}

.login-copy {
  color: #fff;
  z-index: 1;
}

.login-copy span {
  display: inline-flex;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  margin-bottom: 12px;
}

.login-copy h1 {
  font-size: clamp(2.2rem, 7vw, 4.5rem);
  line-height: 1.1;
  margin: 16px 0 24px;
  font-weight: 900;
  color: #fff;
}

.login-copy p {
  font-size: 1.1rem;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 24px;
  max-width: 560px;
}

.login-card {
  margin: 0;
  border-radius: 20px;
  border: 1px solid var(--line);
  padding: 32px;
}

@media (max-width: 640px) {
  .login-card {
    padding: 24px;
    border-radius: 16px;
  }

  .login-copy h1 {
    font-size: 2rem;
  }
}

/* App shell */
.app-shell .topbar {
  background: var(--card);
}

/* Hero sections */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  color: #fff;
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.hero h1 {
  color: #fff;
  margin: 0 0 12px;
}

.hero p {
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 24px;
  }

  .hero-actions {
    width: 100%;
    justify-content: stretch;
  }

  .hero-actions a, .hero-actions button {
    flex: 1;
  }
}

/* Grid layouts */
.grid {
  display: grid;
  gap: 18px;
  margin-bottom: 20px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1024px) {
  .grid.two, .grid.three {
    grid-template-columns: 1fr;
  }

  .grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .grid, .grid.two, .grid.three, .grid.four {
    grid-template-columns: 1fr;
  }
}

/* Cards */
.card, .match-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.card:hover {
  border-color: var(--blue);
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.2rem;
}

.card.accent {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(37, 99, 235, 0.08));
  border-color: rgba(16, 185, 129, 0.2);
}

.compact-card {
  padding: 14px;
  margin-bottom: 12px;
}

/* Pills and badges */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--yellow);
  color: #78350f;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Lists */
.pool-list, .approval-list, .ranking, .prediction-list, .invite-list {
  display: grid;
  gap: 12px;
}

.pool-row, .rank-row, .result-row, .approval-row, .user-row, .invite-row {
  display: grid;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  transition: all 0.2s ease;
}

.pool-row:hover, .rank-row:hover, .user-row:hover {
  border-color: var(--blue);
  background: #f9fafb;
}

.pool-row, .rank-row {
  grid-template-columns: 1fr auto;
}

.user-row {
  grid-template-columns: 1fr 170px 140px 130px 90px;
}

.invite-row {
  grid-template-columns: 1fr 140px 150px 140px 90px;
}

.result-row {
  grid-template-columns: 1fr 70px auto 70px 90px;
}

.pool-row span, .rank-row small, .user-row small, .invite-row small {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .pool-row, .rank-row, .user-row, .invite-row, .result-row, .approval-row {
    grid-template-columns: 1fr;
  }
}

/* Match grid */
.match-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.match-grid.compact {
  grid-template-columns: repeat(4, minmax(220px, 1fr));
}

.match-card {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.match-card.has-prediction {
  background: #ecfdf5;
  border-color: #86efac;
}

.match-card.missing-prediction {
  background: #fefce8;
  border-color: #fde047;
}

@media (max-width: 1200px) {
  .match-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .match-grid.compact {
    grid-template-columns: repeat(2, minmax(200px, 1fr));
  }
}

@media (max-width: 768px) {
  .match-grid, .match-grid.compact {
    grid-template-columns: 1fr;
  }
}

/* Teams display */
.teams {
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  gap: 8px;
  align-items: center;
}

.teams strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.teams em {
  font-style: normal;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  font-size: 0.9rem;
}

.team-badge {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 36px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.2);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
}

.team-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(15, 20, 25, 0.1));
}

.flag {
  font-size: 1.2rem;
  line-height: 1;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  border-radius: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 8px;
}

.stat-card span {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card strong {
  font-size: 1.8rem;
  line-height: 1;
  color: var(--text);
}

.stat-card.green {
  background: #ecfdf5;
  border-color: #86efac;
}

.stat-card.green strong {
  color: var(--green);
}

.stat-card.yellow {
  background: #fefce8;
  border-color: #fde047;
}

.stat-card.yellow strong {
  color: #ca8a04;
}

.stat-card.red {
  background: #fee2e2;
  border-color: #fca5a5;
}

.stat-card.red strong {
  color: var(--red);
}

.stat-card.blue {
  background: #eff6ff;
  border-color: #93c5fd;
}

.stat-card.blue strong {
  color: var(--blue);
}

@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

/* Forms */
.guess-form {
  display: grid;
  grid-template-columns: 50px 1fr 50px 100px;
  gap: 8px;
  align-items: center;
}

.guess-form input {
  text-align: center;
  font-weight: 700;
  padding: 10px 8px;
}

.guess-form button {
  background: var(--blue);
  color: #fff;
  padding: 10px 12px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 20px;
}

.filters label {
  display: grid;
  gap: 8px;
}

@media (max-width: 900px) {
  .guess-form, .filters {
    grid-template-columns: 1fr;
  }
}

/* Rules and scoring */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.score-table {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.score-table span {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.score-table b {
  background: var(--green);
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
}

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

/* Empty state */
.empty {
  padding: 32px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}

/* Utilities */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--blue);
  text-decoration: none;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: #eff6ff;
  border-color: var(--blue);
}

.disabled-link {
  pointer-events: none;
  opacity: 0.6;
}

/* Responsive typography */
@media (max-width: 768px) {
  body {
    font-size: 16px;
  }

  .auth-card h1, .hero h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  h3 {
    font-size: 1.1rem;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text);
}
