/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

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

:root {
  --bg:        #1a1208;
  --bg2:       #261b0c;
  --bg3:       #332210;
  --surface:   #3d2a12;
  --border:    #5a3f1e;
  --gold:      #c9922a;
  --gold-lt:   #e8b84b;
  --red:       #c0392b;
  --red-lt:    #e74c3c;
  --green:     #27ae60;
  --blue:      #2980b9;
  --purple:    #8e44ad;
  --text:      #f0e6d0;
  --text-dim:  #a0896a;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 16px rgba(0,0,0,.5);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Layout helpers ───────────────────────────────────────────────────────── */
.container { max-width: 680px; margin: 0 auto; padding: 0 16px; }

/* ── Top bar ──────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 1.1rem; color: var(--gold-lt); flex: 1; letter-spacing: .03em; }
.topbar .back-btn {
  background: none; border: none; color: var(--gold); font-size: 1.3rem;
  cursor: pointer; padding: 4px 8px; line-height: 1;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-size: .9rem; font-weight: 600; padding: 10px 18px;
  transition: filter .15s, transform .1s;
  min-height: 44px;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--gold); color: #1a0e00; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover  { filter: brightness(1.15); }
.btn-ghost   { background: transparent; color: var(--gold); border: 1.5px solid var(--border); }
.btn-ghost:hover { border-color: var(--gold); }
.btn-sm { font-size: .8rem; padding: 6px 12px; min-height: 36px; }
.btn-icon {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 6px; border-radius: var(--radius-sm); font-size: 1rem; line-height: 1;
  transition: color .15s;
}
.btn-icon:hover { color: var(--text); }

/* ── PIN overlay ──────────────────────────────────────────────────────────── */
#pin-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.pin-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: min(360px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.pin-box h2 { color: var(--gold-lt); margin-bottom: 8px; font-size: 1.3rem; }
.pin-box p  { color: var(--text-dim); font-size: .9rem; margin-bottom: 24px; }
.pin-input {
  width: 100%; padding: 12px 14px; font-size: 1.4rem; letter-spacing: .25em;
  text-align: center; background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
  margin-bottom: 16px;
}
.pin-input:focus { border-color: var(--gold); }
.pin-error { color: var(--red-lt); font-size: .85rem; margin-top: 8px; min-height: 20px; }

/* ── Character cards (dashboard) ──────────────────────────────────────────── */
.char-grid {
  display: grid; gap: 14px; padding: 20px 0;
}
.char-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}
.char-card:hover { border-color: var(--gold); transform: translateY(-1px); }
.char-card-name { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.char-card-class {
  font-size: .8rem; color: var(--gold); text-transform: uppercase;
  letter-spacing: .06em; margin-top: 2px;
}
.char-card-level {
  background: var(--gold); color: #1a0e00;
  font-size: .75rem; font-weight: 800;
  padding: 3px 8px; border-radius: 99px;
  white-space: nowrap; align-self: start;
}
.char-card-bars { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 6px; }
.mini-bar { flex: 1; }
.mini-bar-label { font-size: .7rem; color: var(--text-dim); margin-bottom: 3px; }
.mini-bar-track {
  height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden;
}
.mini-bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.mini-bar-fill.hp  { background: var(--red); }
.mini-bar-fill.san { background: var(--blue); }

.add-char-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 18px;
  background: transparent; border: 2px dashed var(--border);
  border-radius: var(--radius); color: var(--text-dim);
  cursor: pointer; font-size: .95rem; font-weight: 600;
  transition: border-color .15s, color .15s;
  min-height: 64px;
}
.add-char-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky; top: 57px; z-index: 90;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: 1; min-width: 70px; padding: 12px 8px;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-dim); font-size: .8rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: color .15s;
}
.tab-btn.active { color: var(--gold-lt); border-bottom-color: var(--gold); }
.tab-panel { display: none; padding: 16px 0 80px; }
.tab-panel.active { display: block; }

/* ── Section cards ────────────────────────────────────────────────────────── */
.section {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.section-title {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--gold); margin-bottom: 14px; font-weight: 700;
}

/* ── Stat grid ────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.stat-grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat-box {
  background: var(--bg3); border-radius: var(--radius-sm);
  padding: 10px 8px; text-align: center;
}
.stat-box-label {
  font-size: .65rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); margin-bottom: 4px;
}
.stat-box-value { font-size: 1.3rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-box-detail { font-size: .65rem; color: var(--text-dim); margin-top: 3px; }

/* ── Health / Sanity bars ─────────────────────────────────────────────────── */
.resource-bar { margin-bottom: 14px; }
.resource-bar-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 6px;
}
.resource-bar-label { font-size: .8rem; font-weight: 700; }
.resource-bar-label.hp  { color: var(--red-lt); }
.resource-bar-label.san { color: #5dade2; }
.resource-bar-label.cor { color: var(--purple); }
.resource-bar-value { font-size: .9rem; font-weight: 700; }
.resource-bar-track {
  height: 12px; background: var(--bg3); border-radius: 6px; overflow: hidden;
  position: relative;
}
.resource-bar-fill {
  height: 100%; border-radius: 6px; transition: width .3s;
  position: relative;
}
.resource-bar-fill.hp  { background: var(--red); }
.resource-bar-fill.san { background: var(--blue); }
.resource-bar-fill.cor { background: var(--purple); }
.resource-bar-controls {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
}
.resource-bar-controls .current-val {
  flex: 1; text-align: center; font-size: 1rem; font-weight: 800;
  background: var(--bg3); border-radius: var(--radius-sm); padding: 6px;
}
.stepper {
  display: flex; gap: 6px;
}
.stepper button {
  height: 40px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text); font-size: .9rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.stepper button:hover { background: var(--bg2); border-color: var(--gold-lt); }
.stepper button:active { transform: scale(.97); }

/* Small +/− counter button used throughout the sheet */
.step-btn {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 1.15rem; font-weight: 800;
  cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.step-btn:hover { border-color: var(--gold); color: var(--gold-lt); }
.step-btn:active { transform: scale(.95); }
.step-btn:disabled { opacity: .35; cursor: default; pointer-events: none; }

/* ── Token stepper (Grit, Fury, Ki, Mana) ─────────────────────────────────── */
.token-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--bg3);
}
.token-row:last-child { border-bottom: none; }
.token-label { flex: 1; font-size: .9rem; font-weight: 600; }
.token-pips {
  display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end;
}
.pip {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--bg3);
  cursor: pointer; transition: background .15s, border-color .15s;
}
.pip.filled { background: var(--gold); border-color: var(--gold-lt); }
.pip.filled.fury  { background: var(--red);   border-color: var(--red-lt); }
.pip.filled.ki    { background: var(--blue);  border-color: #7fb3d3; }
.pip.filled.mana  { background: var(--purple); border-color: #bb8fce; }

/* ── Status effects ───────────────────────────────────────────────────────── */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.status-item {
  background: var(--bg3); border-radius: var(--radius-sm); padding: 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.status-item-label { font-size: .8rem; color: var(--text-dim); }
.status-item-ctrl { display: flex; align-items: center; gap: 6px; }
.status-count { font-size: 1rem; font-weight: 800; min-width: 24px; text-align: center; }

/* ── Toggle ───────────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg3); border-radius: var(--radius-sm); padding: 10px 12px;
}
.toggle-row label { flex: 1; font-size: .85rem; cursor: pointer; }
.toggle {
  position: relative; width: 42px; height: 24px; flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--bg); border-radius: 12px;
  border: 1.5px solid var(--border); transition: background .2s;
  cursor: pointer;
}
.toggle-slider::before {
  content: ""; position: absolute;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-dim); top: 3px; left: 3px;
  transition: transform .2s, background .2s;
}
.toggle input:checked + .toggle-slider { background: var(--red); border-color: var(--red); }
.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px); background: #fff;
}

/* ── Items ────────────────────────────────────────────────────────────────── */
.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px;
}
.item-card.exhausted { opacity: .5; }
.item-card-header {
  display: flex; align-items: flex-start; gap: 8px;
}
.item-card-name { flex: 1; font-weight: 700; font-size: .95rem; }
.item-card-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.badge {
  font-size: .65rem; font-weight: 700; padding: 2px 6px;
  border-radius: 99px; text-transform: uppercase; letter-spacing: .04em;
}
.badge-starting    { background: var(--gold); color: #1a0e00; }
.badge-personal    { background: var(--purple); color: #fff; }
.badge-exhausted   { background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); }
.badge-upgrade     { background: var(--bg3); color: var(--gold-lt); border: 1px solid var(--gold); }
.badge-restriction { background: var(--red-lt); color: #fff; }
.item-card-desc { font-size: .8rem; color: var(--text-dim); margin-top: 6px; }
.item-card-meta { font-size: .75rem; color: var(--text-dim); margin-top: 5px; }
.item-keywords { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.badge-keyword { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.item-upgrade-section { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; }
.item-upgrade-header { display: flex; align-items: center; gap: 6px; font-size: .75rem; font-weight: 600; color: var(--text-dim); margin-bottom: 4px; }
.item-upgrade-row { display: flex; align-items: flex-start; gap: 6px; padding: 3px 0; }

/* ── Side bag tokens ──────────────────────────────────────────────────────── */
.side-bag {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.token-chip {
  padding: 6px 12px; border-radius: 99px;
  border: 1.5px solid var(--border); background: var(--bg3);
  font-size: .8rem; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.token-chip.active {
  background: var(--gold); border-color: var(--gold-lt); color: #1a0e00;
}

/* ── Abilities ────────────────────────────────────────────────────────────── */
.ability-card {
  background: var(--bg3); border-radius: var(--radius-sm);
  padding: 12px; margin-bottom: 8px;
}
.ability-card-name { font-weight: 700; font-size: .9rem; color: var(--gold-lt); }
.ability-card-desc { font-size: .8rem; color: var(--text-dim); margin-top: 4px; line-height: 1.4; }

.upgrade-track { margin-bottom: 20px; }
.upgrade-track-title {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--gold); margin-bottom: 8px; font-weight: 700;
}
.upgrade-tier {
  display: flex; gap: 6px; align-items: flex-start; margin-bottom: 6px;
}
.tier-label {
  font-size: .65rem; color: var(--text-dim); min-width: 32px;
  padding-top: 10px; text-align: center;
}
.upgrade-node {
  flex: 1; background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px; cursor: pointer;
  transition: border-color .15s, background .15s; position: relative;
}
.upgrade-node.unlocked { border-color: var(--gold); background: var(--surface); }
.upgrade-node.locked   { opacity: .45; cursor: not-allowed; }
.upgrade-node-name { font-size: .8rem; font-weight: 700; }
.upgrade-node-desc { font-size: .7rem; color: var(--text-dim); margin-top: 3px; line-height: 1.35; }
.upgrade-node .unlock-badge {
  position: absolute; top: 6px; right: 6px;
  font-size: .6rem; background: var(--gold); color: #1a0e00;
  padding: 1px 5px; border-radius: 99px; font-weight: 800;
}

/* ── Text fields ──────────────────────────────────────────────────────────── */
.field-label {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); margin-bottom: 6px; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.field-label .help-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: .75rem; width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid var(--border); display: inline-flex;
  align-items: center; justify-content: center; flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
.field-label .help-btn:hover { color: var(--gold); border-color: var(--gold); }
textarea {
  width: 100%; min-height: 90px; background: var(--bg3);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: .9rem; padding: 10px 12px;
  resize: vertical; outline: none; font-family: inherit; line-height: 1.5;
}
textarea:focus { border-color: var(--gold); }
input[type="text"], input[type="number"], select {
  width: 100%; background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: .9rem;
  padding: 10px 12px; outline: none; font-family: inherit;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--gold);
}
select { cursor: pointer; }
select option { background: var(--bg2); }

/* ── Form ─────────────────────────────────────────────────────────────────── */
.form-row { margin-bottom: 16px; }
.form-row label {
  display: block; font-size: .8rem; color: var(--text-dim);
  margin-bottom: 6px; font-weight: 600;
}
.form-row-inline {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.7); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-overlay.center { align-items: center; padding: 16px; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px; max-height: 90dvh;
  overflow-y: auto; padding: 24px 20px 32px;
}
.modal-overlay.center .modal { border-radius: var(--radius); }
.modal h3 { font-size: 1.1rem; color: var(--gold-lt); margin-bottom: 16px; }
.modal-actions {
  display: flex; gap: 10px; margin-top: 20px; flex-direction: column;
}
.modal-actions .btn { width: 100%; }

/* ── Tooltip / popover ────────────────────────────────────────────────────── */
.popover {
  position: fixed; z-index: 300; background: var(--surface);
  border: 1px solid var(--gold); border-radius: var(--radius-sm);
  padding: 10px 14px; max-width: 260px;
  font-size: .8rem; color: var(--text); line-height: 1.45;
  box-shadow: var(--shadow); pointer-events: none;
}

/* ── Injuries / Madness / Mutation lists ──────────────────────────────────── */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag {
  display: flex; align-items: center; gap: 5px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 99px; padding: 4px 10px; font-size: .8rem;
}
.tag-remove {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: .9rem; line-height: 1; padding: 0;
}
.tag-remove:hover { color: var(--red-lt); }
.add-tag-row { display: flex; gap: 8px; }
.add-tag-row input { flex: 1; }

/* Chart tag cards (injuries / madnesses with effect text) */
.tag-list:has(.chart-tag-card) { flex-direction: column; flex-wrap: nowrap; gap: 8px; }
.chart-tag-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.chart-tag-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 3px; }
.chart-tag-name { font-weight: 700; font-size: .875rem; }
.chart-tag-effect { font-size: .8rem; color: var(--text-dim); line-height: 1.4; }

/* ── Reset adventure button ───────────────────────────────────────────────── */
.reset-btn {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, #5d1a0a, #8b2500);
  border: 1.5px solid #c0392b; border-radius: var(--radius);
  color: #fff; font-size: .95rem; font-weight: 700; cursor: pointer;
  letter-spacing: .02em; transition: filter .15s;
}
.reset-btn:hover { filter: brightness(1.15); }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-dim);
}
.empty-state p { font-size: .9rem; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--gold);
  animation: spin .7s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 20px;
  font-size: .9rem; color: var(--text); z-index: 9999;
  transition: transform .25s ease, opacity .25s;
  opacity: 0; pointer-events: none; white-space: nowrap;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.success { border-color: var(--green); color: var(--green); }
#toast.error   { border-color: var(--red-lt); color: var(--red-lt); }
#toast.warning { border-color: var(--gold); color: var(--gold-lt); white-space: normal; max-width: min(90vw, 360px); text-align: center; }

/* ── Responsive tweaks ────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .status-grid { grid-template-columns: repeat(3, 1fr); }
}
