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

:root {
  --bg-deep: #0a0e1a;
  --bg-mid: #141b2d;
  --bg-card: #1a2235;
  --bg-card-hover: #212d45;
  --gold: #c9a84c;
  --gold-dim: #8a7233;
  --indigo: #818cf8;
  --text-primary: #e8e0d0;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: rgba(201, 168, 76, 0.2);
  --border-hover: rgba(201, 168, 76, 0.5);
  --grade-s: #ffd700;
  --grade-a: #a78bfa;
  --grade-b: #60a5fa;
  --grade-c: #34d399;
  --grade-d: #fbbf24;
  --grade-e: #9ca3af;
  --grade-f: #6b7280;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 48px 20px 32px;
  background: linear-gradient(180deg, rgba(201,168,76,0.08) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
}

.header-emblem {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(201,168,76,0.15), transparent);
}

.emblem-icon {
  font-size: 28px;
  color: var(--gold);
  filter: drop-shadow(0 0 8px rgba(201,168,76,0.4));
}

.header-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(201,168,76,0.3);
}

.header-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  letter-spacing: 4px;
  margin-top: 4px;
}

/* ===== Filter Bar ===== */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,14,26,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
}

.filter-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1 1 240px;
  min-width: 200px;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: var(--gold); }
.search-input::placeholder { color: var(--text-muted); }

.search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.filter-select {
  padding: 6px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  min-width: 100px;
}

.filter-select:focus { border-color: var(--gold); }

.reset-btn {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--gold);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  align-self: flex-end;
}

.reset-btn:hover {
  background: rgba(201,168,76,0.1);
  border-color: var(--gold);
}

/* ===== Result Bar ===== */
.result-bar {
  max-width: 1400px;
  margin: 16px auto 8px;
  padding: 0 20px;
  font-size: 13px;
  color: var(--text-secondary);
}

#resultCount { color: var(--gold); font-weight: 700; }

/* ===== Gallery Grid ===== */
.gallery {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 20px 40px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

/* ===== Card ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.25s, border-color 0.25s, box-shadow 0.25s;
  position: relative;
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: 0 8px 32px rgba(201,168,76,0.15);
}

.card-image-wrap {
  width: 100%;
  aspect-ratio: 3/4;
  background: linear-gradient(135deg, var(--bg-mid) 0%, var(--bg-card) 100%);
  position: relative;
  overflow: hidden;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.card-image.loaded { opacity: 1; }

.card-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 2px;
}

.card-image.loaded + .card-placeholder { display: none; }

.card-badge {
  position: absolute;
  top: 8px; right: 8px;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.card-info {
  padding: 12px 14px;
}

.card-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.card-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-dept {
  background: rgba(129,140,248,0.12);
  color: var(--indigo);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
}

.card-gender-m { border-left: 3px solid var(--indigo); }
.card-gender-f { border-left: 3px solid #f472b6; }

/* Badge colors */
.grade-s { color: var(--grade-s); border-color: var(--grade-s); }
.grade-a { color: var(--grade-a); border-color: var(--grade-a); }
.grade-b { color: var(--grade-b); border-color: var(--grade-b); }
.grade-c { color: var(--grade-c); border-color: var(--grade-c); }
.grade-d { color: var(--grade-d); border-color: var(--grade-d); }
.grade-e { color: var(--grade-e); border-color: var(--grade-e); }
.grade-f { color: var(--grade-f); border-color: var(--grade-f); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
}

.modal-close {
  position: sticky;
  top: 8px;
  float: right;
  margin: 8px;
  width: 36px; height: 36px;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.modal-close:hover { background: rgba(201,168,76,0.2); }

.modal-body {
  display: flex;
  gap: 24px;
  padding: 24px;
}

.modal-image-area {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-main-image-wrap {
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(135deg, var(--bg-deep) 0%, var(--bg-card) 100%);
  border: 1px solid var(--border);
  position: relative;
}

.modal-main-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-image-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: var(--text-muted);
}

.modal-thumbs-section { margin-top: 8px; }

.modal-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.modal-thumb {
  aspect-ratio: 3/4;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--bg-card);
  position: relative;
  transition: border-color 0.2s;
}

.modal-thumb:hover,
.modal-thumb.active { border-color: var(--gold); }

.modal-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s;
}

.modal-thumb img.loaded { opacity: 1; }

.modal-thumb .thumb-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7);
  color: var(--text-secondary);
  font-size: 9px;
  text-align: center;
  padding: 2px;
  line-height: 1.2;
}

.modal-thumb .thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
}

.modal-info-area {
  flex: 1;
  min-width: 0;
}

.modal-header-info {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-code {
  font-size: 12px;
  color: var(--gold);
  letter-spacing: 2px;
  font-weight: 500;
}

.modal-name {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 4px;
}

.modal-name-en {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 300;
}

.modal-section {
  margin-bottom: 16px;
}

.modal-section-title {
  font-size: 12px;
  color: var(--gold);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-weight: 500;
}

.modal-info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-label {
  font-size: 11px;
  color: var(--text-muted);
}

.info-value {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.info-value .combat-grade {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 13px;
  background: rgba(0,0,0,0.3);
}

.modal-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.glow-indicator {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  box-shadow: 0 0 6px currentColor;
}

/* ===== Failed Images Collapse ===== */
.modal-failed-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.collapse-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  transition: color 0.2s;
}

.collapse-toggle:hover { color: var(--gold); }

.collapse-icon {
  display: inline-block;
  font-size: 10px;
  transition: transform 0.2s;
}

.collapse-toggle.open .collapse-icon { transform: rotate(90deg); }

.collapse-content {
  display: none;
  padding: 8px 0 0 16px;
}

.collapse-content.open { display: block; }

.failed-list {
  list-style: none;
  font-size: 12px;
  color: var(--text-muted);
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.failed-list li {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.retry-btn {
  padding: 4px 12px;
  background: rgba(201,168,76,0.1);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--gold);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

.retry-btn:hover { background: rgba(201,168,76,0.2); }

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 24px 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 1px;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .gallery { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .gallery { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .header-title { font-size: 24px; letter-spacing: 3px; }
  .filter-bar-inner { gap: 8px; }

  .modal-body {
    flex-direction: column;
    padding: 16px;
  }

  .modal-image-area {
    flex: none;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
  }
}

@media (max-width: 480px) {
  .gallery { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 8px 12px 40px; }
  .card-info { padding: 8px 10px; }
  .card-name { font-size: 14px; }
  .header { padding: 32px 16px 24px; }
  .header-title { font-size: 20px; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* Category separator in thumbs */
.modal-thumbs-category {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--gold);
  padding: 6px 0 2px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 1px;
  margin-top: 4px;
}

.modal-thumbs-category:first-child { margin-top: 0; }
