:root {
  --bg-cream: #fdf6e3;
  --bg-cream-deep: #f5e6c8;
  --surface: #fffdf7;
  --choco: #3d2314;
  --choco-soft: #6b442a;
  --choco-muted: #8c6548;
  --crust: #ca6c2e;
  --crust-dark: #a1461a;
  --butter: #ffd566;
  --butter-soft: #fff1c2;
  --border: #e4cca8;
  --border-dark: #5c3720;
  --shadow: 0 8px 24px rgba(61, 35, 20, 0.08);
  --shadow-lg: 0 20px 50px rgba(61, 35, 20, 0.22);
  --radius: 18px;
}

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

body {
  font-family: 'M PLUS Rounded 1c', 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  background: var(--bg-cream);
  color: var(--choco);
  min-height: 100vh;
  line-height: 1.45;
  position: relative;
}

.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(circle at 8% 12%, rgba(255, 213, 102, 0.35), transparent 34%),
    radial-gradient(circle at 92% 18%, rgba(202, 108, 46, 0.16), transparent 36%),
    radial-gradient(circle at 50% 95%, rgba(255, 213, 102, 0.25), transparent 45%);
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(253, 246, 227, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 2px solid var(--border);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  height: 52px;
  width: auto;
  filter: drop-shadow(0 3px 6px rgba(61, 35, 20, 0.16));
}

.brand-text h1 {
  font-family: 'Jua', 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.45rem;
  letter-spacing: 0.03em;
  color: var(--choco);
  line-height: 1.1;
}

.brand-text p {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--choco-muted);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.lang-switch {
  display: inline-flex;
  background: var(--bg-cream-deep);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--choco-soft);
  font-weight: 800;
  font-size: 0.8rem;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.lang-btn.active {
  background: var(--choco);
  color: var(--butter);
  box-shadow: 0 2px 6px rgba(61, 35, 20, 0.22);
}

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 2px solid var(--crust);
  background: var(--crust);
  color: #fffdf7;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.42rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.refresh-btn:hover {
  background: var(--crust-dark);
  border-color: var(--crust-dark);
  transform: translateY(-1px);
}

.refresh-btn.spinning .refresh-icon {
  display: inline-block;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Main Container */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.4rem 1.25rem 3rem;
}

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  box-shadow: var(--shadow);
}

.kpi-card.accent-dark {
  background: var(--choco);
  border-color: var(--choco);
  color: #fff8eb;
}

.kpi-card.accent-dark .kpi-label {
  color: #f8dfb8;
}

.kpi-card.accent-dark .kpi-sub {
  color: #cfb49a;
}

.kpi-card.accent-gold {
  background: linear-gradient(145deg, #ffe285, #ffd159);
  border-color: #d9a42e;
  color: var(--choco);
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--choco-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.kpi-sub {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--choco-muted);
}

/* Tabs */
.main-tabs {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.85rem;
}

.tab-btn {
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--choco-soft);
  font-weight: 800;
  font-size: 0.94rem;
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.16s ease;
}

.tab-btn:hover {
  border-color: var(--crust);
  color: var(--choco);
}

.tab-btn.active {
  background: var(--choco);
  border-color: var(--choco);
  color: var(--butter);
  box-shadow: 0 4px 12px rgba(61, 35, 20, 0.2);
}

.updated-pill {
  margin-left: auto;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--choco-muted);
  background: var(--bg-cream-deep);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Status Banner */
.status-banner {
  padding: 0.9rem 1.1rem;
  border-radius: 14px;
  background: #fde8e8;
  border: 2px solid #e59c9c;
  color: #7a1c1c;
  font-weight: 700;
  margin-bottom: 1rem;
}

.hidden {
  display: none !important;
}

/* Section Headers */
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--choco);
}

.section-hint {
  font-size: 0.82rem;
  color: var(--choco-muted);
  margin-top: 0.15rem;
}

/* Leaderboards Grid */
.leaders-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.leader-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.leader-card-head {
  background: var(--choco);
  color: #f8dfb8;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: 0.95rem;
}

.leader-card-head .stat-code {
  background: rgba(255, 213, 102, 0.18);
  color: var(--butter);
  font-size: 0.74rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.leader-list {
  list-style: none;
  padding: 0.35rem 0;
}

.leader-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.52rem 0.95rem;
  cursor: pointer;
  transition: background 0.14s ease;
  border-bottom: 1px dashed rgba(228, 204, 168, 0.7);
}

.leader-row:last-child {
  border-bottom: none;
}

.leader-row:hover {
  background: var(--butter-soft);
}

.leader-row.rank-1 {
  background: linear-gradient(90deg, rgba(255, 213, 102, 0.28), transparent 85%);
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.rank-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
  background: var(--bg-cream-deep);
  color: var(--choco-soft);
  flex-shrink: 0;
}

.rank-1 .rank-badge {
  background: var(--crust);
  color: #fffdf7;
}

.rank-2 .rank-badge {
  background: #8c6548;
  color: #fffdf7;
}

.rank-3 .rank-badge {
  background: #b9895e;
  color: #fffdf7;
}

.avatar-mini {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--bg-cream-deep);
  flex-shrink: 0;
}

.avatar-fallback {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--bg-cream-deep);
  color: var(--choco-soft);
  font-weight: 800;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.leader-player {
  min-width: 0;
  flex: 1;
}

.leader-player-name {
  font-weight: 800;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leader-player-sub {
  font-size: 0.72rem;
  color: var(--choco-muted);
  font-weight: 700;
}

.leader-val {
  font-weight: 800;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: var(--choco);
}

.rank-1 .leader-val {
  color: var(--crust-dark);
  font-size: 1.15rem;
}

/* Toolbar & Filters */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 420px;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
}

.search-box input {
  width: 100%;
  padding: 0.6rem 0.9rem 0.6rem 2.35rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--choco);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  outline: none;
  transition: border-color 0.15s ease;
}

.search-box input:focus {
  border-color: var(--crust);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.pos-chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.pos-chip {
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--choco-soft);
  font-weight: 800;
  font-size: 0.76rem;
  padding: 0.32rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.pos-chip.active {
  background: var(--crust);
  border-color: var(--crust);
  color: #fffdf7;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 0.38rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--choco);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--crust);
  width: 15px;
  height: 15px;
}

/* Stats Table */
.table-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.stats-table thead th {
  background: var(--choco);
  color: #f8dfb8;
  font-weight: 800;
  padding: 0.75rem 0.65rem;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  transition: background 0.12s ease;
}

.stats-table thead th:hover {
  background: #52301c;
}

.stats-table thead th.sorted {
  color: var(--butter);
  background: #2b180d;
}

.stats-table thead th.col-player {
  text-align: left;
  padding-left: 1rem;
  min-width: 175px;
}

.stats-table tbody tr {
  border-bottom: 1px solid #f0e1c6;
  cursor: pointer;
  transition: background 0.12s ease;
}

.stats-table tbody tr:hover {
  background: var(--butter-soft);
}

.stats-table tbody td {
  padding: 0.6rem 0.65rem;
  text-align: center;
  white-space: nowrap;
  font-weight: 700;
}

.stats-table tbody td.col-player {
  text-align: left;
  padding-left: 1rem;
}

.stats-table tbody td.col-highlight {
  font-weight: 800;
  color: var(--crust-dark);
  background: rgba(255, 213, 102, 0.14);
}

.player-cell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.player-cell-names {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.player-cell-kor {
  font-weight: 800;
  color: var(--choco);
}

.player-cell-eng {
  font-size: 0.74rem;
  color: var(--choco-muted);
}

.qual-star {
  color: var(--crust);
  font-size: 0.82rem;
  margin-left: 0.25rem;
}

.pos-tag {
  display: inline-block;
  background: var(--bg-cream-deep);
  color: var(--choco);
  border-radius: 8px;
  padding: 0.16rem 0.48rem;
  font-size: 0.76rem;
  font-weight: 800;
}

.empty-cell {
  text-align: center;
  padding: 2.5rem 1rem !important;
  color: var(--choco-muted);
  font-weight: 700;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(34, 18, 9, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-dialog {
  background: var(--bg-cream);
  border: 3px solid var(--choco);
  border-radius: 24px;
  width: 100%;
  max-width: 780px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.25rem 1.35rem;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 0.9rem;
  right: 0.95rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--choco);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--choco);
  color: var(--butter);
  border-color: var(--choco);
}

.modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding-right: 2.6rem;
  margin-bottom: 0.9rem;
}

.modal-player-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.jersey-pill {
  background: var(--choco);
  color: var(--butter);
  font-weight: 800;
  font-size: 1.05rem;
  padding: 0.35rem 0.7rem;
  border-radius: 12px;
}

.modal-player-meta h3 {
  font-size: 1.15rem;
  font-weight: 800;
}

.modal-badges {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.pos-badge {
  background: var(--crust);
  color: #fffdf7;
  font-size: 0.73rem;
  font-weight: 800;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
}

.qual-badge {
  background: var(--bg-cream-deep);
  color: var(--choco-soft);
  font-size: 0.73rem;
  font-weight: 800;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
}

.qual-badge.is-qual {
  background: var(--choco);
  color: var(--butter);
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.type-switch,
.modal-lang-switch {
  display: inline-flex;
  background: var(--bg-cream-deep);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}

.type-btn,
.mlang-btn {
  border: none;
  background: transparent;
  color: var(--choco-soft);
  font-weight: 800;
  font-size: 0.76rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
}

.type-btn.active,
.mlang-btn.active {
  background: var(--choco);
  color: var(--butter);
}

.card-stage {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 0.6rem;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-skeleton {
  color: var(--choco-muted);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 4rem 1rem;
}

.stat-card-img {
  width: 100%;
  height: auto;
  border-radius: 12px;
  display: block;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.9rem;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--crust);
  color: #fffdf7;
  text-decoration: none;
  font-weight: 800;
  font-size: 0.86rem;
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  transition: background 0.15s ease;
}

.download-btn:hover {
  background: var(--crust-dark);
}

.footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--choco-muted);
}

@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .leaders-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .leaders-grid {
    grid-template-columns: 1fr;
  }
  .brand-logo {
    height: 42px;
  }
  .brand-text h1 {
    font-size: 1.2rem;
  }
  .updated-pill {
    margin-left: 0;
  }
}
