*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d1a;
  --bg2: #14142a;
  --card: #1a1a30;
  --card-active: #1e2440;
  --gold: #d4af37;
  --gold-light: #f0d060;
  --red: #c41e3a;
  --red-dark: #8b0000;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --border: #2a2a48;
  --border-active: #d4af37;
  --hp-hi: #22c55e;
  --hp-mid: #f59e0b;
  --hp-lo: #ef4444;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.6);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── HEADER ──────────────────────────────────── */
.header {
  background: var(--bg2);
  border-bottom: 2px solid var(--gold);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: .04em;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-title svg { flex-shrink: 0; }

.round-badge {
  background: var(--red-dark);
  border: 1px solid var(--red);
  color: var(--text);
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: .9rem;
  white-space: nowrap;
}
.round-badge span { color: var(--gold-light); }

.header-spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: 8px; font-size: .85rem;
  font-weight: 600; cursor: pointer; border: none;
  transition: filter .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:hover:not(:disabled) { filter: brightness(1.15); }

.btn-gold { background: var(--gold); color: #1a1200; }
.btn-red { background: var(--red); color: #fff; }
.btn-outline {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) { border-color: var(--text2); filter: brightness(1); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: .78rem; border-radius: 6px; }
.btn-icon {
  background: transparent; border: 1px solid var(--border);
  color: var(--text2); width: 30px; height: 30px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; cursor: pointer; transition: all .15s; font-size: .85rem;
}
.btn-icon:hover { background: var(--border); color: var(--text); }

/* ── MAIN ────────────────────────────────────── */
.main {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 100px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}
.empty-state .emoji { font-size: 3rem; display: block; margin-bottom: 12px; }
.empty-state h2 { color: var(--text2); margin-bottom: 6px; }

/* ── COMBATANT LIST ──────────────────────────── */
#combatant-list { display: flex; flex-direction: column; gap: 10px; }

.combatant-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color .2s, box-shadow .2s;
  position: relative;
}
.combatant-card.is-active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(212,175,55,.18), var(--shadow);
  background: var(--card-active);
}
.combatant-card.is-dead {
  opacity: .6;
  border-color: #333;
}
.combatant-card.turn-done {
  opacity: .75;
}

/* Active turn glow on left border */
.combatant-card.is-active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--gold);
  border-radius: var(--radius) 0 0 var(--radius);
}

/* Row 1: initiative + name + badges + actions */
.card-row1 {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.initiative-badge {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--gold-light);
  font-size: 1.05rem;
  font-weight: 800;
  min-width: 44px;
  height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
  cursor: pointer;
  transition: border-color .15s;
}
.combatant-card.is-active .initiative-badge {
  border-color: var(--gold);
  background: rgba(212,175,55,.12);
}
.initiative-badge:hover { border-color: var(--text2); }

.combatant-name {
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
  min-width: 100px;
}
.combatant-card.is-active .combatant-name { color: var(--gold-light); }

.type-badge {
  font-size: .7rem; font-weight: 700; padding: 2px 8px;
  border-radius: 12px; text-transform: uppercase; letter-spacing: .06em;
  flex-shrink: 0;
}
.type-player  { background: rgba(34,197,94,.15); color: #4ade80; border: 1px solid rgba(34,197,94,.3); }
.type-enemy   { background: rgba(196,30,58,.15);  color: #fb7185; border: 1px solid rgba(196,30,58,.3); }
.type-npc     { background: rgba(234,179,8,.15);  color: #fcd34d; border: 1px solid rgba(234,179,8,.3); }

.ac-badge {
  display: flex; align-items: center; gap: 3px;
  font-size: .8rem; color: var(--text2); flex-shrink: 0;
}
.ac-badge svg { opacity: .7; }

.ddb-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; color: var(--text3);
  text-decoration: none; padding: 3px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  transition: all .15s; flex-shrink: 0;
}
.ddb-link:hover { color: var(--gold); border-color: var(--gold); }

.card-actions { display: flex; gap: 4px; flex-shrink: 0; margin-left: auto; }

/* Active turn label */
.active-label {
  display: none;
  font-size: .7rem; font-weight: 700; color: var(--gold);
  text-transform: uppercase; letter-spacing: .1em;
}
.combatant-card.is-active .active-label { display: inline; }

/* Row 2: HP bar */
.card-row2 { margin-top: 10px; }

.hp-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.hp-label {
  font-size: .8rem; color: var(--text2); white-space: nowrap; min-width: 80px;
}
.hp-label .hp-current { font-weight: 700; font-size: 1rem; }
.hp-label .hp-sep { color: var(--text3); margin: 0 2px; }
.hp-label .hp-max { color: var(--text3); }

.hp-bar-wrap {
  flex: 1; min-width: 80px;
  background: rgba(255,255,255,.07);
  border-radius: 4px; height: 8px; overflow: hidden;
}
.hp-bar {
  height: 100%; border-radius: 4px;
  transition: width .3s ease, background-color .3s;
}

.temp-hp-badge {
  font-size: .75rem; color: #60a5fa;
  display: flex; align-items: center; gap: 3px;
  white-space: nowrap;
}

/* Damage/Heal row */
.dmg-heal-row {
  display: flex; align-items: center; gap: 6px;
  margin-top: 8px; flex-wrap: wrap;
}
.dmg-input {
  width: 68px; padding: 4px 8px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; font-size: .85rem;
  text-align: center;
}
.dmg-input:focus { outline: none; border-color: var(--text2); }
.btn-dmg { background: rgba(196,30,58,.2); color: #fb7185; border: 1px solid rgba(196,30,58,.4); }
.btn-dmg:hover { background: rgba(196,30,58,.35); filter: brightness(1); }
.btn-heal { background: rgba(34,197,94,.15); color: #4ade80; border: 1px solid rgba(34,197,94,.35); }
.btn-heal:hover { background: rgba(34,197,94,.3); filter: brightness(1); }
.btn-temp { background: rgba(96,165,250,.12); color: #60a5fa; border: 1px solid rgba(96,165,250,.3); }
.btn-temp:hover { background: rgba(96,165,250,.25); filter: brightness(1); }

/* Death saves */
.death-saves {
  margin-top: 8px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.death-saves-label {
  font-size: .75rem; color: var(--text3); font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
}
.saves-group { display: flex; align-items: center; gap: 4px; }
.save-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer; transition: all .15s;
}
.save-dot.success.filled { background: #22c55e; border-color: #22c55e; }
.save-dot.failure.filled { background: #ef4444; border-color: #ef4444; }
.save-dot.success { border-color: #22c55e; }
.save-dot.failure { border-color: #ef4444; }

/* Conditions */
.conditions-row {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin-top: 8px; align-items: center;
}
.condition-chip {
  font-size: .72rem; font-weight: 600;
  padding: 2px 8px; border-radius: 12px;
  display: flex; align-items: center; gap: 4px;
  cursor: pointer; transition: opacity .15s;
  background: rgba(234,179,8,.12); color: #fcd34d;
  border: 1px solid rgba(234,179,8,.3);
}
.condition-chip:hover { opacity: .75; }
.condition-chip .remove-cond { font-size: .65rem; opacity: .7; }

.btn-add-condition {
  font-size: .72rem; padding: 2px 8px; border-radius: 12px;
  background: transparent; border: 1px dashed var(--border);
  color: var(--text3); cursor: pointer; transition: all .15s;
}
.btn-add-condition:hover { border-color: var(--text2); color: var(--text2); }

/* Notes */
.notes-row { margin-top: 8px; }
.notes-text {
  font-size: .8rem; color: var(--text3);
  font-style: italic; cursor: pointer;
}
.notes-text:hover { color: var(--text2); }
.notes-input {
  width: 100%; background: var(--bg2);
  border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 10px;
  font-size: .82rem; resize: none; height: 56px;
  font-family: inherit;
}
.notes-input:focus { outline: none; border-color: var(--text2); }

/* ── FLOATING ADD BUTTON ─────────────────────── */
.fab {
  position: fixed; bottom: 28px; right: 24px;
  background: var(--gold); color: #1a1200;
  width: 56px; height: 56px; border-radius: 50%;
  font-size: 1.7rem; font-weight: 300;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(212,175,55,.45);
  cursor: pointer; border: none;
  transition: transform .15s, box-shadow .15s;
  z-index: 40;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(212,175,55,.6); }
.fab:active { transform: scale(.97); }

/* ── MODAL ───────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
  transform: translateY(10px); transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-title {
  font-size: 1.15rem; font-weight: 700; color: var(--gold);
  margin-bottom: 20px;
}

.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--text2); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: .05em;
}
input[type=text], input[type=number], input[type=url], textarea, select {
  width: 100%; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px;
  font-size: .9rem; font-family: inherit;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--gold);
}
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
textarea { resize: vertical; min-height: 60px; }
select option { background: var(--bg2); }

.type-selector {
  display: flex; gap: 8px;
}
.type-option {
  flex: 1; padding: 8px;
  border: 2px solid var(--border); border-radius: 8px;
  text-align: center; cursor: pointer;
  font-size: .82rem; font-weight: 600;
  transition: all .15s; user-select: none; color: var(--text2);
}
.type-option:hover { border-color: var(--text2); color: var(--text); }
.type-option.selected-player  { border-color: #22c55e; color: #4ade80; background: rgba(34,197,94,.08); }
.type-option.selected-enemy   { border-color: var(--red); color: #fb7185; background: rgba(196,30,58,.08); }
.type-option.selected-npc     { border-color: #d97706; color: #fcd34d; background: rgba(234,179,8,.08); }

.initiative-roll-row { display: flex; gap: 8px; align-items: flex-end; }
.initiative-roll-row .form-group { flex: 1; margin: 0; }
.roll-btn {
  padding: 8px 14px; border-radius: 8px; font-size: .85rem;
  font-weight: 700; cursor: pointer; border: none;
  background: rgba(212,175,55,.15); color: var(--gold);
  border: 1px solid rgba(212,175,55,.4);
  transition: all .15s; white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
}
.roll-btn:hover { background: rgba(212,175,55,.28); }
.roll-hint { font-size: .74rem; color: var(--text3); margin-top: 4px; }

.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 20px;
}

/* ── CONDITION PICKER ────────────────────────── */
.condition-picker-modal { max-width: 380px; }
.condition-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 6px; margin-top: 4px;
}
.cond-option {
  padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); cursor: pointer;
  font-size: .82rem; color: var(--text2);
  transition: all .15s; text-align: center;
}
.cond-option:hover { border-color: var(--text2); color: var(--text); }
.cond-option.selected {
  background: rgba(234,179,8,.12); color: #fcd34d;
  border-color: rgba(234,179,8,.5);
}

/* ── CONFIRM MODAL ───────────────────────────── */
.confirm-modal { max-width: 340px; }
.confirm-text { color: var(--text2); font-size: .9rem; line-height: 1.5; }

/* ── TOAST ───────────────────────────────────── */
#toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 24px;
  font-size: .85rem; font-weight: 600;
  opacity: 0; transition: opacity .2s; pointer-events: none;
  z-index: 300; white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ── MISC ────────────────────────────────────── */
.divider {
  border: none; border-top: 1px solid var(--border);
  margin: 8px 0;
}
.text-sm { font-size: .82rem; color: var(--text2); }

/* inline initiative edit */
.init-edit {
  width: 44px; text-align: center; padding: 2px 4px;
  background: var(--bg2); border: 1px solid var(--gold);
  color: var(--gold-light); border-radius: 6px;
  font-size: .95rem; font-weight: 800;
}
.init-edit:focus { outline: none; }

/* ── PARTY MODAL ─────────────────────────────── */
.party-modal { max-width: 560px; }

.party-top-actions {
  display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap;
}

.preset-list { display: flex; flex-direction: column; gap: 8px; }

.preset-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  display: flex; align-items: center; gap: 12px;
  transition: border-color .15s;
}
.preset-card:hover { border-color: var(--text3); }
.preset-card.in-encounter { border-color: rgba(34,197,94,.35); }

.preset-info { flex: 1; min-width: 0; }
.preset-name {
  font-weight: 700; font-size: .95rem;
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; margin-bottom: 2px;
}
.preset-stats { font-size: .8rem; color: var(--text2); }
.preset-notes {
  font-size: .75rem; color: var(--text3); margin-top: 2px;
  font-style: italic; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.preset-in-badge {
  font-size: .68rem; font-weight: 700; padding: 1px 6px;
  border-radius: 10px; background: rgba(34,197,94,.15);
  color: #4ade80; border: 1px solid rgba(34,197,94,.3);
  white-space: nowrap;
}

.preset-actions { display: flex; gap: 4px; flex-shrink: 0; }

.no-presets {
  text-align: center; padding: 32px 16px;
  color: var(--text3); line-height: 1.7;
}

.party-footer {
  display: flex; align-items: center; gap: 8px;
  margin-top: 16px; flex-wrap: wrap;
  border-top: 1px solid var(--border); padding-top: 14px;
}
.party-footer-spacer { flex: 1; }

/* Party button count badge */
.party-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gold); color: #1a1200;
  font-size: .65rem; font-weight: 800;
  width: 16px; height: 16px; border-radius: 50%;
  margin-left: 2px;
}

/* ── HISTORY PANEL ──────────────────────────────────────── */
.history-panel {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.history-title {
  font-size: .72rem; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .1em;
  margin-bottom: 8px;
}
.history-list { display: flex; flex-direction: column; gap: 5px; }
.history-row {
  display: flex; align-items: center; gap: 8px;
  font-size: .82rem; color: var(--text2);
  padding: 7px 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 7px;
}
.history-row.is-first { border-color: rgba(212,175,55,.2); }
.history-icon { font-size: .9rem; flex-shrink: 0; }
.history-name { font-weight: 600; color: var(--text); flex-shrink: 0; }
.history-detail { flex: 1; color: var(--text2); font-size: .8rem; }
.history-hp-arrow { color: var(--text3); margin: 0 3px; }
.history-undo {
  flex-shrink: 0; padding: 3px 10px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text3); border-radius: 5px; font-size: .76rem;
  cursor: pointer; transition: all .15s; font-weight: 600;
}
.history-undo:hover { border-color: var(--gold); color: var(--gold); }

/* ── INLINE INITIATIVE PROMPT (in party card) ───────────── */
.init-prompt {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
input.init-quick-input {
  width: 64px; padding: 5px 8px;
  background: var(--bg2); border: 1px solid var(--gold);
  color: var(--gold-light); border-radius: 6px;
  font-size: .95rem; font-weight: 700; text-align: center;
  -moz-appearance: textfield;
  flex-shrink: 0;
}
input.init-quick-input::-webkit-inner-spin-button { -webkit-appearance: none; }
input.init-quick-input:focus { outline: none; border-color: var(--gold-light); }

/* ── BULK INITIATIVE VIEW ────────────────────────────────── */
.bulk-header {
  font-size: .84rem; color: var(--text2); margin-bottom: 12px; line-height: 1.6;
}
.bulk-init-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 6px;
}
.bulk-init-name {
  flex: 1 1 0%; font-weight: 600; font-size: .9rem;
  display: flex; align-items: center; gap: 6px;
  min-width: 0; overflow: hidden;
}
.bulk-init-name .bulk-name-text {
  flex: 1 1 0%; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bulk-init-mod { font-size: .8rem; color: var(--text2); white-space: nowrap; flex-shrink: 0; }

/* ── EXPORT / IMPORT MODAL ──────────────────────────────────── */
.export-code {
  width: 100%; font-family: monospace; font-size: .75rem;
  padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text2);
  resize: none; word-break: break-all; min-height: 110px;
  line-height: 1.5;
}
.export-code:focus { outline: none; border-color: var(--text2); }
.export-hint { font-size: .8rem; color: var(--text3); margin-bottom: 10px; line-height: 1.6; }
.copy-success { color: var(--hp-hi); font-size: .82rem; margin-left: 8px; }

/* ── WELCOME MODAL ───────────────────────────────────────────── */
.welcome-modal { max-width: 520px; }

.welcome-section {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.welcome-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.welcome-section-title {
  font-weight: 700;
  font-size: .95rem;
  color: var(--gold);
  margin-bottom: 8px;
}

.welcome-section p {
  font-size: .88rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 8px;
}
.welcome-section p:last-child { margin-bottom: 0; }

.welcome-section code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .82rem;
  color: var(--gold-light);
}

.welcome-list {
  font-size: .88rem;
  color: var(--text2);
  line-height: 1.7;
  padding-left: 20px;
}
.welcome-steps { padding-left: 22px; }
.welcome-list li { margin-bottom: 2px; }

.welcome-privacy {
  background: rgba(212, 175, 55, 0.06);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}

.welcome-no-show {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: .82rem;
  color: var(--text3);
  cursor: pointer;
  user-select: none;
}
.welcome-no-show input { cursor: pointer; accent-color: var(--gold); }

@media (max-width: 500px) {
  .header { padding: 10px 12px; gap: 8px; }
  .header-title { font-size: 1.1rem; }
  .main { padding: 16px 10px 100px; }
}

