/* =========================================================
   Godbound Toolkit – Dark Fantasy Theme
   ========================================================= */

/* ─── Custom Properties ─────────────────────────────────── */
:root {
  --bg-base:      #1a083f;
  --bg-surface:   #6727ce7c;
  --bg-card:      #080227;
  --bg-raised:    #150d2500;

  --gold:         #c9a84c;
  --gold-light:   #e8c97a;
  --gold-dim:     #7a6230;

  --red:          #c0392b;
  --red-light:    #e74c3c;
  --green:        #27ae60;
  --green-light:  #2ecc71;
  --yellow:       #f39c12;
  --blue:         #2980b9;
  --blue-light:   #3498db;

  --text-primary:   #f0e8d8;
  --text-secondary: #bbb5d0;
  --text-muted:     #8a8498;

  --border:         #524d73;
  --border-focus:   var(--gold);

  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;

  --shadow:     0 2px 12px rgba(0,0,0,.6);
  --shadow-lg:  0 4px 24px rgba(0,0,0,.8);

  --z-header:  100;
  --z-modal:  1000;

  /* Theme-switchable helpers */
  --header-bg:        linear-gradient(135deg, #12102a 0%, #1e1b38 100%);
  --btn-primary-text: #1a1000;
  --scrollbar-track:  #1a0840;
  --body-font:        'Segoe UI', system-ui, sans-serif;
}

/* ─── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 25.5px; scroll-behavior: smooth; }

body {
  font-family: var(--body-font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); }

/* ─── Header ────────────────────────────────────────────── */
.app-header {
  background: var(--header-bg);
  border-bottom: 2px solid var(--gold-dim);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  box-shadow: var(--shadow-lg);
}

.app-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: .05em;
  text-shadow: 0 0 20px color-mix(in srgb, var(--gold) 40%, transparent);
  white-space: nowrap;
}

.app-logo span { color: var(--text-secondary); font-weight: 300; font-size: 1rem; }

/* ─── Navigation Tabs ───────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: .25rem;
  flex-wrap: nowrap;
  flex: 1;
  align-items: stretch;
}

.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: .9rem;
  padding: .45rem 1rem;
  transition: background .2s, color .2s, border-color .2s;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}

.tab-btn:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-raised);
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 600;
}

/* ─── Header action buttons (Import / Export) ───────────── */
.header-actions {
  display: flex;
  gap: .35rem;
  flex-shrink: 0;
  align-items: stretch;
}

.btn-header-action {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: .85rem;
  padding: .45rem .85rem;
  transition: background .2s, color .2s, border-color .2s;
  white-space: nowrap;
}

.btn-header-action:hover {
  background: var(--bg-raised);
  border-color: var(--gold-dim);
  color: var(--text-primary);
}

/* ─── Main Content ──────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .75rem;
}

.card-title {
  color: var(--gold);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: .03em;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.card-note {
  font-size: .82rem;
  color: var(--text-secondary);
  margin-bottom: .5rem;
}

/* ─── Panel Grid (dice roller columns) ─────────────────── */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

/* ─── Form Elements ─────────────────────────────────────── */
input[type="text"],
input[type="number"],
select,
textarea {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: .9rem;
  text-align: center;
  outline: none;
  transition: border-color .2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus { border-color: var(--border-focus); }

.input-main {
  padding: .4rem .6rem;
  width: 100%;
}

.input-sm {
  padding: .35rem .5rem;
  width: 4.5rem;
}

.form-row {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem;
}

/* Overview layout tweaks */
.overview-level { display: flex; justify-content: center; }
.fact-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
  width: 100%;
}
@media (max-width: 768px) {
  .fact-row { grid-template-columns: 1fr; }
}
.fact-field .notes-area { width: 100%; }

.form-label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .85rem;
  color: var(--text-secondary);
}

.self-end { align-self: flex-end; }

.mt-sm  { margin-top: .5rem; }
.mt-md  { margin-top: 1rem; }

.col-span-2 { grid-column: span 2; }

.notes-area {
  width: 100%;
  padding: .5rem .75rem;
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

/* ─── Buttons ───────────────────────────────────────────── */
button {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  padding: .45rem 1rem;
  transition: background .15s, opacity .15s;
}

button:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary  { background: var(--gold);      color: var(--btn-primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--gold-light); }

.btn-secondary { background: var(--blue);     color: #fff; }
.btn-secondary:hover:not(:disabled) { background: var(--blue-light); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-raised); color: var(--text-primary); }

.btn-danger  { background: var(--red);        color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-light); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: .25rem .5rem;
  font-size: .85rem;
}
.btn-icon:hover:not(:disabled) { color: var(--text-primary); background: var(--bg-raised); }

.btn-lg { padding: .6rem 1.5rem; font-size: 1rem; }

.btn-group {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

/* ─── Dice Roller ───────────────────────────────────────── */
.quick-dice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .5rem;
}

.die-btn {
  background: var(--bg-raised);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--gold);
  font-weight: 700;
  font-size: 1rem;
  padding: .5rem .8rem;
  min-width: 3rem;
  transition: background .15s, border-color .15s, transform .1s;
}
.die-btn:hover { background: var(--bg-card); border-color: var(--gold); transform: translateY(-2px); }
.die-btn:active { transform: translateY(0); }

.input-row {
  display: flex;
  gap: .5rem;
  align-items: center;
}

.fray-badge {
  background: var(--bg-raised);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius-sm);
  color: var(--gold);
  font-weight: 700;
  padding: .3rem .6rem;
  font-size: .9rem;
}

/* ─── Roll Result ───────────────────────────────────────── */
.roll-result {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  padding: 1rem 1.5rem;
  text-align: center;
  transition: border-color .3s;
}

.roll-result.hidden { display: none; }

.roll-result.success { border-color: var(--green); }
.roll-result.failure { border-color: var(--red); }
.roll-result.critical { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 8%, transparent); }
.roll-result.fumble   { border-color: var(--red-light); }

.result-label    { color: var(--text-secondary); font-size: .85rem; margin-bottom: .25rem; }
.result-total    { font-size: 3rem; font-weight: 700; color: var(--gold); line-height: 1; }
.result-breakdown{ color: var(--text-secondary); font-size: .85rem; margin-top: .25rem; }
.result-badge    { display: inline-block; margin-top: .5rem; padding: .2rem .6rem; border-radius: 999px; font-weight: 700; font-size: .85rem; }
.badge-crit   { background: color-mix(in srgb, var(--gold) 30%, transparent); color: var(--gold-light); }
.badge-fumble { background: color-mix(in srgb, var(--red-light) 30%, transparent);  color: var(--red-light); }
.badge-hit    { background: color-mix(in srgb, var(--green) 30%, transparent);  color: var(--green-light); }
.badge-miss   { background: color-mix(in srgb, var(--red) 30%, transparent);  color: var(--red-light); }

/* ─── Roll History ──────────────────────────────────────── */
.dice-history {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.history-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .35rem .5rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-size: .82rem;
  flex-wrap: wrap;
}

.history-row.success  { border-left: 3px solid var(--green); }
.history-row.failure  { border-left: 3px solid var(--red); }
.history-row.critical { border-left: 3px solid var(--gold); }
.history-row.fumble   { border-left: 3px solid var(--red-light); }

.h-label  { color: var(--text-secondary); flex: 1; min-width: 120px; }
.h-rolls  { color: var(--text-muted); font-size: .78rem; }
.h-total  { font-weight: 700; color: var(--gold); min-width: 2rem; text-align: right; }
.h-time   { color: var(--text-muted); font-size: .75rem; margin-left: auto; }

.tag {
  padding: .1rem .4rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
}
.tag-crit   { background: color-mix(in srgb, var(--gold) 30%, transparent);      color: var(--gold-light); }
.tag-fumble { background: color-mix(in srgb, var(--red-light) 30%, transparent);   color: var(--red-light); }
.tag-hit    { background: color-mix(in srgb, var(--green) 30%, transparent);   color: var(--green-light); }
.tag-miss   { background: color-mix(in srgb, var(--red) 30%, transparent);   color: #e0a0a0; }

/* ─── Combat Tracker ────────────────────────────────────── */
.round-badge {
  background: var(--blue);
  border-radius: 999px;
  color: #fff;
  font-size: .78rem;
  padding: .2rem .6rem;
  font-weight: 600;
}

.add-combatant-form {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}

.add-combatant-form .input-main { max-width: 160px; }

.stock-enemy-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .6rem;
  flex-wrap: wrap;
}

.stock-enemy-label {
  font-size: .75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.stock-enemy-row .input-main {
  flex: 1 1 200px;
  max-width: 360px;
}

/* Servants & Minions add form – mirrors add-combatant-form layout */
.add-servant-form {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}

.add-servant-form .input-main { max-width: 180px; }
.add-servant-form .input-sm   { max-width: 80px; }

.combatant-list {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.combatant-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color .2s;
}

.combatant-row.active-turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 20%, transparent);
}

.combatant-row.dead { opacity: .5; }

.c-header {
  background: var(--bg-raised);
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .75rem;
  flex-wrap: wrap;
}

.c-init-badge {
  background: var(--blue);
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  min-width: 2rem;
  padding: .15rem .4rem;
  text-align: center;
}

.c-name {
  font-weight: 600;
  flex: 1;
}

.pc-badge {
  background: color-mix(in srgb, var(--gold) 20%, transparent);
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  color: var(--gold);
  font-size: .7rem;
  padding: .05rem .4rem;
}

.c-ac {
  color: var(--text-secondary);
  font-size: .82rem;
}

.turn-arrow {
  color: var(--gold);
  font-weight: 700;
  font-size: .82rem;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .4; }
}

.btn-remove { color: var(--red-light); margin-left: auto; }

.c-body {
  padding: .6rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

/* HP */
.hp-section {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}

.hp-label { font-size: .78rem; color: var(--text-secondary); min-width: 1.5rem; }

.hp-bar-wrap {
  flex: 1;
  min-width: 80px;
  max-width: 200px;
  height: 8px;
  background: var(--bg-surface);
  border-radius: 999px;
  overflow: hidden;
}

.hp-bar {
  height: 100%;
  border-radius: 999px;
  transition: width .3s;
}

.hp-good   { background: var(--green); }
.hp-warn   { background: var(--yellow); }
.hp-danger { background: var(--red-light); }

.hp-input {
  width: 3.5rem;
  padding: .25rem .3rem;
  text-align: center;
}

.hp-sep { color: var(--text-muted); }

/* Effort */
.effort-section {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}

.effort-label { font-size: .78rem; color: var(--text-secondary); min-width: 2.5rem; }

.effort-pips {
  display: flex;
  gap: .25rem;
}

.pip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--gold-dim);
  cursor: pointer;
  transition: background .15s;
}

.pip-free { background: transparent; }
.pip-used { background: var(--gold); border-color: var(--gold); }

.effort-count {
  font-size: .82rem;
  color: var(--text-secondary);
  min-width: 2.5rem;
}

/* Status effects */
.status-section { display: flex; align-items: flex-start; flex-direction: column; gap: .25rem; }

.status-tags { display: flex; flex-wrap: wrap; gap: .25rem; }

.status-tag {
  background: color-mix(in srgb, var(--blue) 20%, transparent);
  border: 1px solid var(--blue);
  border-radius: 999px;
  color: var(--blue-light);
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: .75rem;
  padding: .1rem .5rem;
}

.tag-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: .75rem;
  line-height: 1;
  opacity: .7;
  padding: 0;
}
.tag-remove:hover { opacity: 1; }

.status-add {
  display: flex;
  gap: .25rem;
}

/* ─── Character Sheet ───────────────────────────────────── */
.char-selector-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.char-selector-bar .input-main { flex: 1; min-width: 140px; }

/* Character top-of-card gold accent */
#character-tab .card {
  border-top: 2px solid var(--gold-dim);
}

/* ─── Character Stat Banner ────────────────────────────── */
.char-stat-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stat-pip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: .7rem .5rem .6rem;
  border-right: 1px solid var(--border);
  text-align: center;
  transition: background .2s;
}

.stat-pip:last-child { border-right: none; }

.stat-pip-label {
  font-size: .58rem;
  color: var(--text-muted);
  letter-spacing: .08em;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: .25rem;
}

.stat-pip-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}

.stat-pip-sub {
  font-size: .7rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: .1rem;
}

.stat-pip.stat-hp-ok   { background: color-mix(in srgb, var(--green)   7%, transparent); }
.stat-pip.stat-hp-warn { background: color-mix(in srgb, var(--yellow)  9%, transparent); }
.stat-pip.stat-hp-low  { background: color-mix(in srgb, var(--red)    11%, transparent); }

@media (max-width: 600px) {
  /* On small screens wrap pips into a 4-column grid */
  .char-stat-banner { grid-template-columns: repeat(4, 1fr); }
  /* Add bottom separators between rows; remove right border at the end of each row */
  .stat-pip { border-bottom: 1px solid var(--border); }
  .stat-pip:nth-child(4n) { border-right: none; }
  /* Remove bottom border from the last row of pips so the banner keeps a clean base edge */
  .stat-pip:last-child,
  .stat-pip:nth-last-child(2),
  .stat-pip:nth-last-child(3),
  .stat-pip:nth-last-child(4) { border-bottom: none; }
}

/* ─── Resources 2×2 grid ───────────────────────────────── */
.resources-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-top: .75rem;
}

@media (max-width: 580px) {
  .resources-grid { grid-template-columns: 1fr; }
}

.resources-grid .resource-group {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .75rem;
}

/* Each resource group already has a full border; gap handles all spacing.
   The adjacent-sibling rule from the outer scope is intentionally not repeated
   here — every group retains uniform padding on all sides. */

/* Attributes */
.attr-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .5rem;
}

@media (max-width: 600px) {
  .attr-grid { grid-template-columns: repeat(3, 1fr); }
}

.attr-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: .4rem .4rem .3rem;
  text-align: center;
}

.attr-score {
  text-align: right;
  width: 2.8rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--text-primary);
  padding: 0;
}
.attr-score:focus { border-bottom: 1px solid var(--gold); }

.attr-bonus-input {
  text-align: right;
  width: 2.5rem;
  padding: .1rem .2rem;
  font-size: .85rem;
}

/* Words of Power */
.word-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: .6rem;
  overflow: hidden;
}

.word-header {
  background: var(--bg-raised);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .45rem .75rem;
}

.word-name {
  color: var(--gold);
  font-weight: 700;
  font-size: .95rem;
}

.gifts-list { padding: .4rem .6rem; display: flex; flex-direction: column; gap: .3rem; }

.practice-category {
  border-top: 1px solid var(--border);
  padding-top: .75rem;
  margin-top: .75rem;
}

.practice-category:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.practice-list {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.practice-header {
  gap: .5rem;
}

.practice-title-input {
  flex: 1 1 220px;
  min-width: 180px;
}

.practice-notes-wrap {
  padding: .55rem .65rem 0;
}

.practice-notes {
  min-height: 4.5rem;
}

.practice-entries-list {
  padding-top: .55rem;
}

.gifts-header {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .15rem 0 .25rem;
  border-bottom: 2px solid var(--border);
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .05em;
  text-transform: uppercase;
}
.gift-col-type   { min-width: 4.5rem; flex-shrink: 0; }
.gift-col-name   { flex: 1; min-width: 100px; }
.gift-col-act    { min-width: 5rem; flex-shrink: 0; }
.gift-col-smite  { min-width: 3.5rem; flex-shrink: 0; }
.gift-col-effort { min-width: 4rem; flex-shrink: 0; }
.gift-col-attr   { min-width: 7.25rem; flex-shrink: 0; }

.gift-row {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
  padding: .2rem 0;
  border-bottom: 1px solid var(--border);
}

.gift-row:last-child { border-bottom: none; }

.gift-row.gift-active { background: color-mix(in srgb, var(--gold) 5%, transparent); }

.practice-entry-toggle-btn {
  min-width: 1.5rem;
}

.gift-description {
  flex: 1 0 100%;
  resize: vertical;
  min-height: 2rem;
  font-size: .8rem;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .25rem .4rem;
  margin-top: .2rem;
  font-family: inherit;
}

.gift-toggle-btn {
  background: transparent;
  border: none;
  color: var(--gold);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 .2rem;
}

/* Gift type badges */
.gift-type-badge {
  font-size: .62rem;
  font-weight: 700;
  padding: .15rem .35rem;
  border-radius: 999px;
  white-space: nowrap;
  min-width: 4.2rem;
  text-align: center;
  flex-shrink: 0;
}
.gift-lesser  { background: rgba(83,83,120,.5);  color: var(--text-secondary); }
.gift-greater { background: color-mix(in srgb, var(--gold) 25%, transparent); color: var(--gold-light); }
.gift-innate  { background: color-mix(in srgb, var(--green) 35%, transparent);  color: #7ecfa0; }

.gift-smite-label {
  font-size: .75rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.gift-modify-label {
  font-size: .75rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.gift-modifier-controls {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  flex-wrap: wrap;
}

.gift-modifier-summary {
  display: inline-flex;
  align-items: center;
  padding: .14rem .4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: .68rem;
  letter-spacing: .02em;
  white-space: nowrap;
}

.gift-modifier-summary.is-active {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 55%, var(--border));
  background: color-mix(in srgb, var(--success) 12%, transparent);
}

.gift-modifier-summary.is-inactive {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
}

.gift-modifier-summary.is-template {
  color: var(--gold-light);
  border-color: color-mix(in srgb, var(--gold-light) 40%, var(--border));
  background: color-mix(in srgb, var(--gold-light) 10%, transparent);
}

/* ─── Overview layout ───────────────────────────────────── */
.overview-header {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.overview-name-label { flex: 1; min-width: 200px; }
.overview-compact { flex-shrink: 0; }

/* Section subtitles */
.section-subtitle {
  color: var(--text-secondary);
  font-size: .88rem;
  font-weight: 600;
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.card-title-ref {
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

/* Formula / hint notes */
.formula-note {
  color: var(--text-muted);
  font-size: .75rem;
  margin-top: .2rem;
}
.level-facts-note {
  color: var(--text-muted);
  font-size: .75rem;
  margin-top: .5rem;
  margin-bottom: .3rem;
  font-style: italic;
}

/* ─── Attribute block (new PDF layout) ───────────────────── */
.attr-abbr {
  color: var(--gold);
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .1em;
}
.attr-full {
  color: var(--text-muted);
  font-size: .62rem;
  letter-spacing: .03em;
  margin-bottom: .2rem;
}
.attr-trow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .1rem 0;
  width: 100%;
}
.attr-row-lbl {
  color: var(--text-muted);
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: .07em;
  min-width: 2.4rem;
}
.attr-check {
  font-size: .88rem;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 1.5rem;
  text-align: right;
}
.attr-mod-display {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: .2rem;
  margin-top: .15rem;
}
.attr-mod  { font-size: 1.1rem; font-weight: 700; line-height: 1; }
.mod-pos   { color: var(--green-light); }
.mod-neg   { color: var(--red-light); }

/* ─── Saves ─────────────────────────────────────────────── */
.saves-section { }
.saves-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
  margin-top: .5rem;
}
.save-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .5rem .4rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
}
.save-name {
  color: var(--text-secondary);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .07em;
}
.save-mod-note {
  color: var(--text-muted);
  font-size: .65rem;
}
.save-input {
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gold);
  width: 3.5rem;
}

/* ─── HP & Armour ────────────────────────────────────────── */
.hp-armor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) {
  .hp-armor-grid { grid-template-columns: 1fr; }
}
.hp-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

/* ─── Combat ─────────────────────────────────────────────── */
.combat-header-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.attack-bonus-grid {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.attack-bonus-grid .form-label {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.formula-hint {
  font-size: .72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .2rem;
  flex-wrap: wrap;
}
.input-inline-select {
  font-size: .72rem;
  padding: .1rem .2rem;
  background: var(--bg-raised);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.input-unarmed {
  padding: .35rem .5rem;
  width: 12rem;
}
.combat-info-static {
  font-size: .88rem;
  color: var(--text-primary);
  padding: .3rem .5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.damage-chart {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .7rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}
.damage-chart-title {
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 600;
  margin-right: .25rem;
}
.damage-chart-val  { color: var(--gold); font-weight: 700; font-size: .85rem; }
.damage-chart-sep  { color: var(--text-muted); }

/* ─── Resources ──────────────────────────────────────────── */
.resource-group { }
.resource-group + .resource-group { border-top: 1px solid var(--border); padding-top: .75rem; }

/* ─── Apotheosis ─────────────────────────────────────────── */
.apotheosis-layout {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 700px) {
  .apotheosis-layout { grid-template-columns: 1fr; }
}
.apo-gifts-wrap { overflow-x: auto; }
.apo-table {
  border-collapse: collapse;
  width: 100%;
  font-size: .82rem;
}
.apo-table th {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: .3rem .5rem;
  text-align: left;
  font-size: .72rem;
  letter-spacing: .04em;
}
.apo-table td    { border: 1px solid var(--border); padding: .3rem .5rem; }
.apo-lvl   { width: 2.5rem; text-align: center; color: var(--gold); font-weight: 700; }
.apo-name  { color: var(--text-primary); }
.apo-act   { color: var(--text-secondary); font-size: .78rem; }
.apo-check { text-align: center; width: 3rem; }
tr.apo-gained td { background: color-mix(in srgb, var(--gold) 8%, transparent); }

.apo-ref-tables { display: flex; flex-direction: column; gap: .5rem; }
.apo-ref-table {
  border-collapse: collapse;
  width: 100%;
  font-size: .78rem;
}
.apo-ref-table caption {
  color: var(--gold-dim);
  font-size: .75rem;
  font-weight: 600;
  text-align: left;
  padding-bottom: .2rem;
  caption-side: top;
}
.apo-ref-table th {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: .2rem .4rem;
  font-size: .7rem;
}
.apo-ref-table td {
  border: 1px solid var(--border);
  padding: .2rem .4rem;
  color: var(--text-secondary);
  font-size: .78rem;
  text-align: center;
}

/* ─── Cult ───────────────────────────────────────────────── */
.cult-stats-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.cult-name-label { flex: 1; min-width: 200px; }
.cult-details-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
}
@media (max-width: 700px) {
  .cult-details-grid { grid-template-columns: 1fr; }
}
.shrines-section { }

/* Equipment */
.equip-section { margin-bottom: 1rem; }

.equip-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .4rem;
}

.equip-section-header h3 { color: var(--text-secondary); font-size: .85rem; font-weight: 600; }

.equip-table {
  border-collapse: collapse;
  width: 100%;
  font-size: .82rem;
}

.equip-table th {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: .3rem .5rem;
  text-align: left;
}

.equip-table td {
  border: 1px solid var(--border);
  padding: .2rem .4rem;
}

.equip-table .input-sm  { width: 5rem; }
.equip-table .input-main { width: 100%; }

/* Save Bar */
.save-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem;
  position: sticky;
  bottom: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 2px solid var(--gold-dim);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .5);
  z-index: 10;
  margin-top: .5rem;
}

.save-status {
  color: var(--green-light);
  font-size: .85rem;
}

.sub-label { color: var(--text-secondary); font-size: .78rem; }

.effort-avail {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold);
}

/* ─── Empty Messages ────────────────────────────────────── */
.empty-msg    { color: var(--text-muted); font-size: .88rem; padding: .5rem 0; }
.empty-msg-sm { color: var(--text-muted); font-size: .8rem; padding: .3rem .6rem; }

/* ─── Toast Notifications ───────────────────────────────── */
#toast-container {
  bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  pointer-events: none;
  position: fixed;
  right: 1.5rem;
  z-index: 9999;
}

.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: .875rem;
  max-width: 320px;
  opacity: 0;
  padding: .6rem 1rem;
  transform: translateX(20px);
  transition: opacity .25s, transform .25s;
}

.toast.toast-show { opacity: 1; transform: translateX(0); }
.toast.toast-success { border-left-color: var(--green); }
.toast.toast-error   { border-left-color: var(--red-light); }
.toast.toast-info    { border-left-color: var(--blue); }

/* ─── Scrollbars ────────────────────────────────────────── */
:root { scrollbar-width: thin; scrollbar-color: var(--gold-dim) var(--scrollbar-track); }
::-webkit-scrollbar       { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); border-left: 1px solid var(--border); }
::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 5px; border: 2px solid var(--scrollbar-track); }
::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 700px) {
  .app-header { flex-direction: column; align-items: flex-start; padding: .6rem 1rem; }
  .panel-grid { grid-template-columns: 1fr; }
  main { padding: 1rem .75rem 3rem; }
  .add-combatant-form .input-main { max-width: 100%; }
  .add-servant-form .input-main   { max-width: 100%; }
}

/* ─── Data Editor ───────────────────────────────────────── */
.de-word-block .word-header { flex-wrap: wrap; }

.de-practice-card .card-header {
  align-items: flex-start;
}

/* Action cell – holds apply + remove buttons side-by-side */
.de-action-cell {
  white-space: nowrap;
  display: flex;
  gap: .3rem;
  align-items: center;
}

/* Apply-to-character button (green-ish secondary style) */
.btn-secondary {
  background: var(--blue);
  color: #fff;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--blue-light);
}

/* ─── Import / Export Modal ─────────────────────────────── */
.iex-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.iex-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 90%;
  padding: 1.5rem;
}

.iex-title {
  color: var(--gold);
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: .75rem;
}

.iex-body {
  color: var(--text-secondary);
  font-size: .9rem;
  margin-bottom: .75rem;
}

.iex-list {
  list-style: disc;
  padding-left: 1.25rem;
  font-size: .85rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.iex-list li strong { color: var(--text-primary); }

.iex-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ─── Theme Selector ────────────────────────────────────── */
.theme-select {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  padding: .45rem .6rem;
  transition: border-color .2s, color .2s;
  white-space: nowrap;
}

.theme-select:hover,
.theme-select:focus {
  border-color: var(--gold-dim);
  color: var(--text-primary);
  outline: none;
}

/* ═══════════════════════════════════════════════════════════
   THEME: High Fantasy
   Deep forest greens, warm amber accents, parchment text.
   ═══════════════════════════════════════════════════════════ */
[data-theme="high-fantasy"] {
  --bg-base:        #0b1a0b;
  --bg-surface:     rgba(20, 60, 20, 0.55);
  --bg-card:        #060f06;
  --bg-raised:      rgba(15, 50, 15, 0.45);

  --gold:           #c8820a;
  --gold-light:     #e8a030;
  --gold-dim:       #7a4f05;

  --red:            #b03020;
  --red-light:      #e05040;
  --green:          #3a9e3a;
  --green-light:    #56c256;
  --yellow:         #d4a020;
  --blue:           #2a6090;
  --blue-light:     #3a80b8;

  --text-primary:   #e8dfc0;
  --text-secondary: #a8c090;
  --text-muted:     #6a8860;

  --border:         #2a5a2a;
  --border-focus:   var(--gold);

  --header-bg:      linear-gradient(135deg, #090f09 0%, #112011 100%);
  --btn-primary-text: #1a0800;
  --scrollbar-track:  #060f06;
  --body-font:        Georgia, 'Times New Roman', serif;
}

/* ═══════════════════════════════════════════════════════════
   THEME: Retro Terminal
   Phosphor-green CRT aesthetics with scanline overlay.
   ═══════════════════════════════════════════════════════════ */
[data-theme="retro-terminal"] {
  --bg-base:        #050e05;
  --bg-surface:     rgba(0, 35, 0, 0.65);
  --bg-card:        #020a02;
  --bg-raised:      rgba(0, 28, 0, 0.55);

  --gold:           #00ff41;
  --gold-light:     #66ff88;
  --gold-dim:       #00882a;

  --red:            #ff3311;
  --red-light:      #ff5533;
  --green:          #00ff41;
  --green-light:    #66ff88;
  --yellow:         #ffcc00;
  --blue:           #00ccff;
  --blue-light:     #33ddff;

  --text-primary:   #00ff41;
  --text-secondary: #00cc33;
  --text-muted:     #007722;

  --border:         #004a00;
  --border-focus:   #00ff41;

  --header-bg:      linear-gradient(135deg, #020902 0%, #030d03 100%);
  --btn-primary-text: #001800;
  --scrollbar-track:  #020902;
  --body-font:        'Courier New', Courier, monospace;
}

/* Phosphor glow on key text elements */
[data-theme="retro-terminal"] .app-logo {
  text-shadow: 0 0 10px #00ff41, 0 0 22px rgba(0, 255, 65, 0.45);
}

[data-theme="retro-terminal"] .card-title,
[data-theme="retro-terminal"] .result-total,
[data-theme="retro-terminal"] .save-input,
[data-theme="retro-terminal"] .effort-avail {
  text-shadow: 0 0 6px currentColor;
}

/* CRT scanlines overlay */
[data-theme="retro-terminal"] body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.13) 2px,
    rgba(0, 0, 0, 0.13) 4px
  );
  pointer-events: none;
  z-index: 99998;
}

/* Terminal-style select / option dropdowns */
[data-theme="retro-terminal"] select option {
  background: #020a02;
  color: #00ff41;
}

/* ═══════════════════════════════════════════════════════════
   THEME: Sci-Fi (Space Opera)
   Deep-space navy, holographic cyan accents, cool-blue text.
   ═══════════════════════════════════════════════════════════ */
[data-theme="sci-fi"] {
  --bg-base:        #020815;
  --bg-surface:     rgba(0, 30, 70, 0.55);
  --bg-card:        #010510;
  --bg-raised:      rgba(0, 22, 55, 0.5);

  --gold:           #00d4ff;
  --gold-light:     #44e8ff;
  --gold-dim:       #007799;

  --red:            #ff3355;
  --red-light:      #ff5577;
  --green:          #00ff99;
  --green-light:    #44ffbb;
  --yellow:         #ffcc00;
  --blue:           #3366ff;
  --blue-light:     #5588ff;

  --text-primary:   #c0d8f0;
  --text-secondary: #7099c0;
  --text-muted:     #405878;

  --border:         #002255;
  --border-focus:   #00d4ff;

  --header-bg:      linear-gradient(135deg, #010310 0%, #020818 100%);
  --btn-primary-text: #001122;
  --scrollbar-track:  #010310;
  --body-font:        'Segoe UI', system-ui, sans-serif;
}

/* Holographic glow on key elements */
[data-theme="sci-fi"] .app-logo {
  text-shadow: 0 0 12px #00d4ff, 0 0 28px rgba(0, 212, 255, 0.35);
}

[data-theme="sci-fi"] .card-title {
  text-shadow: 0 0 8px color-mix(in srgb, var(--gold) 50%, transparent);
}

/* Subtle star-field grid lines behind the page */
[data-theme="sci-fi"] body {
  background-image:
    radial-gradient(circle, rgba(0,212,255,.06) 1px, transparent 1px),
    radial-gradient(circle, rgba(0,212,255,.04) 1px, transparent 1px);
  background-size: 40px 40px, 80px 80px;
  background-position: 0 0, 20px 20px;
}
