:root {
  --bg: #05080d;
  --panel: #0b111a;
  --panel2: #101925;
  --line: #26384f;
  --text: #f4f7fb;
  --muted: #8997aa;
  --blue: #1477ff;
  --blue2: #55a2ff;
  --white: #fff;
  --gold: #ffd700;
  --green: #27ae60;
  --red: #e74c3c;
  --radius: 8px;
  --radius-lg: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: 8px 18px;
  border: none; border-radius: 5px;
  cursor: pointer; font-size: 0.9rem; font-weight: 700;
  text-decoration: none; color: #fff;
  background: var(--blue);
  transition: all .2s;
}
.btn:hover { box-shadow: 0 8px 30px rgba(20,119,255,.25); }
.btn-small { padding: 6px 14px; font-size: .8rem; }
.btn-primary { background: var(--blue); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: #f39c12; }
.btn-warning:hover { background: #d68910; }
.btn-reset { background: #7f8c8d; }
.btn-reset:hover { background: #6c7a7d; }
.btn-edit { background: var(--green); }
.btn-edit:hover { background: #1e8449; }
.btn-cancel { background: #555; }
.btn-cancel:hover { background: #444; }
.btn-logout { background: var(--red); }
.btn-block { display: block; width: 100%; }
.btn-outline { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-outline:hover { border-color: var(--blue); color: var(--blue2); }

/* ===== Header ===== */
.header {
  position: sticky; top: 0; z-index: 50;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 5vw; height: 70px;
  background: rgba(3,7,12,.88); backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.header h1, .header-left h1 { font-size: 1.1rem; color: var(--text); font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-right span { color: var(--muted); font-size: .85rem; }

/* ===== Login ===== */
.login-container {
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; background: var(--bg);
}
.login-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 40px;
  width: 380px; box-shadow: 0 16px 48px rgba(0,0,0,.4);
}
.login-box h1 { text-align: center; color: var(--text); margin-bottom: 32px; font-size: 1.3rem; }
.login-hint { margin-top: 24px; text-align: center; color: var(--muted); font-size: .85rem; line-height: 1.8; }
.login-hint a { color: var(--blue2); text-decoration: none; }
.login-hint a:hover { text-decoration: underline; }
.progress-hint { color: var(--muted); font-size: .8rem; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; color: var(--muted); font-size: .9rem; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--bg); color: var(--text); font-size: .95rem; outline: none;
}
.form-group input:focus, .form-group select:focus { border-color: var(--blue); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.error-message {
  background: rgba(231,76,60,.15); border: 1px solid var(--red);
  color: var(--red); padding: 10px; border-radius: 5px; margin-bottom: 16px; text-align: center;
}

/* ===== Admin Container ===== */
.admin-container {
  max-width: 1400px; margin: 0 auto; padding: 24px 32px;
  overflow-y: auto; flex: 1;
}

/* ===== Settings Sections ===== */
.password-section {
  background: var(--panel); border-radius: var(--radius-lg);
  padding: 1.5rem; margin-bottom: 1.5rem; border: 1px solid var(--line);
}
.password-form-box { max-width: 500px; }
.password-form .form-group { margin-bottom: 12px; }
.password-form .btn { margin-top: 8px; }
.section-title { font-size: 1.2rem; margin: 0 0 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--line); }
.toolbar-hint { color: var(--muted); font-size: .85rem; }

/* ===== Icon Management ===== */
.icon-management-section {
  background: var(--panel); border-radius: var(--radius-lg);
  padding: 1.5rem; margin-bottom: 1.5rem; border: 1px solid var(--line);
}
.icon-section-title { margin: 0 0 1rem; }
.icon-management-body { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.icon-upload-box { flex: 1; min-width: 300px; }
.icon-upload-box h3 { margin: 0 0 .75rem; font-size: .95rem; color: var(--text); }
.icon-form .form-row { display: flex; gap: .75rem; align-items: flex-end; }
.icon-list-box { flex: 0 0 280px; background: var(--panel2); border-radius: var(--radius); padding: 1rem; }
.icon-list-box h3 { margin: 0 0 .75rem; font-size: .95rem; color: var(--text); }
.icon-grid { display: flex; flex-wrap: wrap; gap: .5rem; }
.icon-item {
  display: flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.06); border-radius: 5px; padding: .4rem .6rem;
}
.icon-thumb { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.icon-team-label { font-size: .8rem; color: var(--text); max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-del-btn { font-size: .65rem !important; padding: 2px 6px !important; }
.icon-hidden { display: none; }
.icon-empty-hint { color: var(--muted); font-size: .8rem; }
.icon-count { color: var(--muted); font-weight: 400; font-size: .85rem; }
.icon-toggle-btn { margin-top: .5rem; background: var(--panel2); cursor: pointer; }
.icon-toggle-btn:hover { background: #1a2a3a; }
.icon-msg { margin-top: .5rem; padding: .5rem; border-radius: 5px; font-size: .85rem; }
.icon-msg-ok { background: #1a3a1a; color: #a6e3a1; border: 1px solid #2a5a2a; }
.icon-msg-err { background: #3a1a1a; color: #f38ba8; border: 1px solid #5a2a2a; }
.icon-msg-info { background: #1a2a3a; color: #89b4fa; border: 1px solid #2a3a5a; }

/* ===== Admin Toolbar ===== */
.admin-toolbar {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px; padding: 12px 16px;
  background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line);
}
.admin-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ===== Bracket Sections (Admin) ===== */
.bracket-section { margin-bottom: 32px; }
.bracket-section h2 {
  font-size: 1.1rem; padding: 10px 20px; border-radius: var(--radius) var(--radius) 0 0; margin-bottom: 0;
}
.upper-bracket h2 { background: #0d1f33; color: var(--blue2); border: 1px solid var(--line); border-bottom: 0; }
.lower-bracket h2 { background: #240d15; color: #e87dbe; border: 1px solid var(--line); border-bottom: 0; }
.grand-bracket h2 { background: #1f1806; color: var(--gold); border: 1px solid var(--line); border-bottom: 0; }
.round-row {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 12px 16px; background: var(--panel2);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.round-row:last-child { border-radius: 0 0 var(--radius) var(--radius); }

/* ===== Match Cards (Admin) ===== */
.match-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 16px;
  min-width: 280px; max-width: 350px; flex: 1;
  transition: all .2s;
}
.match-card:hover { border-color: var(--blue); box-shadow: 0 4px 16px rgba(20,119,255,.1); }
.match-card.completed { background: #0a1a0a; border-color: #1a3a1a; }
.match-label {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.match-name { font-weight: 700; color: var(--gold); font-size: .95rem; }
.match-round { font-size: .75rem; color: var(--muted); background: var(--bg); padding: 2px 8px; border-radius: 10px; }
.match-teams { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.team { flex: 1; padding: 6px 8px; background: var(--bg); border-radius: 4px; display: flex; align-items: center; gap: 6px; font-size: .9rem; }
.team.winner { background: #0a1a0a; border: 1px solid #1a3a1a; }
.team.loser { background: #1a0a0a; border: 1px solid #3a1a1a; }
.vs { font-weight: 700; color: var(--blue); font-size: .8rem; }
.match-score { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.match-result { font-size: .85rem; color: var(--green); }
.match-result strong { color: var(--gold); }
.match-pending { font-size: .85rem; color: var(--muted); font-style: italic; margin-bottom: 8px; }
.match-champion { font-size: 1rem; color: var(--gold); text-align: center; margin-top: 8px; padding: 6px; background: rgba(255,215,0,.1); border-radius: 5px; }
.match-note { font-size: .75rem; color: #f39c12; margin-top: 4px; }
.match-flow { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.flow-tag { font-size: .7rem; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.flow-win { background: rgba(39,174,96,.2); color: var(--green); }
.flow-lose { background: rgba(231,76,60,.2); color: var(--red); }
.flow-champion { background: rgba(255,215,0,.2); color: var(--gold); }
.flow-third { background: rgba(192,152,83,.2); color: #cd7f32; }

/* ===== Modal ===== */
.modal {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.7); z-index: 1000; justify-content: center; align-items: center;
}
.modal-content {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 32px;
  width: 420px; box-shadow: 0 16px 48px rgba(0,0,0,.4);
}
.modal-content h3 { color: var(--text); margin-bottom: 20px; font-size: 1.2rem; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; justify-content: flex-end; }

/* ===== Third Place ===== */
.third-place-info { margin-top: 24px; display: flex; justify-content: center; }
.info-card { background: var(--panel); border: 1px solid #cd7f32; border-radius: var(--radius-lg); padding: 20px 40px; text-align: center; }
.info-card h3 { color: #cd7f32; font-size: 1.2rem; margin-bottom: 8px; }
.third-place-name { font-size: 1.3rem; color: var(--text); }
.third-place-desc { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* ===== Legend ===== */
.legend {
  display: flex; align-items: center; gap: 20px;
  padding: 8px 5vw;
  background: var(--panel); border-bottom: 1px solid rgba(255,255,255,.07);
  flex-wrap: wrap; flex-shrink: 0;
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted); }
.legend-line { display: inline-block; width: 30px; height: 3px; border-radius: 2px; }
.legend-line-win { background: var(--green); }
.legend-line-lose { background: var(--red); background-image: repeating-linear-gradient(90deg, var(--red) 0, var(--red) 5px, transparent 5px, transparent 10px); }
.legend-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend-dot-upper { background: linear-gradient(135deg,#0d1f33,#0a2747); border: 2px solid #1a6db5; }
.legend-dot-lower { background: linear-gradient(135deg,#240d15,#310a1a); border: 2px solid #b5283a; }
.legend-dot-grand { background: linear-gradient(135deg,#1f1806,#302408); border: 2px solid #c09a0a; }

/* ===== Bracket Viewer ===== */
.bracket-wrapper {
  position: relative; overflow: hidden; flex: 1;
  margin: 8px 5vw;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  min-height: 600px; cursor: grab; user-select: none;
  -ms-overflow-style: none; scrollbar-width: none;
}
.bracket-wrapper::-webkit-scrollbar { display: none; }
.bracket-inner { position: absolute; top: 0; left: 0; width: 100%; height: 100%; will-change: transform; }
.bracket-svg { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 0; }
.bracket-canvas { position: relative; z-index: 1; width: 100%; height: 120%; }

/* ===== Mind Cards (Viewer) ===== */
.mind-card {
  position: absolute;
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px;
  padding: 6px 8px; z-index: 10;
  transition: all .2s; cursor: default;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); overflow: hidden;
}
.mind-card:hover { border-color: var(--blue); box-shadow: 0 4px 16px rgba(20,119,255,.2); z-index: 20; transform: scale(1.03); }
.mind-card-upper { border-color: #1a6db5; background: linear-gradient(135deg,#0d1f33,#0a2747); border-left: 4px solid var(--blue); }
.mind-card-lower { border-color: #b5283a; background: linear-gradient(135deg,#240d15,#310a1a); border-left: 4px solid var(--red); }
.mind-card-grand { border-color: #c09a0a; background: linear-gradient(135deg,#1f1806,#302408); border-left: 4px solid var(--gold); }
.mind-completed { opacity: .9; }
.mind-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; padding-bottom: 2px; border-bottom: 1px solid rgba(255,255,255,.08); }
.mind-match-name { font-weight: 700; color: var(--gold); font-size: .82rem; }
.mind-match-round { font-size: .6rem; color: var(--muted); background: rgba(0,0,0,.4); padding: 1px 6px; border-radius: 8px; white-space: nowrap; }
.mind-card-body { display: flex; align-items: center; gap: 4px; min-height: 36px; }
.mind-team { flex: 1; padding: 4px 6px; background: rgba(0,0,0,.3); border-radius: 4px; text-align: center; font-size: .75rem; color: #d0d0d0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; display: flex; align-items: center; gap: 3px; }
.mind-team-win { background: rgba(39,174,96,.15); border: 1px solid rgba(39,174,96,.4); color: #5dfc8e; }
.mind-team-lose { background: rgba(231,76,60,.15); border: 1px solid rgba(231,76,60,.4); color: #fc7d7d; }
.mind-vs { font-weight: 700; color: var(--blue); font-size: .65rem; flex-shrink: 0; min-width: 24px; text-align: center; }
.mind-card-result { text-align: center; font-size: .7rem; color: var(--green); margin-top: 2px; }
.mind-card-result strong { color: var(--gold); }
.mind-card-note { text-align: center; font-size: .65rem; color: #f39c12; margin-top: 2px; }
.mind-third-note { color: #cd7f32; }
.mind-card-champion { text-align: center; font-size: .75rem; color: var(--gold); margin-top: 3px; padding: 2px; background: rgba(255,215,0,.1); border-radius: 4px; }
.conn-highlight { stroke-width: 5px !important; opacity: 1 !important; filter: drop-shadow(0 0 8px currentColor) drop-shadow(0 0 14px currentColor); }
.mind-team-icon { width: 14px; height: 14px; border-radius: 50%; object-fit: contain; flex-shrink: 0; border: 1px solid var(--line); }
.team-icon { width: 1.3em; height: 1.3em; border-radius: 50%; object-fit: cover; vertical-align: middle; margin-right: 4px; border: 1px solid var(--line); flex-shrink: 0; }

/* ===== Bracket Settings ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bracket-option { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; cursor: pointer; transition: all .2s; }
.bracket-option:hover { border-color: var(--blue); }
.bracket-option.active { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(20,119,255,.2); }
.bracket-option h4 { color: var(--text); margin-bottom: 6px; }
.bracket-option p { color: var(--muted); font-size: .85rem; }
.bracket-option .status { display: inline-block; font-size: .65rem; padding: 2px 8px; border-radius: 8px; margin-top: 8px; }
.bracket-option .status.active { background: rgba(20,119,255,.15); color: var(--blue2); border: 1px solid rgba(20,119,255,.3); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line);
  color: var(--text); padding: 12px 24px; border-radius: 8px;
  font-size: .9rem; z-index: 9999; display: none;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.show { display: block; animation: fadeIn .3s; }
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header { flex-direction: column; gap: 8px; padding: 12px 16px; }
  .bracket-container, .admin-container { padding: 12px 8px; }
  .match-card { min-width: 100%; max-width: 100%; }
  .round-row { flex-direction: column; }
  .modal-content { width: 90%; padding: 20px; }
  .login-box { width: 90%; padding: 24px; }
  .settings-grid { grid-template-columns: 1fr; }
}