/* common.css — Castela design system.
   Tokens + base + shared components (header, buttons, forms, badges,
   status, spinner, modal, empty states). Loaded by every page;
   page-specific stylesheets that follow this link override anything
   they redeclare. */

/* ===== Design tokens ===== */
:root {
  /* surfaces */
  --bg: #0a0a13;
  --surface: #13131f;
  --surface-2: #181827;
  --surface-3: #1f1f31;
  --border: rgba(159, 143, 220, 0.13);
  --border-strong: rgba(167, 139, 250, 0.4);

  /* text */
  --text: #eae8f4;
  --text-2: #a9a5c3;
  --text-3: #82809f; /* >=4.5:1 on --surface (WCAG AA for small captions) */

  /* brand */
  --accent: #a78bfa;
  --accent-mid: #8b5cf6;
  --accent-deep: #6d28d9;
  /* Filled controls with white body-size labels: both stops >=4.5:1 vs #fff */
  --grad-accent: linear-gradient(135deg, #7c3aed, #6d28d9);
  --gold: #e0b56d;

  /* semantic */
  --success: #34d399;
  --info: #60a5fa;
  --warn: #fbbf24;
  --danger: #f87171;

  /* shape / depth */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 20px rgba(0, 0, 0, 0.25);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.45), 0 16px 40px rgba(0, 0, 0, 0.35);
  --glow-accent: 0 2px 14px rgba(124, 58, 237, 0.38);

  /* type */
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-display: "Cinzel", "Zen Kaku Gothic New", serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(1100px 520px at 12% -8%, rgba(124, 58, 237, 0.13), transparent 62%),
    radial-gradient(900px 460px at 88% -4%, rgba(59, 89, 179, 0.1), transparent 58%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.65;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(139, 92, 246, 0.4); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* Scrollbar (WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #2c2c44; }

.container { max-width: 960px; margin: 0 auto; padding: 28px 20px 72px; }

/* ===== Site header (shared across pages) ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 19, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--accent);
  filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.5));
}
.brand-name {
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: linear-gradient(120deg, #cabcf5 0%, var(--accent) 55%, #7f6ae0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--text-3);
  min-width: 0;
}
.breadcrumb .crumb {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumb .sep { color: #55516f; }
.header-spacer { flex: 1; }

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 32px 16px 40px;
  font-size: 0.78rem;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  margin-top: 48px;
}
.site-footer .brand-name { font-size: 0.85rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.18s, border-color 0.18s, color 0.18s,
    box-shadow 0.18s, transform 0.12s, opacity 0.18s;
}
.btn:hover { text-decoration: none; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--grad-accent);
  color: #fff;
  box-shadow: var(--glow-accent);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 22px rgba(124, 58, 237, 0.55); }

.btn-success {
  background: linear-gradient(135deg, #10b981, #047857);
  color: #fff;
  box-shadow: 0 2px 14px rgba(16, 185, 129, 0.28);
}
.btn-success:hover:not(:disabled) { box-shadow: 0 4px 20px rgba(16, 185, 129, 0.42); }

.btn-info {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  box-shadow: 0 2px 14px rgba(59, 130, 246, 0.28);
}
.btn-info:hover:not(:disabled) { box-shadow: 0 4px 20px rgba(59, 130, 246, 0.42); }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--border-strong);
}
.btn-outline:hover:not(:disabled) { background: rgba(167, 139, 250, 0.09); }

.btn-ghost {
  background: var(--surface-3);
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }

/* ===== Form controls ===== */
input[type="text"], select, textarea {
  font-family: inherit;
}
.field-input, .field-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.88rem;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.field-input:focus, .field-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}
.field-input::placeholder { color: var(--text-3); }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}
.badge-system { background: rgba(16, 185, 129, 0.13); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.4); }
.badge-scenes { background: rgba(167, 139, 250, 0.13); color: #c4b5fd; border: 1px solid rgba(139, 92, 246, 0.4); }
.badge-npcs { background: rgba(251, 191, 36, 0.13); color: var(--warn); border: 1px solid rgba(217, 119, 6, 0.45); }
.badge-model { background: rgba(59, 130, 246, 0.12); color: #93c5fd; border: 1px solid rgba(59, 130, 246, 0.4); }

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 8px;
  opacity: 0.85;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Status banner ===== */
.status {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 0.88rem;
  display: none;
  border: 1px solid;
  animation: status-in 0.25s ease;
}
@keyframes status-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.status.info { display: block; background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.45); color: #bfdbfe; }
.status.error { display: block; background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
.status.success { display: block; background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.45); color: #a7f3d0; }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 12, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 24px;
  width: 620px;
  max-width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: modal-in 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.modal.modal-narrow { width: 440px; }
.modal h3 {
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 700;
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.modal-close {
  background: var(--surface-3);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 18px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  align-self: flex-end;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: #2a2a42; color: var(--text); }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-3);
  font-size: 0.9rem;
}
.empty-state .empty-icon {
  display: block;
  font-size: 2.2rem;
  margin-bottom: 10px;
  opacity: 0.55;
}
.empty-state .empty-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 6px;
}

/* ===== Section scaffolding (shared) ===== */
.section { margin-bottom: 36px; }
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}
.section-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 0.95em;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  margin-right: 9px;
  vertical-align: -2px;
}
.section-count {
  font-size: 0.76rem;
  color: var(--text-2);
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: var(--radius-full);
}
