/* ======================== */
/* Base & Reset             */
/* ======================== */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100vh; background: #0e1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; min-height: 100vh; }

/* ======================== */
/* Header                   */
/* ======================== */
header {
  padding: 16px 28px;
  border-bottom: 1px solid #21262d;
  background: #161b22;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 { margin: 0; font-size: 1.05rem; font-weight: 600; color: #e6edf3; letter-spacing: 0.2px; }

.admin-link {
  color: #8b949e;
  text-decoration: none;
  font-size: 0.8rem;
  padding: 6px 12px;
  border: 1px solid #30363d;
  border-radius: 6px;
}
.admin-link:hover { color: #e6edf3; border-color: #58a6ff; }

/* ======================== */
/* Main                     */
/* ======================== */
main { flex: 1; padding: 24px 28px; max-width: 1200px; margin: 0 auto; width: 100%; }

/* ======================== */
/* Footer                   */
/* ======================== */
footer {
  padding: 14px 28px;
  border-top: 1px solid #21262d;
  text-align: center;
  color: #484f58;
  font-size: 0.73rem;
}

/* ======================== */
/* Landing Page             */
/* ======================== */
.landing-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  gap: 40px;
  max-width: unset;
  margin: unset;
}

.hero { text-align: center; }
.hero h2 {
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  color: #f0f6fc;
  letter-spacing: -0.4px;
}
.hero p { margin: 0; color: #8b949e; font-size: 0.95rem; }

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  max-width: 720px;
  width: 100%;
}

.nav-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 20px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  text-decoration: none;
  color: #e6edf3;
  transition: border-color 0.14s, background 0.14s, transform 0.12s;
}
.nav-card:hover { border-color: #58a6ff; background: #1c2330; transform: translateY(-2px); }

.nav-card .card-icon { font-size: 1.5rem; line-height: 1; }
.nav-card .card-title { font-size: 0.95rem; font-weight: 600; color: #f0f6fc; }
.nav-card .card-desc { font-size: 0.78rem; color: #8b949e; line-height: 1.45; }

/* ======================== */
/* Character Browser        */
/* ======================== */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}
.toolbar input {
  flex: 1;
  padding: 9px 12px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e6edf3;
  font-size: 0.9rem;
}
.toolbar input:focus { outline: none; border-color: #58a6ff; }

.lang-select {
  width: 110px;
  padding: 9px 12px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e6edf3;
  font-size: 0.85rem;
  cursor: pointer;
}
.lang-select:focus { outline: none; border-color: #58a6ff; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 18px 14px;
}
.card {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s;
  text-align: center;
}
.card:hover { transform: translateY(-2px); filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.35)); }
.card:focus-visible { outline: 2px solid #58a6ff; outline-offset: 4px; border-radius: 10px; }
.character-card {
  display: flex;
  justify-content: center;
}

.character-portrait {
  --portrait-size: 112px;
  --portrait-icon-inset: 9px;
  --portrait-corner-icon: 28px;
  --portrait-weapon-icon: 16px;
  width: var(--portrait-size);
  user-select: none;
}
.character-portrait--browser { --portrait-size: 112px; }
.character-portrait--detail { --portrait-size: 120px; }
.character-portrait__stage {
  position: relative;
  width: var(--portrait-size);
  height: var(--portrait-size);
}
.character-portrait__icon-slot {
  position: absolute;
  inset: var(--portrait-icon-inset);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 12px;
}
.character-portrait__icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.character-portrait__frame {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.character-portrait__fallback {
  width: 100%;
  max-height: 100%;
  padding: 8px;
  color: #f0f6fc;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.12;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.85);
  overflow-wrap: anywhere;
}
.character-portrait__element {
  position: absolute;
  top: 2px;
  left: 2px;
  z-index: 4;
  width: var(--portrait-corner-icon);
  height: var(--portrait-corner-icon);
  object-fit: contain;
}
.character-portrait__weapons {
  position: absolute;
  top: calc(var(--portrait-corner-icon) + 4px);
  left: 8px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.character-portrait__weapon {
  width: var(--portrait-weapon-icon);
  height: var(--portrait-weapon-icon);
  object-fit: contain;
}

.empty, .loading { text-align: center; padding: 40px; color: #8b949e; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
.modal-header h2 { margin: 0; font-size: 1.3rem; }
.modal-header .close-btn {
  background: transparent;
  border: none;
  color: #8b949e;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
}
.modal-header .close-btn:hover { color: #e6edf3; }

.detail-top { display: flex; gap: 16px; margin-bottom: 16px; }
.detail-icon {
  flex: 0 0 120px;
  aspect-ratio: 1 / 1;
  background: #0d1117;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-icon > img { width: 100%; height: 100%; object-fit: contain; }

.detail-meta { flex: 1; }
.detail-meta .row { display: flex; gap: 6px; font-size: 0.85rem; margin-bottom: 6px; }
.detail-meta .row .label { color: #8b949e; min-width: 80px; }
.detail-meta .row .value { color: #e6edf3; text-transform: capitalize; }

.detail-section { margin-top: 18px; }
.detail-section h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: #c9d1d9;
  border-bottom: 1px solid #30363d;
  padding-bottom: 4px;
}
.detail-section p { margin: 4px 0; font-size: 0.85rem; color: #c9d1d9; white-space: pre-wrap; }

.status-ref {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid rgba(88, 166, 255, 0.45);
  background: rgba(56, 139, 253, 0.14);
  color: #79c0ff;
  font-size: 0.82em;
  cursor: help;
  vertical-align: baseline;
}
.status-ref-icon { width: 16px; height: 16px; object-fit: contain; flex-shrink: 0; }

.entity-ref {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.82em;
  vertical-align: baseline;
  border: 1px solid rgba(200, 200, 200, 0.25);
  background: rgba(200, 200, 200, 0.08);
}
.entity-ref--char   { border-color: rgba(88, 166, 255, 0.35); color: #79c0ff; }
.entity-ref--weapon { border-color: rgba(227, 179, 65, 0.35);  color: #e3b341; }
.entity-ref--item   { border-color: rgba(210, 168, 255, 0.35); color: #d2a8ff; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  background: #21262d;
  color: #c9d1d9;
  margin-right: 6px;
}
.badge-rarity-SSR { background: #b8860b; color: #fff; }
.badge-rarity-SR  { background: #7c3aed; color: #fff; }
.badge-rarity-R   { background: #2563eb; color: #fff; }
