* {
  box-sizing: border-box;
}

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e1e4e8;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --win: #059669;
  --loss: #dc2626;
  --round-label: #6b7280;
}

html {
  direction: rtl;
}

body {
  margin: 0;
  font-family: "Vazirmatn", Tahoma, "Segoe UI", Arial, sans-serif;
  font-feature-settings: "ss01", "ss02";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  text-align: right;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1,
.header .subtitle {
  direction: rtl;
}

.header h1 {
  font-size: 1.85rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}

/* Setup section */
.setup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.players-input label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.input-row {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.input-row input {
  flex: 1;
  text-align: right;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.input-row input::placeholder {
  color: var(--muted);
}

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

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.5rem 0;
}

.players-input textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  resize: vertical;
  margin-bottom: 0.5rem;
  text-align: right;
  direction: rtl;
}

.players-input textarea::placeholder {
  color: var(--muted);
}

button {
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: var(--border);
  color: var(--text);
  font-size: 0.875rem;
}

button.secondary:hover {
  background: #d1d5db;
}

.players-list {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.players-list strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

#players {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

#players li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}

#players li .player-name {
  flex: 1;
  min-width: 0;
}

#players li .paid-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
  user-select: none;
}

#players li .paid-toggle input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--win);
  cursor: pointer;
}

#players li .paid-toggle input:checked + .paid-label {
  color: var(--win);
  font-weight: 500;
}

#players li button.remove {
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

#players li button.remove:hover {
  color: var(--loss);
  border-color: var(--loss);
}

.generate-row {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.bracket-size-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Bracket section */
.bracket-section {
  margin-top: 2rem;
}

.bracket-actions {
  margin-bottom: 1rem;
}

.bracket-container {
  overflow-x: auto;
  padding-bottom: 1rem;
  direction: rtl;
}

.bracket {
  display: flex;
  gap: 2rem;
  min-width: min-content;
  padding: 1rem 0;
  direction: rtl;
}

.round {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 0.5rem;
  min-width: 200px;
  direction: rtl;
}

.round-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--round-label);
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
  text-align: right;
  direction: rtl;
}

.match-block {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  direction: rtl;
}

.match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-width: 180px;
  direction: rtl;
  text-align: right;
}

.match,
.match * {
  direction: rtl;
  text-align: right;
}

.match-header {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.25rem;
  padding-inline: 0.5rem 0.25rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  direction: rtl;
}

.slot {
  padding: 0.5rem;
  padding-inline: 0.75rem 0.5rem;
  min-height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  text-align: right;
  direction: rtl;
  unicode-bidi: embed;
}

.slot:last-child {
  border-bottom: none;
}

.slot.empty {
  color: var(--muted);
  font-style: italic;
}

.slot.bye {
  color: var(--muted);
  font-style: italic;
}

.slot.winner-placeholder {
  font-size: 0.85em;
  color: var(--muted);
}

.champion-box .name.winner-placeholder {
  font-style: italic;
  font-weight: normal;
}

.slot.winner {
  background: rgba(5, 150, 105, 0.12);
  font-weight: 600;
  color: var(--win);
}

.slot.loser {
  color: var(--muted);
  opacity: 0.8;
}

.match.pick-winner .slot:not(.winner):not(.loser) {
  cursor: pointer;
}

.match.pick-winner .slot:not(.winner):not(.loser):hover {
  background: rgba(37, 99, 235, 0.08);
}

/* Connector lines (optional visual) */
.round:not(:last-child) .match-block {
  position: relative;
}

/* Champion */
.champion-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 200px;
}

.champion-box {
  background: linear-gradient(135deg, rgba(5, 150, 105, 0.15), rgba(5, 150, 105, 0.05));
  border: 2px solid var(--win);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  text-align: center;
  direction: rtl;
}

.champion-box .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--win);
  margin-bottom: 0.35rem;
}

.champion-box .name {
  font-size: 1.1rem;
  font-weight: 700;
}

.champion-box .name.empty {
  color: var(--muted);
  font-style: italic;
  font-weight: normal;
}
