/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg:         #0e0e0e;
  --surface:    #1a1614;
  --surface2:   #221e1b;
  --border:     #4a3b28;
  --gold:       #c9a84c;
  --gold-dim:   #9b7d38;
  --text:       #e8dcc8;
  --text-dim:   #8a7b65;
  --red:        #c0392b;
  --radius:     6px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Georgia', 'Times New Roman', serif;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 2px solid var(--gold);
  padding: 1rem 2rem;
}

header h1 {
  color: var(--gold);
  font-size: 1.75rem;
  letter-spacing: 0.06em;
  text-shadow: 0 2px 10px rgba(201, 168, 76, 0.35);
}

/* ── Main layout ──────────────────────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  border-bottom: 2px solid var(--border);
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
}

.tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  margin-bottom: -2px;
  padding: 0.5rem 1.25rem;
  text-transform: uppercase;
  transition: color 0.2s, border-color 0.2s;
}

.tab.active,
.tab:hover {
  border-bottom-color: var(--gold);
  color: var(--gold);
}

/* ── Selector panel ───────────────────────────────────────────────────────── */
.selector-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  padding: 1.25rem;
}

.selector-panel h2 {
  color: var(--gold);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  margin-bottom: 0.85rem;
  text-transform: uppercase;
}

.selector-row {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.selector-footer {
  align-items: center;
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
}

/* ── Search input ─────────────────────────────────────────────────────────── */
.search-wrapper {
  flex: 1;
  min-width: 200px;
  position: relative;
}

input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.85rem;
  transition: border-color 0.2s;
  width: 100%;
}

input[type="text"]:focus {
  border-color: var(--gold);
  outline: none;
}

input[type="text"]:disabled {
  opacity: 0.45;
}

/* ── Dropdown ─────────────────────────────────────────────────────────────── */
.dropdown {
  background: var(--surface2);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  left: 0;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 100;
}

.dropdown.hidden { display: none; }

.dropdown li {
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0.5rem 0.85rem;
  transition: background 0.12s;
}

.dropdown li:hover,
.dropdown li[aria-selected="true"] {
  background: var(--border);
  color: var(--gold);
}

/* ── Quantity ─────────────────────────────────────────────────────────────── */
input[type="number"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.5rem;
  text-align: center;
  width: 68px;
}

input[type="number"]:focus {
  border-color: var(--gold);
  outline: none;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button { cursor: pointer; font-family: inherit; transition: all 0.2s; }

#add-btn {
  background: var(--gold);
  border: none;
  border-radius: var(--radius);
  color: #0e0e0e;
  font-size: 0.88rem;
  font-weight: bold;
  letter-spacing: 0.07em;
  padding: 0.55rem 1.25rem;
  text-transform: uppercase;
  white-space: nowrap;
}

#add-btn:hover:not(:disabled) { background: #e6c56a; }

#add-btn:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}

#clear-btn {
  background: none;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 0.82rem;
  padding: 0.3rem 0.8rem;
}

#clear-btn:hover {
  background: var(--red);
  color: #fff;
}

/* ── Battle count ─────────────────────────────────────────────────────────── */
#battle-count {
  color: var(--text-dim);
  font-size: 0.82rem;
  flex: 1;
}

/* ── Battle board ─────────────────────────────────────────────────────────── */
.battle-board {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.empty-msg {
  color: var(--text-dim);
  font-style: italic;
  grid-column: 1 / -1;
  padding: 2.5rem;
  text-align: center;
}

/* ── Creature card ────────────────────────────────────────────────────────── */
.creature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.creature-card:hover {
  border-color: var(--gold-dim);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}

.card-header {
  align-items: center;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 0.85rem;
}

.card-name {
  color: var(--gold);
  flex: 1;
  font-size: 0.95rem;
  font-weight: bold;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-qty {
  background: var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
}

.remove-btn {
  background: none;
  border: none;
  border-radius: 3px;
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 0.75rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
}

.remove-btn:hover {
  background: var(--red);
  color: #fff;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.75rem 0.85rem;
}

.card-stat {
  align-items: baseline;
  display: flex;
  font-size: 0.875rem;
  gap: 0.5rem;
}

.stat-label {
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 0.72rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  width: 82px;
}

.stat-value {
  color: var(--text);
  font-weight: bold;
}

.stat-formula {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: normal;
}

/* ── Mass roll buttons ────────────────────────────────────────────────────── */
#roll-all-atk-btn,
#roll-all-dmg-btn {
  background: none;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--gold-dim);
  font-size: 0.82rem;
  padding: 0.3rem 0.8rem;
  white-space: nowrap;
}

#roll-all-atk-btn:hover,
#roll-all-dmg-btn:hover {
  background: var(--gold-dim);
  color: var(--bg);
}

/* ── Selector footer wrap on narrow viewports ─────────────────────────────── */
.selector-footer { flex-wrap: wrap; }

/* ── Roll buttons (per card) ──────────────────────────────────────────────── */
.roll-btn {
  background: none;
  border: 1px solid var(--gold-dim);
  border-radius: 3px;
  color: var(--gold-dim);
  flex-shrink: 0;
  font-size: 0.68rem;
  line-height: 1;
  margin-left: auto;
  padding: 0.15rem 0.4rem;
  white-space: nowrap;
}

.roll-btn:hover:not(:disabled) {
  background: var(--gold-dim);
  color: var(--bg);
}

.roll-btn:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

/* ── Roll results (per card) ──────────────────────────────────────────────── */
.roll-result {
  border-top: 1px solid var(--border);
  margin-top: 0.3rem;
  padding-top: 0.4rem;
}

.roll-line {
  color: var(--text);
  font-size: 0.8rem;
  margin-bottom: 0.15rem;
}

.roll-breakdown {
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: normal;
}

/* ── Mass roll panel ──────────────────────────────────────────────────────── */
.mass-roll-panel {
  background: var(--surface);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
}

.mass-roll-panel.hidden { display: none; }

.mass-roll-header {
  align-items: center;
  display: flex;
  margin-bottom: 0.6rem;
}

.mass-roll-title {
  color: var(--gold);
  flex: 1;
  font-size: 0.82rem;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mass-roll-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 0.1rem 0.3rem;
}

.mass-roll-close:hover { color: var(--red); }

.mass-roll-list {
  display: grid;
  font-size: 0.82rem;
  gap: 0.25rem;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  list-style: none;
}

.mass-roll-list li {
  align-items: baseline;
  display: flex;
  gap: 0.5rem;
}

.mass-roll-name {
  color: var(--text-dim);
  flex-shrink: 0;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roll-na {
  color: var(--text-dim);
  font-style: italic;
}

/* ── HP decrement button ───────────────────────────────────────────────────── */
.hp-dec-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 0.72rem;
  line-height: 1;
  margin-left: auto;
  padding: 0.15rem 0.4rem;
}

.hp-dec-btn:hover:not(:disabled) {
  border-color: var(--red);
  color: var(--red);
}

.hp-dec-btn:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

/* ── Error toast ──────────────────────────────────────────────────────────── */
.error-toast {
  background: var(--red);
  border-radius: var(--radius);
  bottom: 1.5rem;
  color: #fff;
  font-size: 0.88rem;
  max-width: 400px;
  padding: 0.75rem 1.25rem;
  position: fixed;
  right: 1.5rem;
  z-index: 1000;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }
