/* ===================================================
   Position Bias Ranking — Report-Quality Visual Styles
   =================================================== */

/* --- Fonts --- */
.ranking-dashboard,
.ranking-dashboard * {
  font-family: 'Noto Sans KR', 'Fira Sans', system-ui, sans-serif;
}

/* --- Report Hero Banner --- */
.report-hero {
  background: linear-gradient(135deg, #0f1629 0%, #1a1040 40%, #0d1a2d 100%);
  border: 1px solid rgba(99, 102, 241, 0.2);
  position: relative;
  overflow: hidden;
  padding: 36px 32px;
}

.report-hero:hover {
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 0 40px rgba(99, 102, 241, 0.1);
}

.report-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

.report-hero::after {
  content: '';
  position: absolute;
  bottom: -30%;
  left: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.06) 0%, transparent 70%);
  pointer-events: none;
}

.report-hero-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  position: relative;
  z-index: 1;
}

.report-title {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #e2e8f0, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.report-subtitle {
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(167, 139, 250, 0.7);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.report-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.7;
}

.report-hero-stats {
  display: flex;
  gap: 16px;
  flex-shrink: 0;
}

.hero-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  min-width: 100px;
}

.hero-stat-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
}

.hero-stat-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 4px;
  white-space: nowrap;
}

/* --- Insight Cards (Top Metrics) --- */
.card-insight {
  position: relative;
  overflow: hidden;
  padding: 24px;
  border: none;
}

.card-insight::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent 60%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.card-insight-gold {
  background: linear-gradient(135deg, #1a1520, #201a10);
  box-shadow: 0 4px 24px rgba(212, 175, 55, 0.08), inset 0 1px 0 rgba(212, 175, 55, 0.1);
}

.card-insight-blue {
  background: linear-gradient(135deg, #0f1629, #101a30);
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.08), inset 0 1px 0 rgba(99, 102, 241, 0.1);
}

.card-insight-red {
  background: linear-gradient(135deg, #1a1015, #201015);
  box-shadow: 0 4px 24px rgba(239, 68, 68, 0.08), inset 0 1px 0 rgba(239, 68, 68, 0.1);
}

.card-insight-green {
  background: linear-gradient(135deg, #0f1a15, #102010);
  box-shadow: 0 4px 24px rgba(34, 197, 94, 0.08), inset 0 1px 0 rgba(34, 197, 94, 0.1);
}

.card-insight:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.insight-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.card-insight-gold .insight-icon { background: rgba(212, 175, 55, 0.12); color: #D4AF37; }
.card-insight-blue .insight-icon { background: rgba(99, 102, 241, 0.12); color: #818cf8; }
.card-insight-red .insight-icon { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.card-insight-green .insight-icon { background: rgba(34, 197, 94, 0.12); color: #22c55e; }

.card-insight .card-title {
  margin-bottom: 12px;
}

.card-insight .card-metric {
  font-size: 2rem;
  line-height: 1.1;
}

.card-insight .card-subtitle {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 6px;
  -webkit-text-fill-color: var(--text-dim);
}

.card-insight .card-subtitle strong {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
}

.card-metric-danger {
  background: linear-gradient(135deg, var(--red), #f87171) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
}

.card-metric-success {
  background: linear-gradient(135deg, var(--green), #4ade80) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
}

/* --- Section Headers --- */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.section-header .card-title {
  margin-bottom: 0;
}

.section-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.section-icon-main { background: rgba(99, 102, 241, 0.1); color: #818cf8; }
.section-icon-support { background: rgba(6, 182, 212, 0.1); color: #22d3ee; }

.section-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  margin-left: auto;
}

/* --- Character Tiles --- */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.char-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.25s ease;
}

.char-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(99, 102, 241, 0.2);
}

.char-tile-top {
  border-color: rgba(255, 215, 0, 0.15);
}

/* Visual header with image */
.char-tile-visual {
  position: relative;
  height: 140px;
  overflow: hidden;
  background: var(--bg);
}

.char-tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 0.3s ease;
}

.char-tile:hover .char-tile-img {
  transform: scale(1.05);
}

.char-tile-visual::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60%;
  background: linear-gradient(to top, var(--surface), transparent);
  pointer-events: none;
}

.char-tile-rank-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 900;
  background: rgba(11, 15, 26, 0.85);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  z-index: 2;
}

.medal-gold {
  background: linear-gradient(135deg, #D4AF37, #f5d06b) !important;
  color: #1a1000 !important;
  border-color: #D4AF37 !important;
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.4);
}

.medal-silver {
  background: linear-gradient(135deg, #9ca3af, #d1d5db) !important;
  color: #1a1a1a !important;
  border-color: #9ca3af !important;
  box-shadow: 0 0 12px rgba(156, 163, 175, 0.3);
}

.medal-bronze {
  background: linear-gradient(135deg, #b45309, #d97706) !important;
  color: #fff !important;
  border-color: #b45309 !important;
  box-shadow: 0 0 12px rgba(180, 83, 9, 0.3);
}

.char-tile-body {
  padding: 14px 16px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  border-left: 3px solid var(--tile-accent, var(--accent));
}

.char-tile-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.char-tile-name {
  font-size: 1.05rem;
  font-weight: 700;
}

.char-tile-role {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 1px;
}

.char-tile-delta { flex-shrink: 0; }

.char-tile-score-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}

.char-tile-score-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.char-tile-stats { margin-top: auto; }

.char-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  padding: 3px 0;
}

.char-stat-row + .char-stat-row {
  border-top: 1px solid rgba(255, 255, 255, 0.03);
}

.char-stat-label {
  color: var(--text-dim);
}

.char-stat-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.char-stat-highlight {
  color: var(--green) !important;
  font-weight: 700 !important;
}

/* --- Rank Change Pills --- */
.rank-change {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 2px 8px;
  border-radius: 6px;
}

.rank-change.rank-up { background: rgba(34, 197, 94, 0.1); color: var(--green); }
.rank-change.rank-down { background: rgba(239, 68, 68, 0.1); color: var(--red); }
.rank-change.rank-same { background: rgba(255, 255, 255, 0.04); color: var(--text-dim); }

/* --- Weight Chart --- */
.card-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
  line-height: 1.5;
}

.weight-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}

.weight-row + .weight-row {
  border-top: 1px solid rgba(255, 255, 255, 0.03);
}

.weight-row-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 130px;
}

.weight-pos-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.weight-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.weight-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.weight-bar-area { flex: 1; }

.bar-track-lg {
  height: 10px;
  border-radius: 5px;
}

.weight-val {
  min-width: 50px;
  text-align: right;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.weight-pct {
  min-width: 36px;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.weight-divider {
  padding: 10px 0 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 600;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* --- Table (Enhanced) --- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.ranking-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 2;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

.ranking-table th:hover {
  color: var(--text);
}

.ranking-table th.sort-asc::after { content: ' \25B2'; color: var(--accent); }
.ranking-table th.sort-desc::after { content: ' \25BC'; color: var(--accent); }

.ranking-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.15s;
}

.ranking-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.01);
}

.ranking-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.06);
}

.tr-top {
  background: rgba(212, 175, 55, 0.03) !important;
}

.tr-top:hover {
  background: rgba(212, 175, 55, 0.07) !important;
}

.td-char {
  display: flex;
  align-items: center;
  gap: 10px;
}

.td-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.td-name { font-weight: 600; }

.td-group {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
}

.td-group-main { background: rgba(99, 102, 241, 0.1); color: #818cf8; }
.td-group-support { background: rgba(6, 182, 212, 0.1); color: #22d3ee; }

.td-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.td-dim { color: var(--text-dim); }

.td-rank {
  text-align: center;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 0.82rem;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.td-corrected {
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--green);
}

/* --- Comparison Chart --- */
.dual-bar-group {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.dual-bar-group + .dual-bar-group {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.dual-bar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}

.dual-bar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.dual-bar-rank {
  font-weight: 800;
  font-size: 0.82rem;
  min-width: 24px;
}

.dual-bar-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.dual-bar-tracks {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dual-bar-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dual-bar-line-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
}

.dual-bar-line-label-c {
  color: rgba(34, 197, 94, 0.7);
}

.dual-bar-line .bar-track { flex: 1; }
.dual-bar-line .bar-value { min-width: 56px; font-size: 0.8rem; }

.bar-fill-corrected {
  background: linear-gradient(90deg, var(--green), #6ee7b7);
}

.bar-value-corrected {
  color: var(--green);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-left: 8px;
  margin-right: 2px;
  vertical-align: middle;
}

.legend-dot-raw { background: linear-gradient(90deg, var(--accent), #818cf8); }
.legend-dot-corrected { background: linear-gradient(90deg, var(--green), #6ee7b7); }

/* --- Methodology --- */
.method-details summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.method-details summary::-webkit-details-marker { display: none; }
.method-details summary::before {
  content: '\25B8';
  font-size: 0.75rem;
  color: var(--text-dim);
  transition: transform 0.2s;
  display: inline-block;
}
.method-details[open] summary::before { transform: rotate(90deg); }

.method-content {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.7;
}

.method-formula {
  font-family: var(--font-mono);
  background: var(--bg);
  padding: 14px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  font-size: 0.8rem;
  color: var(--accent);
  line-height: 1.8;
}

/* --- Footer --- */
.report-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.report-footer code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
}

/* --- Animations --- */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.loaded .card,
.loaded .card-insight,
.loaded .report-hero,
.loaded .report-footer {
  animation: fadeSlideUp 0.4s ease both;
}

.loaded .report-hero { animation-delay: 0s; }
.loaded .card-insight:nth-of-type(2) { animation-delay: 0.05s; }
.loaded .card-insight:nth-of-type(3) { animation-delay: 0.1s; }
.loaded .card-insight:nth-of-type(4) { animation-delay: 0.15s; }
.loaded .card-insight:nth-of-type(5) { animation-delay: 0.2s; }
.loaded .card:nth-of-type(n+6) { animation-delay: 0.25s; }

/* --- Print Styles --- */
@media print {
  body {
    background: #fff !important;
    color: #111 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .header, .refresh-btn, .nav-links, .loading-overlay, .error-banner {
    display: none !important;
  }

  .dashboard {
    padding: 0 !important;
    max-width: 100% !important;
    gap: 12px !important;
  }

  .card, .card-insight {
    break-inside: avoid;
    border: 1px solid #ddd !important;
    box-shadow: none !important;
    background: #fff !important;
  }

  .report-hero {
    background: linear-gradient(135deg, #f0f0ff, #e8e0f8) !important;
    padding: 20px !important;
  }

  .report-title {
    -webkit-text-fill-color: #111 !important;
    color: #111 !important;
    background: none !important;
  }

  .card-metric {
    -webkit-text-fill-color: #333 !important;
    background: none !important;
  }

  .report-footer { margin-top: 20px; }
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .report-hero-inner {
    flex-direction: column;
    text-align: center;
  }

  .report-hero-stats {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 700px) {
  .report-hero {
    padding: 24px 16px;
  }

  .report-title {
    font-size: 1.2rem;
  }

  .report-hero-stats {
    flex-direction: column;
    gap: 10px;
  }

  .hero-stat {
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 16px;
  }

  .char-grid {
    grid-template-columns: 1fr !important;
  }

  .char-tile-visual {
    height: 120px;
  }

  .weight-row-left {
    min-width: 100px;
  }

  .weight-avatar {
    display: none;
  }

  .dual-bar-label {
    min-width: 100%;
    margin-bottom: 4px;
  }

  .dual-bar-group {
    flex-wrap: wrap;
  }

  .dual-bar-tracks {
    width: 100%;
  }

  .section-header {
    flex-wrap: wrap;
  }

  .card-insight .card-metric {
    font-size: 1.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loaded .card,
  .loaded .card-insight,
  .loaded .report-hero,
  .loaded .report-footer {
    animation: none !important;
  }
}
