*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

#app {
  max-width: 100%;
  padding: 0 16px 40px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0 16px;
  border-bottom: 1px solid #21262d;
  margin-bottom: 32px;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: #f0f6fc;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: #8b949e;
}

.role-badge {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #1f6feb;
  color: #fff;
  padding: 3px 8px;
  border-radius: 4px;
  vertical-align: middle;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.connected {
  background: #3fb950;
}

.status-dot.disconnected {
  background: #f85149;
}

.hidden {
  display: none !important;
}

/* ─── Landing page ────────────────────────────────────────────────────────── */

.landing {
  max-width: 400px;
  margin: 0 auto;
  text-align: center;
}

.role-select {
  margin-top: 48px;
}

.role-select p {
  color: #8b949e;
  margin-bottom: 24px;
  font-size: 1.1rem;
}

.role-btn {
  display: block;
  width: 100%;
  padding: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  transition: background 0.2s, border-color 0.2s;
}

.host-btn {
  background: #1f6feb;
  color: #fff;
  border: 1px solid #1f6feb;
}

.host-btn:hover {
  background: #388bfd;
}

.voter-btn {
  background: #238636;
  color: #fff;
  border: 1px solid #238636;
}

.voter-btn:hover {
  background: #2ea043;
}

.viewer-btn {
  background: #6e40c9;
  color: #fff;
  border: 1px solid #6e40c9;
}

.viewer-btn:hover {
  background: #8957e5;
}

.viewer-badge {
  background: #6e40c9;
}

/* ─── Upload section ──────────────────────────────────────────────────────── */

#upload-section {
  max-width: 600px;
  margin: 0 auto;
}

#drop-zone {
  border: 2px dashed #30363d;
  border-radius: 12px;
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: #161b22;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: #58a6ff;
  background: #1c2128;
}

#drop-zone p {
  color: #8b949e;
  margin-bottom: 16px;
  font-size: 1rem;
}

#drop-zone strong {
  color: #e1e4e8;
}

#file-input {
  display: none;
}

.upload-error {
  color: #f85149;
  font-size: 0.85rem;
  margin-top: 12px;
}

#browse-btn {
  background: #21262d;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 8px 20px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s, border-color 0.2s;
}

#browse-btn:hover {
  background: #30363d;
  border-color: #8b949e;
}

/* ─── Bracket controls ────────────────────────────────────────────────────── */

#bracket-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 20px;
  gap: 16px;
  flex-wrap: wrap;
}

#match-status {
  font-size: 0.875rem;
  color: #8b949e;
  min-height: 1.2em;
}

#download-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#download-csv,
#download-json {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid;
  transition: background 0.2s;
}

#download-csv {
  background: #1f6feb;
  color: #fff;
  border-color: #1f6feb;
}

#download-csv:hover {
  background: #388bfd;
}

#download-json {
  background: #6e40c9;
  color: #fff;
  border-color: #6e40c9;
}

#download-json:hover {
  background: #8957e5;
}

#new-bracket-btn {
  padding: 8px 16px;
  background: transparent;
  color: #8b949e;
  border: 1px solid #30363d;
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

#new-bracket-btn:hover {
  color: #e1e4e8;
  border-color: #8b949e;
}

/* ─── Match panel ─────────────────────────────────────────────────────────── */

#match-panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 24px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  position: sticky;
  top: 12px;
  z-index: 100;
}

.match-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

#panel-match-label {
  font-size: 1.1rem;
  font-weight: 600;
  color: #f0f6fc;
}

.small-btn {
  padding: 4px 12px;
  background: transparent;
  color: #8b949e;
  border: 1px solid #30363d;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.small-btn:hover {
  color: #e1e4e8;
  border-color: #8b949e;
}

.match-panel-teams {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.vs-label {
  color: #484f58;
  font-weight: 600;
  font-size: 0.9rem;
}

.winner-btn {
  flex: 1;
  min-width: 140px;
  padding: 10px 16px;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.winner-btn-a {
  background: #1f6feb;
}

.winner-btn-a:hover {
  background: #388bfd;
}

.winner-btn-b {
  background: #d18f1e;
}

.winner-btn-b:hover {
  background: #e0a030;
}

.match-panel-votes {
  font-size: 0.9rem;
  color: #c9d1d9;
}

.vote-bar {
  display: flex;
  height: 32px;
  border-radius: 6px;
  overflow: hidden;
  background: #21262d;
}

.vote-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-width: 0;
  transition: width 0.3s ease;
}

.seg-a {
  background: #1f6feb;
}

.seg-b {
  background: #d18f1e;
}

.seg-abstain {
  background: #484f58;
}

.seg-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  padding: 0 6px;
}

.vote-bar-empty {
  font-size: 0.8rem;
  color: #484f58;
  text-align: center;
  padding: 4px 0;
}

/* ─── Bracket container ───────────────────────────────────────────────────── */

#bracket-container {
  display: flex;
  flex-direction: column;
  gap: 32px;
  overflow-x: auto;
  padding-bottom: 16px;
  min-height: 200px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

@media (min-width: 768px) {
  #bracket-container {
    padding-left: 48px;
    padding-right: 48px;
  }
}

.region-section {
  display: flex;
  flex-direction: column;
}

.region-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #58a6ff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid #21262d;
}

.region-bracket {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}

.round-column {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex-shrink: 0;
  min-width: 160px;
}

.round-header {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 8px;
  border-bottom: 1px solid #21262d;
  margin-bottom: 4px;
}

.match-wrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex: none;
  position: relative;
}

.match-block {
  display: flex;
  flex-direction: column;
  width: 152px;
  border: 1px solid #30363d;
  border-radius: 8px;
  overflow: hidden;
  background: #161b22;
  position: relative;
  z-index: 1;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.match-block.match-clickable {
  cursor: pointer;
}

.match-block.match-clickable:hover {
  border-color: #58a6ff;
}

.match-block.match-selected {
  border-color: #58a6ff;
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.3);
}

.match-block.has-winner {
  border-color: #238636;
}

.match-divider {
  height: 1px;
  background: #21262d;
}

.slot {
  padding: 7px 10px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  user-select: none;
  position: relative;
  transition: background 0.15s;
}

.slot.bye {
  opacity: 0.35;
  font-style: italic;
}

.slot.tbd {
  opacity: 0.4;
  font-style: italic;
}

.slot.winner {
  background: #0d2818;
}

.slot-seed {
  font-size: 0.7rem;
  color: #8b949e;
  min-width: 18px;
  text-align: right;
  flex-shrink: 0;
}

.slot-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.clear-winner-btn {
  background: transparent;
  border: none;
  color: #f85149;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.clear-winner-btn:hover {
  opacity: 1;
}

/* ─── Voter page ──────────────────────────────────────────────────────────── */

.voter-app {
  max-width: 500px;
  margin: 0 auto;
}

#waiting-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 200px;
  padding-top: 60px;
}

.waiting-message {
  text-align: center;
}

.waiting-message p {
  color: #8b949e;
  font-size: 1.1rem;
  margin-top: 16px;
}

.pulse-dot {
  width: 16px;
  height: 16px;
  background: #58a6ff;
  border-radius: 50%;
  margin: 0 auto;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

.vote-prompt {
  text-align: center;
  padding-top: 40px;
}

.vote-label {
  font-size: 1.1rem;
  color: #8b949e;
  margin-bottom: 24px;
}

.vote-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vote-btn {
  padding: 20px 24px;
  border-radius: 10px;
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  border: 2px solid;
}

.vote-btn:active {
  transform: scale(0.98);
}

.vote-a-btn {
  background: #1a3a5c;
  color: #58a6ff;
  border-color: #1f6feb;
}

.vote-a-btn:hover {
  background: #1f4070;
}

.vote-a-btn.selected {
  background: #1f6feb;
  color: #fff;
  border-color: #58a6ff;
}

.vote-b-btn {
  background: #3d2000;
  color: #f0a030;
  border-color: #d18f1e;
}

.vote-b-btn:hover {
  background: #4a2800;
}

.vote-b-btn.selected {
  background: #d18f1e;
  color: #fff;
  border-color: #f0a030;
}

.vote-abstain-btn {
  background: #21262d;
  color: #8b949e;
  border-color: #30363d;
}

.vote-abstain-btn:hover {
  background: #30363d;
}

.vote-abstain-btn.selected {
  background: #484f58;
  color: #fff;
  border-color: #8b949e;
}

#vote-confirmation {
  margin-top: 20px;
  font-size: 0.95rem;
  color: #3fb950;
  font-weight: 600;
}

/* ─── Connector columns ───────────────────────────────────────────────────── */

.connector-col {
  min-width: 24px !important;
  width: 24px;
}

/* ─── Timer ──────────────────────────────────────────────────────────────── */

.match-panel-timer {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #21262d;
}

.timer-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 8px;
}

.timer-preset-btn {
  padding: 4px 10px;
  background: #21262d;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.timer-preset-btn:hover {
  background: #30363d;
  border-color: #8b949e;
}

#timer-custom {
  width: 60px;
  padding: 4px 8px;
  background: #0d1117;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 4px;
  font-size: 0.8rem;
}

.timer-options-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.auto-timer-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: #8b949e;
  cursor: pointer;
}

.timer-mode-toggle {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: #8b949e;
}

.timer-mode-toggle label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

#timer-display {
  display: flex;
  align-items: center;
  gap: 12px;
}

#timer-countdown,
#voter-timer-countdown,
#viewer-timer-countdown {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #f0f6fc;
}

#timer-mode-label,
#viewer-timer-mode {
  font-size: 0.75rem;
  color: #8b949e;
  text-transform: uppercase;
}

.timer-expired #timer-countdown,
.timer-expired #voter-timer-countdown,
.timer-expired #viewer-timer-countdown {
  color: #f85149;
}

.voter-timer {
  text-align: center;
  margin-bottom: 16px;
}

.voter-timer.timer-expired #voter-timer-countdown {
  color: #f85149;
}

.viewer-timer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viewer-timer.timer-expired #viewer-timer-countdown {
  color: #f85149;
}

.voting-locked .vote-btn {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.not-voted-count {
  font-size: 0.8rem;
  color: #8b949e;
  margin-top: 8px;
  text-align: center;
}

.match-panel-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.release-btn {
  background: #238636;
  color: #fff;
  border-color: #238636;
}

.release-btn:hover {
  background: #2ea043;
  border-color: #2ea043;
  color: #fff;
}

.voter-results {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #21262d;
}

.results-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  text-align: center;
}

/* ─── Saved brackets ─────────────────────────────────────────────────────── */

#saved-brackets-section {
  margin-top: 32px;
}

#saved-brackets-section h3,
.viewer-saved-section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.saved-brackets-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.saved-empty {
  color: #484f58;
  font-size: 0.85rem;
  font-style: italic;
}

.saved-bracket-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #161b22;
  border: 1px solid #21262d;
  border-radius: 8px;
  gap: 12px;
}

.saved-bracket-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.saved-bracket-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e1e4e8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-bracket-date {
  font-size: 0.75rem;
  color: #484f58;
}

.saved-bracket-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.saved-load-btn {
  background: #238636 !important;
  color: #fff !important;
  border-color: #238636 !important;
}

.saved-load-btn:hover {
  background: #2ea043 !important;
}

.saved-delete-btn {
  color: #f85149 !important;
  border-color: #30363d !important;
}

.saved-delete-btn:hover {
  border-color: #f85149 !important;
}

/* ─── Name modal ─────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
}

.modal-box h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #f0f6fc;
  margin-bottom: 16px;
}

.modal-box input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  background: #0d1117;
  color: #e1e4e8;
  border: 1px solid #30363d;
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.modal-box input[type="text"]:focus {
  outline: none;
  border-color: #58a6ff;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-confirm-btn {
  padding: 8px 16px;
  background: #238636;
  color: #fff;
  border: 1px solid #238636;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-confirm-btn:hover {
  background: #2ea043;
}

/* ─── Save indicator ─────────────────────────────────────────────────────── */

.save-indicator {
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 12px;
  transition: opacity 0.3s;
}

.save-ok {
  color: #3fb950;
}

.save-error {
  color: #f85149;
}

/* ─── Saved banner (viewer) ──────────────────────────────────────────────── */

.saved-banner {
  background: #1c1d5c;
  border: 1px solid #3b3dbf;
  border-radius: 8px;
  padding: 8px 16px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: #a5a6ff;
  text-align: center;
}

.viewer-saved-section {
  margin-top: 32px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0f1117;
}

::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}
