/* ═══════════════════════════════════════════════════════════
   MODAL ROOT
   Shared shell for all custom modals (confirm + story). Root
   is created lazily by modal.js — no HTML wiring needed.
   ═══════════════════════════════════════════════════════════ */

.modal-root {
  position: fixed; inset: 0;
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
  pointer-events: auto;
  opacity: 1;
  transition: opacity var(--dur-normal) var(--ease-out);
}
.modal-root.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal-viewport {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - var(--sp-6));
  display: flex; align-items: center; justify-content: center;
}

/* Card entry animation — slight lift + fade */
.modal-card {
  width: 100%;
  background: var(--panel-bg);
  border: var(--panel-border);
  border-radius: var(--panel-radius);
  box-shadow:
    var(--panel-shadow),
    0 24px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex; flex-direction: column;
  max-height: calc(100vh - var(--sp-6));
  outline: none;
  animation: modal-enter var(--dur-normal) var(--ease-out);
}
.modal-root.is-hidden .modal-card { animation: none; }

@keyframes modal-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ── Shared header / footer ─────────────────────────────── */

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-hair);
  background: rgba(255, 255, 255, 0.02);
}
.modal-title {
  margin: 0;
  color: var(--accent-gold);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  letter-spacing: 0.3px;
}
.modal-close {
  background: transparent;
  color: var(--text-2);
  border: none;
  font-size: 24px;
  line-height: 1;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 4px;
  transition: color var(--dur-fast), background var(--dur-fast);
}
.modal-close:hover { color: var(--text-1); background: var(--surface-3); }

.modal-body {
  padding: var(--sp-4);
  color: var(--text-1);
  font-size: var(--text-md);
  line-height: 1.55;
  overflow-y: auto;
}
.modal-body p { margin: 0 0 var(--sp-3); }
.modal-body p:last-child { margin-bottom: 0; }
.modal-body strong { color: var(--accent-gold); }

.modal-footer {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border-hair);
  background: rgba(0, 0, 0, 0.15);
}

.modal-btn {
  padding: var(--sp-2) var(--sp-4);
  min-width: 100px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: 0.3px;
  border: 1px solid var(--border-hair);
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast);
}
.modal-btn:hover { transform: translateY(-1px); }
.modal-btn:active { transform: translateY(0); }
.modal-btn:focus-visible { outline: 2px solid var(--accent-xp); outline-offset: 2px; }

.modal-btn-cancel {
  background: var(--surface-3);
  color: var(--text-1);
}
.modal-btn-cancel:hover { background: var(--surface-4); }

.modal-btn-confirm {
  background: linear-gradient(180deg, #b8860b 0%, #7a5a08 100%);
  border-color: var(--accent-gold);
  color: #14161a;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.modal-btn-confirm:hover {
  background: linear-gradient(180deg, #d4a017 0%, #8a6608 100%);
  box-shadow: 0 0 14px rgba(255, 215, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.modal-btn-confirm.is-danger {
  background: linear-gradient(180deg, #a03030 0%, #6a1a1a 100%);
  border-color: #d44;
  color: #fff;
  box-shadow: 0 0 10px rgba(255, 60, 60, 0.3);
}
.modal-btn-confirm.is-danger:hover {
  background: linear-gradient(180deg, #c04040 0%, #802020 100%);
  box-shadow: 0 0 16px rgba(255, 60, 60, 0.45);
}

/* ═══════════════════════════════════════════════════════════
   STORY MODAL — bigger, portrait-heavy, class-themed
   ═══════════════════════════════════════════════════════════ */

.modal-story {
  max-width: 620px;
  position: relative;
}

/* Faint class-color wash from the top-right corner (same trick as the
   equipment tab's character header). Uses inline --this-class var. */
.modal-story::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top right, var(--this-class, transparent) 0%, transparent 60%);
  opacity: 0.15;
  pointer-events: none;
}
.modal-story > * { position: relative; }

.modal-story-eyebrow {
  padding: var(--sp-3) var(--sp-4) 0;
  color: var(--accent-gold);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-align: center;
}

.modal-story-inner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-4);
  padding: var(--sp-4);
  align-items: start;
}
@media (max-width: 560px) {
  .modal-story-inner {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
}

.modal-story-portrait-wrap { display: flex; align-items: center; justify-content: center; }

/* Portrait slot for the modal — bigger than any in-game slot. Reserves space
   for future hi-res portrait art; today it just shows the SVG larger. */
.slot.sz-portrait-2xl {
  width: 160px;
  height: 160px;
  border-radius: 12px;
  border-width: 2px;
}

.modal-story-body { min-width: 0; }
.modal-story-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}
.modal-story-name {
  margin: 0;
  color: var(--accent-gold);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: 0.5px;
  line-height: 1.1;
}
.modal-story-class { font-size: var(--text-xs); }

.modal-story-text {
  margin: 0;
  color: var(--text-1);
  font-size: var(--text-md);
  line-height: 1.65;
  /* Slight indent + italics to feel like flavor prose, not UI copy */
  font-style: italic;
  padding-left: var(--sp-3);
  border-left: 2px solid var(--border-hair);
}

/* ═══════════════════════════════════════════════════════════
   SETTINGS MODAL (existing) — retuned to match the new modal
   language but preserves the pre-existing structure so
   ui-settings.js keeps working without changes.
   ═══════════════════════════════════════════════════════════ */

.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: var(--sp-4);
}
.modal.hidden { display: none; }
.modal-inner {
  background: var(--panel-bg);
  border: var(--panel-border);
  border-radius: var(--panel-radius);
  box-shadow: var(--panel-shadow), 0 24px 48px rgba(0, 0, 0, 0.5);
  max-width: 560px; width: 100%; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-hair);
  background: rgba(255, 255, 255, 0.02);
}
.modal-head h2 {
  margin: 0;
  color: var(--accent-gold);
  font-size: var(--text-lg);
}
.modal-close-x {
  /* Note: uses same class as older ui-settings.js .modal-close if present */
}

.settings-section {
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
}
.settings-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.settings-section h3 { margin: 0 0 var(--sp-2); color: var(--accent-gold); font-size: var(--text-md); }
.settings-section p { margin: 4px 0; font-size: var(--text-sm); color: var(--text-1); }
.settings-section textarea {
  width: 100%; height: 100px;
  background: var(--surface-1);
  color: var(--text-1);
  border: 1px solid var(--border-hair);
  border-radius: 6px;
  padding: var(--sp-2);
  font-family: monospace;
  font-size: var(--text-xs);
  resize: vertical;
  margin: 4px 0 var(--sp-2);
}
.settings-btn-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.settings-section button {
  background: var(--surface-3);
  color: var(--text-1);
  border: 1px solid var(--border-hair);
  border-radius: 6px;
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.settings-section button:hover { background: var(--surface-4); }
.settings-section button.danger-btn { background: #6a2828; border-color: #a44; color: #fdd; }
.settings-section button.danger-btn:hover { background: #8a3838; }
.settings-section button.flash-ok { background: #2a5a2a; border-color: #5c5; color: #cfc; }
.settings-section button.flash-error { background: #6a2828; border-color: #a44; color: #fdd; }

.settings-advanced {
  margin-top: var(--sp-3);
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--border-subtle);
}
.settings-advanced > summary {
  cursor: pointer; color: var(--text-2); font-size: var(--text-sm);
  padding: 4px 0; user-select: none;
}
.settings-advanced > summary:hover { color: var(--text-1); }
.settings-advanced[open] > summary { color: var(--text-1); margin-bottom: var(--sp-2); }
.modal-body-settings { padding: var(--sp-4); overflow-y: auto; }
