/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  /* Surfaces — warm-dark charcoal with a faint arcane undertone */
  --bg: #131019;
  --bg-elevated: #1a1622;
  --bg-card: #211c2c;
  --bg-card-hover: #292233;
  --bg-input: #201c2a;
  --bg-input-focus: #262032;

  /* Borders */
  --border: #322a3f;
  --border-light: #4a405c;

  /* Text */
  --text: #f2eff7;
  --text-dim: #aca3bd;
  --text-faint: #746c8a;

  /* Brand accents */
  --accent: #e0483d;
  --accent-hover: #f2594c;
  --accent-dim: #4a201c;
  --accent-glow: rgba(224, 72, 61, 0.38);

  --gold: #d9b54a;
  --gold-hover: #ecc964;
  --gold-dim: #453a19;
  --gold-glow: rgba(217, 181, 74, 0.3);

  --good: #4fbf87;
  --good-dim: #1b3a2b;
  --warn: #d9b54a;
  --danger: #e0483d;
  --danger-dim: #4a201c;

  /* Shape */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 10px 28px -10px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, 0.65);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.04);

  /* Motion */
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);

  font-size: 16px;
  color-scheme: dark;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(ellipse 1100px 500px at 15% -8%, rgba(224, 72, 61, 0.10), transparent 60%),
    radial-gradient(ellipse 900px 500px at 100% 0%, rgba(217, 181, 74, 0.07), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  margin: 0 0 0.45em;
  color: var(--text);
  letter-spacing: 0.01em;
  line-height: 1.25;
}
h3 { font-size: 1.15rem; }

p { margin: 0 0 0.75em; }
p:last-child { margin-bottom: 0; }

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

::selection { background: var(--accent-glow); color: var(--text); }

/* Scrollbars (WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: var(--radius-pill); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: padding-box; }

/* Keyboard focus (mouse clicks don't trigger :focus-visible) */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Header / shell
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(26, 22, 34, 0.85);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.site-header .brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.site-header .brand h1 {
  font-size: 1.3rem;
  margin: 0;
  color: var(--gold);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-header .brand .tagline {
  color: var(--text-faint);
  font-size: 0.82rem;
  padding-left: 0.7rem;
  border-left: 1px solid var(--border);
}

.site-header nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-inset);
  transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn:hover { background: var(--bg-card-hover); border-color: var(--text-faint); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn:disabled:hover { background: var(--bg-input); border-color: var(--border-light); }

.btn-primary {
  background: linear-gradient(155deg, var(--accent-hover), var(--accent) 70%);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px -4px var(--accent-glow), var(--shadow-inset);
}
.btn-primary:hover { background: linear-gradient(155deg, #ff685a, var(--accent-hover) 70%); border-color: var(--accent-hover); box-shadow: 0 6px 18px -4px var(--accent-glow), var(--shadow-inset); }

.btn-danger { color: #ffb3a8; border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: rgba(224, 72, 61, 0.14); border-color: var(--accent-hover); }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.char-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.char-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  opacity: 0;
  transition: opacity var(--transition);
}
.char-card:hover { border-color: var(--border-light); transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.char-card:hover::before { opacity: 1; }

.char-card h3 { font-size: 1.1rem; }
.char-card .meta { color: var(--text-dim); font-size: 0.85rem; }

.hp-bar {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}
.hp-bar-fill { height: 100%; background: linear-gradient(90deg, #3aa06f, var(--good)); transition: width var(--transition-slow); }
.hp-bar-fill.low { background: linear-gradient(90deg, #b8901f, var(--warn)); }
.hp-bar-fill.critical { background: linear-gradient(90deg, #a8362c, var(--danger)); }

.char-card .card-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  margin-top: 1.5rem;
}
.empty-state h3 { color: var(--text); }
.empty-state-icon { font-size: 2.75rem; margin-bottom: 0.75rem; opacity: 0.75; }

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

/* ==========================================================================
   Forms
   ========================================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}
.field label { font-size: 0.85rem; color: var(--text-dim); font-weight: 500; }
.field .hint { font-size: 0.78rem; color: var(--text-faint); }

input[type=text], input[type=number], input[type=search], select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
  box-shadow: var(--shadow-inset);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
textarea { resize: vertical; min-height: 5em; }
input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Wizard
   ========================================================================== */
.wizard-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.75rem;
}
.wizard-step {
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  color: var(--text-faint);
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.wizard-step.active {
  background: linear-gradient(155deg, var(--accent-hover), var(--accent));
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 3px 12px -3px var(--accent-glow);
}
.wizard-step.done { background: var(--good-dim); color: var(--good); border-color: var(--good); }

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.option-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}
.option-card:hover { border-color: var(--border-light); transform: translateY(-2px); }
.option-card.selected { border-color: var(--accent); background: linear-gradient(160deg, rgba(224, 72, 61, 0.12), rgba(224, 72, 61, 0.04)); box-shadow: 0 0 0 1px var(--accent) inset; }
.option-card h4 { margin-bottom: 0.25rem; font-size: 1rem; }
.option-card .desc { color: var(--text-dim); font-size: 0.82rem; }
.option-card .row-header { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; }
.option-card .row-header h4 { margin-bottom: 0; }

.info-btn {
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-faint);
  border-radius: var(--radius-pill);
  width: 20px;
  height: 20px;
  min-width: 20px;
  font-size: 0.85rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.info-btn:hover { border-color: var(--gold); color: var(--gold); background: var(--gold-dim); }

.pill-choice {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-pill);
  padding: 0.32rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}
.pill-choice:hover { border-color: var(--text-faint); transform: translateY(-1px); }
.pill-choice.selected { background: linear-gradient(155deg, var(--accent-hover), var(--accent)); border-color: var(--accent); color: #fff; }
.pill-choice.disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.wizard-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ==========================================================================
   Character sheet
   ========================================================================== */
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.sheet-header .identity h2 { margin-bottom: 0.15rem; }
.sheet-header .identity .sub { color: var(--text-dim); }

.stat-block {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 780px) {
  .stat-block { grid-template-columns: repeat(3, 1fr); }
}
.ability-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  padding: 0.7rem 0.3rem;
  transition: border-color var(--transition), transform var(--transition);
}
.ability-box:hover { border-color: var(--border-light); transform: translateY(-2px); }
.ability-box .label { font-size: 0.7rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.ability-box .score { font-size: 1.6rem; font-weight: 700; font-family: Georgia, serif; }
.ability-box .mod { font-size: 0.85rem; color: var(--text-dim); }

.top-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}
.top-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  padding: 0.65rem 0.3rem;
  transition: border-color var(--transition), transform var(--transition);
}
.top-stat:hover { border-color: var(--gold); transform: translateY(-2px); }
.top-stat .value { font-size: 1.35rem; font-weight: 700; color: var(--gold); font-family: Georgia, serif; }
.top-stat .label { font-size: 0.7rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.03em; }

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.65rem 0.95rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 0.92rem;
  font-weight: 500;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.skill-row, .save-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.3rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.skill-row:hover, .save-row:hover { background: var(--bg-input); }
.skill-row .dot, .save-row .dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1.5px solid var(--border-light);
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}
.skill-row .dot.proficient, .save-row .dot.proficient { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.skill-row .dot.expertise { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 6px var(--gold-glow); }
.skill-row .bonus, .save-row .bonus { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

.list-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.6rem;
  transition: border-color var(--transition);
}
.list-item:hover { border-color: var(--border-light); }
.list-item .row-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.list-item h4 { font-size: 0.98rem; margin: 0; }
.list-item .desc { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.35rem; white-space: pre-line; }
.list-item .tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.4rem; }
.tag { background: var(--bg-input); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 0.15rem 0.45rem; font-size: 0.72rem; color: var(--text-dim); }

.spell-slot-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.45rem; }
.slot-pip {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--gold);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.slot-pip:hover { transform: scale(1.15); }
.slot-pip.used { background: var(--gold); box-shadow: 0 0 8px var(--gold-glow); }

.death-pip.success { border-color: var(--good); }
.death-pip.success.used { background: var(--good); box-shadow: 0 0 8px rgba(79, 191, 135, 0.4); }
.death-pip.failure { border-color: var(--danger); }
.death-pip.failure.used { background: var(--danger); box-shadow: 0 0 8px var(--accent-glow); }

/* ==========================================================================
   Modal & toast
   ========================================================================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 8, 14, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 1rem;
  animation: overlayIn 160ms ease-out;
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  animation: modalIn 200ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0.75rem 1.1rem;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  animation: toastIn 220ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================================================
   Utilities
   ========================================================================== */
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }
.text-good { color: var(--good); }
.text-danger { color: var(--danger); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; }
.hidden { display: none !important; }
