*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[x-cloak] { display: none !important; }

:root {
  --font-heading: 'Cinzel', Georgia, 'Times New Roman', serif;
  --font-body: 'Lato', system-ui, -apple-system, sans-serif;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --accent-cyan: #2aa198;
  --accent-magenta: #d33682;
  color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }

:root, [data-theme="light"] {
  --bg-page: #fdf6e3;
  --bg-gradient: radial-gradient(ellipse at 20% 50%, rgba(238,232,213,0.6) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 30%, rgba(253,246,227,0.5) 0%, transparent 50%);
  --bg-dark-card: #fefcf4;
  --bg-card: #eee8d5;
  --bg-input: #fefcf4;
  --bg-parchment: #fdf6e3;
  --bg-parchment-light: #eee8d5;
  --bg-highlight: #eee8d5;

  --text-main: #657b83;
  --text-light: #586e75;
  --text-muted: #93a1a1;
  --text-dark: #073642;
  --text-heading: #073642;

  --accent-gold: #b58900;
  --accent-red: #dc322f;
  --accent-green: #859900;
  --accent-blue: #268bd2;

  --border-light: #ddd6c2;
  --border-dark: #93a1a1;
  --border-parchment: #c4b69a;

  --color-error-bg: #fbe3e3;
  --color-error-border: #e3b3b3;
  --color-error-text: #b33;
  --color-btn-send: var(--accent-blue);
  --color-combat-enemy: #dc322f;
  --color-hp-mid: #b58900;
  --color-hp-low: #dc322f;
  --scroll-thumb: #c4b69a;
  --scroll-track: #eee8d5;
  --color-glow: rgba(181,137,0,0.5);
}

[data-theme="dark"] {
  --bg-page: #211a13;
  --bg-gradient: radial-gradient(ellipse at 20% 50%, rgba(60,40,25,0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 30%, rgba(50,35,20,0.3) 0%, transparent 50%);
  --bg-dark-card: #2c231a;
  --bg-card: #1a1510;
  --bg-input: #1a1510;
  --bg-parchment: #d1c4a9;
  --bg-parchment-light: #e0d5be;
  --bg-highlight: #f0e8d8;

  --text-main: #cdc5b8;
  --text-light: #b8a99a;
  --text-muted: #8a8378;
  --text-dark: #312d2a;
  --text-heading: #d1c4a9;

  --accent-gold: #d1a360;
  --accent-red: #8c2b2b;
  --accent-green: #5b8133;
  --accent-blue: #4a7fb5;

  --border-light: #5c4a38;
  --border-dark: #4d3f38;
  --border-parchment: #c4b69a;

  --color-error-bg: #3a1a1a;
  --color-error-border: #6b2a2a;
  --color-error-text: #e88;
  --color-btn-send: var(--accent-gold);
  --color-combat-enemy: #8c2b2b;
  --color-hp-mid: #b58900;
  --color-hp-low: #dc322f;
  --scroll-thumb: #5c4a38;
  --scroll-track: #1a1510;
  --color-glow: rgba(209,163,96,0.5);
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--scroll-track); }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }

body {
  font-family: var(--font-body);
  background: var(--bg-page);
  background-image: var(--bg-gradient);
  color: var(--text-light);
  line-height: 1.5; letter-spacing: .01em;
}

main {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1rem;
}

a { color: var(--accent-gold); }
a:hover { color: var(--accent-cyan); }

/* ── JSON syntax highlight ────────────────────── */

.hl-key { color: var(--accent-blue); }
.hl-str { color: var(--accent-green); }
.hl-num { color: var(--accent-magenta); }
.hl-kw  { color: var(--accent-red); }

/* ── tabs ─────────────────────────────────────── */

.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-dark);
  margin-bottom: 1.5rem;
}

.tab-btn {
  padding: .6rem 1.4rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: .95rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: .15s;
}

.tab-btn:hover { color: var(--text-light); }
.tab-btn.active {
  color: var(--text-heading);
  font-weight: 600;
  border-bottom-color: var(--accent-gold);
}

/* ── tables ───────────────────────────────────── */

fieldset { border: 1px solid var(--border-light); padding: 1rem; margin-bottom: 1rem; }
legend { font-weight: 700; font-size: 1.05rem; padding: 0 .5rem; color: var(--text-heading); }

table { width: 100%; border-collapse: collapse; font-size: .8rem; margin-top: .5rem; }
th, td { border: 1px solid var(--border-light); padding: .3rem .5rem; text-align: left; }
th { background: var(--bg-dark-card); font-weight: 700; position: sticky; top: 0; color: var(--text-heading); word-break: keep-all; }
td { white-space: pre-wrap; word-break: break-word; }

/* ── copy-id cells ────────────────────────────── */

.copy-id {
  text-decoration: underline dotted var(--accent-gold) 1.5px;
  text-underline-offset: 3px;
  cursor: pointer;
}
.copy-id:hover {
  background: var(--bg-dark-card);
}

/* ── copied tooltip ───────────────────────────── */

.copy-feedback {
  position: fixed;
  pointer-events: none;
  background: var(--text-dark);
  color: var(--bg-parchment);
  padding: .2rem .5rem;
  border-radius: var(--radius-sm);
  font-size: .75rem;
  z-index: 9999;
  opacity: 0;
  transition: opacity .15s;
}
.copy-feedback.show { opacity: 1; }

/* ── sections ─────────────────────────────────── */

.section-title {
  font-weight: 700; margin-top: 1rem; padding: .3rem .5rem;
  background: var(--bg-dark-card); user-select: none;
}
.section-title .row-count { font-weight: 400; color: var(--text-muted); }

pre.result, pre.error {
  padding: .75rem; overflow-x: auto;
  font-size: .8rem; max-height: 400px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}
pre.result { background: var(--bg-dark-card); color: var(--text-light); }
pre.error { background: var(--color-error-bg); color: var(--color-error-text); }

#params { min-height: 250px; font-family: monospace; font-size: .8rem; }
#tool-result { margin-top: .5rem; }

/* ── page layout ───────────────────────────────── */

.page-layout {
  display: flex; flex-direction: column; height: 100vh; padding: .5rem 0 0;
}
.app-footer {
  flex: 0 0 auto; text-align: center; font-size: .7rem;
  color: var(--text-muted); padding: .2rem 0; user-select: none;
}

/* ── main layout ───────────────────────────────── */

.main-layout {
  display: flex; flex: 1; min-height: 0;
}
.main-layout__chat {
  flex: 0 0 auto; width: 400px; min-width: 260px; max-width: 70%; height: 100%;
}
.main-layout__chat .chat-container { height: 100%; }
.main-layout__chat .chat-messages { max-height: none; }
.main-layout__resizer {
  flex: 0 0 6px; cursor: col-resize; background: transparent;
  transition: background .15s;
}
.main-layout__resizer:hover,
.main-layout__resizer:active {
  background: var(--accent-gold);
}
.main-layout__sheet {
  flex: 1; min-width: 0; border: 1px solid var(--border-light); padding: 1rem;
  overflow-y: auto; margin: 0 0 1rem 1rem;
}

/* ── chat ─────────────────────────────────────── */

.chat-container {
  display: flex; flex-direction: column; height: 100%; padding-top: .25rem;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: .5rem; border: 1px solid var(--border-light);
  background: var(--bg-dark-card); margin-bottom: .5rem;
  font-family: system-ui, -apple-system, sans-serif;
}
.chat-msg { margin-bottom: .75rem; }
.chat-error {
  padding: .5rem; margin-bottom: .5rem; border-radius: var(--radius-sm);
  background: var(--color-error-bg); color: var(--color-error-text); font-size: .8rem; text-align: center;
}
.chat-msg__header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: .15rem;
}
.chat-msg__role { font-size: .75rem; font-weight: 700; color: var(--text-muted); }
.chat-msg--user .chat-msg__role { color: var(--accent-blue); }
.chat-msg--assistant .chat-msg__role { color: var(--accent-gold); }

.chat-msg__tts-btn {
  background: none; border: 1px solid var(--border-light); border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-muted); padding: 2px 4px; line-height: 1; display: inline-flex; align-items: center;
  transition: .15s; opacity: .6;
}
.chat-msg__tts-btn:hover,
.chat-msg__tts-btn.playing { opacity: 1; color: var(--accent-gold); border-color: var(--accent-gold); }

@keyframes tts-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}
.chat-msg__tts-btn.playing svg { animation: tts-pulse 1s ease-in-out infinite; }
.chat-msg__text { padding: .4rem .6rem; border-radius: var(--radius-sm); line-height: 1.65; font-size: .9rem; }
.chat-msg__text p { margin: .3rem 0; }
.chat-msg__text p:first-child { margin-top: 0; }
.chat-msg__text p:last-child { margin-bottom: 0; }
.chat-msg__text ul, .chat-msg__text ol { padding-left: 1.5rem; margin: .25rem 0; }
.chat-msg__text li { margin: .1rem 0; }
.chat-msg__text code { background: var(--bg-card); padding: .1rem .3rem; border-radius: 2px; font-size: .8rem; }
.chat-msg__text pre { background: rgba(0,0,0,.3); padding: .5rem; border-radius: var(--radius-sm); overflow-x: auto; font-size: .8rem; margin: .3rem 0; }
.chat-msg__text pre code { background: none; padding: 0; }
.chat-msg--user .chat-msg__text { background: var(--bg-card); }
.chat-msg--assistant .chat-msg__text { background: var(--bg-card); border: 1px solid var(--border-light); }
.chat-msg--error .chat-msg__text { background: var(--color-error-bg); border: 1px solid var(--color-error-border); color: var(--color-error-text); }
.chat-msg__retry {
  display: flex; justify-content: flex-end; padding: .25rem .6rem 0;
}
.chat-retry-btn {
  background: none; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); font-size: 1rem; padding: .15rem .4rem;
  line-height: 1; transition: .1s;
}
.chat-retry-btn:hover {
  border-color: var(--accent-gold); color: var(--accent-gold);
}
.chat-msg--tool .chat-msg__role { color: var(--accent-green); }
.chat-msg--tool .chat-msg__text { background: rgba(133,153,0,.12); border: 1px solid rgba(133,153,0,.3); font-size: .8rem; font-family: monospace; white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto; color: var(--text-light); }
.chat-sessions { margin-bottom: .5rem; display: flex; align-items: center; gap: .5rem; }
.chat-session-select,
#session-select {
  flex: 1; background: var(--bg-input); color: var(--text-main);
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: .35rem .5rem; font-size: .85rem; font-family: var(--font-body);
  cursor: pointer; transition: .15s;
}
.chat-session-select:hover,
#session-select:hover { border-color: var(--accent-gold); }
.chat-session-select:focus,
#session-select:focus { outline: none; border-color: var(--accent-gold); box-shadow: 0 0 0 2px rgba(218,165,32,.2); }
.chat-session-select option,
#session-select option { background: var(--bg-dark-card); color: var(--text-main); }

.tts-error-icon {
  color: #e74c3c;
  font-weight: bold;
  cursor: help;
  margin-right: 6px;
  font-size: 18px;
}

.chat-input { display: flex; flex-direction: column; gap: 0; font-family: system-ui, -apple-system, sans-serif; }
.chat-input__row { display: flex; gap: .5rem; align-items: stretch; }
.chat-input__row button { align-self: flex-end; height: 60px; }
.chat-input__tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 0 4px 0; }
.chat-tag {
  cursor: pointer; padding: 2px 8px; border-radius: var(--radius-sm); font-size: .75rem;
  background: var(--bg-dark-card); color: var(--text-muted); border: 1px solid var(--border-light);
  user-select: none; transition: .15s; display: inline-flex; align-items: center;
}
.chat-tag.active { background: var(--bg-dark-card); color: var(--accent-gold); border-color: var(--accent-gold); }
.chat-new-btn {
  flex-shrink: 0; background: none; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: .3rem; cursor: pointer; line-height: 1; display: flex; align-items: center;
  color: var(--text-muted); transition: .15s;
}
.chat-new-btn:hover {
  border-color: var(--accent-gold); color: var(--accent-gold);
}
.chat-new-btn svg { display: block; }

.chat-tts-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .78rem; color: var(--text-light); cursor: pointer;
}
.chat-tts-row span { white-space: nowrap; }
.chat-tts-row input[type=range] {
  flex: 0 0 80px; accent-color: var(--accent-gold); cursor: pointer; height: 1rem;
}
.chat-tts-voice-toggle { display: flex; gap: 2px; }
.chat-tts-voice-toggle button {
  background: none; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 3px 10px; font-size: .8rem; cursor: pointer; color: var(--text-muted);
  font-family: var(--font-body); transition: .1s; white-space: nowrap;
}
.chat-tts-voice-toggle button.active {
  background: var(--accent-gold); color: var(--bg-page); border-color: var(--accent-gold);
}
.chat-tts-voice-toggle button:not(.active):hover {
  border-color: var(--accent-gold); color: var(--accent-gold);
}
.chat-tts-select {
  background: var(--bg-page); color: var(--text-light); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 3px 6px; font-size: .8rem; font-family: var(--font-body);
  cursor: pointer; max-width: 140px;
}
.chat-tts-select:focus { outline: none; border-color: var(--accent-gold); }
.settings-modal .chat-tts-select {
  min-width: 200px;
}
.settings-modal .chat-tts-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 30px;
  margin: 4px 0;
  font-size: .9rem;
}
.settings-modal .chat-tts-row > :first-child {
  width: 130px;
  flex: none;
  text-align: right;
}
.s-value-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.s-value-group input[type=range] {
  flex: 1;
  min-width: 80px;
}
.s-value-group span {
  white-space: nowrap;
  font-size: .85rem;
  color: var(--text-muted);
}
.settings-modal {
  max-width: 600px;
  margin: 0 auto;
}
.settings-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 16px 0 8px;
}
.settings-group-title span {
  font-weight: 700;
  font-size: .85rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.settings-group-box {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: .6rem .75rem;
  background: color-mix(in srgb, var(--bg-dark-card) 85%, var(--bg-card));
}
.settings-group-box:last-child {
  margin-bottom: 16px;
}

.chat-input textarea {
  flex: 1; resize: none; padding: .5rem; font-family: var(--font-body); font-size: .9rem;
  border: 1px solid var(--border-light); border-radius: var(--radius-sm); background: var(--bg-input); color: var(--text-light);
  height: 60px;
}
.chat-input__field { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-input__field textarea { flex: none; width: 100%; }
.chat-input__resize-handle {
  flex-shrink: 0; height: 10px; cursor: ns-resize; position: relative;
  display: flex; align-items: center; justify-content: center; user-select: none; -webkit-user-select: none;
}
.chat-input__resize-handle::before {
  content: ''; width: 28px; height: 3px; border-radius: 2px; background: var(--border-light);
}
.chat-input__resize-handle:hover::before { background: var(--accent-gold); }
.chat-input textarea:disabled { opacity: .6; }
.chat-input textarea:focus {
  outline: none; border-color: var(--accent-blue);
}
.chat-input button {
  padding: .5rem 1.2rem; border: 1px solid var(--color-btn-send); background: var(--color-btn-send);
  color: var(--bg-page); font-family: var(--font-body); font-size: .9rem; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
}
.chat-input button:disabled { opacity: .5; cursor: default; }
.chat-input button:not(:disabled):hover { background: var(--accent-gold); border-color: var(--accent-gold); }

.voice-btn {
  padding: .5rem .75rem;
  border: 1px solid var(--border-light);
  background: var(--bg-dark-card);
  color: var(--text-muted);
  font-size: 0;
  line-height: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.voice-btn svg {
  display: block;
}
.voice-btn:hover:not(:disabled) {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
}
.voice-btn:disabled {
  opacity: .5;
  cursor: default;
}
.voice-btn--recording {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: var(--text-light);
  animation: voice-pulse .8s ease-in-out infinite;
}
.voice-btn--processing {
  background: var(--bg-dark-card);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}
@keyframes voice-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.typing-indicator {
  display: inline-flex; align-items: center; gap: 4px; padding: .3rem 0;
}
.typing-indicator span {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted); animation: pulse-dot 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse-dot {
  0%, 80%, 100% { opacity: .3; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1.1); }
}

/* ── chat status bar ──────────────────────────── */

.chat-status {
  font-size: .7rem; color: var(--text-muted);
  padding: .15rem .3rem; min-height: 1.2rem; user-select: none;
  display: flex; gap: .5rem; align-items: center;
  transition: background .2s, color .2s;
}
.chat-status--warn {
  background: rgba(255, 200, 0, .15);
  color: var(--accent-gold);
}
.chat-status--critical {
  background: rgba(255, 80, 50, .2);
  color: #ff5032;
}


.tool-progress-list {
  display: flex; flex-wrap: wrap; gap: .3rem; font-size: .75rem;
}
.tool-progress-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .5rem; border-radius: 10px;
  border: 1px solid var(--border-light); background: var(--bg-dark-card);
}
.tool-progress-badge.active {
  border-color: var(--accent-gold); background: rgba(209,163,96,.1);
}

.tool-progress-icon {
  font-size: .7rem;
}

.tool-progress-name {
  font-weight: 600; color: var(--text-light); max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-progress-badge.active .tool-progress-name { color: var(--accent-gold); }
.tool-progress-badge.done .tool-progress-name { color: var(--text-muted); }
.tool-progress-summary {
  color: var(--text-muted); font-size: .65rem;
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-progress-toggle {
  background: none; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); font-size: .65rem; padding: 0 .3rem;
  line-height: 1;
}
.tool-progress-toggle:hover { border-color: var(--accent-gold); color: var(--accent-gold); }
.tool-progress-detail {
  grid-column: 1 / -1; margin-top: .2rem;
  background: rgba(0,0,0,.3); border-radius: var(--radius-sm); padding: .3rem .4rem;
  font-family: monospace; font-size: .65rem; white-space: pre-wrap;
  word-break: break-word; max-height: 120px; overflow-y: auto;
  color: var(--text-light);
}
.spinner {
  display: inline-block;
  width: .7rem;
  height: .7rem;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  opacity: 1;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.choice-cards {
  display: flex; flex-direction: column; gap: .4rem; margin: .5rem 0;
}
.choice-card {
  display: block; text-align: left; padding: .6rem .8rem;
  border: 1px solid var(--border-light); border-radius: var(--radius-sm); cursor: pointer;
  background: var(--bg-dark-card); font-family: var(--font-body); font-size: .85rem;
  color: var(--text-light); transition: .15s;
}
.choice-card:hover {
  border-color: var(--accent-gold); color: var(--text-heading); background: rgba(209,163,96,.08);
}
.choice-card.disabled {
  opacity: .5; cursor: default; pointer-events: none;
}

/* ── multichoice ─────────────────────────────── */

.multichoice-list {
  display: flex; flex-direction: column; gap: .3rem; margin: .5rem 0;
}
.multichoice-item {
  display: flex; align-items: flex-start; gap: .4rem;
  padding: .4rem .6rem; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  background: var(--bg-dark-card); cursor: pointer; transition: .1s;
}
.multichoice-item:hover { border-color: var(--accent-gold); background: rgba(209,163,96,.08); }
.multichoice-item.disabled { opacity: .5; cursor: default; pointer-events: none; }
.multichoice-item input[type="checkbox"] { margin-top: .2rem; flex-shrink: 0; }
.multichoice-item__label { font-weight: 600; color: var(--text-light); font-size: .85rem; }
.multichoice-item__desc { display: block; color: var(--text-muted); font-size: .75rem; margin-top: .1rem; }

/* ── choice group ────────────────────────────── */

.choice-group-block {
  margin: .75rem 0; padding: .5rem .6rem;
  border: 1px solid var(--border-light); border-radius: var(--radius-sm); background: var(--bg-dark-card);
}
.choice-group-prompt { font-weight: 600; margin-bottom: .4rem; color: var(--text-heading); font-size: .85rem; }
.choice-group-block .choice-card {
  display: flex; align-items: center; gap: .4rem;
  margin: .2rem 0; padding: .35rem .5rem; font-size: .8rem;
}
/* ── choice submit button ────────────────────── */

.choice-card.active {
  border-color: var(--accent-green); background: rgba(91,129,51,.15); color: var(--text-heading);
}
.choice-submit {
  display: inline-block; margin-top: .5rem; padding: .4rem 1.2rem;
  border: 1px solid var(--border-light); background: transparent; color: var(--text-light);
  font-family: var(--font-body); font-size: .85rem; border-radius: var(--radius-sm);
  cursor: pointer; transition: .1s;
}
.choice-submit:hover { border-color: var(--accent-green); color: var(--accent-green); }
.choice-submit.disabled { opacity: .5; cursor: default; pointer-events: none; }
.chat-status__text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}

/* ── utility ──────────────────────────────────── */

.muted { color: var(--text-muted); }

/* ── right panel tabs ─────────────────────────── */

.right-tab-bar {
  display: flex; gap: 0; flex-wrap: wrap;
  border-bottom: 1px solid var(--border-dark); margin-bottom: .75rem;
}
.right-tab-btn {
  padding: .35rem .75rem; border: none; background: transparent;
  color: var(--text-muted); font-family: var(--font-body); font-size: .8rem;
  cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: .1s; white-space: nowrap;
}
.right-tab-btn:hover { color: var(--text-light); }
.right-tab-btn.active {
  color: var(--text-heading); font-weight: 600;
  border-bottom-color: var(--accent-gold);
}
.right-tab-pane { display: none; }
.right-tab-pane.active { display: block; }

/* ── presets (Приключения) ──────────────────────── */

.gen-container {
  font-size: .85rem; line-height: 1.4; padding: .25rem;
}
.gen-title {
  font-family: var(--font-heading); font-size: 1rem;
  color: var(--text-heading); margin-bottom: .75rem;
}
.gen-table-wrap {
  margin-top: .75rem; overflow-x: auto;
}
.gen-table {
  width: 100%; border-collapse: collapse; font-size: .82rem;
}
.gen-table th {
  text-align: left; color: var(--text-muted);
  font-weight: 600; padding: .3rem .4rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.gen-table td {
  padding: .35rem .4rem; color: var(--text-main);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.gen-table-actions {
  white-space: nowrap; text-align: right;
}
.gen-btn-sm {
  display: inline-block; padding: .15rem .45rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-card); color: var(--text-main);
  font-size: .8rem; cursor: pointer; transition: .1s;
  margin-left: .2rem;
}
.gen-btn-sm:hover { background: var(--bg-highlight); }
.gen-btn-sm--danger { color: var(--accent-magenta); border-color: var(--accent-magenta); }
.gen-empty { text-align: center; color: var(--text-muted); padding: 2rem 0; font-style: italic; }

.gen-btn {
  display: inline-block; padding: .4rem 1rem;
  border: 1px solid var(--accent-gold); border-radius: var(--radius-sm);
  background: var(--accent-gold); color: var(--bg-page);
  font-family: var(--font-body); font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: .1s;
}
.gen-btn:hover { opacity: .85; }
.gen-btn:disabled { opacity: .6; cursor: default; }
.gen-btn--primary { background: var(--accent-gold); color: var(--bg-page); }
.gen-btn--secondary { background: transparent; color: var(--text-main); }
.gen-btn--link { background: transparent; border: none; color: var(--accent-cyan); padding: 0; font-weight: 400; }
.gen-btn--link:hover { text-decoration: underline; opacity: 1; }

.gen-spinner-btn {
  display: inline-block; width: 1rem; height: 1rem;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%;
  animation: gen-spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes gen-spin { to { transform: rotate(360deg); } }

.gen-field { margin-bottom: .75rem; }
.gen-label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--text-light); margin-bottom: .25rem;
}
.gen-textarea {
  width: 100%; padding: .5rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-input);
  color: var(--text-main); font-family: var(--font-body);
  font-size: .85rem; resize: vertical; min-height: 4rem;
}
.gen-input {
  width: 100%; padding: .4rem .5rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-input);
  color: var(--text-main); font-family: var(--font-body); font-size: .85rem;
}
.gen-row { display: flex; gap: .75rem; }
.gen-field--half { flex: 1; }
.gen-actions { display: flex; gap: .5rem; justify-content: center; margin-top: .75rem; }

.gen-done { text-align: center; padding: 1rem 0; }
.gen-success-icon {
  width: 3rem; height: 3rem; line-height: 3rem; margin: 0 auto .75rem;
  background: var(--accent-green, #859900); color: #fff;
  border-radius: 50%; font-size: 1.5rem; font-weight: 700;
}
.gen-success-text { font-weight: 600; color: var(--text-heading); margin-bottom: .5rem; }
.gen-filename { color: var(--text-muted); font-size: .8rem; margin-bottom: .5rem; }
.gen-details { margin: .75rem 0; text-align: left; }
.gen-summary {
  cursor: pointer; color: var(--accent-cyan); font-size: .85rem;
  font-weight: 600; user-select: none;
}
.gen-editor {
  width: 100%; padding: .5rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-input);
  color: var(--text-main); font-family: 'Courier New', monospace;
  font-size: .8rem; resize: vertical; margin-top: .5rem;
}
.gen-saved-msg { margin-top: .5rem; }
.gen-saved-msg p { color: var(--accent-green, #859900); font-size: .85rem; }
.gen-error { text-align: center; padding: .5rem 0; }
.gen-error-text { color: var(--accent-magenta); margin-bottom: .5rem; }

/* ── character sheet ──────────────────────────── */

.char-sheet {
  font-size: .85rem; line-height: 1.4; position: relative;
}
.char-sheet__header {
  background: var(--bg-dark-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-md); padding: 1rem;
}
.char-sheet__name {
  font-family: var(--font-heading);
  font-size: 1.5rem; font-weight: 700; color: var(--accent-gold);
  text-transform: uppercase; letter-spacing: .03em;
}
.char-sheet__subtitle { color: var(--text-muted); font-size: .9rem; }
.char-sheet__desc { color: var(--text-light); font-size: .85rem; margin-top: .25rem; line-height: 1.6; }
.char-sheet__section-title {
  font-family: var(--font-heading);
  font-weight: 600; color: var(--text-heading);
  border-bottom: 1px solid var(--border-dark); margin: 1.1rem 0 .4rem;
  padding-bottom: .15rem; font-size: .8rem; text-transform: uppercase;
  letter-spacing: .08em;
}

.char-sheet__header--stats {
  display: flex; align-items: center; gap: 1rem;
}
.char-sheet__header-left { flex: 1; min-width: 0; }

/* ── ability score blocks (horizontal) ── */
.stat-row {
  display: flex; gap: .5rem;
}
.stat-row__abilities {
  flex: 1; max-width: 50%;
  display: flex; flex-direction: row; gap: .5rem; flex-wrap: wrap;
  background: var(--bg-dark-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-md); padding: .75rem;
}
.stat-row__quick {
  flex: 1; max-width: 50%;
  display: flex; flex-direction: column; gap: .5rem;
  background: var(--bg-dark-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-md); padding: .75rem;
}
.stat-row__quick-stats {
  display: flex; gap: 1rem; flex-wrap: wrap;
}
.stat-row__quick-hp {
  display: flex; flex-direction: column; gap: .15rem;
}
.stat-row__quick-hp strong {
  font-size: .8rem; color: var(--text-heading);
}

.char-sheet > * + * {
  margin-top: .5rem;
}
.stat-pill {
  text-align: center; padding: .4rem .6rem;
  background: transparent;
  border-radius: var(--radius-sm);
  min-width: 0; flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 0;
}
.stat-pill__abbr {
  font-family: var(--font-heading);
  font-size: .65rem; font-weight: 700; color: var(--text-heading);
  text-transform: uppercase; letter-spacing: .1em; line-height: 1.2;
}
.stat-pill__score {
  font-size: 1.1rem; font-weight: 700; color: var(--text-heading); line-height: 1.3;
  font-family: var(--font-heading);
  display: inline-flex; align-items: baseline; gap: .15rem;
}
.stat-pill__mod {
  font-size: .8rem; font-weight: 700; line-height: 1;
  color: var(--text-muted);
}
.stat-pill__mod.pos { color: var(--accent-green); }
.stat-pill__mod.neg { color: var(--accent-red); }

.char-sheet__stats-row {
  display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem;
}
.char-sheet__stat-item { font-size: .8rem; }
.char-sheet__stat-item strong { color: var(--text-heading); }

.hp-bar-track {
  width: 100%; height: 8px; background: transparent;
  border-radius: var(--radius-sm);
  overflow: hidden; border: 1px solid var(--border-light);
}
.hp-bar-track--inline {
  width: 100%; margin: .1rem 0 0;
}
.hp-bar-fill {
  height: 100%; background: var(--accent-green); border-radius: var(--radius-sm);
  transition: width .3s;
}
.char-sheet__stat-item--hp {
  flex: 1; display: flex; flex-direction: column; min-width: 6rem;
}

.skill-list { font-size: .8rem; columns: 3; column-gap: 1rem; }
.skill-item { break-inside: avoid; padding: .08rem 0; }
.skill-item--proficient { font-weight: 600; color: var(--text-heading); }
.skill-item--expertise { font-weight: 700; }
.skill-item--proficient::before { content: "● "; color: var(--accent-gold); font-size: .6rem; }

.feature-list { font-size: .8rem; padding-left: .5rem; columns: 2; column-gap: 1rem; }
.feature-list li { margin: .15rem 0; break-inside: avoid; }
.trait-list { font-size: .8rem; padding-left: .5rem; }
.trait-list li { margin: .15rem 0; }
.trait-list--cols { columns: 2; column-gap: 1rem; }
.trait-list--cols li { break-inside: avoid; }

.attack-list { font-size: .8rem; }
.attack-row { padding: .2rem 0; }

/* ── main content column ── */
.char-sheet__body {
  min-width: 0;
  background: var(--bg-dark-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem;
}

/* ── inventory ────────────────────────────────── */

.inv-grid {
  display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 .75rem;
}
.inv-grid__item {
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: .4rem .6rem; line-height: 1.3;
}
.inv-grid__item .inv-props { font-size: .65rem; color: var(--text-muted); margin-top: 1px; }
.inv-lookup {
  cursor: pointer; color: var(--accent-gold);
  text-decoration: underline dotted var(--accent-gold) 1.5px; text-underline-offset: 3px;
}
.inv-lookup:hover { background: rgba(181,137,0,.1); }
.lookup-overlay {
  position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
}
.lookup-popup {
  background: var(--bg-dark-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
  max-width: 420px; width: 90%; max-height: 70vh; overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); padding: 0;
}
.lookup-popup__header {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border-dark);
  background: rgba(0,0,0,.2); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.lookup-popup__title { font-size: 1.05rem; color: var(--text-heading); font-family: var(--font-heading); }
.lookup-popup__close {
  cursor: pointer; font-size: 1.4rem; line-height: 1; color: var(--text-muted);
  padding: 0 .2rem;
}
.lookup-popup__close:hover { color: var(--accent-red); }
.lookup-popup__body { padding: .75rem 1rem 1rem; }
.lookup-popup__desc { font-size: .85rem; line-height: 1.65; margin-bottom: .75rem; color: var(--text-light); }
.lookup-popup__fields { width: 100%; font-size: .8rem; border-collapse: collapse; }
.lookup-popup__fields td { padding: .25rem .3rem; border-bottom: 1px solid var(--border-dark); }
.lookup-popup__field-label { color: var(--text-muted); width: 40%; }
.money-row {
  margin-top: .4rem; font-size: .8rem; color: var(--accent-gold);
  display: flex; gap: .5rem; flex-wrap: wrap;
}
.money-item { display: inline-flex; align-items: center; gap: .15rem; }

/* ── preset picker ───────────────────────────── */

.preset-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
}
.preset-modal {
  background: var(--bg-dark-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
  max-width: 520px; width: 90%; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); padding: 1.5rem;
}
.preset-modal__header { margin-bottom: 1rem; display: flex; justify-content: space-between; align-items: center; }
.preset-modal__title {
  font-size: 1.2rem; color: var(--text-heading); font-weight: 700; margin: 0; font-family: var(--font-heading);
}
.preset-modal__close {
  font-size: 1.5rem; color: var(--text-muted); cursor: pointer; line-height: 1;
  padding: 0 .25rem; transition: .1s;
}
.preset-modal__close:hover { color: var(--text-main); }
.preset-grid { display: flex; flex-direction: column; gap: .5rem; }
.preset-card {
  display: block; text-align: left; padding: .8rem 1rem;
  border: 1px solid var(--border-light); border-radius: var(--radius-md); cursor: pointer;
  background: var(--bg-dark-card); transition: .15s;
}
.preset-card:hover {
  border-color: var(--accent-gold); background: rgba(181,137,0,.08);
}
.preset-card__title { font-size: 1rem; font-weight: 700; color: var(--text-heading); margin-bottom: .2rem; }
.preset-card__meta { display: flex; gap: .75rem; font-size: .75rem; color: var(--text-muted); margin-bottom: .2rem; }
.preset-card__genre { font-size: .8rem; color: var(--text-light); }
.preset-empty { text-align: center; padding: 2rem 1rem; }
.preset-empty__title { font-size: 1.1rem; color: var(--text-heading); font-weight: 600; margin-bottom: .5rem; font-family: var(--font-heading); }
.preset-empty__desc { font-size: .85rem; color: var(--text-muted); }

/* ── sessions tab ──────────────────────────── */

.sessions-tab { font-size: .85rem; }
.sessions-tab__header {
  display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem;
}
.sessions-tab__header h3 {
  font-size: 1rem; color: var(--text-heading); font-weight: 700;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border-dark);
  font-family: var(--font-heading); text-transform: uppercase; letter-spacing: .05em;
  flex: 1; margin: 0;
}
.sessions-tab table { width: 100%; border-collapse: collapse; }
.sessions-row td { padding: .2rem .5rem; border-bottom: 1px solid var(--border-dark); vertical-align: middle; }
.sessions-row:hover td { background: var(--bg-card); }
.sessions-cell-title { font-weight: 600; color: var(--text-heading); }
.sessions-cell-date { color: var(--text-muted); font-size: .78rem; white-space: nowrap; }
.sessions-cell-actions { text-align: right; white-space: nowrap; }
.sessions-btn-delete {
  padding: .2rem .6rem; font-size: .75rem; border: 1px solid var(--accent-red);
  background: transparent; color: var(--accent-red); border-radius: var(--radius-sm);
  cursor: pointer; font-family: var(--font-body); transition: .1s;
}
.sessions-btn-delete:hover { background: var(--accent-red); color: var(--text-light); }
.sessions-btn-danger { border-color: var(--accent-red); color: var(--accent-red); }
.sessions-btn-danger:hover { background: #dc322f; color: var(--text-light); }
.sessions-badge-done {
  display: inline-block; font-size: .7rem; padding: .1rem .4rem;
  border-radius: var(--radius-sm); background: var(--bg-dark-card); color: var(--text-muted);
}

/* ── location tab ──────────────────────────── */

.location-view { padding: 1rem; margin-top: .5rem; background: var(--bg-dark-card); border: 1px solid var(--border-light); border-radius: var(--radius-md); }
.location-header { display: block; margin-bottom: 1rem; }
.location-image { width: 100%; max-width: 100%; border-radius: var(--radius-md); box-shadow: 0 2px 8px rgba(0,0,0,.3); display: block; }
.location-image-wrap { position: relative; display: inline-block; width: 100%; }
.location-regen-btn {
  position: absolute; bottom: -8px; right: 4px; z-index: 2;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--bg-page); background: var(--text-muted); color: var(--bg-page);
  font-size: .75rem; line-height: 1; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.location-regen-btn:hover { background: var(--accent-gold); }
.location-regen-btn:disabled { opacity: .5; cursor: default; }
.location-info { }
.location-title { margin: 0 0 .5rem; font-size: 1.2rem; color: var(--accent-gold); font-family: var(--font-heading); }
.location-desc { font-size: .85rem; color: var(--text-main); line-height: 1.65; }
.location-empty { padding: 2rem; text-align: center; color: var(--text-muted); }

/* location route strip */
.loc-nav { display: flex; align-items: center; gap: .3rem; margin-bottom: .75rem; }
.loc-nav__strip {
  display: flex; gap: .35rem; flex: 1; min-width: 0;
  overflow-x: auto; -ms-overflow-style: none;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.loc-nav__strip::-webkit-scrollbar { display: none; }
.loc-nav__chip {
  display: inline-flex; align-items: center; gap: .25rem; flex: 0 0 auto;
  max-width: 14rem; padding: .28rem .6rem;
  border: 1px solid var(--border-light); border-radius: 999px;
  background: var(--bg-card); color: var(--text-main);
  font-family: var(--font-body); font-size: .78rem; white-space: nowrap;
  cursor: pointer; scroll-snap-align: center;
  transition: border-color .15s, background .15s, color .15s;
}
.loc-nav__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.loc-nav__chip:hover { border-color: var(--text-muted); color: var(--text-heading); }
.loc-nav__chip--selected { border-color: var(--accent-blue); background: var(--bg-dark-card); color: var(--text-heading); }
.loc-nav__chip--selected:hover { border-color: var(--accent-blue); }
.loc-nav__chip--current { border-color: var(--accent-gold); color: var(--accent-gold); font-weight: 600; }
.loc-nav__chip--current:hover { border-color: var(--accent-gold); color: var(--accent-gold); }
.loc-nav__star { flex: 0 0 auto; font-size: .7rem; }
.loc-nav__arrow {
  flex: 0 0 auto; width: 1.6rem; height: 1.6rem; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-light); border-radius: 50%;
  background: var(--bg-card); color: var(--text-main);
  font-size: 1rem; line-height: 1; cursor: pointer;
}
.loc-nav__arrow:hover:not(:disabled) { border-color: var(--accent-gold); color: var(--accent-gold); }
.loc-nav__arrow:disabled { opacity: .35; cursor: default; }
.loc-return {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-bottom: .75rem; padding: .4rem .6rem;
  border: 1px solid var(--border-light); border-left: 3px solid var(--accent-gold);
  border-radius: var(--radius-sm); background: var(--bg-card);
  font-size: .78rem; color: var(--text-main);
}
.loc-return__text { min-width: 0; }
.loc-return__btn {
  flex: 0 0 auto; padding: .2rem .45rem;
  border: 1px solid var(--accent-gold); border-radius: var(--radius-sm);
  background: transparent; color: var(--accent-gold);
  font-family: var(--font-body); font-size: .75rem; cursor: pointer;
}
.loc-return__btn:hover { background: var(--accent-gold); color: var(--text-dark); }

/* NPC grid */
.npc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.npc-card { background: var(--bg-dark-card); border: 1px solid var(--border-light); border-radius: var(--radius-md); overflow: hidden; text-align: center; padding-bottom: .5rem; }
.npc-card__img { width: 100%; height: 140px; object-fit: cover; display: block; }
.npc-card__img.img-error { object-fit: contain; padding: 8px; }
.npc-card__img-placeholder { width: 100%; height: 140px; display: flex; align-items: center; justify-content: center; background: var(--bg-input); color: var(--text-muted); font-size: .75rem; }
.npc-card__name { font-size: .8rem; font-weight: 600; color: var(--text-heading); padding: .3rem .5rem 0; }
.npc-card__attitude { font-size: .7rem; padding: .1rem .4rem; display: inline-block; border-radius: var(--radius-sm); margin-top: .2rem; }
.npc-card__attitude--friendly { background: var(--accent-green); color: var(--text-light); }
.npc-card__attitude--neutral { background: #b58900; color: var(--text-light); }
.npc-card__attitude--hostile { background: #dc322f; color: var(--text-light); }

/* Combat tracker */
.combat-tracker { margin-bottom: 1rem; }

.combat-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .6rem;
}

@media (min-width: 768px) {
  .combat-cards { grid-template-columns: repeat(4, 1fr); }
}

.combat-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--border-light);
  background: var(--bg-page);
}

.combat-card--player { border-color: var(--accent-green); }
.combat-card--enemy { border-color: var(--color-combat-enemy); }

.combat-card--active { box-shadow: 0 0 12px var(--color-glow); }
.combat-card--dimmed { opacity: .7; }

.combat-card__hp {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 20px;
  z-index: 2;
  background: var(--bg-page);
  overflow: hidden;
}
.combat-card__hp-bar {
  width: 100%;
  height: 100%;
}
.combat-card__hp-fill {
  height: 100%;
  transition: width .3s ease;
}
.combat-card__hp-fill--high { background: var(--accent-green); }
.combat-card__hp-fill--mid  { background: var(--color-hp-mid); }
.combat-card__hp-fill--low  { background: var(--color-hp-low); }
.combat-card__hp-fill--unknown { background: var(--text-muted); }

.combat-card__hp--unknown { opacity: .5; }
.combat-card__hp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .65rem;
  font-weight: 600;
  color: var(--text-light);
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}

.combat-card__img {
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: var(--bg-input);
}

.combat-card__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.combat-card__stub { opacity: .5; }

.combat-card__stub-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.combat-card__stub-wrap .combat-card__stub {
  width: 100%;
  flex-shrink: 0;
  display: block;
  opacity: .5;
}

.combat-card__name {
  text-align: center;
  padding: .35rem .4rem;
  font-size: .8rem;
  font-weight: 600;
  background: var(--bg-dark-card);
  color: var(--text-light);
  line-height: 1.2;
}

.combat-card--dead .combat-card__content {
  filter: grayscale(1);
  opacity: .35;
}

.combat-card__death-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  font-size: 3.5rem;
  pointer-events: none;
  color: var(--border-dark);
  text-shadow: 0 0 8px rgba(0,0,0,.4), 1px 1px 0 rgba(0,0,0,.2);
}

/* Character portrait */
.char-sheet__portrait { width: 72px; height: 84px; flex-shrink: 0; position: relative; }
.char-portrait-img { width: 72px; height: 84px; object-fit: cover; border: 2px solid var(--border-light); border-radius: var(--radius-sm); }
.char-portrait-placeholder { width: 72px; height: 84px; display: flex; align-items: center; justify-content: center; background: var(--bg-input); border-radius: var(--radius-sm); color: var(--text-muted); font-size: .7rem; }
.char-portrait__regenerate {
  position: absolute; bottom: -4px; right: 0;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--bg-page); background: var(--text-muted); color: var(--bg-page);
  font-size: .75rem; line-height: 1; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.char-portrait__regenerate:hover { background: var(--accent-gold); }
.char-portrait__regenerate:disabled { opacity: .5; cursor: default; }
.char-portrait__regenerate .spinner,
.location-regen-btn .spinner { background: var(--text-muted); border-radius: 50%; box-shadow: 0 0 0 3px var(--text-muted); }

/* Image placeholder */
.img-placeholder { display: flex; align-items: center; justify-content: center; gap: .4rem; font-size: .8rem; color: var(--text-muted); }
.img-regen-btn { background: none; border: 1px solid var(--border-light); color: var(--text-muted); border-radius: 50%; width: 22px; height: 22px; font-size: .85rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; margin-top: 4px; transition: background .15s; }
.img-regen-btn:hover { background: var(--accent-gold); border-color: var(--accent-gold); color: var(--bg-page); }
.img-error { opacity: .6; }

/* ── QR button ───────────────────────────────── */
.qr-btn {
  position: absolute; top: 2px; right: 2px;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--bg-page); background: var(--text-muted); color: var(--bg-page);
  font-size: .65rem; line-height: 1; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s; z-index: 1;
}
.qr-btn:hover { background: var(--accent-gold); }
.qr-btn svg { width: 12px; height: 12px; }

/* ── QR modal ────────────────────────────────── */
.qr-modal-overlay {
  position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
}
.qr-modal {
  background: var(--bg-dark-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
  max-width: 360px; width: 90%; box-shadow: 0 10px 30px rgba(0,0,0,0.5); padding: 0;
}
.qr-modal__header {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border-dark);
  background: rgba(0,0,0,.2); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.qr-modal__title { font-size: 1rem; color: var(--text-heading); }
.qr-modal__close {
  cursor: pointer; font-size: 1.4rem; line-height: 1; color: var(--text-muted);
  padding: 0 .2rem;
}
.qr-modal__close:hover { color: var(--accent-red); }
.qr-modal__body { padding: 1rem; text-align: center; }
.qr-code { display: inline-block; margin-bottom: .75rem; }
.qr-code img, .qr-code canvas { display: block; margin: 0 auto; }
.qr-link-row { display: flex; gap: .4rem; }
.qr-link-input {
  flex: 1; padding: .4rem .5rem; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  font-family: monospace; font-size: .75rem; color: var(--text-light); background: var(--bg-input);
}
.qr-copy-btn {
  padding: .4rem .75rem; border: 1px solid var(--accent-gold); background: var(--accent-gold);
  color: var(--bg-page); font-family: var(--font-body); font-size: .8rem; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
}
.qr-copy-btn:hover { background: var(--accent-gold); border-color: var(--accent-gold); color: var(--bg-page); }

/* ── player page layout ──────────────────────── */
.player-layout { padding: .5rem; max-width: 100%; margin: 0 auto; }
.player-tab-bar {
  display: flex; gap: 0; border: 1px solid var(--border-light); border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin-bottom: .75rem; overflow: hidden;
}
.player-tab-btn {
  flex: 1; padding: .5rem .75rem; border: none;
  background: var(--bg-dark-card); color: var(--text-muted);
  font-family: var(--font-body); font-size: .9rem;
  cursor: pointer; transition: .1s; text-align: center;
  border-right: 1px solid var(--border-light);
}
.player-tab-btn:last-child { border-right: none; }
.player-tab-btn:hover { color: var(--text-light); background: var(--bg-card); }
.player-tab-btn.active {
  background: var(--bg-parchment); color: var(--text-dark); font-weight: 600;
}
.player-tab-pane { display: none; }
.player-tab-content { position: relative; min-height: 60vh; }
.player-tab-pane.active { display: block; position: relative; }

/* slide animation for mobile tab switch */
@keyframes paneSlideIn {
  from { transform: translateX(20px); opacity: 0.5; }
  to { transform: translateX(0); opacity: 1; }
}
.player-tab-pane.pane-slide-in { animation: paneSlideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1); }

/* ── mobile responsive ───────────────────────── */
@media (max-width: 480px) {
  .player-layout { padding: .25rem; }
  .player-tab-btn { font-size: .85rem; padding: .4rem .5rem; }

  .char-sheet { font-size: .8rem; }
  .char-sheet__header--stats { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .stat-pill { min-width: 3rem; padding: .3rem; flex: 1; }
  .stat-pill__score { font-size: .9rem; }
  .stat-row { flex-direction: column; }
  .stat-row__abilities, .stat-row__quick { max-width: 100%; }
  .char-sheet__name { font-size: 1.1rem; }
  .skill-list { columns: 2; }
  .feature-list { columns: 1; }
  .inv-grid { gap: .35rem; }
  .inv-grid__item { font-size: .75rem; padding: .3rem .45rem; }
  .npc-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: .5rem; }
  .npc-card__img { height: 100px; }
  .combat-cards { gap: .4rem; }
  .location-image { max-height: 180px; object-fit: cover; }
  .loc-nav { gap: .2rem; }
  .loc-nav__chip { max-width: 8.5rem; font-size: .75rem; }
  .loc-nav__name { overflow: hidden; text-overflow: ellipsis; }
  .loc-return { flex-direction: column; align-items: flex-start; }
  .char-sheet__portrait { width: 60px; height: 70px; }
  .char-portrait-img { width: 60px; height: 70px; }
  .char-portrait-placeholder { width: 60px; height: 70px; }
  .qr-code img, .qr-code canvas { width: 160px !important; height: 160px !important; }
}

/* ── Metrics tab ── */

.metrics-tab { padding: .75rem; }
.metrics-tab__header { margin-bottom: 1rem; }
.metrics-section { margin-bottom: 1.5rem; }
.metrics-section h4 { font-size: .85rem; color: var(--accent-gold); margin-bottom: .35rem; }
.metric-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; font-size: .82rem; }
.metric-label { color: var(--text-light); }
.metric-value { color: var(--text-dark); font-weight: 600; font-variant-numeric: tabular-nums; }
.metrics-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.metrics-table td, .metrics-table th { padding: .1rem .25rem; text-align: left; vertical-align: middle; }
.metrics-table th { color: var(--text-muted); font-weight: 400; font-size: .75rem; }

.progress-bar { height: .5rem; background: var(--bg-card); border-radius: var(--radius-sm); overflow: hidden; margin-top: .25rem; }
.progress-bar--dual { display: flex; }
.progress-fill { height: 100%; background: var(--accent-blue); border-radius: var(--radius-sm); transition: width .3s; }
.progress-fill--narrative { background: var(--accent-gold); }
.progress-fill--tool { background: var(--accent-cyan); }

.hist-bar-container, .td-hist-bar { display: flex; align-items: center; gap: .15rem; }
.hist-bar { height: .6rem; background: var(--accent-blue); border-radius: var(--radius-sm); transition: width .3s; }
.hist-count { font-size: .78rem; color: var(--text-dark); font-variant-numeric: tabular-nums; white-space: nowrap; }
.metrics-histogram td:first-child { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .76rem; }

.metrics-group-header td { font-weight: 700; font-size: .82rem; color: var(--accent-gold); padding-top: .5rem; padding-bottom: .15rem; letter-spacing: .03em; }
.metric-label--indent { padding-left: 1.2rem !important; }
.group-divider td { border-bottom: 1px solid var(--border-light); padding: 0; line-height: .5rem; }

/* ── invite form spinner ── */

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request .button-text { display: none; }
form.htmx-request button[type=submit] { pointer-events: none; opacity: .7; }

/* ── auth pages (login, register, forgot/reset password) ── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-container {
  max-width: 400px;
  width: 100%;
  background: var(--bg-dark-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 2rem 2rem 1.5rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
}

.auth-container h1 {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 1.6rem;
  color: var(--accent-gold);
  margin: 0 0 1.5rem;
  letter-spacing: .04em;
}

.auth-container .form-group {
  margin-bottom: 1rem;
}

.auth-container .form-group label {
  display: block;
  margin-bottom: .35rem;
  font-weight: 600;
  font-size: .85rem;
  color: var(--text-light);
}

.auth-container .form-group input {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: .9rem;
  transition: border-color .15s;
}

.auth-container .form-group input:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 2px rgba(218,165,32,.15);
}

.auth-container button[type=submit] {
  width: 100%;
  padding: .7rem;
  font-size: 1rem;
  border: 1px solid var(--accent-gold);
  background: var(--accent-gold);
  color: var(--bg-page);
  font-family: var(--font-body);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: opacity .15s;
}

.auth-container button[type=submit]:hover {
  opacity: .85;
}

.auth-container .error {
  color: var(--accent-red);
  font-size: .85rem;
  margin-bottom: .75rem;
  text-align: center;
}

.auth-container .success {
  color: var(--accent-green);
  font-size: .85rem;
  margin-bottom: .75rem;
  text-align: center;
}

.auth-container .info {
  color: var(--accent-green);
  font-size: .85rem;
  margin-bottom: .75rem;
  text-align: center;
}

.auth-links {
  text-align: center;
  margin-top: 1.25rem;
  font-size: .85rem;
}

.auth-links a {
  display: inline-block;
  margin: 0 .4rem;
}

/* ── app header ── */

.app-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem 1rem;
  flex: 0 0 auto;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  margin-right: auto;
  color: var(--accent-gold);
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .03em;
}

.app-header__brand:hover {
  opacity: .85;
}

.app-header__username {
  font-size: .85rem;
  color: var(--text-light);
  text-decoration: none;
  padding: .2rem .3rem;
  border-radius: var(--radius-sm);
  transition: background .15s;
}

.app-header__username:hover {
  background: var(--bg-card);
  color: var(--accent-gold);
}

/* ── user dropdown ────────────────────────────── */

.app-header__dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  cursor: pointer;
  padding: .2rem .3rem;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.app-header__dropdown:hover {
  background: var(--bg-card);
}
.app-header__dropdown-arrow {
  color: var(--text-muted);
  transition: transform .15s;
}
.app-header__dropdown:hover .app-header__dropdown-arrow {
  color: var(--accent-gold);
}
.app-header__dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 9998;
  min-width: 160px;
  background: var(--bg-dark-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  padding: .3rem 0;
  margin-top: .25rem;
}
.app-header__dropdown-item {
  display: block;
  width: 100%;
  padding: .45rem .8rem;
  font-size: .85rem;
  color: var(--text-light);
  text-decoration: none;
  background: none;
  border: none;
  font-family: var(--font-body);
  text-align: left;
  cursor: pointer;
  transition: background .1s;
}
.app-header__dropdown-item:hover {
  background: var(--bg-card);
  color: var(--accent-gold);
}
.app-header__dropdown-divider {
  margin: .25rem 0;
  border: none;
  border-top: 1px solid var(--border-light);
}

/* ── universal modal ───────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; z-index: 9997;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
}
.modal-content {
  background: var(--bg-dark-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
  max-width: 66vw; width: 90%; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.modal-content--narrow {
  max-width: 40vw;
  width: 40%;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border-dark);
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-dark-card); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-title {
  font-size: 1.1rem; color: var(--text-heading); font-weight: 700; font-family: var(--font-heading);
}
.modal-close {
  font-size: 1.5rem; color: var(--text-muted); cursor: pointer; line-height: 1;
  padding: 0 .25rem; transition: .1s;
}
.modal-close:hover { color: var(--accent-red); }
.modal-body {
  padding: 1rem;
}

/* ── metrics button ───────────────────────────── */

.chat-input .chat-metrics-btn {
  flex-shrink: 0; background: none; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: .3rem; cursor: pointer; line-height: 1; display: flex; align-items: center;
  color: var(--text-muted); transition: .15s; font-family: inherit; font-size: inherit; white-space: normal;
}
.chat-input button.chat-metrics-btn:hover {
  background: none;
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
.chat-input .chat-metrics-btn svg { display: block; }
