:root {
  --bg:           #0d0e10;
  --surface:      #17181c;
  --surface-2:    #1f2024;
  --user-bubble:  #2a2c33;
  --border:       #2a2c33;
  --border-soft:  #23252a;
  --text:         #ececec;
  --text-muted:   #8a8d95;
  --gold:         #d4af6a;
  --gold-soft:    #e9d49a;
  --gold-dim:     #8a6e30;
  --gold-faint:   rgba(212, 175, 106, 0.18);
  --danger:       #c98a8a;

  /* Item type accent colors */
  --type-boss:        #c14d4d;
  --type-weapon:      #b88b3c;
  --type-armor:       #6b8e9e;
  --type-food:        #7ba35a;
  --type-mead:        #a06bc4;
  --type-magic:       #c47fb8;
  --type-trophy:      #c9a05a;
  --type-resource:    #8a7355;
  --type-misc:        #888888;
  --type-workstation: #5a8aa5;
  --type-biome:       #4a7a4a;
  --type-enemy:       #944a3a;
  --max-col:      720px;
  --composer-h:   88px;
  --topbar-h:     56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Frank Ruhl Libre", "Georgia", serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

html, body { height: 100%; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; }

/* ============ topbar ============ */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
  /* topbar layout is positional (logo + icons), not textual — use LTR
     so HTML order maps directly to visual left → center → right. */
  direction: ltr;
}

.topbar-left  { justify-self: start; min-width: 0; }
.topbar-right { justify-self: end; display: inline-flex; align-items: center; gap: 4px; }

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: "Cinzel", serif;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.12em;
  color: var(--gold);
  user-select: none;
  white-space: nowrap;
}

.wordmark-rune {
  font-family: "Cinzel", serif;
  font-size: 18px;
  color: var(--gold-soft);
  opacity: 0.9;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover {
  color: var(--gold-soft);
  background: var(--surface);
  border-color: var(--border);
}
.icon-btn:active { transform: scale(0.96); }

/* ============ brain toggle (top-left pills) ============ */
.brain-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.brain-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.04em;
  line-height: 1;
  min-height: 28px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.brain-btn .brain-name {
  font-family: "Cinzel", serif;
  font-weight: 600;
}
.brain-btn .brain-status {
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.brain-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--gold-dim);
}
.brain-btn.available { color: var(--text); }
.brain-btn.available .brain-status { color: #7fc97f; }
.brain-btn.unavailable {
  opacity: 0.45;
  cursor: not-allowed;
}
.brain-btn.unavailable .brain-status { color: var(--danger); }
.brain-btn.selected {
  color: var(--gold-soft);
  border-color: var(--gold);
  background: rgba(212, 175, 106, 0.08);
}
.brain-btn.selected .brain-status { color: var(--gold-soft); }

/* ============ conversation column ============ */
.conversation {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.conversation::-webkit-scrollbar { width: 8px; }
.conversation::-webkit-scrollbar-track { background: transparent; }
.conversation::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.conversation::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }

.conversation-inner {
  max-width: var(--max-col);
  margin: 0 auto;
  padding: 28px 20px calc(var(--composer-h) + 150px);
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100%;
}

.chat-empty {
  margin: auto 0;
  align-self: center;
  font-size: 18px;
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0.02em;
  padding: 60px 12px;
  text-align: center;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---- message entries ---- */
.chat-entry {
  display: flex;
  width: 100%;
  animation: msg-rise 0.35s ease-out;
}

@keyframes msg-rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* User: dark gray bubble, hugs the start (right in RTL) */
.chat-entry.user {
  justify-content: flex-start;
}
.chat-entry.user .chat-bubble {
  max-width: 75%;
  padding: 10px 14px;
  background: var(--user-bubble);
  color: var(--text);
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  user-select: text;
}

/* Oracle: no bubble, gold-tinted text */
.chat-entry.oracle {
  flex-direction: column;
  align-items: stretch;
}
.chat-entry.oracle .chat-bubble {
  background: none;
  padding: 0;
  color: var(--gold-soft);
  font-family: "Frank Ruhl Libre", serif;
  font-weight: 500;
  font-size: 18px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  user-select: text;
}
.chat-entry.oracle.error .chat-bubble { color: var(--danger); }

/* ---- per-message entity image strip ---- */
.image-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  direction: rtl;
}

.image-thumb {
  width: 100px;
  height: 100px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(212, 175, 106, 0.08), 0 2px 6px rgba(0,0,0,0.35);
}
.image-thumb:hover {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold-faint);
}
.image-thumb:active { transform: scale(0.96); }
.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---- image lightbox overlay ---- */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.88);
  animation: sheet-fade-in 0.18s ease-out;
  cursor: zoom-out;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.image-lightbox img {
  /* Force a true visual enlargement: the wiki sprites are 64×64, so without
     this they'd just sit at thumbnail size in the lightbox. Lock the SHORT
     edge to ~70% of the smaller viewport dimension and let aspect-ratio do
     the rest. image-rendering: crisp-edges keeps small pixel art readable
     instead of mushy on upscale. */
  width: min(70vw, 70dvh);
  height: auto;
  max-width: 92vw;
  max-height: 85dvh;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(212, 175, 106, 0.12), 0 12px 40px rgba(0,0,0,0.6);
}
.image-lightbox-caption {
  color: var(--gold-soft);
  font-size: 16px;
  letter-spacing: 0.02em;
  text-align: center;
  max-width: 85vw;
  direction: rtl;
  font-family: "Frank Ruhl Libre", serif;
}
.image-lightbox-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--gold-dim);
  color: var(--gold-soft);
  border-radius: 50%;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.image-lightbox-close:hover { background: rgba(0,0,0,0.75); border-color: var(--gold); }
.image-lightbox-close:active { transform: scale(0.94); }
.image-lightbox-close svg { display: block; }

/* ---- per-message audio player ---- */
.message-audio {
  display: block;
  width: 100%;
  margin-top: 10px;
  height: 38px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color-scheme: dark;
  filter: hue-rotate(15deg) sepia(0.1);
}

.audio-expired-note {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  opacity: 0.8;
}

/* ---- typing indicator (three pulsing dots) ---- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
}
.typing-indicator[hidden] { display: none; }
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold-soft);
  opacity: 0.35;
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-3px); }
}

/* ============ composer (fixed at bottom) ============ */
/* ============ action bar (mobile-friendly toolbar above composer) ============ */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  /* sits above the fixed composer with a breathing gap */
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 14;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 6px;
  padding: 6px 12px;
  pointer-events: none;
}
.action-btn {
  pointer-events: auto;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 54px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 14px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.action-btn svg { width: 19px; height: 19px; }
.action-btn .action-label {
  font-family: "Frank Ruhl Libre", serif;
  font-size: 10px;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
}
.action-btn:hover {
  color: var(--gold-soft);
  border-color: var(--gold-dim);
  background: var(--surface-2);
}
.action-btn:active { transform: scale(0.94); }
.action-btn[hidden] { display: none; }
.action-btn.length-btn .action-label { color: var(--gold-soft); }

@media (max-width: 720px) {
  .action-bar { gap: 4px; padding: 5px 8px; }
  .action-btn { min-width: 0; flex: 1 1 0; padding: 6px 4px; }
  .action-btn .action-label { font-size: 9px; }
}

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(13,14,16,0) 0%, var(--bg) 30%);
  pointer-events: none;
}

.composer-inner {
  max-width: var(--max-col);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 6px 6px 6px 6px;
  transition: border-color 0.18s, box-shadow 0.18s;
  pointer-events: auto;
}

.composer-inner:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold-faint);
}

#askInput {
  flex: 1;
  min-height: 36px;
  max-height: 144px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  direction: rtl;
  user-select: text;
  overflow-y: auto;
}

#askInput::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

#askInput:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--gold);
  color: #1a1408;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.send-btn svg { display: block; }

.send-btn:hover:not(:disabled) { filter: brightness(1.1); }
.send-btn:active:not(:disabled) { transform: scale(0.94); }

.send-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.composer-status {
  max-width: var(--max-col);
  margin: 0 auto 6px;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.02em;
  min-height: 14px;
  pointer-events: none;
}

.composer-status:empty { visibility: hidden; min-height: 0; }

/* ============ archive banner (read-only mode) ============ */
.archive-banner {
  flex: 0 0 auto;
  position: sticky;
  top: var(--topbar-h);
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(212, 175, 106, 0.08);
  border-bottom: 1px solid var(--gold-dim);
  color: var(--gold-soft);
  font-size: 13px;
  letter-spacing: 0.02em;
  direction: rtl;
}
.archive-banner[hidden] { display: none; }
.archive-banner-label {
  flex: 1;
  text-align: center;
  font-style: italic;
  opacity: 0.9;
}
.archive-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--gold-soft);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  min-height: 32px;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.archive-back:hover { background: var(--gold-faint); border-color: var(--gold); }
.archive-back svg { transform: scaleX(-1); }

/* ============ bottom-sheet / modal ============ */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  direction: rtl;
}
.sheet[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: sheet-fade-in 0.18s ease-out;
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: min(82dvh, 720px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
  animation: sheet-rise 0.22s cubic-bezier(0.2, 0.7, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}

@keyframes sheet-fade-in {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes sheet-rise {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.sheet-handle {
  width: 44px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 8px auto 0;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border-soft);
}
.sheet-head h2 {
  margin: 0;
  font-family: "Cinzel", serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--gold-soft);
}
.sheet-close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sheet-close:hover { color: var(--gold-soft); background: var(--surface-2); }

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 8px 16px;
  -webkit-overflow-scrolling: touch;
}
.sheet-body::-webkit-scrollbar { width: 8px; }
.sheet-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sheet-loading, .sheet-empty, .sheet-error {
  padding: 28px 14px;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  font-size: 14px;
}
.sheet-error { color: var(--danger); font-style: normal; }

/* ---- voice rows ---- */
.voice-group-label {
  padding: 10px 12px 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  font-family: "Cinzel", serif;
}

.voice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: start;
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.voice-row:hover { background: var(--surface-2); }
.voice-row.selected {
  background: var(--gold-faint);
  border-color: var(--gold-dim);
}

.voice-name {
  flex: 1;
  font-size: 15px;
  color: var(--gold-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.voice-tags {
  display: inline-flex;
  gap: 4px;
  flex-shrink: 0;
}
.voice-tag {
  font-size: 10px;
  letter-spacing: 0.05em;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-family: "Cinzel", serif;
}
.voice-tag.lang-he { color: var(--gold); border-color: var(--gold-dim); }
.voice-tag.lang-en { color: #9bb7d4; border-color: #3a4a5c; }
.voice-tag.voice-tag-google      { color: #8fd1a4; border-color: #355a44; }
.voice-tag.voice-tag-elevenlabs  { color: #c9b0d8; border-color: #4a3b58; }

.voice-info-note {
  padding: 6px 12px 10px;
  font-size: 12px;
  color: var(--text-muted);
  direction: rtl;
  line-height: 1.5;
}

.voice-check {
  width: 22px;
  flex-shrink: 0;
  color: var(--gold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---- archive rows ---- */
.archive-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 6px 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  direction: rtl;
}
.archive-row:hover { background: var(--surface-2); }

.archive-row-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: start;
  padding: 4px 6px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.archive-preview {
  font-size: 15px;
  color: var(--gold-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.archive-meta {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  display: inline-flex;
  gap: 8px;
}
.archive-delete {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.archive-delete:hover { color: var(--danger); background: var(--surface-2); }

/* ============ profile sheet ============ */
.profile-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 8px 4px 12px;
  direction: rtl;
}

.profile-intro {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border-soft);
}

.profile-field {
  margin: 0;
  padding: 0;
  border: none;
}

.profile-field legend,
.profile-label {
  display: block;
  font-size: 13px;
  color: var(--gold-soft);
  font-family: "Cinzel", serif;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
  padding: 0;
}

.profile-radios {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.profile-radios label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.profile-radios label:hover { background: var(--surface); }
.profile-radios input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--gold-dim);
  border-radius: 50%;
  margin: 0;
  flex-shrink: 0;
  position: relative;
  background: var(--bg);
  cursor: pointer;
}
.profile-radios input[type="radio"]:checked {
  border-color: var(--gold);
}
.profile-radios input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--gold);
}
.profile-radios label:has(input:checked) {
  border-color: var(--gold);
  background: var(--gold-faint);
  color: var(--gold-soft);
}

.profile-text input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  direction: rtl;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.profile-text input::placeholder { color: var(--text-muted); opacity: 0.7; }
.profile-text input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold-faint);
}

.profile-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--gold-dim);
  border-radius: 10px;
  cursor: pointer;
}
.profile-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--gold-dim);
  border-radius: 4px;
  margin: 2px 0 0;
  flex-shrink: 0;
  position: relative;
  background: var(--bg);
  cursor: pointer;
}
.profile-toggle input[type="checkbox"]:checked {
  background: var(--gold);
  border-color: var(--gold);
}
.profile-toggle input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 6px;
  height: 12px;
  border: solid #1a1408;
  border-width: 0 2.4px 2.4px 0;
  transform: rotate(45deg);
}
.profile-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
}
.profile-toggle-text strong { color: var(--gold-soft); font-weight: 600; }
.profile-toggle-text small { color: var(--text-muted); font-size: 12px; }

.profile-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.profile-btn {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.profile-btn-primary {
  background: var(--gold);
  color: #1a1408;
  border: none;
  font-weight: 600;
}
.profile-btn-primary:hover { filter: brightness(1.1); }
.profile-btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.profile-btn-secondary:hover { color: var(--text); border-color: var(--gold-dim); }

@media (max-width: 380px) {
  .profile-radios { grid-template-columns: 1fr; }
}

/* ============ responsive ============ */
@media (max-width: 640px) {
  :root { --composer-h: 84px; --topbar-h: 56px; }

  .topbar { padding: 0 8px; }
  .wordmark { font-size: 14px; letter-spacing: 0.1em; gap: 6px; }
  .wordmark-rune { font-size: 16px; }

  .icon-btn { width: 44px; height: 44px; }
  .topbar-right { gap: 2px; }

  .brain-btn { padding: 7px 10px; font-size: 11px; min-height: 36px; }

  .sheet-panel { max-height: 88dvh; }
  .archive-banner { padding: 8px 10px; font-size: 12px; }
  .archive-banner-label { font-size: 12px; }

  .conversation-inner {
    padding: 20px 14px calc(var(--composer-h) + 150px);
    gap: 20px;
  }

  .chat-entry.user .chat-bubble { font-size: 15px; max-width: 82%; }
  .chat-entry.oracle .chat-bubble { font-size: 17px; line-height: 1.65; }

  .composer { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer-inner { gap: 6px; padding: 6px; }
  #askInput { font-size: 16px; padding: 11px 10px; min-height: 44px; }
  .send-btn { width: 44px; height: 44px; }

  .chat-empty { font-size: 16px; padding: 40px 8px; }
}

@media (max-width: 380px) {
  .wordmark-text { font-size: 13px; }
  .brain-btn .brain-name { font-size: 11px; }
}

/* ============================================================
 * ITEMS CODEX PANEL
 * ============================================================ */

/* topbar-left now hosts both codex toggle and brain-toggle */
.topbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---- Side panel ---- */
.codex-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 380px;
  z-index: 40;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.18s ease-out;
  padding-top: env(safe-area-inset-top);
}

.codex-panel[aria-hidden="false"] {
  transform: translateX(0);
}

/* Mobile: full-width overlay */
@media (max-width: 900px) {
  .codex-panel {
    width: 100%;
    border-right: none;
  }
}

/* Desktop (> 900px): shift main content to make room */
@media (min-width: 901px) {
  .topbar,
  .archive-banner,
  .conversation {
    transition: margin-left 0.18s ease-out;
  }
  .composer {
    transition: left 0.18s ease-out;
  }
  body.codex-open .topbar,
  body.codex-open .archive-banner,
  body.codex-open .conversation {
    margin-left: 380px;
  }
  body.codex-open .composer {
    left: 380px;
  }
}

/* ---- Panel inner wrapper ---- */
.codex-inner {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- Sticky header (shared by list + detail views) ---- */
.codex-header {
  flex: 0 0 auto;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  direction: rtl;
}

.codex-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.codex-detail-header .codex-title-row {
  margin-bottom: 0;
}

.codex-title {
  margin: 0;
  font-family: "Cinzel", serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--gold-soft);
  letter-spacing: 0.08em;
}

.codex-close-x {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, background 0.15s;
}
.codex-close-x:hover { color: var(--gold-soft); background: var(--surface-2); }

.codex-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  min-height: 36px;
  direction: ltr;
  transition: color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.codex-back-btn:hover { color: var(--gold-soft); border-color: var(--gold-dim); }

/* ---- Search input ---- */
.codex-search {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  direction: rtl;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.codex-search::placeholder { color: var(--text-muted); opacity: 0.7; }
.codex-search:focus { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold-faint); }
.codex-search::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ---- Item list ---- */
.codex-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 6px 8px calc(16px + env(safe-area-inset-bottom));
}
.codex-list::-webkit-scrollbar { width: 6px; }
.codex-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- Item row ---- */
.codex-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: start;
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.codex-item-row:hover { background: var(--surface-2); }
.codex-item-row:active { transform: scale(0.98); }

/* ---- Thumbnail image / rune placeholder ---- */
.codex-item-img {
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--surface-2);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.codex-item-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 14px;
}

/* ---- Item name ---- */
.codex-item-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
  min-width: 0;
}

/* ---- Type badges ---- */
.codex-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: "Cinzel", serif;
}

.codex-badge-boss        { background: var(--type-boss);        color: #f0ede8; border-color: transparent; }
.codex-badge-trophy      { background: var(--type-trophy);      color: #f0ede8; border-color: transparent; }
.codex-badge-weapon      { background: var(--type-weapon);      color: #f0ede8; border-color: transparent; }
.codex-badge-armor       { background: var(--type-armor);       color: #f0ede8; border-color: transparent; }
.codex-badge-food        { background: var(--type-food);        color: #f0ede8; border-color: transparent; }
.codex-badge-mead        { background: var(--type-mead);        color: #f0ede8; border-color: transparent; }
.codex-badge-magic       { background: var(--type-magic);       color: #f0ede8; border-color: transparent; }
.codex-badge-resource    { background: var(--type-resource);    color: #f0ede8; border-color: transparent; }
.codex-badge-misc        { background: var(--type-misc);        color: #f0ede8; border-color: transparent; }
.codex-badge-workstation { background: var(--type-workstation); color: #f0ede8; border-color: transparent; }
.codex-badge-biome       { background: var(--type-biome);       color: #f0ede8; border-color: transparent; }
.codex-badge-enemy       { background: var(--type-enemy);       color: #f0ede8; border-color: transparent; }

/* ---- Loading / empty ---- */
.codex-loading-msg,
.codex-empty {
  padding: 40px 14px;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  font-size: 14px;
}

/* ---- Detail scrollable body ---- */
.codex-detail-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  direction: rtl;
}
.codex-detail-body::-webkit-scrollbar { width: 6px; }
.codex-detail-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- Detail: image block ---- */
.codex-detail-img-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.codex-detail-img-wrap .codex-item-img {
  border-radius: 12px;
  border: 1px solid var(--gold-dim);
}
.codex-detail-img-wrap .codex-item-placeholder {
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 30px;
}

/* ---- Detail: name ---- */
.codex-detail-name {
  margin: 6px 0 4px;
  font-family: "Frank Ruhl Libre", serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--gold-soft);
  line-height: 1.4;
  text-align: center;
}

/* ---- Detail: badge row ---- */
.codex-detail-badge-row {
  display: flex;
  justify-content: center;
  margin: 4px 0 10px;
}

/* ---- Detail: notes ---- */
.codex-detail-notes {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border-soft);
}

/* ---- Recipe / reverse sections ---- */
.codex-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.codex-section-heading {
  font-family: "Cinzel", serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.codex-recipe-station {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.5;
}

.codex-link {
  background: transparent;
  border: none;
  color: var(--gold-soft);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 0 2px;
  text-decoration: underline;
  text-decoration-color: var(--gold-dim);
  text-underline-offset: 2px;
  -webkit-tap-highlight-color: transparent;
}
.codex-link:hover { color: var(--gold); }

/* ---- Materials list ---- */
.codex-materials-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.codex-material-row { display: block; }

.codex-material-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  width: 100%;
  text-align: start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.codex-material-btn:hover { background: var(--bg); border-color: var(--gold-dim); }
.codex-material-btn:active { transform: scale(0.98); }

.codex-mat-qty {
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  direction: ltr;
}

.codex-mat-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.codex-mat-arrow {
  color: var(--gold-dim);
  font-size: 12px;
  flex-shrink: 0;
  direction: ltr;
}

/* ---- No-recipe note ---- */
.codex-no-recipe {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
}

/* ---- Row type left-border accent ---- */
.codex-item-row {
  border-left: 4px solid var(--row-type-color, transparent);
}

/* ---- English name subtitle in detail ---- */
.codex-detail-en-name {
  text-align: center;
  font-size: 13px;
  color: var(--gold-dim);
  font-style: italic;
  margin: 0 0 6px;
  letter-spacing: 0.03em;
}

/* ---- Type color stripe under badge in detail ---- */
.codex-detail-type-stripe {
  height: 3px;
  border-radius: 2px;
  margin: 6px 0 12px;
  opacity: 0.65;
}

/* ---- Sort / filter toolbar ---- */
.codex-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  direction: rtl;
}

.codex-sort-select {
  flex: 1;
  min-height: 30px;
  padding: 4px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  direction: rtl;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.codex-sort-select:focus { border-color: var(--gold-dim); }

.codex-dir-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, border-color 0.15s;
}
.codex-dir-btn:hover { color: var(--gold-soft); border-color: var(--gold-dim); }

/* ---- Group heading (type mode) ---- */
.codex-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px 5px;
  margin-top: 6px;
  font-family: "Cinzel", serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  cursor: pointer;
  user-select: none;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.codex-group-heading:hover { background: var(--surface-2); }

.codex-group-chevron {
  font-size: 9px;
  opacity: 0.6;
  flex-shrink: 0;
}

/* ---- Search highlight ---- */
mark.codex-highlight {
  background: rgba(212, 175, 106, 0.28);
  color: var(--gold-soft);
  border-radius: 2px;
  padding: 0 1px;
}

/* ---- Unknown material (entity not in kg) ---- */
.codex-material-btn-unknown { cursor: default !important; }
.codex-material-btn-unknown:hover {
  background: var(--surface-2) !important;
  border-color: var(--border) !important;
}
.codex-mat-name-en {
  font-style: italic;
  color: var(--text-muted) !important;
}

/* ---- Overflow safety ---- */
.codex-item-name,
.codex-detail-name { overflow-wrap: anywhere; }

/* ---- Mobile responsive ---- */
@media (max-width: 640px) {
  .codex-item-row { min-height: 56px; }
  .codex-detail-name { font-size: 16px; }
}

/* ============================================================
 * CODEX v2 — new styles
 * ============================================================ */

/* ---- Section fade-in animation ---- */
@keyframes codex-fadein {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}
.codex-section { animation: codex-fadein 150ms ease both; }

/* ---- Breadcrumb ---- */
.codex-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 12px 2px;
  font-size: 11px;
  color: var(--text-muted);
  direction: rtl;
  overflow: hidden;
}
.codex-crumb-btn {
  background: transparent;
  border: none;
  color: var(--gold-dim);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  min-height: 24px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.12s;
}
.codex-crumb-btn:hover { color: var(--gold-soft); }
.codex-crumb-sep { color: var(--text-muted); font-size: 10px; opacity: 0.5; }
.codex-crumb-current { color: var(--text-muted); padding: 2px 4px; font-size: 11px; }
.codex-crumb-ellipsis { color: var(--text-muted); font-size: 11px; padding: 2px 4px; }

/* ---- Detail name row (name + star + share) ---- */
.codex-detail-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.codex-detail-name-row .codex-detail-name { margin: 0; flex: 1 1 auto; min-width: 0; }

/* ---- Star (favorite) button ---- */
.codex-star-btn {
  flex-shrink: 0;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}
.codex-star-btn:hover { color: var(--gold-soft); border-color: var(--gold-dim); }
.codex-star-btn.active { color: var(--gold); border-color: var(--gold-dim); }

/* ---- Share button ---- */
.codex-share-btn {
  flex-shrink: 0;
  min-height: 32px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.codex-share-btn:hover { color: var(--gold-soft); border-color: var(--gold-dim); }
.codex-share-btn.copied { color: var(--gold); border-color: var(--gold); background: var(--gold-faint); }

/* ---- Star in list row ---- */
.codex-row-star {
  color: var(--gold);
  font-size: 12px;
  flex-shrink: 0;
  line-height: 1;
}

/* ---- Favorites filter chip row ---- */
.codex-chip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.codex-filter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.codex-filter-chip:hover { color: var(--gold-soft); border-color: var(--gold-dim); }
.codex-filter-chip.active { color: var(--gold); border-color: var(--gold); background: var(--gold-faint); }

/* ---- Jump button (inherits codex-dir-btn) ---- */
.codex-jump-btn { font-size: 16px; }

/* ---- Jump dropdown menu ---- */
.codex-jump-menu {
  position: absolute;
  top: auto;
  left: 8px;
  right: 8px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  animation: codex-fadein 120ms ease both;
  max-height: 40vh;
  overflow-y: auto;
}
.codex-jump-option {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  direction: rtl;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.codex-jump-option:hover { background: var(--surface-2); }

/* ---- Back-to-list button (piggybacks codex-back-btn) ---- */
.codex-list-btn { opacity: 0.7; }
.codex-list-btn:hover { opacity: 1; }

/* ---- Meta section (tier / biome / patch) ---- */
.codex-meta-section {
  padding-top: 10px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.codex-tier-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.codex-tier-bar {
  display: inline-block;
  width: 4px;
  height: 16px;
  border-radius: 2px;
  flex-shrink: 0;
}
.codex-tier-label {
  font-family: "Cinzel", serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.codex-meta-row {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.codex-meta-muted { font-size: 11px; opacity: 0.65; }

/* ---- Stats grid ---- */
.codex-stats-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
}
.codex-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
  padding: 5px 8px;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 12px;
}
.codex-stat-label {
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
}
.codex-stat-value {
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  direction: ltr;
}

/* ---- Upgrades list ---- */
.codex-upgrades-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.codex-upgrade-item {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  line-height: 1.5;
  direction: ltr;
}

/* ---- Mobile additions ---- */
@media (max-width: 640px) {
  .codex-stats-grid { grid-template-columns: 1fr; }
  .codex-detail-name-row { gap: 4px; }
  .codex-jump-menu { max-height: 50vh; }
}

/* Original English in-game name on material/drop/used-in rows.
   RTL row: qty + Hebrew name on the right, English label on the left. */
.codex-mat-en {
  margin-inline-start: auto;
  padding-inline-start: 8px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 11px;
  font-style: italic;
  opacity: 0.55;
  color: var(--text-muted, #b8a87a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
  letter-spacing: 0.02em;
  direction: ltr;
  unicode-bidi: isolate;
}
.codex-material-btn:hover .codex-mat-en { opacity: 0.8; }

/* ---------- Chat bubble entity links ---------- */
.entity-link {
  color: #5db4ff;
  text-decoration: underline;
  text-decoration-color: rgba(93, 180, 255, 0.5);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  cursor: pointer;
  font-weight: 500;
  border-radius: 3px;
  padding: 0 2px;
  margin: 0 1px;
  transition: color 120ms ease, background 120ms ease, text-decoration-color 120ms ease;
  -webkit-tap-highlight-color: rgba(93, 180, 255, 0.25);
}
.entity-link:hover,
.entity-link:focus {
  color: #8cc9ff;
  text-decoration-color: #8cc9ff;
  background: rgba(93, 180, 255, 0.10);
  outline: none;
}
.entity-link:active { color: #b5dbff; }
.entity-link-hinted {
  /* Server hinted that this entity is one of the answer's main subjects.
     Render it a touch warmer so important entities stand out. */
  color: #7dc7ff;
  text-decoration-color: rgba(125, 199, 255, 0.7);
}

/* ============ Build Card (ToME visual build output) ============ */
.build-intro-text {
  font-size: 14px !important;
  color: var(--text-muted) !important;
  line-height: 1.4 !important;
}

.build-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  direction: rtl;
  text-align: right;
}

.build-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.build-entity-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px 5px 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.build-entity-chip-class {
  border-color: var(--gold-dim);
  color: var(--gold-soft);
}

.build-entity-chip-race {
  border-color: #5a8aa5;
  color: #7eb0c8;
}

.build-entity-img {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
  image-rendering: pixelated;
}

.build-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.build-badge-diff {
  background: rgba(212, 175, 106, 0.10);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
}

.build-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.build-section-heading {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--gold-dim);
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-soft);
}

.build-stats-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.build-stat-chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 13px;
  color: var(--text-muted);
}

.build-stat-chip.primary {
  border-color: var(--gold-dim);
  color: var(--gold-soft);
  background: rgba(212, 175, 106, 0.08);
}

.build-talents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
}

.build-talent-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 8px 4px 6px;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}

.build-talent-tile:hover {
  border-color: var(--gold-dim);
  background: rgba(212, 175, 106, 0.04);
}

.build-talent-tile:active { transform: scale(0.96); }

.build-talent-tile.priority-max {
  border-color: var(--gold-dim);
  background: rgba(212, 175, 106, 0.07);
}

.build-talent-tile.priority-high {
  border-color: #4a7a9b;
  background: rgba(74, 122, 155, 0.07);
}

.build-talent-icon {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}

.build-talent-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.build-small-placeholder {
  width: 40px !important;
  height: 40px !important;
  font-size: 9px;
}

.build-talent-caption {
  font-size: 9px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
  max-width: 68px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
}

.build-priority-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  background: var(--gold-dim);
  color: #0d0e10;
  font-size: 7px;
  font-weight: 800;
  padding: 1px 3px;
  border-radius: 3px;
  letter-spacing: 0.06em;
}

.build-icons-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.build-small-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 52px;
  max-width: 72px;
}

.build-small-icon {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  image-rendering: pixelated;
  border: 1px solid var(--border);
  display: block;
}

.build-playstyle {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  padding-top: 6px;
  border-top: 1px solid var(--border-soft);
  font-style: italic;
  direction: rtl;
}

/* Talent tree view (requires talent_trees.json data) */
.build-tree-section {
  margin-bottom: 8px;
}

.build-tree-name {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  direction: ltr;
  text-align: left;
}

.build-tree-tiles {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.build-tree-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px 4px;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  position: relative;
  cursor: pointer;
  min-width: 54px;
  max-width: 66px;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.build-tree-tile.recommended {
  border-color: var(--gold-dim);
  background: rgba(212, 175, 106, 0.06);
}

.build-tree-tile.context-only {
  opacity: 0.45;
}

.build-tree-tile:hover { opacity: 1; border-color: var(--gold-dim); }

.build-tree-level-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 7px;
  color: var(--text-muted);
  letter-spacing: 0;
}

.build-tree-icon {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}

.build-tree-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
}

.build-tree-points-badge {
  font-size: 8px;
  color: var(--gold-soft);
  font-weight: 600;
  letter-spacing: 0;
}

.build-tree-connector {
  font-size: 14px;
  color: var(--border);
  user-select: none;
  flex-shrink: 0;
}

.build-tree-connector::before { content: '→'; }

/* profile-select: reuse profile form styling for the build sheet select */
.profile-select {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  appearance: none;
  cursor: pointer;
}

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

/* ---- build sheet DLC toggles ---- */
.build-dlc-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  margin-bottom: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.dlc-toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.dlc-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg, rgba(0,0,0,0.2));
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, opacity 0.15s;
}
.dlc-toggle input { accent-color: var(--gold-dim); cursor: pointer; }
.dlc-toggle:has(input:not(:checked)) { opacity: 0.5; }
.dlc-toggle:has(input:checked) { border-color: var(--gold-dim); }

/* ---- ToME codex detail info ---- */
.codex-tome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.codex-tome-chip {
  display: inline-block;
  padding: 3px 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--gold-dim, #c9a05a);
  white-space: nowrap;
}
.codex-tome-text .codex-section-heading,
.codex-tome-list .codex-section-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-dim, #c9a05a);
  margin-bottom: 4px;
}
.codex-tome-para {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}
.codex-tome-ul {
  margin: 0;
  padding-inline-start: 18px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
}
.codex-tome-ul li { margin-bottom: 3px; }
.codex-tome-text, .codex-tome-list, .codex-tome-chips {
  margin-bottom: 12px;
}

/* ---- answer-length toggle button ---- */
.length-btn {
  width: auto;
  min-width: 40px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
}
.length-label {
  color: var(--text);
}
.length-btn.is-long .length-label {
  color: var(--gold-dim, #c9a05a);
}
.length-btn.is-long {
  border-color: var(--gold-dim, #c9a05a);
}

/* ---- Word-for-word talent tooltip (in-game text) ---- */
.talent-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: min(360px, 92vw);
  background: linear-gradient(180deg, rgba(24,21,15,0.98), rgba(16,14,10,0.98));
  border: 1px solid rgba(196, 160, 90, 0.5);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 12px 34px rgba(0,0,0,0.65);
  color: #ece3cf;
  font-size: 13.5px;
  line-height: 1.55;
  pointer-events: none;
  backdrop-filter: blur(3px);
  text-align: start;
}
.talent-tooltip .tt-name {
  font-weight: 700;
  font-size: 15px;
  color: #f3cd7a;
  margin-bottom: 7px;
  letter-spacing: 0.2px;
}
.talent-tooltip .tt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 9px;
}
.talent-tooltip .tt-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #d8cdb0;
  background: rgba(196,160,90,0.13);
  border: 1px solid rgba(196,160,90,0.28);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.talent-tooltip .tt-chip-mode {
  color: #1a160e;
  background: #d8b86a;
  border-color: #d8b86a;
  font-weight: 600;
  text-transform: capitalize;
}
.talent-tooltip .tt-desc { color: #e6dcc4; }
.talent-tooltip .tt-desc p {
  margin: 0 0 6px 0;
}
.talent-tooltip .tt-desc p:last-child { margin-bottom: 0; }
.talent-tooltip .tt-desc.tt-missing { color: #9b9078; font-style: italic; }
.talent-tooltip .tt-req {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(196,160,90,0.22);
  font-size: 11px;
  color: #a89a78;
  line-height: 1.6;
}
.talent-tooltip .tt-req-label { color: #d8b86a; font-weight: 600; }


/* ============ Leveling order (what to pump FIRST) ============ */
.build-leveling-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  direction: rtl;
}
.build-leveling-step {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 9px;
  background: rgba(35,28,18,.55);
  border: 1px solid rgba(120,95,55,.25);
  transition: background .15s ease;
}
.build-leveling-step:hover { background: rgba(55,44,26,.7); }
.build-leveling-num {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: linear-gradient(180deg, #c89a4a 0%, #9a7330 100%);
  color: #1a1208;
  font-weight: 800;
  font-size: 12px;
}
.build-leveling-icon {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border-radius: 6px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(140,111,62,.35);
}
.build-leveling-icon img { width: 100%; height: 100%; object-fit: cover; }
.build-leveling-icon.placeholder {
  font-size: 10px; font-weight: 700; color: #c8a866; letter-spacing: .5px;
}
.build-leveling-body { flex: 1 1 auto; min-width: 0; text-align: right; }
.build-leveling-name {
  font-size: 13px; font-weight: 700; color: #e8ddc8;
  display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
  flex-direction: row-reverse; justify-content: flex-end;
}
.build-leveling-pts { font-size: 11.5px; font-weight: 700; color: #7fc97f; }
.build-leveling-meta { font-size: 11px; color: #b09a6a; margin-top: 1px; }

/* ============ Build combined panel (leveling on the side + final build) ============ */
.build-combined {
  display: flex;
  flex-direction: row-reverse;
  gap: 12px;
  align-items: flex-start;
}
.build-col { min-width: 0; }
.build-col-leveling {
  flex: 0 0 auto;
  width: 44%;
  max-width: 260px;
}
.build-col-final { flex: 1 1 auto; }
.build-col .build-section-heading {
  font-size: 12.5px;
  font-weight: 700;
  color: #f0c674;
  margin-bottom: 8px;
  direction: rtl;
  text-align: right;
}
/* On narrow phones, stack the two columns (leveling on top) */
@media (max-width: 560px) {
  .build-combined { flex-direction: column; }
  .build-col-leveling { width: 100%; max-width: none; }
}

/* ============ Talent pools (class vs generic) + locked trees ============ */
/* Container wrapping all trees of one kind. Pools stack vertically. */
.build-pool {
  direction: rtl;
  text-align: right;
}
.build-pool + .build-pool {
  margin-top: 12px;
}

/* Header band at the top of each pool */
.build-pool-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(120, 95, 55, 0.30);
  margin-bottom: 8px;
  direction: rtl;
}

/* Class pool = gold tint */
.build-pool-class .build-pool-band {
  background: linear-gradient(135deg, rgba(196, 160, 90, 0.18), rgba(35, 28, 18, 0.55));
  border-color: rgba(196, 160, 90, 0.45);
}
/* Generic pool = cool slate/blue tint */
.build-pool-generic .build-pool-band {
  background: linear-gradient(135deg, rgba(90, 138, 165, 0.20), rgba(24, 21, 15, 0.55));
  border-color: rgba(90, 138, 165, 0.45);
}

/* Pool name label (with emoji) */
.build-pool-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.build-pool-class .build-pool-label {
  color: #d8b86a;
}
.build-pool-generic .build-pool-label {
  color: #8fc0d8;
}

/* Small points pill on the other side of the band */
.build-pool-points {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(24, 21, 15, 0.55);
  border: 1px solid rgba(120, 95, 55, 0.30);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}
.build-pool-class .build-pool-points {
  color: #c8a866;
  border-color: rgba(196, 160, 90, 0.35);
}
.build-pool-generic .build-pool-points {
  color: #8fc0d8;
  border-color: rgba(90, 138, 165, 0.35);
}

/* Colored accent bar on the inline-start (RTL = right) of each tree row */
.build-tree-section.tree-kind-class {
  border-inline-start: 3px solid rgba(196, 160, 90, 0.65);
  padding-inline-start: 8px;
}
.build-tree-section.tree-kind-generic {
  border-inline-start: 3px solid rgba(90, 138, 165, 0.65);
  padding-inline-start: 8px;
}

/* Locked tree row: desaturated + dimmed */
.build-tree-section.tree-locked {
  filter: grayscale(0.5);
  opacity: 0.72;
}

/* Small inline "locked" chip appended to the tree name */
.build-tree-lock {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  color: #d8a05a;
  background: rgba(120, 70, 40, 0.22);
  border: 1px solid rgba(180, 110, 60, 0.30);
  border-radius: 999px;
  padding: 0 6px;
  margin-inline-start: 6px;
  letter-spacing: 0;
  vertical-align: middle;
}

/* Centered summary note under the talents */
.build-summary-note {
  font-size: 11.5px;
  color: #b09a6a;
  text-align: center;
  padding: 6px 0;
  margin-top: 6px;
  border-top: 1px solid rgba(120, 95, 55, 0.22);
  direction: rtl;
  line-height: 1.4;
}

/* Note line listing locked trees (amber/muted) */
.build-locked-note {
  font-size: 11px;
  color: #c79a55;
  text-align: right;
  padding: 4px 0;
  direction: rtl;
  line-height: 1.4;
}
