:root {
  --bg: #0d1117;
  --panel: #161b22;
  --text: #e6edf3;
  --muted: #8b949e;
  --primary: #2f81f7;
  --danger: #f85149;
  --ok: #3fb950;
  --border: #30363d;
}

/* Light theme override */
[data-theme="light"] {
  --bg: #f6f8fa;
  --panel: #ffffff;
  --text: #0c1116;
  --muted: #57606a;
  --primary: #0969da;
  --danger: #d1242f;
  --ok: #1a7f37;
  --border: #d0d7de;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  position: relative;
}

/* Фоновый слой с картинками */
.background-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.background-image {
  position: absolute;
  opacity: 0.3;
  user-select: none;
  pointer-events: none;
}

.container {
  width: 90%;
  max-width: 1600px;
  padding: 24px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.auth-status {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(47,129,247,.1);
}
[data-theme="light"] .auth-user {
  background: rgba(9,105,218,.12);
}
.auth-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
}
.auth-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.auth-user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.auth-user-name {
  font-size: 14px;
  font-weight: 600;
}
.auth-user-username {
  font-size: 12px;
  color: var(--muted);
}
.auth-logout {
  margin-top: 4px;
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.auth-logout:hover {
  color: var(--text);
  border-color: var(--border);
}
.auth-login-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.auth-input {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  width: 100px;
}
.auth-input:focus {
  outline: none;
  border-color: var(--primary);
}
.auth-submit-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--primary);
  color: white;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.auth-submit-btn:hover {
  background: var(--primary);
  opacity: 0.9;
}
.auth-placeholder {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: not-allowed;
}
.auth-placeholder:hover {
  color: var(--text);
}
.auth-warning {
  font-size: 12px;
  color: var(--muted);
}
.switch {
  position: relative;
  width: 52px;
  height: 28px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  transition: .2s;
  border-radius: 999px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  top: 2px;
  background-color: var(--muted);
  transition: .2s;
  border-radius: 50%;
}
input:checked + .slider {
  background: rgba(47,129,247,.2);
  border-color: var(--primary);
}
input:checked + .slider:before {
  transform: translateX(24px);
  background: var(--primary);
}

h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; color: var(--muted); font-weight: 600; }
/* Ensure emoji images (Twemoji) align nicely inside headings */
img.emoji, img.twemoji { height: 1em; width: 1em; vertical-align: -0.15em; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.team-template-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto 16px auto;
}

#teamsList {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.team-delete-cross {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #dc3545;
  cursor: pointer;
  font-size: 20px;
  font-weight: bold;
  line-height: 1;
  transition: transform 0.2s, color 0.2s;
  z-index: 10;
  user-select: none;
}

.team-delete-cross:hover {
  transform: scale(1.2);
  color: #c82333;
}

.team-name-input {
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  width: 59.5%;
  margin: 0 auto;
}

.team-template-players {
  display: flex;
  flex-direction: row;
  gap: 24px;
  margin-top: 16px;
}

.player-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex: 1;
}

@media (max-width: 768px) {
  .team-template-players {
    flex-direction: column;
    gap: 16px;
  }
}

.player-avatar-bubble {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 1px dashed rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform .2s, border-color .2s, opacity .2s;
}

.player-avatar-bubble img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.player-avatar-bubble.fallback span {
  font-weight: 600;
  font-size: 48px;
  color: var(--text);
  opacity: 0.85;
  line-height: 1;
}

.player-avatar-bubble.fallback svg {
  width: 100%;
  height: 100%;
  display: block;
}

.player-avatar-bubble.readonly {
  cursor: default;
  opacity: 0.85;
}

.player-avatar-bubble.interactive:hover {
  transform: scale(1.05);
  border-color: var(--primary);
}

[data-theme="light"] .player-avatar-bubble {
  border-color: rgba(0,0,0,0.2);
  background: rgba(0,0,0,0.05);
}

.avatar-upload-area {
  transition: background 0.2s, border-color 0.2s;
}

[data-theme="light"] .avatar-upload-area {
  background: rgba(0, 0, 0, 0.03);
  border-color: var(--border);
}

.player-input {
  width: 100%;
  text-align: center;
}

.team-stats-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.team-stats-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  text-align: center;
}

.team-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  justify-content: center;
}

.team-stat-item {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.team-stat-item strong {
  color: var(--text);
  font-weight: 600;
  margin-left: 4px;
}

@media (max-width: 768px) {
  .team-stats-row {
    gap: 10px 12px;
    justify-content: flex-start;
  }
  
  .team-stat-item {
    font-size: 11px;
  }
}

.team-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.team-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.team-card-title {
  font-size: 16px;
  font-weight: 600;
}

.team-player-name {
  font-size: 14px;
  color: var(--text);
}

.team-card button.danger {
  align-self: flex-end;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
  flex-wrap: nowrap;
}
.tabs .tab {
  flex: 0 0 auto;
}
.tabs::-webkit-scrollbar {
  height: 4px;
}
.tabs::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
#tab-teams {
  margin-left: auto;
}
#panel-teams {
  width: 100%;
  max-width: 100%;
}
.tab {
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  cursor: pointer;
  transition: .2s;
}
.tab.active {
  color: var(--text);
  border-color: var(--primary);
  background: rgba(47,129,247,.12);
}
.tab:hover {
  color: var(--text);
}
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

#matrixQual .card, #matrixFinal .card { overflow: hidden; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 720px; }

.row { display: grid; gap: 12px; margin-bottom: 12px; }
.row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { font-size: 12px; color: var(--muted); }
input, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  background: #0b0f14;
  border: 1px solid var(--border);
  color: var(--text);
}
/* Light theme inputs */
[data-theme="light"] input,
[data-theme="light"] select {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border);
}
button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
}
button.danger { background: var(--danger); }

.icon-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 8px;
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--primary);
}
.top-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.list {
  border-top: 1px solid var(--border);
}
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.muted { color: var(--muted); }

table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
}
th, td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: center;
  background: transparent; /* Прозрачный фон для PNG изображений */
}
th { background: #0f141a; color: var(--muted); font-weight: 600; }
td.right, th.right { text-align: right; }
.col-idx { min-width: 48px; }
.col-team { min-width: 200px; text-align: center; }
.col-stat { min-width: 60px; width: 80px; }
.col-sr { width: 126px; white-space: nowrap; }
.td-muted { background: #0f141a; color: var(--muted); }
/* Light table header/diagonal */
[data-theme="light"] th { background: #f0f2f6; }
[data-theme="light"] .td-muted { background: #f0f2f6; color: var(--muted); }

/* Изображения в ячейках таблицы должны быть на прозрачном фоне */
td img {
  background: transparent;
  display: block;
}
.cell-input {
  width: 64px;
  padding: 6px 8px;
  background: #0b0f14;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  text-align: center;
}
.cell-editor input { outline: none; }
[data-theme="light"] .cell-input { background: #ffffff; color: var(--text); }
.cell-editor {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
}
.cell-num {
  width: 42px;
  padding: 6px 6px;
  text-align: center;
  background: #0b0f14;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
}
[data-theme="light"] .cell-num { background: #ffffff; color: var(--text); }
.cell-colon { color: var(--muted); }

@media (max-width: 768px) and (orientation: portrait) {
  .table-scroll {
    zoom: 0.7;
  }
  @supports not (zoom: 0.7) {
    .table-scroll {
      transform: scale(0.7);
      transform-origin: top left;
    }
  }
}

/* Mobile tweaks */
#matrix { overflow-x: visible; }
/* remove fixed min-width to avoid horizontal page scroll */
table { min-width: 0; }
@media (max-width: 640px) {
  .team-edit .name-input { width: 160px; }
  .cell-num { width: 36px; padding: 8px 6px; }
  .col-team { min-width: 200px; }
  .col-idx { min-width: 40px; }
}

/* Hide number spinners (just in case) */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
}

/* Disabled inputs styling */
input:disabled,
input[readonly],
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--panel) !important;
}

[data-theme="light"] input:disabled,
[data-theme="light"] input[readonly],
[data-theme="light"] select:disabled {
  background: #f6f8fa !important;
}
.team-edit { display: grid; gap: 6px; }
.team-edit .name-input { width: 220px; }
.team-edit .pair-row { display: grid; gap: 6px; grid-template-columns: 1fr 1fr; }
.team-edit input {
  padding: 6px 8px;
  background: #0b0f14;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
}
[data-theme="light"] .team-edit input {
  background: #ffffff;
  color: var(--text);
}
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
}
.tag.ok { background: rgba(63,185,80,.12); border-color: rgba(63,185,80,.5); }
.tag.bad { background: rgba(248,81,73,.12); border-color: rgba(248,81,73,.5); }

.team-display {
  padding: 4px 0;
  line-height: 1.4;
  text-align: center;
  position: relative;
}
.team-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.team-info-icon {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 5;
  opacity: 0.7;
  transition: opacity 0.2s, background 0.2s;
  user-select: none;
}

.team-info-icon:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

.team-card-popup {
  width: 90% !important;
  max-width: 500px !important;
}

@media (max-width: 768px) {
  .container {
    padding: 12px;
  }
  
  .card {
    padding: 12px;
  }
  
  .tab-panel {
    width: 100%;
  }
  
  .team-template-card {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  #teamsList {
    width: 100% !important;
  }
  
  #panel-teams {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
  }
  
  .team-card-overlay {
    align-items: stretch !important;
    justify-content: stretch !important;
    padding: 0 !important;
  }
  
  .team-card-popup {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 16px !important;
    border-radius: 0 !important;
    max-height: 100vh !important;
    height: 100vh !important;
    box-sizing: border-box !important;
    align-self: stretch !important;
  }
}
.team-players {
  font-size: 0.9em;
  color: var(--muted);
}


