:root {
  --bg: #14100d;
  --bg-panel: #1d1712;
  --bg-card: #241c15;
  --bg-input: #2a2119;
  --border: #4a3a26;
  --gold: #c9a24b;
  --gold-bright: #e6c369;
  --crimson: #a13a3a;
  --text: #e8ddc9;
  --text-dim: #a8967c;
  --success: #5b8c5a;
  --danger: #a13a3a;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Georgia", "Iowan Old Style", serif;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: linear-gradient(180deg, #241c15, #1a140f);
  border-bottom: 2px solid var(--gold);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.switch-player {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.switch-player:hover { color: var(--gold-bright); border-color: var(--gold); }

/* ---- player gate ---- */

.player-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.player-gate-card {
  max-width: 380px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
}

.player-gate-card h1 {
  color: var(--gold-bright);
  font-size: 1.3rem;
  margin: 0 0 0.25rem;
}

.player-gate-sub {
  color: var(--text-dim);
  margin: 0 0 1rem;
}

.existing-players {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.existing-player-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  text-align: left;
}
.existing-player-btn:hover { border-color: var(--gold); }
.existing-player-btn .sub { color: var(--text-dim); font-size: 0.78rem; }

.join-form {
  display: flex;
  gap: 0.5rem;
}
.join-form input { flex: 1; }

/* ---- party roster (campaign tab) ---- */

.roster {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.roster-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg-input);
  border-radius: var(--radius);
  font-size: 0.88rem;
}
.roster-row .name { font-weight: bold; color: var(--gold-bright); }
.roster-row .stat { color: var(--text-dim); font-size: 0.8rem; }

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
  color: var(--gold-bright);
  letter-spacing: 0.03em;
}

.health {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: monospace;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  display: inline-block;
}

.dot.ok { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.bad { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

.tabs {
  display: flex;
  overflow-x: auto;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1 0 auto;
  padding: 0.6rem 0.9rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); }

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

.panels {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.panel { display: none; }
.panel.active { display: block; }

.panel h2 {
  margin-top: 0;
  color: var(--gold-bright);
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

.panel h3 {
  color: var(--gold);
  font-size: 0.95rem;
  margin: 1rem 0 0.4rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

/* ---- forms / inputs ---- */

input, textarea, select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
}

input:focus, textarea:focus, select:focus {
  outline: 1px solid var(--gold);
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

label.block { width: 100%; margin: 0.5rem 0; }

button {
  background: var(--bg-input);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  font-family: inherit;
  cursor: pointer;
  font-size: 0.85rem;
}

button:hover { background: #3a2d1d; }
button:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  border-color: var(--border);
  color: var(--text-dim);
}

button.danger {
  border-color: var(--crimson);
  color: #e08a8a;
}

.hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.4rem;
}

.save-flash {
  margin-left: 0.6rem;
  color: var(--success);
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.3s;
}
.save-flash.show { opacity: 1; }

/* ---- chat ---- */

#panel-chat.active { display: flex; flex-direction: column; height: 100%; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-bottom: 0.75rem;
}

.msg {
  max-width: 85%;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  line-height: 1.45;
  white-space: pre-wrap;
  font-size: 0.92rem;
}

.msg.user {
  align-self: flex-end;
  background: #2f3d2e;
  border: 1px solid #4a5f47;
}

.msg .author {
  display: block;
  font-size: 0.72rem;
  color: var(--gold);
  font-weight: bold;
  margin-bottom: 0.15rem;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.msg.system {
  align-self: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
}

.msg.typing {
  display: flex;
  align-items: center;
  min-height: 1.1rem;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.roll-card {
  align-self: flex-start;
  background: #2a2016;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  max-width: 85%;
}

.roll-card .roll-label {
  font-size: 0.85rem;
  color: var(--gold-bright);
  margin-bottom: 0.4rem;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.chat-input textarea {
  flex: 1;
  resize: none;
}

/* ---- character ---- */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1rem;
}

.abilities {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.6rem;
}

.ability-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  text-align: center;
}

.ability-box label {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.ability-box input {
  width: 100%;
  text-align: center;
  font-size: 1.1rem;
  margin: 0.25rem 0;
}

.ability-box .mod {
  font-size: 0.85rem;
  color: var(--gold);
}

/* ---- dice ---- */

.quick-dice {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.dice-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

.last-roll {
  min-height: 2.2rem;
  font-size: 1.1rem;
  color: var(--gold-bright);
  margin-bottom: 0.5rem;
}

.ledger-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ledger {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.3rem;
}

.ledger-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg-input);
  border-radius: var(--radius);
}

.ledger-row .result { color: var(--gold-bright); font-weight: bold; }

/* ---- initiative ---- */

.round-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.add-combatant, .add-item, .kv-add, .list-add {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}

.add-combatant input, .add-item input { flex: 1 1 100px; }

.pc-toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
}

.combatants { display: flex; flex-direction: column; gap: 0.4rem; }

.combatant-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.combatant-row.current {
  border-color: var(--gold);
  background: #332918;
}

.combatant-row .name { flex: 1; font-weight: bold; }
.combatant-row .tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: var(--crimson);
  color: #fff;
}
.combatant-row .tag.pc { background: #3a6b3a; }
.combatant-row .stat { font-size: 0.8rem; color: var(--text-dim); }

/* ---- inventory ---- */

.items { display: flex; flex-direction: column; gap: 0.4rem; }

.item-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.item-row .name { flex: 1; font-weight: bold; }
.item-row .notes { font-size: 0.78rem; color: var(--text-dim); flex-basis: 100%; }
.item-row .qty-controls { display: flex; align-items: center; gap: 0.3rem; }
.item-row .qty-controls button { padding: 0.1rem 0.5rem; }

.inv-total {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* ---- campaign kv/list ---- */

.kv-list, .list-items {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}

.kv-row, .list-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg-input);
  border-radius: var(--radius);
}

.kv-row .k { color: var(--gold); font-weight: bold; }
.kv-row .v, .list-row .v { flex: 1; }

.remove-btn {
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 0.3rem;
}
.remove-btn:hover { color: var(--danger); }

@media (max-width: 480px) {
  .grid-2 { grid-template-columns: 1fr; }
  .tab-btn { font-size: 0.75rem; padding: 0.5rem 0.5rem; }
}
