/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --bg:            #06090f;
  --surface:       #0d1423;
  --surface-hi:    #141f35;
  --border:        rgba(255, 255, 255, 0.07);
  --border-hi:     rgba(255, 255, 255, 0.14);

  --text:          #e9e2d4;
  --text-muted:    rgba(233, 226, 212, 0.45);
  --text-dim:      rgba(233, 226, 212, 0.22);

  --primary:       #6366f1;
  --primary-hi:    #818cf8;
  --primary-glow:  rgba(99, 102, 241, 0.22);
  --primary-ring:  rgba(99, 102, 241, 0.45);

  --gold:          #f0b429;
  --gold-dim:      rgba(240, 180, 41, 0.18);
  --gold-ring:     rgba(240, 180, 41, 0.4);
  --silver:        #94a3b8;
  --silver-dim:    rgba(148, 163, 184, 0.12);
  --silver-ring:   rgba(148, 163, 184, 0.3);
  --bronze:        #c27c3e;

  --danger:        #ef4444;
  --danger-dim:    rgba(239, 68, 68, 0.12);
  --danger-ring:   rgba(239, 68, 68, 0.35);

  --radius-sm:     8px;
  --radius:        12px;
  --radius-lg:     18px;
  --radius-xl:     24px;

  --transition:    0.18s ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
a { color: inherit; }

/* ============================================================
   LAYOUT
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* HEADER */
#header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(6, 9, 15, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--text);
  padding: 0;
  line-height: 1;
}
.header-brand:hover .brand-name { color: var(--primary-hi); }

.brand-name  { font-weight: 700; font-size: 16px; letter-spacing: -0.4px; transition: color var(--transition); }

.btn-settings {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  color: var(--text-muted);
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-settings:hover { background: var(--surface-hi); color: var(--text); border-color: var(--primary); }
.btn-settings .icon { width: 14px; height: 14px; }

/* MAIN */
#main {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 16px 60px;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.fade-in  { animation: fadeUp 0.24s ease-out both; }

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border-hi);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

/* ============================================================
   SCREEN WRAPPERS
   ============================================================ */
.screen { width: 100%; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all var(--transition);
  line-height: 1.2;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.38; cursor: default; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary-hi);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hi); box-shadow: 0 0 20px var(--primary-glow); }

.btn-ghost {
  background: var(--surface);
  border-color: var(--border-hi);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-hi); border-color: var(--border-hi); }

.btn-danger {
  background: var(--danger-dim);
  border-color: var(--danger-ring);
  color: #fca5a5;
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-text {
  background: none;
  border-color: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
}
.btn-text:hover { color: var(--text); }
.btn-text:disabled { opacity: 0.3; }

.btn-full { width: 100%; }
.btn-lg   { padding: 15px 24px; font-size: 15px; }
.btn-sm   { padding: 7px 14px; font-size: 12px; }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-wrap {
  margin-bottom: 28px;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
  letter-spacing: 0.3px;
}
.progress-meta strong { color: var(--text-muted); font-weight: 600; }
.progress-track {
  height: 3px;
  background: var(--border-hi);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.progress-fill.indigo { background: var(--primary); }
.progress-fill.gold   { background: var(--gold); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

/* ============================================================
   HOME SCREEN
   ============================================================ */
.home-hero {
  text-align: center;
  padding: 36px 0 32px;
}
.home-title  { font-size: 34px; font-weight: 800; letter-spacing: -1.5px; line-height: 1.1; margin-bottom: 12px; }
.home-sub    { color: var(--text-muted); font-size: 16px; max-width: 400px; margin: 0 auto 20px; line-height: 1.65; }
.home-badge  {
  display: inline-block;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.home-actions { max-width: 340px; margin: 0 auto; }

.home-btn {
  width: 100%;
  display: block;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  color: var(--text);
  text-align: left;
  transition: all var(--transition);
  margin-bottom: 10px;
  cursor: pointer;
}
.home-btn:hover { background: var(--surface-hi); border-color: var(--primary); }
.home-btn.primary { background: rgba(99,102,241,0.18); border-color: var(--primary); }
.home-btn.primary:hover { background: rgba(99,102,241,0.28); box-shadow: 0 0 24px var(--primary-glow); }

.home-btn-title  { font-size: 15px; font-weight: 700; margin-bottom: 3px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.home-btn-sub    { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.rec-tag {
  display: inline-block;
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: rgba(99,102,241,0.25);
  color: var(--primary-hi);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
}

.home-note {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 14px;
  line-height: 1.6;
}
.home-note.accent-indigo { border-left: 3px solid var(--primary); }
.home-note.accent-gold   { border-left: 3px solid var(--gold); }

.home-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 32px;
  line-height: 1.7;
  max-width: 380px;
  margin-left: auto;
  margin-right: auto;
}

/* ============================================================
   SEEDING SCREEN
   ============================================================ */
.seed-card {
  text-align: center;
  padding: 44px 32px 40px;
  margin-bottom: 24px;
  border-radius: var(--radius-xl);
  position: relative;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.seed-eyebrow {
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 16px;
}
.seed-value-name {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1.5px;
  line-height: 1.05;
  margin-bottom: 14px;
}
.seed-value-desc {
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1.7;
  max-width: 380px;
  margin: 0 auto;
  min-height: 3.4em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.seed-edit-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.seed-edit-btn:hover { color: var(--text); border-color: var(--primary); }

.seed-desc-edit { max-width: 380px; margin: 0 auto; }
.seed-desc-edit textarea { resize: vertical; min-height: 80px; }

.seed-remove-link {
  display: inline-block;
  margin-top: 18px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: color var(--transition), text-decoration-color var(--transition);
}
.seed-remove-link:hover { color: #fca5a5; text-decoration-color: currentColor; }

.seed-already-rated {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
}

.seed-rating-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.seed-btn {
  flex: 1;
  padding: 18px 0;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  cursor: pointer;
  position: relative;
}
.seed-btn.active {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.seed-btn:hover:not(:disabled) { transform: translateY(-3px) scale(1.05); filter: brightness(1.2); }
.seed-btn:active { transform: scale(0.96); }
.seed-btn:disabled { opacity: 0.3; cursor: default; }

.seed-btn-1 { background: #334155; border-color: #475569; }
.seed-btn-2 { background: #3730a3; border-color: #4338ca; }
.seed-btn-3 { background: #6d28d9; border-color: #7c3aed; }
.seed-btn-4 { background: #a16207; border-color: #ca8a04; }
.seed-btn-5 { background: #b45309; border-color: #d97706; box-shadow: 0 0 16px rgba(240,180,41,0.25); }

.seed-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  padding: 0 2px;
  margin-bottom: 24px;
}

.seed-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.seed-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 16px;
  letter-spacing: 0.5px;
}

/* ============================================================
   TOURNAMENT SCREEN
   ============================================================ */
.tournament-question {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 22px;
  letter-spacing: 0.2px;
}

.match-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 20px;
}

.match-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 22px;
  text-align: center;
  color: var(--text);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  min-height: 210px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.match-card:hover {
  transform: translateY(-5px) scale(1.015);
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--primary-ring);
  box-shadow:
    0 8px 40px rgba(99, 102, 241, 0.18),
    0 0 0 1px var(--primary-ring),
    inset 0 1px 0 rgba(255,255,255,0.06);
}
.match-card:active { transform: scale(0.97); }

.match-card-key {
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.match-card-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.2;
}
.match-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.65;
}

.match-vs {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
}
.match-vs-inner {
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.tournament-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tournament-hint { font-size: 11px; color: var(--text-dim); letter-spacing: 0.3px; }

/* ============================================================
   RESULTS SCREEN
   ============================================================ */
.results-header {
  text-align: center;
  margin-bottom: 36px;
}
.results-title { font-size: 30px; font-weight: 800; letter-spacing: -1px; margin-bottom: 6px; }
.results-meta  { font-size: 13px; color: var(--text-muted); }

.results-section { margin-bottom: 28px; }
.results-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.results-section-label.gold   { color: rgba(240, 180, 41, 0.65); border-color: var(--gold-dim); }
.results-section-label.silver { color: rgba(148, 163, 184, 0.55); border-color: var(--silver-dim); }

.rank-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border-radius: var(--radius);
  margin-bottom: 7px;
  border: 1px solid transparent;
  transition: background var(--transition);
}

.rank-item.top1 {
  background: linear-gradient(135deg, rgba(240,180,41,0.18), rgba(240,150,20,0.08));
  border-color: var(--gold-ring);
}
.rank-item.top2 {
  background: linear-gradient(135deg, rgba(200,220,240,0.12), rgba(180,200,220,0.06));
  border-color: var(--silver-ring);
}
.rank-item.top3 {
  background: linear-gradient(135deg, rgba(194,124,62,0.15), rgba(180,110,50,0.06));
  border-color: rgba(194,124,62,0.4);
}
.rank-item.top5  { background: rgba(240,180,41,0.06);  border-color: rgba(240,180,41,0.15); }
.rank-item.top10 { background: rgba(148,163,184,0.04); border-color: rgba(148,163,184,0.12); }
.rank-item.rest  { background: transparent; border-color: var(--border); }

.rank-badge {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}
.badge-gold   { background: linear-gradient(135deg,#f0b429,#c9890a); color:#1a1305; box-shadow:0 0 14px rgba(240,180,41,0.35); }
.badge-silver { background: linear-gradient(135deg,#cbd5e1,#94a3b8); color:#1a1f29; }
.badge-bronze { background: linear-gradient(135deg,#d99a5b,#a8693a); color:#1f1409; }
.badge-top5   { background: var(--gold-dim); color: var(--gold); border: 1px solid var(--gold-ring); }
.badge-top10  { background: var(--silver-dim); color: var(--silver); border: 1px solid var(--silver-ring); }
.badge-plain  { background: transparent; color: var(--text-dim); font-weight: 600; font-size: 13px; }

.rank-body   { flex: 1; min-width: 0; }
.rank-name   { font-weight: 700; font-size: 16px; line-height: 1.2; margin-bottom: 3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.tied-tag {
  font-size: 9px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--surface-hi);
  color: var(--text-dim);
  border: 1px solid var(--border-hi);
  padding: 1px 7px;
  border-radius: 8px;
  font-weight: 700;
}

.tie-warning {
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--gold-dim);
  border: 1px solid var(--gold-ring);
  border-left: 3px solid var(--gold);
  margin-bottom: 20px;
  line-height: 1.6;
}
.tie-warning-sub {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
}
.tie-note {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 20px;
}
.rank-desc   { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.rank-score  { text-align: right; flex-shrink: 0; }
.rank-rating { font-size: 15px; font-weight: 700; color: var(--text-muted); }
.rank-rd     { font-size: 10px; color: var(--text-dim); margin-top: 1px; }

.rank-item.top1 .rank-name { font-size: 19px; }

.show-all-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
  transition: color var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}
.show-all-btn:hover { color: var(--text-muted); }

.results-actions {
  display: flex;
  gap: 10px;
  margin-top: 32px;
}
.results-actions .btn { flex: 1; }

/* ============================================================
   SETTINGS / BROWSE SCREENS
   ============================================================ */
.settings-title { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 24px; }

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 14px;
}
.settings-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.btn-row {
  display: flex;
  gap: 10px;
}
.btn-row .btn { flex: 1; }

.settings-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
  line-height: 1.6;
}

.input-field {
  width: 100%;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 8px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-field::placeholder { color: var(--text-dim); }
.input-field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

.danger-section {
  border-color: var(--danger-ring);
  background: var(--danger-dim);
}
.danger-section .settings-section-title { color: rgba(239,68,68,0.6); }
.danger-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.6; }

/* ============================================================
   BROWSE VALUES
   ============================================================ */
.browse-intro {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 22px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 3px solid var(--primary);
}

.browse-item {
  border-bottom: 1px solid var(--border);
  padding: 14px 4px;
}
.browse-item:last-child { border-bottom: none; }

.browse-item-display {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.browse-item-info { flex: 1; min-width: 0; }
.browse-item-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.browse-item-desc { font-size: 12px; color: var(--text-muted); margin-top: 3px; line-height: 1.5; }
.browse-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

.browse-item-edit { margin-top: 10px; }

.custom-tag {
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--primary-glow);
  color: var(--primary-hi);
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
}

.icon-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: 7px;
  color: var(--text-dim);
  transition: all var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--primary); }
.icon-btn-danger:hover { color: #fca5a5; border-color: var(--danger-ring); background: var(--danger-dim); }

/* ============================================================
   EMPTY / ERROR STATES
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.empty-state-desc  { font-size: 14px; color: var(--text-dim); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 560px) {
  .seed-value-name  { font-size: 32px; }
  .seed-card        { padding: 34px 20px 30px; min-height: 280px; }
  .seed-btn         { padding: 15px 0; font-size: 17px; }

  .match-row {
    flex-direction: column;
    gap: 8px;
  }
  .match-card { min-height: 150px; }
  .match-vs { width: auto; height: 28px; }
  .match-vs-inner { width: auto; height: 28px; padding: 0 14px; border-radius: 14px; }

  .results-actions { flex-direction: column; }
  .home-title { font-size: 28px; }
  .btn-row { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
