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

:root {
  --bg-dark: #1a1a2e;
  --bg-mid: #16213e;
  --bg-card: #1f2b47;
  --bg-input: #0f1626;
  --gold: #e2b714;
  --gold-dim: #a68510;
  --text: #e0e0e0;
  --text-dim: #8899aa;
  --hp-green: #4caf50;
  --hp-yellow: #ff9800;
  --hp-red: #f44336;
  --accent-blue: #4fc3f7;
  --accent-purple: #b39ddb;
  --danger: #e74c3c;
  --radius: 8px;
}

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

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }

/* ── Lobby ────────────────────────────────────────────────────────────────── */
#lobby {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
}

.lobby-card {
  background: var(--bg-mid);
  padding: 2.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--gold-dim);
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.logo {
  font-size: 2.2rem;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

/* ── Lobby Tabs ──────────────────────────────────────────────────────────── */
.lobby-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #2a3a5c;
}

.tab-btn {
  flex: 1;
  padding: 0.6rem 1rem;
  background: var(--bg-input);
  color: var(--text-dim);
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

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

.tab-btn.active {
  background: var(--gold);
  color: var(--bg-dark);
}

.tab-content {
  display: none;
  text-align: left;
}

.tab-content.active { display: block; }

/* ── Role Selector ───────────────────────────────────────────────────────── */
.role-selector {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.role-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.role-option input[type="radio"] {
  accent-color: var(--gold);
}

.role-radio-label {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}

/* ── Join Code Input ─────────────────────────────────────────────────────── */
.join-code-input {
  text-transform: uppercase;
  letter-spacing: 6px;
  text-align: center;
  font-size: 1.4rem !important;
  font-weight: 700;
  font-family: monospace;
}

/* ── Game Created Success ────────────────────────────────────────────────── */
.created-success {
  text-align: center;
}

.success-label {
  font-size: 1.1rem;
  color: var(--hp-green);
  font-weight: 600;
  margin-bottom: 1rem;
}

.join-code-display {
  background: var(--bg-input);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}

.join-code-display .join-code-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.3rem;
}

.join-code-value {
  display: block;
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 8px;
  font-family: monospace;
}

.share-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  text-align: left;
  margin-bottom: 1rem;
  flex: 1;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid #2a3a5c;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
}

.form-group input:focus {
  outline: none;
  border-color: var(--gold);
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.abilities-row .form-group {
  min-width: 0;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

.full-width { width: 100%; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--gold);
  color: #1a1a2e;
}
.btn-primary:hover { background: #f0c830; }

.btn-secondary {
  background: #2a3a5c;
  color: var(--text);
}
.btn-secondary:hover { background: #354a6e; }

.btn-accent {
  background: var(--accent-blue);
  color: #1a1a2e;
}
.btn-accent:hover { background: #7dd4fa; }

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-mic {
  background: var(--danger);
  color: white;
  font-size: 0.95rem;
  padding: 0.5rem 1.5rem;
}
.btn-mic.listening {
  background: var(--hp-green);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(76, 175, 80, 0); }
}

.btn-edit-small {
  background: transparent;
  color: var(--accent-blue);
  border: 1px solid var(--accent-blue);
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
  border-radius: var(--radius);
}
.btn-edit-small:hover {
  background: var(--accent-blue);
  color: var(--bg-dark);
}

.btn-danger-small {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
  border-radius: var(--radius);
}
.btn-danger-small:hover {
  background: var(--danger);
  color: white;
}

.char-actions {
  display: flex;
  gap: 0.3rem;
  align-items: flex-start;
}

.lobby-buttons {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}
.lobby-buttons .btn { flex: 1; }

/* ── Game Layout ──────────────────────────────────────────────────────────── */
#game {
  flex-direction: column;
  height: 100vh;
}

.game-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.2rem;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--gold-dim);
}

.logo-small {
  font-size: 1.1rem;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 1px;
}

.game-name-label {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}

.join-code-badge {
  font-size: 0.8rem;
  color: var(--gold);
  background: var(--bg-input);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-family: monospace;
  font-weight: 700;
  letter-spacing: 2px;
  border: 1px solid var(--gold-dim);
}

.role-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  background: var(--gold);
  color: var(--bg-dark);
  margin-left: auto;
}

.game-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.left-panel {
  width: 380px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0;
  border-right: 1px solid #2a3a5c;
  overflow-y: auto;
}

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

.panel {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #2a3a5c;
}

.panel h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-header h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--gold);
  letter-spacing: 1px;
}

/* ── DM Controls ──────────────────────────────────────────────────────────── */
.mic-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.mic-status {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.manual-input {
  display: flex;
  gap: 0.5rem;
}

.manual-input input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  background: var(--bg-input);
  border: 1px solid #2a3a5c;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
}

.manual-input input:focus {
  outline: none;
  border-color: var(--gold);
}

/* ── Logs ─────────────────────────────────────────────────────────────────── */
.log-scroll {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.83rem;
  line-height: 1.5;
}

.transcript-entry {
  padding: 0.15rem 0;
  border-bottom: 1px solid rgba(42, 58, 92, 0.3);
}

.transcript-entry.interim {
  color: var(--text-dim);
  font-style: italic;
}

.transcript-entry.final {
  color: var(--text);
}

.event-entry {
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(42, 58, 92, 0.3);
}

.event-entry .event-narration {
  color: var(--accent-purple);
}

.event-entry .event-mutation {
  color: var(--accent-blue);
  font-size: 0.78rem;
  margin-left: 0.5rem;
}

/* ── Character Cards ──────────────────────────────────────────────────────── */
.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.char-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid #2a3a5c;
  padding: 1rem;
  transition: border-color 0.3s;
}

.char-card:hover {
  border-color: var(--gold-dim);
}

.char-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.6rem;
}

.char-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
}

.char-info {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.owner-badge {
  display: inline-block;
  background: rgba(79, 195, 247, 0.15);
  color: var(--accent-blue);
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  margin-left: 0.3rem;
  vertical-align: middle;
}

/* HP Bar */
.hp-bar-container {
  margin: 0.5rem 0;
}

.hp-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
}

.hp-bar-label span:first-child { color: var(--text-dim); }

.hp-bar {
  height: 10px;
  background: var(--bg-input);
  border-radius: 5px;
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.5s ease, background 0.5s ease;
}

/* Stats Row */
.char-stats {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
  flex-wrap: wrap;
}

.stat-badge {
  background: var(--bg-input);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  text-align: center;
}

.stat-badge .stat-label {
  color: var(--text-dim);
  font-size: 0.6rem;
  text-transform: uppercase;
  display: block;
}

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

.stat-badge .stat-mod {
  color: var(--gold);
  font-size: 0.65rem;
}

/* Conditions */
.conditions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.4rem 0;
}

.condition-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-weight: 600;
  text-transform: capitalize;
}

.condition-badge.negative {
  background: rgba(231, 76, 60, 0.2);
  color: #e74c3c;
  border: 1px solid rgba(231, 76, 60, 0.3);
}

.condition-badge.positive {
  background: rgba(76, 175, 80, 0.2);
  color: #4caf50;
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.condition-badge.neutral {
  background: rgba(79, 195, 247, 0.2);
  color: #4fc3f7;
  border: 1px solid rgba(79, 195, 247, 0.3);
}

/* Gold + AC */
.char-resources {
  display: flex;
  gap: 1rem;
  font-size: 0.83rem;
  margin: 0.4rem 0;
}

.char-resources span {
  color: var(--text-dim);
}

.char-resources strong {
  color: var(--gold);
}

/* Inventory */
.inventory-section {
  margin-top: 0.5rem;
}

.inventory-toggle {
  font-size: 0.75rem;
  color: var(--text-dim);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
}

.inventory-toggle:hover { color: var(--text); }

.inventory-list {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  display: none;
}

.inventory-list.open { display: block; }

.inventory-item {
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0;
  border-bottom: 1px solid rgba(42, 58, 92, 0.3);
}

.inventory-item .item-name { color: var(--text); }
.inventory-item .item-qty { color: var(--text-dim); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background: var(--bg-mid);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  color: var(--gold);
  margin-bottom: 1rem;
  font-size: 1.2rem;
}

.modal-content h4 {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  margin: 0.8rem 0 0.4rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.2rem;
}

/* ── Combat Stats / Saves Row ─────────────────────────────────────────────── */
.char-combat-stats,
.char-saves {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.78rem;
  margin: 0.3rem 0;
  color: var(--text-dim);
}

.char-combat-stats strong,
.char-saves strong {
  color: var(--text);
}

/* ── Log Entries ──────────────────────────────────────────────────────────── */
.log-entry {
  padding: 0.15rem 0;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(42, 58, 92, 0.2);
}

.log-entry .log-time {
  color: var(--text-dim);
  font-size: 0.7rem;
  margin-right: 0.4rem;
}

.log-info .log-msg { color: var(--text-dim); }
.log-warn .log-msg { color: var(--hp-yellow); }
.log-error .log-msg { color: var(--danger); }

/* ── Select / Dropdown ────────────────────────────────────────────────────── */
.form-group select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid #2a3a5c;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
}

.form-group select:focus {
  outline: none;
  border-color: var(--gold);
}

/* ── Toast Notifications ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 400px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateX(100%);
  transition: opacity 0.3s, transform 0.3s;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast-error {
  background: #3a1a1a;
  border: 1px solid var(--danger);
  color: #f88;
}

.toast-success {
  background: #1a3a1a;
  border: 1px solid var(--hp-green);
  color: #8f8;
}

.toast-warn {
  background: #3a2a0a;
  border: 1px solid var(--hp-yellow);
  color: #fd8;
}

.toast-info {
  background: #1a2a3a;
  border: 1px solid var(--accent-blue);
  color: #8df;
}

.toast-msg {
  flex: 1;
}

.toast-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.2rem;
  opacity: 0.6;
  line-height: 1;
}

.toast-close:hover { opacity: 1; }

/* ── Button Loading State ────────────────────────────────────────────────── */
.btn-loading {
  opacity: 0.7;
  cursor: wait !important;
  position: relative;
}

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

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

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .game-layout {
    flex-direction: column;
  }
  .left-panel {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid #2a3a5c;
    max-height: 40vh;
  }
  .character-grid {
    grid-template-columns: 1fr;
  }
}
