/* ──────────────────────────────────────────────────────────
   Gloomhaven Tracker – Styles
   Dark Gloomhaven theme, mobile-first, responsive.
   Palette mirrors the existing Google Sheets tools.
   ────────────────────────────────────────────────────────── */

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

:root {
  --color-bg:        #909092;
  --color-surface:   #3658b4;
  --color-normal:    #af2a31;
  --color-elite:     #533483;
  --color-alt-row:   #4b4b85;
  --color-dead-bg:   #3a1a1a;
  --color-accent:    #f0c040;
  --color-active:    #e94560;
  --color-text:      #e0e0e0;
  --color-muted:     #070707;
  --color-border:    #2a2a4a;
  --color-player:    #3959b1;
  --radius:          6px;
  --gap:             8px;
}

html, body {
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: inherit;
  transition: opacity 0.1s, filter 0.1s;
}
button:active { opacity: 0.75; }

input[type="number"], input[type="text"] {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: inherit;
  padding: 4px 6px;
}
input[type="number"]:focus, input[type="text"]:focus {
  outline: 2px solid var(--color-accent);
}
input[type="checkbox"] { accent-color: var(--color-accent); width: 16px; height: 16px; }

/* ── Layout ─────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
}

/* ── Header ─────────────────────────────────────────────── */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

#app-header h1 {
  font-size: 1.1rem;
  color: var(--color-accent);
  font-weight: bold;
  letter-spacing: 0.03em;
}

#header-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

#round-badge {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.85rem;
  color: var(--color-accent);
  font-weight: bold;
}

#dungeon-level-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--color-text);
}

#dungeon-level-control label {
  color: var(--color-accent);
  font-weight: 600;
}

#dungeon-level-select {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  padding: 2px 6px;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
}

/* ── Tab bar ────────────────────────────────────────────── */
#tab-bar {
  display: flex;
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 10px 0;
  background: transparent;
  color: var(--color-muted);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 0;
  border-bottom: 3px solid transparent;
}

.tab-btn.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* ── Main content ───────────────────────────────────────── */
#tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.tab-section { display: none; }
.tab-section.active { display: block; }

/* ── Toolbars ───────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.btn-primary {
  background: var(--color-active);
  color: #fff;
  padding: 7px 12px;
  font-weight: 600;
}

.btn-secondary {
  background: var(--color-normal);
  color: var(--color-text);
  padding: 7px 12px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 6px 10px;
  font-size: 0.85rem;
}

.btn-danger {
  background: #6b1a1a;
  color: var(--color-text);
  padding: 7px 12px;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
  padding: 4px 7px;
  font-size: 1rem;
  line-height: 1;
}
.btn-icon:hover { color: var(--color-text); }

.btn-sm {
  padding: 4px 8px;
  font-size: 0.8rem;
}

/* ── Participant cards (shared) ─────────────────────────── */
.participant-card {
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.card-header {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 8px 10px;
}

.initiative-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 2px 6px;
  background: var(--color-bg);
  border: 1px solid var(--color-accent);
  border-radius: 4px;
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--color-accent);
  flex-shrink: 0;
}
.initiative-badge.empty { border-color: var(--color-border); color: var(--color-muted); }

.initiative-input {
  width: 52px;
  text-align: center;
  font-weight: bold;
  color: var(--color-accent);
  background: var(--color-bg);
  border: 1px solid var(--color-accent);
}

.participant-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.type-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
  flex-shrink: 0;
}
.type-badge.player  { background: #1b4080; color: #90c0ff; }
.type-badge.monster { background: #3a1260; color: #c090ff; }

/* ── Player card ────────────────────────────────────────── */
.player-card .card-header { background: var(--color-player); }
.player-card .card-body   { background: var(--color-alt-row); padding: 8px 10px; }

/* ── Monster group card ─────────────────────────────────── */
.monster-card .card-header { background: var(--color-normal); }

/* ── Stand rows ─────────────────────────────────────────── */
.stand-list { padding: 4px 0; }

.stand-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px;
  border-top: 1px solid var(--color-border);
}
.stand-row.elite  { background: var(--color-elite); }
.stand-row.normal { background: var(--color-alt-row); }
.stand-row.dead   { background: var(--color-dead-bg); opacity: 0.65; }

.stand-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stand-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 700;
  flex-shrink: 0;
}
.stand-badge.elite  { background: #7b4ab0; color: #f0d0ff; }
.stand-badge.normal { background: #1a4080; color: #b0d0ff; }

.stand-num {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--color-muted);
  flex-shrink: 0;
}

/* ── HP tracker ─────────────────────────────────────────── */
.hp-tracker {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.hp-display {
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 52px;
  text-align: center;
}
.hp-display.dead { color: var(--color-muted); }

.btn-hp {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  width: 28px;
  height: 28px;
  font-size: 1.1rem;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 4px;
}
.btn-hp:active { filter: brightness(1.4); }

/* ── Conditions row ─────────────────────────────────────── */
.conditions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.cond-btn {
  width: 100px;
  height: 30px;
  border-radius: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0.4;
  transition: opacity 0.1s, background 0.1s;
  color: var(--color-text);
  
}
.cond-btn.active {
  opacity: 1;
  background: var(--color-active);
  border-color: var(--color-active);
  color: #fff;
}

/* ── Setup list ─────────────────────────────────────────── */
.setup-section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  font-weight: 700;
  padding: 8px 0 4px;
}

.setup-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 6px;
}

.setup-item-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setup-item-meta {
  font-size: 0.8rem;
  color: var(--color-muted);
}

/* ── Modal ──────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
#modal-overlay.hidden { display: none; }

#modal-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 680px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 16px;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: 14px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.form-row label {
  font-size: 0.82rem;
  color: var(--color-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-row input[type="text"],
.form-row input[type="number"] {
  width: 100%;
  padding: 8px 10px;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

/* ── Inline stands editor (inside modal) ────────────────── */
#stands-editor { margin-top: 10px; }
#stands-editor .stands-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.stand-form-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--color-alt-row);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 5px;
}

.stand-form-row input[type="number"] { width: 52px; text-align: center; }
.stand-form-row label { font-size: 0.8rem; color: var(--color-muted); }

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--color-muted);
  padding: 32px 16px;
  font-size: 0.9rem;
  line-height: 1.8;
}

/* ── Sorted indicator ───────────────────────────────────── */
.sorted-active { border-left: 3px solid var(--color-active); }

/* ── Scrollbar styling ──────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
