:root {
  --bg: #0a0f14;
  --bg-card: #121a24;
  --bg-elevated: #1a2535;
  --border: #2a3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #00c853;
  --accent-dim: #00a844;
  --gold: #ffc107;
  --danger: #ff5252;
  --brazil: #009c3b;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: "DM Sans", system-ui, sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 156, 59, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(255, 193, 7, 0.08), transparent),
    linear-gradient(180deg, var(--bg) 0%, #0d1520 100%);
  pointer-events: none;
  z-index: 0;
}

.screen {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
}

.screen.hidden {
  display: none;
}

/* Login */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo {
  display: block;
  width: 120px;
  height: 120px;
  margin: 0 auto 0.75rem;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 200, 83, 0.3));
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

#form-login label {
  display: block;
  text-align: left;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

#form-login input {
  width: 100%;
  padding: 0.875rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  margin-bottom: 1.25rem;
  transition: border-color 0.2s;
}

#form-login input:focus {
  outline: none;
  border-color: var(--accent);
}

.sync-hint {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.75rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  text-align: left;
}

.sync-hint.warn {
  border-left: 3px solid var(--gold);
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: rgba(18, 26, 36, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
}

.logo-sm {
  font-size: 1.25rem;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

#user-nome {
  color: var(--accent);
  font-weight: 600;
}

.admin-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: rgba(255, 193, 7, 0.2);
  color: var(--gold);
  border: 1px solid rgba(255, 193, 7, 0.35);
}

/* Nav */
.nav-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  flex: 1;
  min-width: max-content;
  padding: 0.625rem 1rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text);
  background: var(--bg-elevated);
}

.nav-tab.active {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text);
}

/* Main */
.main {
  padding: 1rem 1.25rem 6rem;
  max-width: 720px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h2,
.card h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #000;
}

.btn-google {
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #dadce0;
  gap: 0.75rem;
  font-weight: 500;
}

.btn-google:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.2);
}

.google-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

.ranking-table .player-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ranking-table .player-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.btn-block {
  width: 100%;
}

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

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

.btn-danger:hover {
  background: rgba(186, 26, 26, 0.08);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-save {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  right: 1.25rem;
  max-width: 672px;
  margin: 0 auto;
  z-index: 20;
  box-shadow: var(--shadow);
}

/* Ranking */
.table-wrap {
  overflow-x: auto;
}

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

.ranking-table th,
.ranking-table td {
  padding: 0.75rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.ranking-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ranking-table tbody tr:first-child td {
  color: var(--gold);
}

.ranking-table .pos {
  font-weight: 700;
  width: 2rem;
}

.ranking-table .pts {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.1rem;
}

.rules-list {
  list-style: none;
  font-size: 0.9rem;
}

.rules-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.rules-list li:last-child {
  border-bottom: none;
}

.rules-list .pts-badge {
  color: var(--accent);
  font-weight: 600;
}

/* Filters */
.filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.select {
  flex: 1;
  min-width: 140px;
  padding: 0.625rem 0.875rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Match cards */
.matches-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.match-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  transition: border-color 0.2s;
}

.match-card.locked {
  opacity: 0.7;
}

.match-card.brazil {
  border-color: rgba(0, 156, 59, 0.5);
  background: linear-gradient(135deg, var(--bg-card), rgba(0, 156, 59, 0.08));
}

.match-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.match-venue {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  opacity: 0.9;
}

.match-card.placeholder-match {
  border-style: dashed;
}

.match-meta .grupo {
  background: var(--bg-elevated);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
}

.match-tz {
  opacity: 0.75;
  font-weight: 400;
}

.match-teams {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  text-align: center;
}

.team.home {
  align-items: flex-end;
  text-align: right;
}

.team.away {
  align-items: flex-start;
  text-align: left;
}

.team-flag {
  width: 48px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  display: block;
}

.team-flag--fallback {
  font-size: 1.75rem;
  line-height: 1;
  width: auto;
  height: auto;
  box-shadow: none;
}

.team-name {
  font-size: 0.8rem;
  font-weight: 500;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-inputs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.score-inputs input {
  width: 2.5rem;
  height: 2.5rem;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  -moz-appearance: textfield;
}

.score-inputs input::-webkit-outer-spin-button,
.score-inputs input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.score-inputs input:focus {
  outline: none;
  border-color: var(--accent);
}

.score-inputs input:disabled {
  opacity: 0.6;
}

.score-sep {
  font-size: 1.25rem;
  color: var(--text-muted);
  font-weight: 300;
}

.match-result {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.match-result .pending {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

.match-points {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}

.match-points.zero {
  color: var(--text-muted);
}

.matches-list.compact .match-card {
  padding: 0.75rem 1rem;
}

.participants-list {
  list-style: none;
}

.participants-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: var(--shadow);
  max-width: 90%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: var(--accent);
}

.toast.error {
  border-color: var(--danger);
}

/* Ranking grupo / geral */
.ranking-head {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.ranking-controls {
  flex-shrink: 0;
}

.ranking-context-select {
  min-width: 11rem;
  max-width: 16rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 480px) {
  .ranking-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }
}

/* Grupos */
#screen-groups {
  padding: 1.25rem;
  max-width: 520px;
  margin: 0 auto;
}

.groups-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.groups-header .hint {
  margin-bottom: 1.25rem;
}

.join-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.join-form input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.groups-actions {
  margin: 1rem 0;
}

.groups-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
}

.group-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s;
}

.group-card:hover {
  border-color: var(--accent);
}

.group-card--active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.subsection-title {
  font-size: 0.95rem;
  margin: 1.25rem 0 0.35rem;
  color: var(--text-muted);
}

.group-active-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.group-card-photo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.group-card-photo--fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  font-size: 1.5rem;
}

.group-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  min-width: 0;
}

.group-card-code {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.group-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(0, 200, 83, 0.15);
  color: var(--accent);
  width: fit-content;
}

.group-badge--pending {
  background: rgba(255, 193, 7, 0.15);
  color: var(--gold);
}

.groups-logout {
  display: block;
  margin: 2rem auto 0;
}

.btn-group-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
}

.header-group-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-group-name {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.invite-code-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

.invite-code {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--gold);
}

.pending-list {
  list-style: none;
  margin-top: 0.5rem;
}

.pending-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.pending-item:last-child {
  border-bottom: none;
}

.pending-user {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.pending-user span,
.pending-user__name {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-user .player-avatar,
.pending-user .group-member-avatar--fallback {
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  border-radius: 999px;
  object-fit: cover;
}

.pending-user .group-member-avatar--fallback {
  font-size: 1rem;
}

.pending-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  width: 100%;
}

.pending-actions .btn {
  width: 100%;
  justify-content: center;
  min-height: 2rem;
  padding: 0.3rem 0.45rem;
  font-size: 0.75rem;
}

@media (min-width: 480px) {
  .pending-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .pending-actions {
    display: flex;
    width: auto;
    flex-shrink: 0;
  }

  .pending-actions .btn {
    width: auto;
    min-height: auto;
  }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  z-index: 1;
}

.modal-card label {
  display: block;
  font-size: 0.85rem;
  margin: 1rem 0 0.35rem;
  color: var(--text-muted);
}

.modal-card input[type="text"],
.modal-card input[type="file"] {
  width: 100%;
}

.photo-picker {
  margin-top: 0.5rem;
}

.group-photo-preview {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  object-fit: cover;
  margin-bottom: 0.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

@media (min-width: 640px) {
  .main {
    padding-bottom: 2rem;
  }

  .btn-save {
    position: static;
    margin-top: 1rem;
  }
}
