/* ==================== BASE ==================== */
:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --surface2: #2a2a2a;
  --border: #3a3a3a;
  --primary: #d600e6;
  --primary-dark: #b000c0;
  --primary-glow: rgba(214, 0, 230, 0.15);
  --accent: #ff00ff;
  --danger: #ff5f6d;
  --danger-dark: #d74250;
  --warning: #ffb020;
  --text: #f5f5f5;
  --text-dim: #888888;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --green: #00e676;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

html {
  background: var(--bg);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea, a, [onclick] {
  -webkit-appearance: none;
  touch-action: manipulation;
  cursor: pointer;
}

input[type="text"],
input[type="number"] {
  -webkit-appearance: none;
  appearance: none;
  cursor: text;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body.modal-open {
  overflow: hidden;
}

body.license-locked {
  overflow: hidden;
}

#app {
  max-width: 500px;
  margin: 0 auto;
  padding: var(--safe-top) 16px var(--safe-bottom);
  padding-bottom: calc(var(--safe-bottom) + 20px);
  transition: filter 0.25s ease, opacity 0.25s ease;
}

body.license-locked #app {
  pointer-events: none;
  user-select: none;
  filter: blur(14px) saturate(0.7);
  opacity: 0.28;
}

/* ==================== SCREENS ==================== */
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== HEADER ==================== */
.header {
  text-align: center;
  padding: 20px 0 16px;
  position: relative;
}

.header h1 {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
}

.back-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== CARD ==================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* ==================== FORM ==================== */
.form-group {
  margin-bottom: 20px;
}

.form-group.compact {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.form-group.compact label {
  min-width: 80px;
  font-size: 14px;
  margin-bottom: 0;
}

.form-group.compact input {
  flex: 1;
}

.form-group label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.form-group small {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 6px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus {
  border-color: var(--primary);
}

/* ==================== STEPPER ==================== */
.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stepper input {
  text-align: center;
  width: 80px;
  font-size: 22px;
  font-weight: 700;
}

.stepper-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.stepper-btn:active {
  background: var(--primary-dark);
  transform: scale(0.95);
}

/* ==================== BUTTONS ==================== */
.btn {
  padding: 14px 24px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

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

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

.btn.primary:active {
  opacity: 0.85;
}

.btn.secondary {
  background: var(--surface2);
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn.accent {
  background: linear-gradient(135deg, var(--green), #00c853);
  color: white;
}

.btn.danger {
  background: linear-gradient(135deg, var(--danger), #ff7b54);
  color: white;
}

.btn.danger:active {
  background: linear-gradient(135deg, var(--danger-dark), #e1603b);
}

.btn.full {
  width: 100%;
  display: block;
}

/* ==================== TABS ==================== */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-top: 12px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--primary);
  color: white;
}

.tab-content { display: none; padding-top: 16px; }
.tab-content.active { display: block; }

/* ==================== ROUND ==================== */
.round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.round-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge.active {
  background: var(--primary-glow);
  color: var(--primary);
}

.badge.completed {
  background: rgba(0, 230, 118, 0.15);
  color: var(--green);
}

/* ==================== MATCH CARD ==================== */
.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.court-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.match-teams {
  display: flex;
  align-items: center;
  gap: 8px;
}

.team {
  flex: 1;
  text-align: center;
}

.team-players {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.player-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vs {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-dim);
  flex-shrink: 0;
}

.score-input {
  width: 80px !important;
  text-align: center;
  font-size: 22px !important;
  font-weight: 800;
  padding: 10px 4px !important;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  margin: 0 auto;
  display: block;
  -moz-appearance: textfield;
}

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

.score-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.score-input:disabled {
  opacity: 0.5;
}

/* ==================== ROUND ACTIONS ==================== */
.round-actions {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.management-card {
  margin-top: 16px;
}

.management-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.management-text {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 14px;
}

.management-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.license-summary {
  background: linear-gradient(180deg, rgba(214, 0, 230, 0.12), rgba(42, 42, 42, 0.9));
  border: 1px solid rgba(214, 0, 230, 0.18);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.license-summary strong {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
}

.license-summary p {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

.license-summary p + p {
  margin-top: 4px;
}

.warning-text {
  color: var(--warning);
}

/* ==================== RANKING ==================== */
.ranking-row {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--surface2);
}

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

.rank {
  width: 40px;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  flex-shrink: 0;
}

.rank-name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

.rank-points {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
}

.top-1 .rank-name { color: var(--gold); }
.top-2 .rank-name { color: var(--silver); }
.top-3 .rank-name { color: var(--bronze); }

/* ==================== PODIUM ==================== */
.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 8px;
  padding: 30px 10px 20px;
}

.podium-place {
  text-align: center;
  flex: 1;
  max-width: 120px;
}

.podium-name {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.podium-points {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.podium-block {
  font-size: 24px;
  font-weight: 900;
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.first .podium-block {
  height: 100px;
  background: linear-gradient(180deg, var(--gold), #b8860b);
}

.first .podium-name { color: var(--gold); }

.second .podium-block {
  height: 70px;
  background: linear-gradient(180deg, var(--silver), #808080);
}

.second .podium-name { color: var(--silver); }

.third .podium-block {
  height: 50px;
  background: linear-gradient(180deg, var(--bronze), #8b4513);
}

.third .podium-name { color: var(--bronze); }

/* ==================== HISTORY ==================== */
.history-round {
  margin-bottom: 12px;
}

.history-round h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--primary);
}

.history-match {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface2);
  font-size: 13px;
}

.history-match:last-child {
  border-bottom: none;
}

.history-team {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}

.history-team.winner {
  color: var(--green);
}

.history-team strong {
  font-size: 16px;
  min-width: 28px;
  text-align: center;
}

.history-vs {
  color: var(--text-dim);
  font-weight: 700;
  margin: 0 6px;
}

.empty-text {
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
}

/* ==================== DIALOG ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: rgba(5, 5, 12, 0.78);
  backdrop-filter: blur(10px);
  z-index: 999;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  width: min(100%, 420px);
  background: linear-gradient(180deg, rgba(214, 0, 230, 0.1), rgba(26, 26, 26, 0.98));
  border: 1px solid rgba(214, 0, 230, 0.22);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.45);
}

.modal-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 10px;
}

.modal-message {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

/* ==================== LICENSE OVERLAY ==================== */
.license-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(24px, var(--safe-top)) 16px max(24px, var(--safe-bottom));
  background:
    radial-gradient(circle at top, rgba(214, 0, 230, 0.25), transparent 38%),
    linear-gradient(180deg, rgba(5, 5, 12, 0.96), rgba(13, 13, 13, 0.98));
  z-index: 1200;
}

.license-overlay.active {
  display: flex;
}

.license-shell {
  width: min(100%, 440px);
}

.license-card {
  background: rgba(26, 26, 26, 0.94);
  border: 1px solid rgba(214, 0, 230, 0.22);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.45);
}

.license-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(214, 0, 230, 0.15);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.license-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 10px;
}

.license-text {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.65;
}

.license-info {
  margin-top: 18px;
  margin-bottom: 18px;
  display: grid;
  gap: 10px;
}

.license-info-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.license-info-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.license-info-value {
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.license-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.license-field {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.license-field:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.license-error {
  min-height: 20px;
  color: #ff9aa5;
  font-size: 13px;
  line-height: 1.5;
}

.license-help {
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}

.license-help a {
  color: var(--primary);
}

/* ==================== PLAYER NAMES SCROLL ==================== */
#player-names-list {
  max-height: 55vh;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-right: 4px;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 520px) {
  .match-teams {
    flex-direction: column;
    align-items: stretch;
  }

  .team {
    width: 100%;
  }

  .vs {
    padding: 2px 0;
  }

  .history-match {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .history-team {
    padding: 0;
  }

  .history-vs {
    text-align: center;
    margin: 0;
  }
}

@media (max-width: 380px) {
  .player-chip { font-size: 11px; }
  .score-input { width: 70px !important; font-size: 18px !important; }
  .form-group.compact {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .form-group.compact label {
    min-width: 0;
  }
}
