* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: #1a1a1a;
  color: #e8d8b8;
  height: 100vh;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }

/* ============== MAP AREA ============== */
#map-container {
  flex: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: radial-gradient(ellipse at center, #1a1410 0%, #0a0805 100%);
  overflow: hidden;
  min-width: 0;
}
#map-header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; max-width: 900px; margin: 0 auto 12px;
  flex: 0 0 auto;
}
#map-title {
  font-size: 22px; color: #d4af37; letter-spacing: 1.5px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  font-weight: normal; font-variant: small-caps;
}
#map-actions button {
  background: #2a2218; color: #d4af37; border: 1px solid #5a4830;
  padding: 8px 14px; font-family: inherit; font-size: 13px;
  cursor: pointer; border-radius: 3px; transition: all 0.15s;
}
#map-actions button:hover { background: #3a2f1f; border-color: #d4af37; }
#map-viewport {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #0d0d0d;
  border: 3px solid #5a4830;
  border-radius: 4px;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.8), inset 0 0 12px rgba(0, 0, 0, 0.4);
  cursor: grab;
  touch-action: none;
}
#map-viewport.dragging { cursor: grabbing; }
#map-viewport canvas { display: block; }
#map-status {
  margin-top: 10px; font-size: 12px; color: #888; font-style: italic;
  min-height: 18px;
}

/* ============== SIDEBAR ============== */
#sidebar {
  width: 360px;
  display: flex; flex-direction: column;
  background: #2a2218;
  border-left: 3px solid #5a4830;
  box-shadow: -4px 0 12px rgba(0, 0, 0, 0.5);
}

/* ============== QUEST PANEL ============== */
#quest-panel {
  background: linear-gradient(180deg, #3a2810 0%, #2a1f10 100%);
  border-bottom: 2px solid #d4af37;
  padding: 10px 14px 12px;
  position: relative;
  transition: background 0.5s;
}
#quest-panel.flash {
  background: linear-gradient(180deg, #6a4a18 0%, #3a2810 100%);
}
.quest-header {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.quest-icon { font-size: 14px; }
.quest-label {
  flex: 1;
  color: #d4af37; font-size: 11px;
  font-variant: small-caps; letter-spacing: 1px;
}
#quest-detail-toggle {
  background: none; border: 1px solid #5a4830;
  color: #d4af37; cursor: pointer;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 11px; padding: 0;
}
#quest-title {
  color: #ffe8a0; font-size: 14px; font-weight: bold;
  margin-bottom: 4px;
}
#quest-hint {
  color: #c8b888; font-size: 12px; line-height: 1.4;
  font-style: italic;
  display: none;
}
#quest-panel.expanded #quest-hint { display: block; }

#player-bar, #map-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid #3a2f1f; background: #1f1810;
}
#player-bar label, #map-bar label {
  color: #d4af37; font-size: 11px; font-variant: small-caps; letter-spacing: 1px;
  min-width: 80px;
}
#player-select, #map-select {
  flex: 1; background: #1a1410; color: #e8d8b8; border: 1px solid #5a4830;
  padding: 5px 7px; font-family: inherit; font-size: 13px; cursor: pointer; border-radius: 2px;
}
#player-select:focus, #map-select:focus { outline: none; border-color: #d4af37; }
#btn-my-sheet {
  background: #2a2218; color: #d4af37; border: 1px solid #5a4830;
  padding: 5px 10px; cursor: pointer; border-radius: 2px; font-size: 14px;
}
#btn-my-sheet:hover { background: #3a2f1f; border-color: #d4af37; }

/* ============== INITIATIVE PANEL ============== */
#initiative-panel { background: #1f1810; border-bottom: 1px solid #3a2f1f; }
#initiative-panel .panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; color: #d4af37; font-size: 13px; font-variant: small-caps;
  letter-spacing: 1px; border-bottom: 1px solid #3a2f1f;
}
#initiative-panel .panel-actions { display: flex; gap: 4px; }
#initiative-panel .panel-actions button {
  background: #2a2218; color: #d4af37; border: 1px solid #5a4830;
  width: 24px; height: 24px; cursor: pointer; border-radius: 2px;
  font-size: 12px; padding: 0; line-height: 1;
}
#initiative-panel .panel-actions button:hover { background: #3a2f1f; border-color: #d4af37; }
#init-list {
  list-style: none; max-height: 180px; overflow-y: auto;
  padding: 4px 0;
}
#initiative-panel.collapsed #init-list { display: none; }
#init-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
  border-left: 3px solid transparent;
}
#init-list li:hover { background: #2a2218; }
#init-list li.current {
  background: linear-gradient(90deg, #4a3010, #1f1810);
  border-left-color: #ff8040;
  color: #ffd0a0;
}
.init-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; border: 1px solid #1a0a04; }
.init-name { flex: 1; }
.init-hp { color: #888; font-size: 11px; }
.init-val { color: #d4af37; font-weight: bold; min-width: 24px; text-align: right; }
.init-del {
  background: none; border: none; color: #888; cursor: pointer; font-size: 14px; padding: 0 4px;
}
.init-del:hover { color: #c4604a; }
.init-empty { padding: 10px 12px; color: #666; font-style: italic; font-size: 12px; }

#sidebar h2 {
  padding: 10px 14px; border-bottom: 1px solid #5a4830;
  color: #d4af37; font-size: 14px; font-variant: small-caps; letter-spacing: 1px;
  font-weight: normal;
}

#chat-log { flex: 1; overflow-y: auto; padding: 12px; font-size: 13px; line-height: 1.55; }
#chat-log::-webkit-scrollbar { width: 8px; }
#chat-log::-webkit-scrollbar-track { background: #1a1410; }
#chat-log::-webkit-scrollbar-thumb { background: #5a4830; border-radius: 4px; }

.chat-entry { margin-bottom: 8px; word-wrap: break-word; }
.chat-entry.system { color: #888; font-style: italic; font-size: 12px; }
.chat-entry.travel { color: #c4a060; font-style: italic; font-size: 12px; padding-left: 6px; border-left: 2px solid #c4a060; }
.chat-entry.gm {
  background: linear-gradient(180deg, #2a1f10 0%, #1f1808 100%);
  border-left: 3px solid #d4af37;
  border-right: 3px solid #d4af37;
  padding: 10px 14px; margin: 8px 0;
  color: #e8d8a8; font-style: italic; font-size: 13px; line-height: 1.6;
  border-radius: 2px;
  box-shadow: inset 0 0 8px rgba(212, 175, 55, 0.1);
}
.chat-entry.gm .gm-quill {
  color: #d4af37; font-size: 11px; font-variant: small-caps;
  letter-spacing: 2px; margin-bottom: 6px; font-style: normal;
  border-bottom: 1px dotted #5a4830; padding-bottom: 4px;
}
.chat-entry.ping { color: #ffe080; font-size: 12px; }
.chat-entry.whisper {
  background: rgba(80, 60, 100, 0.3); color: #d8c8e0;
  padding: 5px 8px; border-left: 3px solid #a060c0; border-radius: 2px;
  font-size: 12px;
}
.chat-entry.whisper strong { color: #e0b0ff; }
.chat-entry.roll {
  background: linear-gradient(180deg, #3a2f1f 0%, #2a2218 100%);
  border-left: 3px solid #d4af37;
  padding: 8px 10px; border-radius: 2px; margin: 6px 0;
}
.chat-entry.roll.attack { border-left-color: #c44030; }
.chat-entry.roll.damage { border-left-color: #a02000; }
.chat-entry.roll.save   { border-left-color: #4a90c0; }
.chat-entry.roll .roll-header { font-size: 12px; color: #c8b888; margin-bottom: 4px; }
.chat-entry.roll .roll-detail { font-family: 'Courier New', monospace; font-size: 12px; color: #a89878; }
.chat-entry.roll .total { color: #d4af37; font-weight: bold; font-size: 18px; margin-left: 6px; }
.chat-entry.roll .crit { color: #5db04a; font-weight: bold; margin-left: 6px; }
.chat-entry.roll .fumble { color: #c44030; font-weight: bold; margin-left: 6px; }
.chat-entry.roll .success { color: #5db04a; font-weight: bold; margin-left: 6px; }
.chat-entry.roll .fail { color: #c44030; font-weight: bold; margin-left: 6px; }
.chat-entry.move { color: #7ab87a; font-style: italic; font-size: 12px; }
.chat-entry.message strong { color: #d4af37; }

/* ============== MACROS BAR ============== */
#macros-bar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px; border-top: 1px solid #5a4830; background: #1f1810;
}
.macro-btn {
  flex: 1; min-width: 70px;
  background: #3a2f1f; color: #e8d8b8;
  border: 1px solid #5a4830;
  padding: 7px 8px; font-family: inherit; font-size: 12px;
  cursor: pointer; border-radius: 3px;
}
.macro-btn:hover { background: #4a3a2a; border-color: #d4af37; color: #ffe0a0; }
.macros-empty { font-size: 11px; color: #666; font-style: italic; padding: 4px 6px; }

#chat-form { border-top: 1px solid #5a4830; }
#chat-input {
  width: 100%; padding: 11px 14px;
  background: #1a1410; border: none; color: #e8d8b8;
  font-family: inherit; font-size: 14px; outline: none;
}
#chat-input:focus { background: #221a13; box-shadow: inset 0 0 0 1px #d4af37; }
#chat-help { padding: 8px 14px; font-size: 11px; color: #888; border-top: 1px solid #3a2f1f; background: #1a1410; }
#chat-help em { color: #d4af37; font-style: normal; }

/* ============== ACTION CONTEXT MENU ============== */
.action-menu {
  position: fixed; z-index: 60;
  background: #2a2218;
  border: 1px solid #d4af37;
  border-radius: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
  padding: 4px;
  min-width: 180px;
}
.action-menu.hidden { display: none; }
.action-item {
  display: block; width: 100%;
  background: none; border: none;
  color: #e8d8b8; text-align: left;
  padding: 8px 12px; cursor: pointer;
  font-family: inherit; font-size: 13px;
  border-radius: 2px;
}
.action-item:hover { background: #4a3a1f; color: #ffe0a0; }
.action-sep { height: 1px; background: #5a4830; margin: 4px 6px; }

/* ============== MODAL ============== */
.modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.75); }
.modal-box {
  position: relative; background: #2a2218;
  border: 2px solid #d4af37; border-radius: 6px;
  width: 580px; max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}
.modal-box.sheet-box { width: 640px; }
.modal-box.dialog-box { width: 600px; }
.modal-box header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid #5a4830;
}
.modal-box header h3 {
  color: #d4af37; font-size: 17px; font-variant: small-caps;
  letter-spacing: 1px; font-weight: normal;
}
.modal-close {
  background: none; border: none; color: #d4af37;
  font-size: 22px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-intro { font-size: 13px; line-height: 1.5; color: #c8b888; margin-bottom: 14px; }
.modal-intro a { color: #d4af37; }
.modal-label {
  display: block; color: #d4af37; font-size: 12px;
  font-variant: small-caps; letter-spacing: 1px;
  margin-bottom: 6px; margin-top: 12px;
}
#grok-prompt {
  width: 100%; background: #1a1410; color: #e8d8b8;
  border: 1px solid #5a4830; border-radius: 3px; padding: 10px;
  font-family: 'Courier New', monospace; font-size: 12px; resize: vertical;
}
#grok-prompt:focus { outline: none; border-color: #d4af37; }
.modal-path {
  display: block; background: #1a1410; color: #d4af37;
  padding: 8px 10px; border-radius: 3px;
  font-family: 'Courier New', monospace; font-size: 12px;
  border: 1px solid #5a4830; word-break: break-all;
}
.modal-row { display: flex; gap: 10px; margin-top: 10px; }
.modal-row button {
  flex: 1; background: #2a2218; color: #d4af37;
  border: 1px solid #5a4830; padding: 9px 12px;
  font-family: inherit; font-size: 13px; cursor: pointer; border-radius: 3px;
}
.modal-row button:hover { background: #3a2f1f; border-color: #d4af37; }
.modal-row button.primary { background: #4a3a1f; color: #f0e0a0; border-color: #d4af37; }
.modal-row button.primary:hover { background: #5a4830; }
.modal-status { margin-top: 12px; font-size: 12px; color: #888; font-style: italic; min-height: 18px; }
.modal-status.ok { color: #7ab87a; font-style: normal; }
.modal-status.err { color: #c4604a; font-style: normal; }

/* ============== INTRO MODAL ============== */
.modal-fullscreen .modal-backdrop { background: #050302; }
.modal-box.intro-box {
  width: 720px; max-width: 92vw;
  background: linear-gradient(180deg, #2a1f10 0%, #1a1208 100%);
  border: 2px solid #d4af37;
  padding: 32px 40px;
  text-align: center;
  font-family: Georgia, serif;
}
.intro-brand {
  font-family: Georgia, serif; font-weight: bold;
  font-size: 34px; letter-spacing: 3px;
  color: #f0d878; font-variant: small-caps;
  text-shadow: 0 2px 10px rgba(212, 175, 55, 0.5), 0 1px 2px rgba(0,0,0,0.8);
  margin-bottom: 6px;
}
.intro-brand span { color: #b03c3c; font-size: 28px; }
.intro-progress {
  color: #888; font-size: 11px; letter-spacing: 2px;
  margin-bottom: 16px; text-transform: uppercase;
}
.intro-box h2 {
  color: #d4af37; font-size: 28px; font-variant: small-caps;
  letter-spacing: 2px; margin-bottom: 18px; font-weight: normal;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}
.intro-box p {
  color: #d8c8a8; font-size: 16px; line-height: 1.7;
  margin-bottom: 24px; font-style: italic;
}
.char-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin: 12px 0 20px;
  max-height: 46vh; overflow-y: auto; padding: 4px;
}
.char-class {
  color: #b8a060; font-size: 11px; margin: 2px 0 4px; font-style: italic;
}
.char-card.char-star {
  border-color: #f0c040;
  box-shadow: 0 0 14px rgba(240, 192, 64, 0.35);
  background: linear-gradient(180deg, #2a1f08 0%, #1a1208 100%);
}
.char-card.char-star .char-name { color: #f0d878; }
.char-card {
  background: #1a1208; border: 2px solid #5a4830;
  padding: 14px; border-radius: 4px; cursor: pointer;
  text-align: left; transition: all 0.2s;
}
.char-card:hover { border-color: #d4af37; background: #2a1f10; }
.char-card.selected {
  border-color: #d4af37; background: #4a3010;
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.4);
}
.char-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 16px; margin-bottom: 6px; color: #fff;
  border: 2px solid #f0e0c0;
}
.char-name {
  color: #d4af37; font-size: 16px; font-variant: small-caps;
  letter-spacing: 1px; margin-bottom: 4px;
}
.char-desc { color: #c8b888; font-size: 12px; line-height: 1.4; }
.intro-actions {
  display: flex; gap: 12px; justify-content: center;
  margin-top: 12px;
}
.intro-actions button {
  padding: 12px 28px; font-family: inherit; font-size: 14px;
  border: 2px solid #5a4830; border-radius: 4px;
  cursor: pointer; min-width: 160px;
  font-variant: small-caps; letter-spacing: 1.5px;
}
.intro-actions button.ghost {
  background: transparent; color: #888;
}
.intro-actions button.ghost:hover { color: #d4af37; border-color: #d4af37; }
.intro-actions button.primary {
  background: linear-gradient(180deg, #5a4818 0%, #3a2f10 100%);
  color: #ffe8a0; border-color: #d4af37;
  box-shadow: 0 4px 16px rgba(212, 175, 55, 0.3);
}
.intro-actions button.primary:hover { background: #6a5820; }
.intro-actions button.primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============== DIALOG MODAL ============== */
.dialog-npc-text {
  background: #1a1410;
  border-left: 3px solid #d4af37;
  padding: 14px 16px;
  font-size: 14px; line-height: 1.6;
  color: #e8d8b8;
  font-style: italic;
  margin-bottom: 16px;
  border-radius: 2px;
}
.dialog-choices {
  display: flex; flex-direction: column; gap: 6px;
}
.dialog-choice {
  background: #2a2218; color: #d4af37;
  border: 1px solid #5a4830; padding: 10px 14px;
  font-family: inherit; font-size: 13px;
  cursor: pointer; border-radius: 3px;
  text-align: left;
}
.dialog-choice:hover {
  background: #4a3a1f; color: #ffe8a0; border-color: #d4af37;
}

/* ============== SHEET MODAL ============== */
.sheet-row { display: flex; gap: 10px; margin-bottom: 8px; }
.sheet-field { flex: 1; }
.sheet-field.small { flex: 0 0 80px; }
.sheet-field label {
  display: block; font-size: 11px; color: #d4af37;
  font-variant: small-caps; letter-spacing: 1px; margin-bottom: 3px;
}
.sheet-field input {
  width: 100%; background: #1a1410; color: #e8d8b8;
  border: 1px solid #5a4830; padding: 6px 8px;
  font-family: inherit; font-size: 14px; border-radius: 2px;
}
.sheet-field input:focus { outline: none; border-color: #d4af37; }
.sheet-stats {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  margin: 12px 0;
}
.sheet-stats .stat {
  background: #1a1410; border: 1px solid #5a4830;
  border-radius: 3px; padding: 6px; text-align: center;
}
.sheet-stats .stat label {
  display: block; color: #d4af37; font-size: 10px;
  font-variant: small-caps; letter-spacing: 1px;
}
.sheet-stats .stat input {
  width: 100%; background: transparent; color: #e8d8b8;
  border: none; text-align: center; font-size: 18px; font-weight: bold;
  font-family: inherit; outline: none; padding: 2px 0 0;
}
.sheet-conditions {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px;
}
.cond-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 4px; background: #1a1410;
  border: 1px solid #5a4830; border-radius: 14px;
  font-size: 12px; cursor: pointer; user-select: none;
}
.cond-chip input { margin: 0; }
.cond-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; color: #fff;
  font-size: 11px; font-weight: bold;
  border: 1px solid rgba(0,0,0,0.4);
}
.sheet-macros { display: flex; flex-direction: column; gap: 4px; }
.macro-row { display: grid; grid-template-columns: 1.2fr 1.4fr 0.8fr; gap: 6px; }
.macro-row input {
  background: #1a1410; color: #e8d8b8;
  border: 1px solid #5a4830; padding: 6px 8px;
  font-family: inherit; font-size: 12px; border-radius: 2px;
}
.macro-row input:focus { outline: none; border-color: #d4af37; }

/* ================================================================
   MULTIPLAYER — widget, lobby, toast
   ================================================================ */
#mp-widget {
  background: linear-gradient(180deg, #241c12 0%, #1c1610 100%);
  border-bottom: 1px solid #5a4830;
  padding: 8px 12px;
}
.mp-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mp-status { font-size: 12px; font-variant: small-caps; letter-spacing: 0.5px; }
.mp-status.mp-on { color: #5db04a; }
.mp-status.mp-off { color: #8a7a5a; }
.mp-row button {
  background: #2a2218; color: #d4af37; border: 1px solid #5a4830;
  padding: 6px 10px; font-family: inherit; font-size: 12px;
  cursor: pointer; border-radius: 3px; transition: all 0.15s;
}
.mp-row button:hover { background: #3a2f1f; border-color: #d4af37; }
.mp-members { margin-top: 6px; font-size: 11px; color: #b8a888; line-height: 1.5; }
.mp-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 3px; vertical-align: middle; }

.mp-box { width: 420px; max-width: 92vw; }
.mp-box input {
  width: 100%; background: #1a1410; color: #e8d8b8;
  border: 1px solid #5a4830; padding: 10px 12px; font-family: inherit;
  font-size: 15px; border-radius: 3px; margin-bottom: 4px;
}
.mp-box input:focus { outline: none; border-color: #d4af37; }
#mp-code { text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: bold; }
.mp-actions { margin: 12px 0 6px; }
.mp-actions .primary, .mp-box .primary {
  width: 100%; background: linear-gradient(145deg, #4a3a1f, #2a2010);
  color: #f0d878; border: 1px solid #d4af37; padding: 12px;
  font-family: inherit; font-size: 15px; cursor: pointer; border-radius: 4px;
  transition: all 0.15s;
}
.mp-box .primary:hover { background: linear-gradient(145deg, #5a4a2a, #3a3018); }
.mp-or { text-align: center; color: #8a7a5a; font-size: 12px; margin: 12px 0; font-variant: small-caps; letter-spacing: 1px; }
.mp-join { display: flex; gap: 8px; }
.mp-join input { flex: 1; margin: 0; }
.mp-join button {
  background: #2a2218; color: #d4af37; border: 1px solid #5a4830;
  padding: 0 16px; font-family: inherit; font-size: 14px; cursor: pointer;
  border-radius: 3px; white-space: nowrap;
}
.mp-join button:hover { background: #3a2f1f; border-color: #d4af37; }
.mp-hint { margin-top: 14px; font-size: 12px; color: #b8a888; line-height: 1.6; font-style: italic; }

#mp-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #2a2218; color: #f0d878; border: 1px solid #d4af37;
  padding: 12px 20px; border-radius: 6px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6); z-index: 200;
  opacity: 0; pointer-events: none; transition: all 0.25s; max-width: 90vw;
  word-break: break-all; text-align: center;
}
#mp-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== AI Conteur button ===== */
#ai-conteur-btn {
  display: block; width: calc(100% - 24px); margin: 8px 12px 4px;
  background: linear-gradient(145deg, #3a2a52, #241830);
  color: #e0c8ff; border: 1px solid #7a5aa0;
  padding: 10px; font-family: inherit; font-size: 13px;
  cursor: pointer; border-radius: 4px; transition: all 0.15s;
  font-variant: small-caps; letter-spacing: 0.5px;
}
#ai-conteur-btn:hover:not(:disabled) { background: linear-gradient(145deg, #4a3568, #2e2040); border-color: #b088e0; }
#ai-conteur-btn:disabled { opacity: 0.7; cursor: wait; }
#ai-conteur-btn.ai-disabled { opacity: 0.45; border-color: #5a4830; color: #9a8a7a; }

/* ================================================================
   AUDIO BAR (mute + volume) — desktop & mobile
   ================================================================ */
#audio-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid #3a2f1f; background: #1f1810;
}
#audio-bar label {
  color: #d4af37; font-size: 11px; font-variant: small-caps; letter-spacing: 1px;
  min-width: 80px;
}
#btn-sound-toggle {
  background: #2a2218; color: #d4af37; border: 1px solid #5a4830;
  padding: 5px 10px; cursor: pointer; border-radius: 2px; font-size: 14px;
}
#btn-sound-toggle:hover { background: #3a2f1f; border-color: #d4af37; }
#btn-sound-toggle.muted { color: #8a7a5a; border-color: #4a3f30; }
#sound-volume { flex: 1; accent-color: #d4af37; cursor: pointer; height: 4px; }

/* ================================================================
   MOBILE CHROME (action bar + drawer tabs) — hidden on desktop
   ================================================================ */
#mobile-actionbar { display: none; }
#drawer-tabs { display: none; }

/* ================================================================
   MOBILE TOGGLE / BACKDROP (hidden on desktop)
   ================================================================ */
#sidebar-toggle { display: none; }
#sidebar-backdrop { display: none; }

/* ================================================================
   RESPONSIVE — phones & small tablets
   ================================================================ */
@media (max-width: 860px) {
  body { height: 100dvh; }
  #app { flex-direction: column; height: 100dvh; }

  #map-container {
    flex: 1;
    padding: 6px;
    min-height: 0;
  }
  #map-header {
    margin-bottom: 6px;
    padding-right: 56px; /* room for floating toggle */
  }
  #map-title { font-size: 17px; }
  #map-actions button { padding: 7px 10px; font-size: 12px; }
  #map-viewport { border-width: 2px; }
  #map-status { display: none; }

  /* Sidebar becomes a slide-up drawer */
  #sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 82dvh;
    max-height: 82dvh;
    border-left: none;
    border-top: 3px solid #d4af37;
    border-radius: 16px 16px 0 0;
    transform: translateY(calc(100% + 4px));
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 60;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.7);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  #sidebar::before {
    content: "";
    position: sticky; top: 6px;
    display: block; width: 42px; height: 5px;
    margin: 6px auto 2px;
    background: #5a4830; border-radius: 3px;
  }
  #sidebar.open { transform: translateY(0); }

  #sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0; pointer-events: none;
    transition: opacity 0.28s;
    z-index: 55;
  }
  #sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

  #sidebar-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; right: 14px; bottom: 16px;
    width: 56px; height: 56px; border-radius: 50%;
    background: linear-gradient(145deg, #d4af37, #9a7b1f);
    color: #1a1208; border: 2px solid #f0d878;
    font-size: 24px; cursor: pointer; z-index: 65;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
  }
  #sidebar-toggle:active { transform: scale(0.94); }
  #sidebar-toggle .badge {
    position: absolute; top: -4px; right: -4px;
    min-width: 18px; height: 18px; padding: 0 4px;
    background: #c0392b; color: #fff; font-size: 11px;
    border-radius: 9px; display: none;
    align-items: center; justify-content: center;
  }
  #sidebar-toggle.has-unread .badge { display: flex; }

  #chat-log { max-height: 34vh; }

  /* Bigger touch targets */
  #map-actions button,
  .macro-btn,
  .panel-actions button,
  #btn-my-sheet,
  .modal-row button { min-height: 40px; }

  .modal-box { width: 94vw !important; max-width: 94vw; padding: 18px; }
  .modal-box.intro-box { padding: 22px 18px; }
  .intro-brand { font-size: 26px; }
  .char-grid { grid-template-columns: repeat(2, 1fr); max-height: 52vh; }
}

/* very small phones */
@media (max-width: 420px) {
  #map-title { font-size: 15px; letter-spacing: 0.5px; }
  .intro-box h2 { font-size: 22px; }
  .intro-box p { font-size: 14px; }
}

/* landscape phones: keep canvas usable */
@media (max-height: 520px) and (orientation: landscape) {
  #map-container { padding: 4px; }
  #map-header { margin-bottom: 4px; }
  #sidebar { height: 94dvh; max-height: 94dvh; }
}

/* ================================================================
   MOBILE-FIRST UI v2 — barre d'action tactile + tiroir à onglets
   (placé après les règles mobiles historiques : il les complète/affine)
   ================================================================ */
@media (max-width: 860px) {
  :root { --mab-h: 60px; }

  /* La carte reste dégagée de la barre d'action du bas */
  #map-container {
    padding-bottom: calc(var(--mab-h) + env(safe-area-inset-bottom, 0px) + 4px);
  }
  /* Plus de bouton flottant : on libère l'espace du header */
  #map-header { padding-right: 8px; }

  /* L'ancien bouton rond flottant est remplacé par la barre d'action */
  #sidebar-toggle { display: none !important; }

  /* ---- Barre d'action tactile (bas d'écran) ---- */
  #mobile-actionbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 65;
    background: linear-gradient(180deg, #241c12 0%, #18120c 100%);
    border-top: 2px solid #d4af37;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.6);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mab-btn {
    position: relative;
    flex: 1 1 0; min-width: 0;
    min-height: 56px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    background: none; border: none; cursor: pointer;
    color: #cdb27a; font-family: inherit;
    padding: 6px 2px;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s, background 0.15s;
  }
  .mab-btn:active { background: rgba(212, 175, 55, 0.14); }
  .mab-btn.active { color: #ffe8a0; }
  .mab-btn.active::before {
    content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px;
    background: #d4af37; border-radius: 0 0 3px 3px;
  }
  .mab-ico { font-size: 21px; line-height: 1; }
  .mab-lbl { font-size: 10px; letter-spacing: 0.3px; font-variant: small-caps; white-space: nowrap; }
  .mab-badge {
    position: absolute; top: 7px; left: calc(50% + 6px);
    min-width: 16px; height: 16px; padding: 0 4px;
    background: #c0392b; color: #fff; font-size: 10px; border-radius: 8px;
    display: none; align-items: center; justify-content: center; line-height: 1;
  }
  #mab-chat.has-unread .mab-badge { display: flex; }

  /* ---- Tiroir : repose au-dessus de la barre d'action ---- */
  #sidebar {
    top: auto;
    bottom: calc(var(--mab-h) + env(safe-area-inset-bottom, 0px));
    height: auto;
    max-height: 78dvh;
    border-radius: 16px 16px 0 0;
    padding-bottom: 10px;
  }

  /* ---- En-tête à onglets, collant en haut du tiroir ---- */
  #drawer-tabs {
    display: flex; gap: 6px;
    position: sticky; top: 0; z-index: 6;
    padding: 10px 10px 8px;
    background: #241c12;
    border-bottom: 1px solid #5a4830;
  }
  .drawer-tab {
    flex: 1; min-height: 44px;
    background: #1f1810; color: #b8a060;
    border: 1px solid #5a4830; border-radius: 9px;
    font-family: inherit; font-size: 12px; cursor: pointer;
    font-variant: small-caps; letter-spacing: 0.5px;
    transition: all 0.15s;
  }
  .drawer-tab.active {
    background: linear-gradient(180deg, #4a3a1f, #2a2010);
    color: #ffe8a0; border-color: #d4af37;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.25);
  }

  /* ---- Visibilité par onglet : on masque tout, puis on révèle ---- */
  #sidebar #mp-widget,
  #sidebar #quest-panel,
  #sidebar #player-bar,
  #sidebar #map-bar,
  #sidebar #audio-bar,
  #sidebar #initiative-panel,
  #sidebar > h2,
  #sidebar #chat-log,
  #sidebar #macros-bar,
  #sidebar #chat-form,
  #sidebar #chat-help,
  #sidebar #ai-conteur-btn { display: none; }

  /* Onglet CHAT & jets */
  #sidebar.tab-chat > h2,
  #sidebar.tab-chat #chat-form,
  #sidebar.tab-chat #chat-help,
  #sidebar.tab-chat #ai-conteur-btn { display: block; }
  #sidebar.tab-chat #chat-log { display: block; max-height: 46dvh; flex: none; }
  #sidebar.tab-chat #macros-bar { display: flex; }

  /* Onglet COMBAT (initiative) */
  #sidebar.tab-combat #initiative-panel { display: block; }
  #sidebar.tab-combat #player-bar { display: flex; }

  /* Onglet CARTE / quête / réglages */
  #sidebar.tab-quest #mp-widget { display: block; }
  #sidebar.tab-quest #quest-panel { display: block; }
  #sidebar.tab-quest #player-bar { display: flex; }
  #sidebar.tab-quest #map-bar { display: flex; }
  #sidebar.tab-quest #audio-bar { display: flex; }

  /* Cibles tactiles plus généreuses dans le tiroir */
  #player-select, #map-select { min-height: 44px; font-size: 15px; }
  #btn-my-sheet, #btn-sound-toggle { min-height: 44px; min-width: 44px; }
  #init-list { max-height: none; }
  #chat-input { padding: 14px; font-size: 16px; } /* >=16px : pas de zoom iOS au focus */
  #macros-bar .macro-btn { min-height: 44px; }
}

/* ================================================================
   ONBOARDING — accueil (mode de jeu) + tutoriel guidé + bouton d'aide
   z-index : accueil 300 (au-dessus de tout) · tuto 250 · pense-bête 120
   · bouton ? 96 (au-dessus des modales pour rester accessible)
   ================================================================ */

/* ---- Écran d'accueil « mode de jeu » ---- */
.onb-welcome {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1a1410 0%, #050302 100%);
  padding: 20px; overflow-y: auto;
}
.onb-welcome.hidden { display: none; }
.onb-welcome-inner { width: 100%; max-width: 760px; text-align: center; }
.onb-brand {
  font-family: Georgia, serif; font-weight: bold;
  font-size: 40px; letter-spacing: 3px; color: #f0d878; font-variant: small-caps;
  text-shadow: 0 2px 14px rgba(212, 175, 55, 0.5), 0 1px 2px rgba(0,0,0,0.8);
  margin-bottom: 8px;
}
.onb-brand span { color: #b03c3c; font-size: 32px; }
.onb-tagline { color: #d8c8a8; font-size: 17px; line-height: 1.6; font-style: italic; margin-bottom: 28px; }
.onb-tagline em { color: #f0d878; font-style: normal; }
.onb-modes { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.onb-mode-card {
  flex: 1 1 260px; max-width: 320px; min-height: 200px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(180deg, #2a1f10 0%, #1a1208 100%);
  border: 2px solid #5a4830; border-radius: 8px;
  padding: 26px 22px; cursor: pointer; color: inherit; font-family: inherit;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.onb-mode-card:hover, .onb-mode-card:focus-visible {
  border-color: #d4af37; transform: translateY(-3px);
  box-shadow: 0 8px 26px rgba(212, 175, 55, 0.28);
}
.onb-mode-card:active { transform: translateY(0); }
.onb-mode-ico { font-size: 46px; line-height: 1; }
.onb-mode-title { color: #d4af37; font-size: 21px; font-variant: small-caps; letter-spacing: 1px; }
.onb-mode-desc { color: #c8b888; font-size: 14px; line-height: 1.5; }
.onb-welcome-foot { color: #8a7a5a; font-size: 13px; margin-top: 26px; font-style: italic; }

/* ---- Bouton d'aide « ? » flottant ---- */
#onb-help {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 10px); right: 12px;
  z-index: 96; width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(145deg, #3a2f1f, #221a10);
  color: #f0d878; border: 2px solid #d4af37;
  font-family: Georgia, serif; font-size: 20px; font-weight: bold; cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.6);
  transition: transform 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#onb-help:hover { background: linear-gradient(145deg, #4a3a1f, #2a2010); transform: scale(1.06); }
#onb-help:active { transform: scale(0.94); }

/* ---- Pense-bête (réutilise .modal, z-index relevé) ---- */
#onb-cheatsheet.modal { z-index: 120; }
.onb-cheats-box { width: 520px; }
.onb-cheats { list-style: none; margin: 0 0 6px; padding: 0; }
.onb-cheats li {
  color: #d8c8a8; font-size: 14px; line-height: 1.5;
  padding: 9px 4px 9px 26px; position: relative;
  border-bottom: 1px solid #2a2218;
}
.onb-cheats li:last-child { border-bottom: none; }
.onb-cheats li::before { content: "▸"; position: absolute; left: 6px; color: #d4af37; }
.onb-cheats b { color: #d4af37; font-weight: normal; }
.onb-cheats em { color: #f0d878; font-style: normal; }

/* ---- Tutoriel guidé (spotlight + bulle) ---- */
.onb-tour { position: fixed; inset: 0; z-index: 250; }
.onb-tour.hidden { display: none; }
.onb-backdrop { position: absolute; inset: 0; background: rgba(5, 3, 2, 0.74); display: none; }
.onb-spotlight {
  position: absolute; border-radius: 8px;
  border: 2px solid #d4af37;
  box-shadow: 0 0 0 9999px rgba(5, 3, 2, 0.74), 0 0 18px rgba(212, 175, 55, 0.55);
  pointer-events: none; transition: all 0.2s ease;
}
.onb-bubble {
  position: absolute; width: 320px; max-width: calc(100vw - 24px);
  background: linear-gradient(180deg, #2a1f10 0%, #1a1208 100%);
  border: 2px solid #d4af37; border-radius: 8px;
  padding: 16px 18px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
}
.onb-bubble-title {
  color: #d4af37; font-size: 18px; font-variant: small-caps;
  letter-spacing: 1px; margin-bottom: 8px;
}
.onb-bubble-text { color: #d8c8a8; font-size: 14px; line-height: 1.6; margin-bottom: 14px; }
.onb-bubble-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.onb-bubble-skipnext { color: #9a8a6a; font-size: 12px; display: flex; align-items: center; gap: 5px; cursor: pointer; }
.onb-bubble-skipnext input { accent-color: #d4af37; }
.onb-bubble-progress { color: #888; font-size: 12px; letter-spacing: 1px; margin-left: auto; }
.onb-bubble-actions { display: flex; gap: 8px; }
.onb-bubble-actions button {
  background: #2a2218; color: #d4af37; border: 1px solid #5a4830;
  padding: 8px 12px; font-family: inherit; font-size: 13px; cursor: pointer; border-radius: 4px;
}
.onb-bubble-actions button:hover { background: #3a2f1f; border-color: #d4af37; }
.onb-bubble-actions button.primary { background: #4a3a1f; color: #f0e0a0; border-color: #d4af37; }

@media (max-width: 860px) {
  .onb-brand { font-size: 30px; }
  .onb-tagline { font-size: 15px; margin-bottom: 22px; }
  .onb-mode-card { min-height: 160px; padding: 22px 18px; }
  .onb-mode-ico { font-size: 38px; }
  .onb-cheats-box { width: 94vw; }
  .onb-bubble-actions button { min-height: 40px; }
}
