/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
}

a { color: #63b3ed; text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  transition: opacity .15s;
}
button:hover { opacity: .85; }

input, textarea, select {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 6px;
  color: #e2e8f0;
  padding: 8px 12px;
  font-size: 14px;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #4c6ef5;
}

select { cursor: pointer; }

/* ── Buttons ── */
.btn-primary { background: #4c6ef5; color: #fff; }
.btn-secondary { background: #2d3148; color: #e2e8f0; }
.btn-danger { background: #e53e3e; color: #fff; }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 2px 6px;
  font-size: 11px;
  border-radius: 4px;
  flex-shrink: 0;
}

.btn-icon {
  background: transparent;
  border: 1px solid #2d3148;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 16px;
  line-height: 1.4;
  color: #e2e8f0;
  transition: background .15s;
}
.btn-icon:hover { background: #2d3148; }

/* ── Config page ── */
.config-wrapper {
  max-width: 640px;
  margin: 48px auto;
  padding: 0 24px;
}

.config-wrapper h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.config-wrapper .subtitle {
  color: #718096;
  margin-bottom: 32px;
  font-size: 14px;
}

.presenter-link {
  display: inline-block;
  margin-bottom: 32px;
  background: #2d3148;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
}

.card {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 24px;
}

.card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: #a0aec0;
  margin-bottom: 6px;
  font-weight: 500;
}

.error-msg {
  color: #fc8181;
  font-size: 13px;
  margin-top: 8px;
  display: none;
}

/* Tournament list */
.tournament-list { list-style: none; }

.tournament-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #2d3148;
}

.tournament-list li:last-child { border-bottom: none; }

.tournament-list .t-name { font-weight: 500; }

.tournament-list .t-meta {
  font-size: 12px;
  color: #718096;
  margin-top: 2px;
}

.t-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.active-tournament .t-name { color: #68d391; }

.active-badge {
  font-size: 10px;
  font-weight: 600;
  background: #1d4a2f;
  color: #68d391;
  border: 1px solid #2d6a45;
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 8px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.empty-state {
  color: #718096;
  font-size: 14px;
  text-align: center;
  padding: 24px 0;
}

.sidebar-empty {
  font-size: 12px;
  color: #718096;
  margin-bottom: 8px;
}

/* ── Presenter page ── */
.presenter-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}


.presenter-body {
  flex: 1;
  overflow: auto;
  padding: 48px 32px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bracket-title {
  font-size: 32px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 40px;
  letter-spacing: -0.02em;
}

.bracket-scroll {
  display: flex;
  justify-content: center;
}

.no-tournaments {
  text-align: center;
  color: #718096;
  margin-top: 80px;
  font-size: 16px;
}

/* ── Bracket layout ── */
.bracket {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  min-width: max-content;
}

.round-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-width: 180px;
}

.round-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #718096;
  text-align: center;
  margin-bottom: 12px;
}

/* Match wrapper */
.match-wrapper {
  padding: 6px 0;
}

/* Match box */
.match {
  border: 1px solid #2d3148;
  border-radius: 8px;
  overflow: hidden;
  width: 160px;
  background: #1a1d27;
  position: relative;
  min-height: 60px;
}

.match.clickable { cursor: pointer; }

.match.clickable:hover { border-color: #4c6ef5; }

.match.settled { border-color: #2d4a3e; }

.match.settled:hover { border-color: #48bb78; }

.match.empty-match {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-style: dashed;
  opacity: 0.5;
}

/* Match slots — N competitors, each separated by a line */
.match-slot {
  padding: 8px 12px;
  font-size: 13px;
  min-height: 36px;
  display: flex;
  align-items: center;
  transition: background .1s;
}

.match-slot:not(:last-child) {
  border-bottom: 1px solid #2d3148;
}

.match-slot.winner {
  font-weight: 600;
  color: #68d391;
}

.match-slot.tbd {
  color: #4a5568;
  font-style: italic;
}

/* Match edit icon overlay */
.match.editable { cursor: pointer; }

.match-edit-icon {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 11px;
  color: #4c6ef5;
  opacity: 0;
  transition: opacity .12s;
  pointer-events: none;
  line-height: 1;
}

.match.editable:hover .match-edit-icon { opacity: 1; }

/* ── Popover (winner picker) ── */
.popover-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.popover {
  position: fixed;
  z-index: 101;
  background: #1a1d27;
  border: 1px solid #4c6ef5;
  border-radius: 10px;
  padding: 12px;
  min-width: 180px;
  max-width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}

.popover h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #718096;
  margin-bottom: 10px;
}

.popover-option {
  display: block;
  width: 100%;
  text-align: left;
  background: #2d3148;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 14px;
  transition: background .12s;
}

.popover-option:last-of-type { margin-bottom: 0; }
.popover-option:hover { background: #4c6ef5; color: #fff; }

.popover-option.active {
  background: #2d4a3e;
  color: #68d391;
  font-weight: 600;
}

.popover-clear {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: #fc8181;
  border: 1px solid #fc8181;
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 8px;
  font-size: 14px;
  transition: background .12s, color .12s;
}

.popover-clear:hover { background: #fc8181; color: #1a1d2e; }

/* ── Tournament config page layout ── */
.tc-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.tc-header {
  background: #1a1d27;
  border-bottom: 1px solid #2d3148;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.tc-back {
  font-size: 13px;
  color: #718096;
  white-space: nowrap;
  flex-shrink: 0;
}

.tc-back:hover { color: #a0aec0; text-decoration: none; }

.tc-header h1 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tc-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.tc-header-actions a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.tc-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.tc-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #12151e;
  border-right: 1px solid #2d3148;
  overflow-y: auto;
  padding: 16px;
}

.tc-bracket-area {
  flex: 1;
  overflow: auto;
  padding: 32px;
}

/* ── Sidebar sections ── */
.sidebar-section { margin-bottom: 24px; }

.sidebar-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #718096;
  font-weight: 600;
  margin-bottom: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.settings-row label {
  font-size: 12px;
  color: #a0aec0;
  flex-shrink: 0;
}

.settings-row input,
.settings-row select {
  flex: 1;
  font-size: 12px;
  padding: 5px 8px;
}

.settings-row-toggle { margin-top: 4px; }

/* ── CSS toggle switch ── */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle-switch input {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
}

.toggle-track {
  width: 36px;
  height: 20px;
  background: #2d3148;
  border-radius: 20px;
  position: relative;
  transition: background .2s;
}

.toggle-switch input:checked + .toggle-track { background: #4c6ef5; }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}

.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }

/* ── Round sections in sidebar ── */
.round-section { margin-bottom: 6px; }

.round-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.round-name-input {
  flex: 1;
  font-size: 12px;
  color: #a0aec0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  min-width: 0;
}

.round-name-input:hover {
  border-color: #2d3148;
  background: #1a1d27;
}

.round-name-input:focus {
  border-color: #4c6ef5;
  background: #1a1d27;
  color: #e2e8f0;
}

.round-section-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.round-delete-btn {
  color: #718096;
  font-size: 13px;
  padding: 2px 5px;
}

.round-delete-btn:hover {
  color: #fc8181;
  background: #2d3148;
}

.tc-add-round {
  margin-top: 8px;
  width: 100%;
}

/* ── Match editor panel ── */
.me-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
}

.match-editor-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 201;
  background: #1a1d27;
  border: 1px solid #4c6ef5;
  border-radius: 12px;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  box-shadow: 0 12px 48px rgba(0,0,0,.6);
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid #2d3148;
  position: sticky;
  top: 0;
  background: #1a1d27;
  z-index: 1;
}

.editor-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.editor-close {
  background: transparent;
  color: #718096;
  padding: 2px 6px;
  font-size: 14px;
  border-radius: 4px;
}

.editor-close:hover { background: #2d3148; color: #e2e8f0; }

.editor-section {
  padding: 14px 16px;
  border-bottom: 1px solid #2d3148;
}

.editor-section:last-child { border-bottom: none; }

.editor-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #718096;
  margin-bottom: 10px;
}

/* Competitor rows in match editor */
.competitor-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.competitor-row input {
  flex: 1;
  font-size: 13px;
  padding: 5px 8px;
}

.competitor-remove-btn {
  background: transparent;
  color: #4a5568;
  border: none;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
  flex-shrink: 0;
  opacity: 0.7;
}

.competitor-remove-btn:hover {
  color: #fc8181;
  opacity: 1;
}

/* Winner select */
.editor-select {
  width: 100%;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 6px;
  color: #e2e8f0;
  padding: 6px 8px;
  font-size: 13px;
}

.editor-select:focus { outline: none; border-color: #4c6ef5; }

/* Danger section */
.editor-danger-section { background: #1a1117; }

.editor-remove-match-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: #fc8181;
  border: none;
  border-radius: 0;
  padding: 10px 16px;
  font-size: 13px;
  opacity: 0.7;
}

.editor-remove-match-btn:hover {
  opacity: 1;
  background: #2d1a1a;
}
