:root {
  --bg-main: #050607;
  --bg-elevated: #101417;
  --bg-elevated-soft: #151a1f;
  --accent: #33d17a;
  --accent-soft: rgba(51, 209, 122, 0.12);
  --accent-strong: #26a35c;
  --accent-danger: #ff4b5c;
  --border-subtle: #242a30;
  --text-main: #f4f7fb;
  --text-muted: #9ba5b3;
  --text-softer: #6e7783;
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.55);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --transition-fast: 0.15s ease-out;
  --transition-med: 0.22s ease;
  --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at top left, #111922 0, #050607 40%, #020304 100%);
  color: var(--text-main);
  font-family: var(--font-main);
}

body {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/* Root container: optimized for a single mobile viewport but usable on desktop */
#app {
  width: 100%;
  max-width: 1100px;
  max-height: 640px;
  height: 100vh;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: auto;
}

/* HEADER */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: linear-gradient(135deg, rgba(16, 20, 23, 0.96), rgba(8, 12, 15, 0.98));
  border-radius: var(--radius-lg);
  border: 1px solid rgba(51, 209, 122, 0.18);
  box-shadow: var(--shadow-soft);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tournament-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex-shrink: 0;
}

.title-block h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.insta-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(51, 209, 122, 0.12);
  border: 1px solid rgba(51, 209, 122, 0.4);
  color: var(--accent);
  text-decoration: none;
  flex-shrink: 0;
}

.insta-icon {
  width: 16px;
  height: 16px;
  fill: var(--accent);
}

.clock {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(3, 5, 7, 0.85);
}

.admin-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid transparent;
}

.badge-off {
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--text-softer);
  background: rgba(15, 19, 23, 0.9);
}

.badge-on {
  border-color: rgba(51, 209, 122, 0.6);
  color: var(--accent);
  background: rgba(18, 71, 43, 0.9);
}

/* NAVIGATION */
.main-nav {
  display: flex;
  gap: 6px;
  padding: 0 3px;
}

.nav-btn {
  flex: 1;
  border: none;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(10, 14, 18, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
    border-color var(--transition-fast), transform var(--transition-fast);
}

.nav-btn:hover {
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.nav-btn.active {
  background: radial-gradient(circle at top left, #34d182, #1b8048);
  color: #020304;
  border-color: rgba(0, 0, 0, 0.4);
  font-weight: 600;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  min-height: 0;
  background: rgba(6, 9, 12, 0.95);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.03);
  padding: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  display: none;
  height: 100%;
  flex-direction: column;
}

.view.active {
  display: flex;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.view-header h2 {
  font-size: 15px;
  margin: 0;
}

/* BUTTONS */
.btn {
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #020304;
  border-color: var(--accent-strong);
  font-weight: 600;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.65);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast),
    background var(--transition-fast);
}

.btn-primary:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 9px 24px rgba(0, 0, 0, 0.7);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: rgba(255, 255, 255, 0.15);
  padding-inline: 10px;
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* GROUPS / TABLES */
.groups-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
}

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

.group-card {
  background: linear-gradient(145deg, var(--bg-elevated), var(--bg-elevated-soft));
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.group-header h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-softer);
}

.table-wrapper {
  flex: 1;
  min-height: 0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  background: radial-gradient(circle at top left, rgba(51, 209, 122, 0.04), transparent 50%);
  overflow: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table thead {
  position: sticky;
  top: 0;
  background: rgba(11, 15, 18, 0.98);
  backdrop-filter: blur(8px);
  z-index: 1;
}

.table th,
.table td {
  padding: 5px 6px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.table th {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 11px;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.01);
}

.table tbody tr:hover {
  background: rgba(51, 209, 122, 0.08);
}

.pos-cell {
  width: 32px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.team-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.team-logo {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: #050607;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.team-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-cell {
  text-align: center;
  font-variant-numeric: tabular-nums;
  width: 30px;
}

.actions-cell {
  text-align: right;
  width: 40px;
}

.icon-btn {
  border: none;
  background: none;
  color: var(--text-softer);
  cursor: pointer;
  padding: 2px;
  border-radius: 6px;
  transition: background var(--transition-fast), color var(--transition-fast),
    transform var(--transition-fast);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--accent);
  transform: translateY(-0.5px);
}

.icon-sm {
  width: 14px;
  height: 14px;
}

/* MATCHES */
.matches-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#matches-date {
  background: rgba(7, 10, 12, 0.9);
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 11px;
  padding: 6px 8px;
  outline: none;
}

#matches-date:focus {
  border-color: var(--accent);
}

.matches-list {
  flex: 1;
  min-height: 0;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
}

.match-card {
  display: grid;
  grid-template-columns: 1.2fr auto 1.2fr auto;
  gap: 8px;
  align-items: center;
  background: linear-gradient(145deg, rgba(11, 15, 18, 0.96), rgba(7, 10, 13, 0.98));
  border-radius: var(--radius-md);
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

@media (max-width: 600px) {
  .match-card {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
}

.match-team {
  display: flex;
  align-items: center;
  gap: 6px;
}

.match-team .team-logo {
  width: 36px;
  height: 36px;
  cursor: zoom-in;
}

.match-team-name {
  font-size: 14px;
  font-weight: 600;
  transition: color var(--transition-fast);
}

.match-team-side {
  font-size: 10px;
  text-transform: uppercase;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: bold;
}

.side-azul {
  color: #3b82f6;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.side-vermelho {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.text-winner {
  color: #33d17a !important;
}

.text-loser {
  color: #ff4b5c !important;
}

.match-center {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.match-time {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
}

.match-meta {
  display: inline-flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 2px;
}

.match-date-tag {
  display: block;
  font-size: 9px;
  color: var(--text-softer);
  margin-bottom: 2px;
}

.match-actions-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 11, 14, 0.9);
}

.tag-accent {
  border-color: rgba(51, 209, 122, 0.5);
  color: var(--accent);
}

.tag-winner {
  border-color: rgba(51, 209, 122, 0.75);
  background: rgba(51, 209, 122, 0.16);
  color: var(--accent);
}

/* TEAMS & PLAYERS */
.teams-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  padding-right: 2px;
}

.team-card {
  background: linear-gradient(145deg, var(--bg-elevated), var(--bg-elevated-soft));
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.team-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.team-card-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.team-card-main .team-logo {
  width: 32px;
  height: 32px;
}

.team-card-main .team-name {
  font-size: 15px;
}

.team-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.group-pill {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.team-card-actions {
  display: flex;
  gap: 6px;
}

.team-card-actions .btn {
  padding-block: 4px;
  font-size: 11px;
}

.team-instagram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid rgba(51, 209, 122, 0.6);
  color: var(--accent);
  background: rgba(51, 209, 122, 0.05);
}

.team-instagram svg {
  width: 12px;
  height: 12px;
  fill: var(--accent);
}

.players-list {
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: rgba(7, 10, 13, 0.9);
  padding: 6px;
  font-size: 11px;
  max-height: 140px;
  overflow: auto;
}

.players-list-title {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.player-row {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.9fr 0.9fr;
  gap: 4px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.player-row:last-child {
  border-bottom: none;
}

.player-nick {
  font-weight: 500;
}

.player-pos {
  color: var(--text-muted);
}

.player-id,
.player-profile {
  color: var(--text-softer);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 8, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(480px, 100% - 32px);
  max-height: min(540px, 100% - 40px);
  background: radial-gradient(circle at top left, #101820, #050607);
  border-radius: 14px;
  border: 1px solid rgba(51, 209, 122, 0.3);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 14px;
}

.modal-close {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.modal-footer {
  padding: 8px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* FORM */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.form-grid-full {
  grid-column: 1 / -1;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.form-field label {
  font-size: 11px;
  color: var(--text-muted);
}

.form-field input,
.form-field select {
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(8, 12, 14, 0.95);
  color: var(--text-main);
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--accent);
}

.form-helper {
  font-size: 10px;
  color: var(--text-softer);
}

.players-form-list {
  margin-top: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px;
  background: rgba(7, 11, 14, 0.95);
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 190px;
  overflow: auto;
}

.player-form-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 4px;
  align-items: center;
}

.player-form-row input {
  font-size: 11px;
  padding: 4px 6px;
}

.remove-player-btn {
  border: none;
  background: none;
  color: var(--accent-danger);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}

.modal-logo-preview {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto;
  object-fit: contain;
}

/* TOAST */
.toast {
  position: fixed;
  inset-inline: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(7, 11, 14, 0.96);
  border: 1px solid rgba(51, 209, 122, 0.5);
  color: var(--accent);
  font-size: 12px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  z-index: 60;
}

.toast.hidden {
  display: none;
}