:root {
  /* Light theme */
  --bg: #f5f0e8;
  --panel: #fffdf8;
  --panel-2: #f0ebe0;
  --text: #1a1410;
  --muted: #6b6050;
  --accent: #7c4f1e;
  --accent-light: #c8944a;
  --danger: #b91c1c;
  --warning: #b45309;
  --ok: #15803d;
  --border: #d6cfc0;
  --user: #1e3a5f;
  --assistant: #2d4a2d;
  --system: #5a5040;
  --radius: 12px;
  --gap: 12px;
  --shadow: 0 4px 16px rgba(80, 50, 20, 0.10);
  --bubble-max: min(78%, 860px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.controls,
.composer,
.statusbar {
  display: grid;
  gap: var(--gap);
}

.statusbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.status-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  min-height: 44px;
  color: var(--muted);
}

.controls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.llm-controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(255, 253, 248, 0.7);
  margin-bottom: 4px;
}

.llm-settings-toggle-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 2px;
}

.llm-settings-toggle-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-session-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.settings-logout-btn {
  flex: 0 0 auto;
  width: auto !important;
  min-width: 0;
  min-height: 32px !important;
  padding: 5px 12px !important;
  font-size: 12px !important;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.campaign-character-in-llm {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

#llm-settings-toggle-hint {
  font-size: 12px;
  color: var(--muted);
}

#llm-controls-body {
  grid-column: 1 / -1;
}

.llm-controls.llm-controls--collapsed #llm-controls-body {
  display: none;
}

.llm-controls .field {
  margin-bottom: 0;
}

.llm-controls select,
.llm-controls input,
.llm-controls button {
  min-height: 36px;
  padding: 6px 9px;
  font-size: 13px;
  border-radius: 8px;
}

.llm-controls .field label {
  font-size: 11px;
}

#openai-models-toggle-wrap {
  margin-top: 4px !important;
}

#openai-models-toggle-wrap label {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

#openai-models-toggle-wrap input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-height: 14px;
  padding: 0;
  margin: 0;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--panel);
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.top-row-field {
  order: -1;
}

.visually-hidden {
  display: none !important;
}

.bottom-system-field {
  position: fixed;
  left: 14px;
  bottom: 10px;
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 1100;
}

/* Kept in DOM for mechanics; not shown in UI. */
.bottom-system-field.bottom-system-field--hidden {
  position: fixed !important;
  left: -10000px !important;
  top: auto !important;
  bottom: auto !important;
  width: 1px !important;
  height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: -1 !important;
}

.bottom-system-field label {
  color: var(--muted);
  font-size: 11px;
  font-family: Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bottom-system-field select {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-family: Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: stretch;
}

.field-row.single-action {
  grid-template-columns: 1fr auto;
}

.ollama-host-row {
  max-width: 100%;
  grid-template-columns: minmax(240px, 1fr) auto;
}

select,
input,
button,
textarea {
  width: 100%;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: Arial, sans-serif;
}

select:focus,
input:focus,
textarea:focus {
  outline: 2px solid var(--accent-light);
  border-color: var(--accent-light);
}

button {
  cursor: pointer;
  background: var(--accent);
  color: #fff8f0;
  font-weight: bold;
  font-family: Arial, sans-serif;
  transition: transform 0.16s ease, filter 0.16s ease, opacity 0.16s ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.12);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

button.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button:disabled,
select:disabled,
textarea:disabled,
input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 420px;
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: 16px;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.play-area.sheet-open {
  grid-template-columns: minmax(0, 1fr) auto;
}

.play-main {
  min-width: 0;
}

.sheet-panel {
  display: none;
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.play-area.sheet-open .sheet-panel {
  display: block;
}

.sheet-panel-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet-name {
  font-size: 16px;
  font-weight: 700;
}

.sheet-archetype {
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sheet-resource {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-resource-top {
  display: flex;
  justify-content: space-between;
  font-family: Arial, sans-serif;
  font-size: 12px;
}

.sheet-bar {
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f0ebe0;
  overflow: hidden;
}

.sheet-bar-fill {
  height: 100%;
}

.sheet-bar-fill.hp {
  background: #22a746;
}

.sheet-bar-fill.mana {
  background: #3b82f6;
}

.sheet-section-title {
  margin: 0;
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sheet-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.sheet-stat {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 6px;
  text-align: center;
}

.sheet-stat-key {
  display: block;
  font-family: Arial, sans-serif;
  font-size: 11px;
  color: var(--muted);
}

.sheet-stat-val {
  display: block;
  font-size: 15px;
  font-weight: 700;
}

.sheet-stat-mod {
  display: block;
  font-family: Arial, sans-serif;
  font-size: 11px;
  color: var(--muted);
}

.sheet-skills-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.sheet-skill {
  display: flex;
  justify-content: space-between;
  font-family: Arial, sans-serif;
  font-size: 12px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 2px;
}

.status-dock {
  position: fixed;
  right: 14px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 1100;
}

.status-dot-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d2c8b5;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.status-dot.unknown {
  background: #d2c8b5;
}

.status-dot.ok {
  background: #16a34a;
}

.status-dot.warn {
  background: #d97706;
}

.status-dot.error {
  background: #dc2626;
}

.status-dot-label {
  font-family: Arial, sans-serif;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.character-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.72);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.character-modal-overlay[data-creation-busy='1'] {
  cursor: wait;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.78);
  z-index: 1400;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-overlay-panel {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
  animation: bubble-in 180ms ease-out;
  display: grid;
  gap: 12px;
}

.character-modal {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
  animation: bubble-in 180ms ease-out;
}

.campaign-modal {
  width: min(560px, 100%);
}

.character-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
}

.history-summary-body {
  white-space: pre-wrap;
  max-height: 60vh;
  overflow: auto;
  font-size: 14px;
  line-height: 1.55;
  margin-top: 8px;
  color: var(--text, #e8e4dc);
}

.history-summary-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding-right: 48px;
}

.history-summary-title-row h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.history-summary-regen-btn {
  font-size: 12px;
  padding: 6px 10px;
  min-height: 32px;
  white-space: nowrap;
}

.character-modal h2 {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 22px;
  padding-right: 48px;
}

.history-summary-modal .history-summary-title-row h2 {
  padding-right: 0;
}

.character-modal textarea {
  min-height: 120px;
}

.archetype-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.archetype-card {
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  min-height: 110px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  justify-content: flex-start;
}

.archetype-card:hover:not(:disabled) {
  filter: brightness(1.03);
}

.archetype-card.selected {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 2px rgba(200, 148, 74, 0.18);
  background: rgba(200, 148, 74, 0.12);
}

.archetype-title {
  font-weight: 700;
  font-size: 16px;
}

.archetype-desc {
  font-weight: 400;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.history-panel {
  display: none;
  min-height: 220px;
  max-height: 32vh;
}

.message {
  display: block;
  width: fit-content;
  max-width: var(--bubble-max);
  min-width: 120px;
  border-radius: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow);
  animation: bubble-in 180ms ease-out;
  font-family: 'Georgia', serif;
  font-size: 15px;
  line-height: 1.6;
}

.message.user {
  align-self: flex-end;
  background: rgba(30, 58, 95, 0.08);
  border-color: rgba(30, 58, 95, 0.22);
  border-bottom-right-radius: 6px;
  color: var(--user);
}

/* /mem — przypomnienia (bez wpływu na narrację): żółte tło, czarny tekst */
.message.user.memory-turn {
  background: #f5d84a;
  border-color: #b8960f;
  color: #111;
}

.message.assistant.memory-turn {
  background: #f5d84a;
  border-color: #b8960f;
  color: #111;
}

.message.user.memory-turn .meta,
.message.assistant.memory-turn .meta {
  color: #1a1a1a;
}

.message.user.memory-turn .route-badge,
.message.assistant.memory-turn .route-badge {
  background: rgba(0, 0, 0, 0.08);
  color: #222;
  border-color: rgba(0, 0, 0, 0.18);
}

/* /helpme — OOC doradca (róż, odrębny od narracji i /mem) */
.chat-back-in-game {
  align-self: center;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-family: Georgia, serif;
  font-style: italic;
  margin: 6px 0 10px;
  letter-spacing: 0.02em;
}

.ooc-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f4a0a0;
  color: #5c1010;
  border: 1px solid #e07070;
}

.message.user.helpme-turn,
.message.assistant.helpme-turn {
  background: #fde8e8;
  border-color: #f4a0a0;
  color: #9b1c1c;
}

.message.user.helpme-turn .meta,
.message.assistant.helpme-turn .meta {
  color: #741010;
}

.message.user.helpme-turn .route-badge,
.message.assistant.helpme-turn .route-badge {
  background: rgba(155, 28, 28, 0.12);
  color: #7a1515;
  border-color: rgba(155, 28, 28, 0.25);
}

.message.assistant {
  align-self: flex-start;
  background: rgba(45, 74, 45, 0.08);
  border-color: rgba(45, 74, 45, 0.22);
  border-bottom-left-radius: 6px;
  color: var(--assistant);
}

/*
  Streaming bubble:
  - Fixed width from the start so it never resizes as tokens arrive.
  - After finalizeStreamingBubble removes .streaming, the bubble keeps
    its rendered width via the max-width cap — no snap/jitter.
  - overflow: hidden prevents scrollbars during token fill.
  - No bubble-in animation (was already visible as thinking bubble).
*/
.message.assistant.streaming {
  width: var(--bubble-max);
  max-width: var(--bubble-max);
  min-width: 260px;
  overflow: hidden;
  animation: none;
}

/*
  Once .streaming is removed, preserve visual stability:
  - max-width keeps the bubble from jumping wider.
  - width auto lets it be narrower if content is short (natural).
*/
.message.assistant:not(.streaming):not(.thinking) {
  width: auto;
  max-width: var(--bubble-max);
}

/*
  The <pre> inside the streaming bubble:
  - will-change: contents hints browser this text updates frequently
  - min-height keeps bubble from collapsing before first token
*/
.message.assistant.streaming pre.streaming-text {
  display: block;
  min-height: 1.6em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  will-change: contents;
}

/* Blinking cursor at end of streaming text */
.message.assistant.streaming pre.streaming-text::after {
  content: '\258b';
  display: inline-block;
  animation: stream-cursor 0.7s step-end infinite;
  color: var(--accent-light);
  font-size: 0.85em;
  vertical-align: baseline;
  margin-left: 2px;
}

@keyframes stream-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.message.system {
  align-self: center;
  width: 100%;
  max-width: 100%;
  background: rgba(90, 80, 64, 0.07);
  border-color: var(--border);
  color: var(--system);
  font-style: italic;
  font-size: 13px;
}

.message.error {
  align-self: stretch;
  width: 100%;
  max-width: 100%;
  background: rgba(185, 28, 28, 0.08);
  border-color: var(--danger);
  color: var(--danger);
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
  font-family: Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.route-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  border: 1px solid var(--border);
}

.composer {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.composer-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 150px;
}

.composer-actions button {
  min-height: 38px;
}

.sheet-inline-btn {
  font-size: 13px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  font-family: Arial, sans-serif;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-family: 'Georgia', serif;
}

.muted {
  color: var(--muted);
  font-family: Arial, sans-serif;
}

/* ── Thinking bubble ── */
/*
  Use display:flex with !important to override the .message display:block.
  Without this the thinking-wrap row (text + dots) would stack vertically.
*/
.message.assistant.thinking.memory-turn {
  background: #f5d84a;
  border-color: #b8960f;
  color: #111;
}

.message.assistant.thinking.memory-turn .meta {
  color: #1a1a1a;
}

.message.assistant.thinking.memory-turn .thinking-text {
  color: #111;
}

.message.assistant.thinking.memory-turn .typing-dots span {
  background: #333;
}

.message.assistant.thinking.helpme-turn {
  background: #fde8e8;
  border-color: #f4a0a0;
  color: #9b1c1c;
}

.message.assistant.thinking.helpme-turn .meta {
  color: #741010;
}

.message.assistant.thinking.helpme-turn .thinking-text {
  color: #9b1c1c;
}

.message.assistant.thinking.helpme-turn .typing-dots span {
  background: #9b1c1c;
}

.message.thinking {
  display: flex !important;
  flex-direction: column;
  justify-content: center;
  position: relative;
  min-width: 200px;
  width: var(--bubble-max);
  max-width: var(--bubble-max);
  min-height: 72px;
  padding: 14px 18px;
  gap: 8px;
  animation: bubble-in 180ms ease-out;
}

.message.thinking .thinking-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.message.thinking .thinking-text {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  line-height: 1.4;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 20px;
  flex-shrink: 0;
}

.typing-dots span {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent-light);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

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

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

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Action bar ── */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.action-bar button {
  min-height: 34px;
  padding: 4px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  width: auto;
}

.action-bar .action-dice-btn {
  background: rgba(200, 148, 74, 0.18);
  border-color: var(--accent-light);
  color: var(--accent);
}

.action-bar .action-dice-btn:hover:not(:disabled) {
  background: rgba(200, 148, 74, 0.32);
}

.action-bar .action-dice-choose-btn {
  background: rgba(124, 79, 30, 0.10);
  border-color: var(--accent);
  color: var(--accent);
}

.action-bar .action-dice-choose-btn:hover:not(:disabled) {
  background: rgba(124, 79, 30, 0.20);
}

/* ── Dice chooser dialog ── */
.dice-dialog {
  position: relative;
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--accent-light);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(80, 50, 20, 0.14);
  animation: bubble-in 140ms ease-out;
}

.dice-dialog-title {
  font-size: 12px;
  font-family: Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 8px;
}

.dice-quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.dice-quick-btns .dice-quick {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
  width: auto;
  border-radius: 8px;
  background: rgba(200, 148, 74, 0.15);
  border-color: var(--accent-light);
  color: var(--accent);
  letter-spacing: 0.03em;
}

.dice-quick-btns .dice-quick:hover:not(:disabled) {
  background: rgba(200, 148, 74, 0.30);
}

.dice-custom-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dice-custom-row input.dice-custom-input {
  min-height: 34px;
  width: 120px;
  padding: 4px 10px;
  font-size: 13px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.dice-custom-row .dice-custom-roll {
  min-height: 34px;
  padding: 4px 14px;
  font-size: 13px;
  width: auto;
  border-radius: 7px;
  background: var(--accent);
  color: #fff8f0;
  font-weight: 700;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .play-area.sheet-open {
    grid-template-columns: 1fr;
  }

  .sheet-panel {
    width: 100%;
  }

  :root {
    --bubble-max: 88%;
  }
}

@media (max-width: 640px) {
  .llm-controls {
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .controls,
  .composer {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    width: 100%;
  }

  .ollama-host-row {
    max-width: 100%;
  }

  .field-row,
  .field-row.single-action {
    grid-template-columns: 1fr;
  }

  .chat {
    min-height: 320px;
    max-height: 52vh;
  }

  .message,
  .message.user,
  .message.assistant {
    max-width: 100%;
  }

  .message.assistant.streaming {
    width: 100%;
  }

  .message.thinking {
    width: 100%;
    max-width: 100%;
  }

  .archetype-grid {
    grid-template-columns: 1fr;
  }

  .character-modal-overlay {
    padding: 12px;
  }

  .character-modal {
    padding: 16px;
  }

  .sheet-stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-bar {
    gap: 6px;
  }

  .dice-quick-btns {
    gap: 4px;
  }

  .status-dock {
    right: 8px;
    bottom: 8px;
    padding: 5px 8px;
    gap: 8px;
  }

}

/* --- Character creation wizard (Phase 7.6.9–7.6.11) --- */
.wizard-step-indicator {
  font-size: 13px;
  margin: 0 0 12px;
  letter-spacing: 0.02em;
}

.character-wizard-host {
  display: grid;
  gap: 14px;
}

.character-wizard-panel {
  min-height: 120px;
}

.wizard-section-title {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--accent);
}

.wizard-hint {
  font-size: 14px;
  margin: 0 0 10px;
}

.wizard-points,
.wizard-swaps {
  margin: 0 0 12px;
  font-size: 15px;
}

.wizard-class-note {
  font-size: 13px;
  margin: 0 0 14px;
}

.wizard-stat-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.wizard-stat-row {
  display: grid;
  grid-template-columns: minmax(0, 56px) minmax(0, 48px) 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.wizard-stat-row--invalid {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.06);
}

.wizard-stat-label {
  font-weight: 700;
  font-size: 15px;
}

.wizard-stat-mod {
  font-size: 14px;
  text-align: center;
}

.wizard-stat-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.wizard-stat-val {
  min-width: 2ch;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}

.wizard-stat-btn {
  width: auto;
  min-width: 44px;
  min-height: 44px;
  font-size: 20px;
  line-height: 1;
  padding: 0;
}

button.wizard-stat-btn {
  width: auto;
}

.wizard-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.wizard-nav-row {
  display: flex;
  justify-content: flex-start;
}

.wizard-nav-back {
  min-height: 44px;
  padding: 0 18px;
}

.wizard-skill-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 720px) {
  .wizard-skill-columns {
    grid-template-columns: 1fr;
  }
}

.wizard-subtitle {
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.wizard-skill-preview {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.wizard-actions--inline {
  margin-top: 0.75rem;
  justify-content: flex-start;
  gap: 0.5rem;
}

.wizard-skill-rep-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wizard-skill-rep-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text);
}

.wizard-skill-rep-row:hover {
  filter: brightness(1.03);
}

.wizard-skill-row--inactive {
  opacity: 0.55;
  cursor: not-allowed;
}

.wizard-sum-hint {
  font-size: 0.85rem;
  margin: 0.25rem 0;
}

.sheet-identity-block {
  margin-top: 12px;
}

.sheet-identity-field {
  margin-bottom: 10px;
}

.sheet-identity-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.sheet-identity-text {
  margin: 0;
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.35;
}

.wizard-skill-list {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.wizard-skill-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.wizard-skill-row:hover:not(:disabled) {
  filter: brightness(1.03);
}

.wizard-skill-row--selected {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 2px rgba(200, 148, 74, 0.22);
  background: rgba(200, 148, 74, 0.1);
}

.wizard-skill-row--budget {
  cursor: default;
}

.wizard-skill-row--budget .wizard-skill-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.wizard-skill-name {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.wizard-skill-rank {
  font-size: 14px;
  color: var(--muted);
  flex-shrink: 0;
}

/* ↔ swap button */
.wizard-skill-swap-btn {
  background: none;
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 5px;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.wizard-skill-swap-btn:hover:not(:disabled) {
  color: var(--primary, #4f46e5);
  border-color: var(--primary, #4f46e5);
}
.wizard-skill-swap-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.wizard-skill-swap-btn--revert {
  color: var(--accent, #f59e0b);
  border-color: var(--accent, #f59e0b);
}
.wizard-skill-swap-btn--revert:hover {
  color: var(--accent-dark, #d97706);
  border-color: var(--accent-dark, #d97706);
}

/* Swapped row highlight */
.wizard-skill-row--swapped {
  border-left: 3px solid var(--accent, #f59e0b);
  padding-left: 6px;
}

/* Swap selection mode */
.wizard-skill-row--swapping {
  border-left: 3px solid var(--primary, #4f46e5);
  padding-left: 6px;
}
.wizard-skill-swap-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 4px 0;
}
.wizard-skill-swap-dropdown {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  padding: 4px 8px;
  border: 1px solid var(--border, #ccc);
  border-radius: 6px;
  background: var(--surface, #fff);
  color: var(--text, #111);
  cursor: pointer;
}

.wizard-center {
  text-align: center;
  padding: 24px 12px;
}

.wizard-loading {
  font-size: 16px;
  margin: 0 0 16px;
}

.wizard-error {
  color: var(--danger);
  font-size: 14px;
  margin: 0 0 12px;
}

.wizard-secret-hint {
  font-size: 14px;
  margin: 12px 0 0;
}

/* --- Phase 7.6.12: solo campaign death tombstone (modal — nie ukrywa #game-app) --- */
.campaign-death-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1200;
  color: #e6e1d8;
}

body.campaign-death-active .campaign-death-screen {
  display: block;
}

.campaign-death-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 6, 0.72);
  cursor: pointer;
}

.campaign-death-dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(540px, calc(100% - 32px));
  max-height: min(92vh, 900px);
  overflow-y: auto;
  padding: 0;
  background: linear-gradient(180deg, #0e0c0a 0%, #16120e 45%, #1a1510 100%);
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  border: 1px solid #3a342c;
}

.campaign-death-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #e6e1d8;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.campaign-death-close:hover {
  background: rgba(255, 255, 255, 0.14);
}

.campaign-death-card {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 22px;
  box-sizing: border-box;
}

.death-tomb-inner {
  text-align: center;
  padding: 20px 8px;
}

.death-cross {
  font-size: 2rem;
  color: #7a6f5e;
  margin-bottom: 8px;
}

.death-title {
  font-size: 1.1rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #a89880;
  margin: 0 0 12px;
  font-weight: 600;
}

.death-name {
  font-size: 1.55rem;
  font-weight: 700;
  margin: 0 0 8px;
  color: #f0ebe3;
}

.death-meta,
.death-reason {
  font-size: 0.95rem;
  color: #9a8f7e;
  margin: 0 0 6px;
  line-height: 1.45;
}

.death-epitaph {
  margin: 18px 0;
  padding: 14px 16px;
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.55;
  color: #d4cdc0;
  border-left: 3px solid #5c5346;
  background: rgba(255, 255, 255, 0.04);
  text-align: left;
}

.death-secret-block {
  text-align: left;
  margin: 16px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid #3a342c;
}

.death-secret-label {
  font-size: 0.8rem;
  color: #8a8070;
  margin-bottom: 6px;
}

.death-secret-text {
  margin: 0;
  font-size: 0.95rem;
  color: #c9c2b6;
}

.death-bonds-block {
  text-align: left;
  margin: 14px 0 20px;
}

.death-bonds-label {
  font-size: 0.85rem;
  color: #8a8070;
  margin-bottom: 6px;
}

.death-bonds-list {
  margin: 0;
  padding-left: 1.2em;
  color: #c9c2b6;
  font-size: 0.95rem;
}

.death-bond-meta {
  color: #7a7165;
  font-size: 0.85rem;
}

.death-new-campaign-btn {
  margin-top: 8px;
  min-height: 48px;
  padding: 12px 24px;
  width: auto;
  max-width: 100%;
}

.death-loading,
.death-error {
  text-align: center;
  padding: 24px;
}

/* --- Phase 7.6.13: /helpme OOC bubble --- */
.message.message-ooc-helpme {
  background: rgba(79, 152, 163, 0.12);
  border-left: 3px solid #4f98a3;
  border-radius: 10px;
}

.message.message-ooc-helpme .message-body pre {
  color: #4d4a45;
}

.ooc-helpme-label {
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  padding: 2px 12px 8px;
  letter-spacing: 0.02em;
}

.action-trigger-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.action-trigger-btn {
  background: var(--color-surface-2, #2a2a2a);
  border: 1px solid var(--color-border, #444);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 1.1em;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s;
}
.action-trigger-btn:hover {
  background: var(--color-surface-offset, #333);
}

.action-popup {
  position: fixed;
  top: 0;
  left: 0;
  transform: none;
  background: var(--panel, #fffdf8);
  border: 1px solid var(--border, #d6cfc0);
  border-radius: 12px;
  box-shadow: var(--shadow, 0 4px 16px rgba(80, 50, 20, 0.10));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  min-width: 220px;
  max-width: min(92vw, 360px);
  z-index: 1201;
}
.action-popup.hidden {
  display: none;
}

.action-popup-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.45);
  z-index: 1200;
}

.action-popup-backdrop.hidden {
  display: none;
}

.action-popup__btn {
  background: var(--panel-2, #f0ebe0);
  border: 1px solid var(--border, #d6cfc0);
  border-radius: 7px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  color: var(--text, #1a1410);
  font-size: 0.96em;
  transition: background 0.15s;
  white-space: nowrap;
}
.action-popup__btn:hover {
  background: rgba(200, 148, 74, 0.16);
}

/* ------------------------------------------------------------------ */
/* Inline status dots (Backend / Ollama) obok Logout w pasku Settings  */
/* ------------------------------------------------------------------ */
.status-inline {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  height: 28px;
}

.status-inline .status-dot-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-inline .status-dot {
  width: 9px;
  height: 9px;
}

/* ------------------------------------------------------------------ */
/* Pasek nad czatem z przyciskiem "archiwum"                           */
/* ------------------------------------------------------------------ */
.chat-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 6px;
}

.archive-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(80, 50, 20, 0.08);
  transition: background 0.15s, border-color 0.15s;
}

.archive-toggle-btn:hover {
  background: rgba(200, 148, 74, 0.10);
}

.archive-toggle-btn[aria-pressed="true"] {
  background: rgba(200, 148, 74, 0.18);
  border-color: var(--accent-light);
}

.archive-toggle-btn[data-count="0"] {
  opacity: 0.55;
  cursor: default;
}

.archive-toggle-icon {
  font-size: 13px;
  line-height: 1;
}

.archive-toggle-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.archive-toggle-btn[aria-pressed="true"] .archive-toggle-count {
  background: rgba(124, 79, 30, 0.12);
  color: var(--accent);
  border-color: var(--accent-light);
}

/* ------------------------------------------------------------------ */
/* Ukrywanie "archiwalnych" dymków (OOC, /mem, system, error,          */
/* separator "wracamy do gry") gdy archive-hidden jest aktywne.        */
/* ------------------------------------------------------------------ */
#chat.archive-hidden .is-archived-bubble,
#chat.archive-hidden .chat-back-in-game {
  display: none !important;
}
