:root {
  --bg: #1a0f1a;
  --surface: #2a1a2a;
  --surface-2: #3a2438;
  --border: #4a3548;
  --text: #f5e6d3;
  --text-muted: #b89aa0;
  --accent: #c0392b;
  --accent-2: #e67e22;
  --success: #27ae60;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

header {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, #4a1d2c 0%, #2a1a2a 100%);
  color: var(--text);
  padding: 16px;
  text-align: center;
  border-bottom: 2px solid var(--accent);
  z-index: 5;
}

header h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

header p {
  margin: 4px 0 0;
  font-size: 0.85rem;
  opacity: 0.85;
}

main {
  padding: 16px;
  padding-bottom: 100px;
  max-width: 700px;
  margin: 0 auto;
}

h2 {
  margin: 0 0 16px;
  font-size: 1.4rem;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 8px;
}

h3 {
  margin: 24px 0 12px;
  font-size: 1.1rem;
  color: var(--text);
}

h4 {
  margin: 16px 0 6px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

p { margin: 0 0 12px; }

.empty {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 32px 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

.hint {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ----- Tabs (bottom nav) ----- */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 2px solid var(--border);
  display: flex;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 4px;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: color 0.2s;
}

.tab-btn .icon {
  font-size: 1.4rem;
}

.tab-btn.active {
  color: var(--accent-2);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ----- Buttons ----- */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-align: center;
  justify-content: center;
}

.btn:hover { background: var(--border); }
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: #a83224; }
.btn-success { background: var(--success); border-color: var(--success); color: white; }
.btn-success:hover { background: #1e8449; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { background: #962820; }
.btn-danger-outline {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text-muted);
}

.btn-icon-sm {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
}

.btn-step {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  font-weight: 600;
}

/* ----- Dashboard / podium ----- */
.podium {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.podium-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border-left: 6px solid var(--border);
  border-radius: var(--radius);
}

.podium-rank {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-2);
}

.podium-name {
  font-size: 1.1rem;
  font-weight: 600;
}

.podium-score {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-2);
}

.compact-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.compact-item {
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
}

.compact-emoji { font-size: 1.2rem; }
.compact-meta { color: var(--text-muted); font-size: 0.85rem; }
.compact-winner { font-size: 0.85rem; font-weight: 600; }

/* ----- Teams ----- */
.team-card {
  background: var(--surface);
  border-left: 6px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.team-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.team-name {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
  font-family: inherit;
}

.team-name:focus { outline: none; border-bottom-color: var(--accent); }

.team-color {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: none;
  padding: 0;
}

.member-list {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
}

.member-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: var(--surface-2);
  border-radius: 6px;
  margin-bottom: 4px;
}

.add-member {
  display: flex;
  gap: 6px;
}

.add-member input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
}

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

/* ----- Catalog ----- */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 120px;
}

.filter span {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.filter select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
}

.game-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 600px) {
  .game-grid { grid-template-columns: 1fr 1fr; }
}

.game-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: transform 0.15s;
  border: 1px solid var(--border);
}

.game-card:hover { transform: translateY(-2px); border-color: var(--accent-2); }

.game-card-head {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.game-card-title {
  margin: 0 0 6px;
  font-size: 1rem;
}

.game-card-meta {
  display: flex;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
}

.badge-outline {
  background: transparent;
  border: 1px solid;
}

/* ----- Modal ----- */
#modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

#modal.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 500px;
  width: 100%;
  position: relative;
  box-shadow: var(--shadow);
  margin: 16px 0 80px;
  border: 1px solid var(--border);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.game-rules { white-space: pre-wrap; }
.game-meta { color: var(--text-muted); font-size: 0.9rem; }

.mat-list, .res-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}

.mat-list li {
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.res-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--surface-2);
  border-left: 4px solid var(--border);
  border-radius: 6px;
  margin-bottom: 4px;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.form-field span {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.form-field input,
.form-field select,
.form-field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

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

/* ----- Validation ----- */
.val-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.val-card h3 { margin: 8px 0; font-size: 1.1rem; }
.val-card p { font-size: 0.9rem; color: var(--text-muted); }

.val-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.val-actions .btn { font-size: 0.85rem; padding: 8px 12px; }

/* ----- Scoring ----- */
.game-selector {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  margin-bottom: 12px;
}

.scoring-hint {
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-left: 3px solid var(--accent-2);
}

.score-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius);
  border-left: 6px solid var(--border);
}

.score-team {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.score-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-input {
  width: 60px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: 8px;
  font-size: 1.1rem;
  text-align: center;
  font-family: inherit;
  font-weight: 600;
}

/* ----- Participants ----- */
.participant-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
}

.participant-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface);
  border-radius: 8px;
  margin-bottom: 6px;
  border-left: 4px solid var(--accent);
}

.participant-list input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  padding: 4px 0;
}

.participant-list input:focus { outline: none; }

/* ----- Teams view (per-game) ----- */
.teams-view {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 16px;
}

.mini-team {
  background: var(--surface-2);
  border-left: 5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.mini-team-name {
  font-weight: 700;
  margin-bottom: 4px;
  font-size: 0.95rem;
}

.mini-team-members {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-team-members li {
  background: var(--surface);
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.85rem;
}

.teams-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}

.teams-row-title {
  margin: 0;
  font-size: 1.05rem;
}

.teams-picker {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  margin: 12px 0;
}

.team-count-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}

.team-count-row .btn { flex: 1; min-width: 80px; }

.btn-big {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
}

.btn-icon-text {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}

/* ----- Settings ----- */
.settings-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
