:root {
  --ink: #211b16;
  --paper: #f4ead7;
  --paper-deep: #dfcda9;
  --red: #a23b2a;
  --red-dark: #71291f;
  --line: rgba(48, 34, 23, .25);
  --shadow: 0 16px 50px rgba(22, 15, 10, .28);
  --bg-modal: #27272a;
  --bg-input: #18181b;
  --text-main: #e4e4e7;
  --text-muted: #a1a1aa;
  --border-color: #3f3f46;
  --accent-color: #6366f1;
  --bg-hover: rgba(255, 255, 255, .08);
}

body.light-theme {
  --bg-modal: #ffffff;
  --bg-input: #f8fafc;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --accent-color: #4f46e5;
  --bg-hover: rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: #19130f;
  font-family: "Inter", sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.panel-head, .settings-head, .section-title, .button-row, .panel-actions {
  display: flex;
  align-items: center;
}

input, textarea {
  width: 100%;
  padding: 9px 10px;
  color: var(--ink);
  background: rgba(255, 252, 242, .92);
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 2px rgba(162,59,42,.12); }
textarea { resize: vertical; }

button {
  padding: 8px 11px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 5px;
  color: inherit;
  background: rgba(255,255,255,.08);
}
button:hover { filter: brightness(1.12); }
button.primary { color: white; background: var(--accent-color); border-color: var(--accent-color); }
button.danger { color: #8b241c; border-color: #b87068; background: transparent; }
button:disabled { cursor: wait; opacity: .55; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.workspace.log-hidden { grid-template-columns: minmax(0, 1fr); }
.workspace.log-hidden .log-panel { display: none; }

.stage-wrap { min-width: 0; display: flex; flex-direction: column; background: #17110d; }
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
}
.stage-background {
  position: absolute;
  z-index: 1;
  inset: 0;
  background-position: center;
  background-size: cover;
}
.stage-shade {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(180deg, rgba(0,0,0,.08), transparent 55%, rgba(0,0,0,.42));
  pointer-events: none;
}
.characters, .character-names {
  position: absolute;
  left: 2%;
  right: 2%;
  bottom: 17%;
  height: min(42%, 330px);
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  align-items: end;
}
.characters { z-index: 5; }
.table-decoration {
  position: absolute;
  z-index: 10;
  bottom: -2%;
  left: 50%;
  width: 105%;
  max-height: 48%;
  object-fit: fill;
  object-position: center bottom;
  transform: translateX(-50%);
  pointer-events: none;
  user-select: none;
}
.scene-slot {
  position: relative;
  align-self: end;
  height: 100%;
  transform: translateY(var(--slot-offset, 0));
}
.scene-slot.slot-1 { grid-column: 1; }
.scene-slot.slot-2 { grid-column: 2; }
.scene-slot.slot-3 { grid-column: 3; }
.scene-slot.slot-4 { grid-column: 4; }
.scene-slot.slot-5 { grid-column: 5; }
.scene-slot.slot-6 { grid-column: 6; }
.scene-slot.slot-7 { grid-column: 7; }
.scene-slot.slot-8 { grid-column: 8; }
.scene-slot.slot-1, .scene-slot.slot-8 { --slot-offset: 30px; }
.scene-slot.slot-2, .scene-slot.slot-7 { --slot-offset: 3px; }
.scene-slot.slot-3, .scene-slot.slot-6 { --slot-offset: -10px; }
.scene-slot.slot-4, .scene-slot.slot-5 { --slot-offset: -20px; }
.characters .character,
.character-names .character-name-anchor {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(12vw, 160px);
  min-width: 72px;
  height: min(18vw, 205px);
  min-height: 105px;
  transform: translateX(-50%);
}
.characters .character {
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  pointer-events: auto;
  cursor: context-menu;
  user-select: none;
}
.characters .character-avatar {
  position: relative;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 12px 8px rgba(0,0,0,.35));
}
.characters .character-avatar img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}
.characters .character.mirrored .character-avatar { transform: scaleX(-1); }
.characters .character-avatar-base { z-index: 1; }
.characters .character-emotion { z-index: 2; }
characters .character-avatar img.hat-layer,
.characters .hat-layer {
  position: absolute;
  top: auto !important; /* Убиваем старое прилипание к верху */
  bottom: 0%;
  left: -25%;
  width: 100% !important; /* Заставляем браузер слушать именно этот размер */
  height: auto !important;
  pointer-events: none;
  z-index: 10;
}
.character-names {
  z-index: 11;
  pointer-events: none;
}
.character-names .character-name-anchor {
  border: 0;
  outline: 0;
  background: transparent;
}
.character-names .character-name {
  position: absolute;
  bottom: -10px;
  left: 50%;
  display: inline-block;
  max-width: 100%;
  padding: 4px 12px;
  overflow: hidden;
  color: #333;
  background: #fff;
  border: 0;
  border-radius: 12px;
  transform: translateX(-50%);
  font-weight: bold;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 2px 3px 0 rgba(0,0,0,.3);
}
.speech {
  position: absolute;
  z-index: 20;
  top: 20px;
  left: 20px;
  width: min(480px, 46%);
  min-width: 260px;
  min-height: 130px;
  height: auto;
  padding: 17px 20px 14px;
  color: #17120f;
  background: rgba(255,253,247,.96);
  border: 3px solid #1a1a1a;
  border-radius: 8px;
  box-shadow: 6px 7px 0 rgba(25,16,11,.38);
  overflow: visible;
}
.speech::before, .speech::after {
  content: "";
  position: absolute;
  left: var(--speech-tail-offset, 50%);
  width: 0;
  height: 0;
  border-style: solid;
  border-color: transparent;
  transform: translateX(-50%);
  pointer-events: none;
}
.speech::before {
  bottom: -20px;
  border-width: 20px 14px 0;
  border-top-color: #1a1a1a;
}
.speech::after {
  bottom: -14px;
  border-width: 17px 11px 0;
  border-top-color: rgba(255,253,247,.96);
}
.speech-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.speech-text {
  height: auto;
  margin: 10px 0 12px;
  font-size: clamp(17px, 2vw, 22px);
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.typing-indicator {
  display: flex;
  min-height: 31px;
  align-items: center;
  gap: 7px;
  padding: 4px 2px;
}
.typing-indicator span {
  width: 9px;
  height: 9px;
  background: #5c4635;
  border-radius: 50%;
  animation: typing-bounce 1.15s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .14s; }
.typing-indicator span:nth-child(3) { animation-delay: .28s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: .42; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-7px); }
}
@media (prefers-reduced-motion: reduce) {
  .typing-indicator span { animation: none; opacity: .72; }
}
.speech-actions { justify-content: flex-end; }
.speech-actions button {
  padding: 5px 10px;
  color: #5c4635;
  background: transparent;
  border-color: rgba(48,34,23,.28);
  font: 11px "Inter", sans-serif;
}

.composer {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: 1fr;
  gap: 7px 9px;
  padding: 10px 13px 12px;
  color: var(--text-main);
  background: var(--bg-modal);
  border-top: 2px solid var(--border-color);
}
.composer textarea { min-height: 48px; max-height: 130px; color: var(--text-main); background: var(--bg-input); border-color: var(--border-color); resize: none; }
.composer textarea:focus { border-color: var(--accent-color); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-color) 18%, transparent); }
.prompt-row { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 7px; }
.prompt-row textarea { width: 100%; }
.attach-image { display: grid; width: 42px; min-height: 48px; padding: 9px; place-items: center; color: var(--text-main); background: var(--bg-input); border-color: var(--border-color); }
.attach-image:hover { background: var(--bg-hover); }
.attach-image svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.image-preview { display: grid; grid-template-columns: 52px minmax(0, 1fr) 28px; align-items: center; gap: 10px; padding: 8px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 6px; }
.image-preview img { width: 52px; height: 52px; object-fit: cover; border-radius: 5px; }
.image-preview strong, .image-preview small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-preview strong { color: var(--text-main); font-size: 11px; }
.image-preview small { margin-top: 3px; color: var(--text-muted); font-size: 10px; }
.image-preview button { width: 28px; height: 28px; padding: 0 0 2px; color: var(--text-muted); background: transparent; border-color: transparent; font-size: 20px; }
.image-preview button:hover { color: var(--text-main); background: var(--bg-hover); }
.composer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.composer-actions button { min-height: 38px; }
.composer #send { color: white; background: var(--accent-color); border-color: var(--accent-color); }
.composer #continueDialogue { color: var(--text-main); background: var(--bg-input); border-color: var(--border-color); }
.composer #continueDialogue:hover { background: var(--bg-hover); filter: none; }
.composer-actions button:disabled { cursor: wait; opacity: .48; }
.target { color: var(--text-muted); font-size: 12px; }
.target.has-target { color: var(--accent-color); font-weight: 700; }

.log-panel {
  position: fixed;
  z-index: 80;
  top: 78px;
  right: 14px;
  width: 350px;
  height: calc(100vh - 92px);
  min-width: 280px;
  min-height: 300px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  resize: both;
  color: var(--text-main);
  background: var(--bg-modal);
  border: 2px solid var(--border-color);
  border-radius: 7px;
  box-shadow: var(--shadow);
}
.stage-wrap, .log-panel { min-height: 0; }
.panel-head, .settings-head {
  min-height: 64px;
  padding: 12px 14px;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}
.history-heading { min-width: 0; flex: 1; }
.history-tabs { display: flex; gap: 4px; margin-top: 7px; }
.history-tab { padding: 4px 7px; color: var(--text-muted); background: transparent; border-color: transparent; border-radius: 4px; font-size: 11px; }
.history-tab.active { color: white; background: var(--accent-color); border-color: var(--accent-color); }
.private-recipient { display: flex; align-items: center; gap: 6px; margin-top: 7px; color: var(--text-muted); font-size: 11px; }
.private-recipient select { min-width: 0; flex: 1; padding: 4px 6px; color: var(--text-main); background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; cursor: pointer; }
.log-panel .panel-head { cursor: move; touch-action: none; user-select: none; }
.log-panel .panel-head button { cursor: pointer; }
.panel-head strong, .panel-head small, .settings-head strong, .settings-head small { display: block; }
.panel-head small, .settings-head small { margin-top: 3px; color: var(--text-muted); font-size: 11px; }
.log-panel .panel-head { border-bottom-color: var(--border-color); }
.icon-button { padding: 6px 8px; color: var(--text-muted); border-color: var(--border-color); background: transparent; font-size: 12px; }
.log-panel button:hover { background: var(--bg-hover); filter: none; }
.panel-actions { gap: 6px; }
.messages { flex: 1; overflow-y: auto; padding: 14px 16px 24px; }
.message {
  position: relative;
  margin-bottom: 12px;
  padding: 12px 13px 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(52,35,23,.07);
}
.message.user, .message.character { background: var(--bg-input); }
.message-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.message-author { color: var(--accent-color); font-weight: 700; }
.message-time { color: var(--text-muted); font: 10px "Inter", sans-serif; }
.message-content { font-size: 15px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-image-link { display: block; width: fit-content; margin-top: 9px; }
.message-image { display: block; max-width: 250px; max-height: 320px; object-fit: contain; border-radius: 8px; }
.message.user .message-author { color: var(--accent-color); }
.reasoning-toggle { margin-top: 7px; padding: 4px 7px; color: var(--text-muted); border-color: var(--border-color); background: transparent; font-size: 11px; }
.message-actions { position: absolute; right: 9px; bottom: 7px; display: flex; gap: 3px; opacity: 0; pointer-events: none; transition: opacity .16s ease; }
.message:hover .message-actions, .message:focus-within .message-actions { opacity: 1; pointer-events: auto; }
.message-action { display: grid; width: 25px; height: 25px; padding: 5px; place-items: center; color: var(--text-muted); background: transparent; border-color: transparent; border-radius: 4px; }
.message-action:hover { color: var(--text-main); }
.message-action.delete:hover { color: #c84d45; }
.message-action svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.message.removing { opacity: 0; transform: translateY(-5px); transition: opacity .2s ease, transform .2s ease; }
.reasoning-body { margin-top: 7px; padding: 8px; color: var(--text-muted); background: var(--bg-modal); border-left: 2px solid var(--accent-color); white-space: pre-wrap; font-size: 12px; }
.empty { padding: 30px 10px; color: var(--text-muted); text-align: center; }
.streaming .message-content::after { content: "▋"; color: var(--accent-color); animation: blink .8s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.settings-panel {
  position: fixed;
  z-index: 100;
  top: 0;
  right: 0;
  width: min(430px, 100%);
  height: 100%;
  overflow-y: auto;
  background: #f7efdf;
  box-shadow: var(--shadow);
}
.settings-panel.hidden, .hidden { display: none; }
.settings-section { padding: 16px 18px 21px; border-bottom: 1px solid var(--line); }
.settings-section h2 { margin: 0 0 12px; font-size: 17px; }
.settings-section label { display: block; margin: 0 0 11px; color: #66513e; font-size: 12px; }
.settings-section label input, .settings-section label textarea, .settings-section label select { margin-top: 5px; }
.settings-section select {
  width: 100%;
  padding: 9px 10px;
  color: var(--ink);
  background: rgba(255, 252, 242, .92);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.settings-section .check { display: flex; align-items: center; gap: 8px; }
.settings-section .check input { width: auto; margin: 0; }
.settings-section .field-hint { display: block; margin: -5px 0 11px; color: #8a7561; line-height: 1.4; }
.voice-settings { margin: 0 0 13px; padding: 12px 12px 3px; border: 1px solid var(--line); border-radius: 5px; }
.voice-settings legend { padding: 0 5px; color: #604834; font-size: 13px; font-weight: 700; }
.provider-actions { margin: -3px 0 10px; }
.selected-providers { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.selected-provider { display: inline-flex; align-items: center; gap: 7px; padding: 6px 8px; color: #5d4634; background: #eadcc3; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }
.selected-provider button { padding: 0; color: #8b241c; background: transparent; border: 0; }
.catalog-details { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; max-width: 720px; margin: -4px 0 12px; overflow: hidden; background: var(--border-color); border: 1px solid var(--border-color); border-radius: 3px; }
.catalog-metric { min-width: 0; padding: 9px 10px; background: var(--bg-input); }
.catalog-metric span, .catalog-metric strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catalog-metric span { margin-bottom: 3px; color: var(--text-muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.catalog-metric strong { color: var(--text-main); font-size: 12px; font-weight: 600; }
.section-title { justify-content: space-between; }
.section-title button { color: #66513e; border-color: var(--line); background: transparent; }
.button-row { gap: 8px; }
.empty-note { padding: 12px; color: #88715b; border: 1px dashed var(--line); }

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: 92px;
  max-width: min(480px, 90%);
  padding: 11px 15px;
  transform: translateX(-50%);
  color: white;
  background: #33261d;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 5px;
  box-shadow: var(--shadow);
  font-family: "Inter", sans-serif;
  font-size: 13px;
}
.mobile-only { display: none; }

@media (max-width: 850px) {
  .workspace { position: relative; grid-template-columns: 1fr; }
  .log-panel {
    position: fixed;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    resize: none;
    border: 0;
    border-radius: 0;
  }
  .log-panel.mobile-hidden { display: none; }
  .log-panel .panel-head { cursor: default; touch-action: auto; }
  .message-actions { opacity: 1; pointer-events: auto; }
  .mobile-only { display: inline-block; }
  .speech { width: calc(100% - 28px); min-width: 0; padding: 14px 15px 12px; }
  .characters, .character-names { left: 0; right: 0; bottom: 18%; }
  .characters .character, .character-names .character-name-anchor { min-width: 48px; min-height: 82px; }
  .character-names .character-name { max-width: 90px; padding: 3px 6px; font-size: 10px; }
}

@media (max-width: 520px) {
  .composer #send { min-height: 40px; }
}

/* Compact game menu */
body { display: block; }
.workspace { width: 100%; height: 100%; }

.game-actions { position: fixed; z-index: 160; top: 12px; right: 12px; display: flex; gap: 8px; }
.game-action {
  display: grid; width: 42px; height: 42px; padding: 9px; place-items: center;
  color: #f8ecd7; background: rgba(20, 16, 13, .66); border: 1px solid rgba(255, 239, 207, .32);
  border-radius: 4px; box-shadow: 0 7px 22px rgba(0, 0, 0, .28), inset 0 0 0 1px rgba(255, 255, 255, .04);
  backdrop-filter: blur(8px);
}
.game-action svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.game-action:hover { color: white; background: rgba(255, 255, 255, .13); border-color: rgba(255, 255, 255, .42); }
.game-action.active { color: #c7d2fe; background: rgba(20, 16, 13, .66); border-color: #818cf8; }
.log-panel { top: 66px; height: calc(100vh - 80px); }

.settings-overlay {
  position: fixed; z-index: 300; inset: 0; display: grid; padding: 24px; place-items: center;
  background: rgba(9, 7, 6, .76); backdrop-filter: blur(5px);
}
.seating-overlay {
  position: fixed; z-index: 290; inset: 0; display: grid; padding: 24px; place-items: center;
  background: rgba(9, 7, 6, .76); backdrop-filter: blur(5px);
}
.seating-overlay.hidden { display: none; }
.seating-modal {
  width: min(760px, 100%); overflow: hidden; color: var(--text-main); background: var(--bg-modal);
  border: 1px solid var(--border-color); border-radius: 6px; box-shadow: 0 30px 90px rgba(0, 0, 0, .68);
}
.seating-head {
  min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px; border-bottom: 1px solid var(--border-color);
}
.seating-head strong, .seating-head small { display: block; }
.seating-head strong { margin-bottom: 4px; font-size: 20px; }
.seating-head small { color: var(--text-muted); font-size: 11px; }
.seating-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding: 20px; }
.seating-slot { position: relative; min-width: 0; aspect-ratio: 1; }
.seating-summary {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 12px; color: var(--text-muted); background: var(--bg-input);
  border: 1px dashed var(--border-color); border-radius: 5px;
}
.seating-slot.occupied .seating-summary { color: var(--text-main); border-style: solid; }
.seating-summary img { width: 70%; height: 68%; object-fit: contain; object-position: center bottom; }
.seating-summary strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.seating-summary span { font-size: 32px; font-weight: 600; }
.seating-picker {
  position: absolute; z-index: 2; left: 6px; right: 6px; bottom: 6px; width: calc(100% - 12px);
  padding: 7px; color: var(--text-main); background: var(--bg-modal);
  border: 1px solid var(--accent-color); border-radius: 3px;
}
.character-context-menu {
  position: fixed; z-index: 400; min-width: 142px; padding: 5px; color: var(--text-main);
  background: var(--bg-modal); border: 1px solid var(--border-color); border-radius: 5px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .48); font-family: "Inter", sans-serif;
}
.character-context-menu button {
  width: 100%; padding: 9px 11px; color: var(--text-main); background: transparent;
  border: 0; border-radius: 3px; text-align: left; font-size: 12px;
}
.character-context-menu button:hover, .character-context-menu button:focus-visible { background: var(--bg-hover); }
.inventory-modal { max-height: calc(100vh - 48px); display: grid; grid-template-rows: auto minmax(0, 1fr); }
.inventory-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px;
  max-height: min(620px, calc(100vh - 150px)); padding: 20px; overflow-y: auto;
  scrollbar-color: var(--border-color) var(--bg-input); scrollbar-width: thin;
}
.inventory-item {
  min-width: 0; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; padding: 12px; color: var(--text-main); background: var(--bg-input);
  border: 1px solid var(--border-color); border-radius: 5px;
}
.inventory-item:hover { background: var(--bg-hover); border-color: var(--accent-color); }
.inventory-item.active { border-color: var(--accent-color); box-shadow: inset 0 0 0 1px var(--accent-color); }
.inventory-item img { width: 76%; height: 70%; object-fit: contain; }
.inventory-item strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.inventory-remove-icon { display: grid; height: 70%; place-items: center; color: var(--text-muted); font-size: 48px; font-weight: 300; }
.settings-overlay.hidden, .hidden { display: none; }
.settings-modal {
  position: relative; width: min(65vw, 1040px); min-width: 680px; height: min(72vh, 780px); min-height: 500px;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr); overflow: hidden; color: var(--text-main);
  background: var(--bg-modal);
  border: 1px solid var(--border-color); border-radius: 6px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .68), inset 0 0 0 1px rgba(255, 255, 255, .025);
  font-family: "Inter", sans-serif;
}
.settings-modal::before { position: absolute; z-index: 2; top: 0; left: 0; width: 26%; height: 2px; content: ""; background: var(--accent-color); }
.settings-modal .settings-head { min-height: 70px; padding: 15px 20px 13px 24px; background: var(--bg-modal); border-bottom-color: var(--border-color); }
.settings-modal .settings-head strong { color: var(--text-main); font-size: 21px; font-weight: 600; letter-spacing: .02em; }
.settings-modal .settings-head small { color: var(--text-muted); letter-spacing: .08em; text-transform: uppercase; }
.modal-close { width: 36px; height: 36px; padding: 0 0 3px; color: var(--text-muted); background: transparent; border-color: var(--border-color); border-radius: 3px; font: 25px/1 "Inter", sans-serif; }
.modal-close:hover { color: var(--text-main); background: var(--bg-hover); filter: none; }

.settings-tabs { display: grid; grid-template-columns: repeat(4, 1fr); padding: 0 20px; background: var(--bg-modal); border-bottom: 1px solid var(--border-color); }
.settings-tab { position: relative; margin-bottom: -1px; padding: 13px 10px 11px; color: var(--text-muted); background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }
.settings-tab:hover { color: var(--text-main); background: var(--bg-hover); filter: none; }
.settings-tab.active { color: var(--accent-color); background: var(--bg-modal); border-bottom-color: var(--accent-color); }
.settings-content { min-height: 0; overflow-y: auto; scrollbar-color: var(--border-color) var(--bg-input); scrollbar-width: thin; }
.settings-modal .settings-section { display: none; padding: 24px 28px 32px; border: 0; }
.settings-modal .settings-section.active { display: block; }

.section-intro { display: flex; align-items: center; gap: 13px; margin-bottom: 23px; }
.section-intro > span { color: var(--accent-color); font: 11px/1 "Inter", sans-serif; letter-spacing: .12em; }
.section-intro h2 { margin: 0 0 4px; color: var(--text-main); font: 600 20px/1.1 "Inter", sans-serif; }
.section-intro p { margin: 0; color: var(--text-muted); font-size: 11px; }
.section-intro.section-title > button { margin-left: auto; }
.settings-modal .settings-section label { margin-bottom: 14px; color: var(--text-muted); font-size: 11px; font-weight: 600; letter-spacing: .04em; }
.settings-modal input, .settings-modal textarea, .settings-modal select { padding: 9px 10px; color: var(--text-main); background: var(--bg-input); border-color: var(--border-color); border-radius: 3px; font-family: "Inter", sans-serif; }
.settings-modal input:focus, .settings-modal textarea:focus, .settings-modal select:focus { border-color: var(--accent-color); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-color) 18%, transparent); }
.settings-modal select option { color: var(--text-main); background: var(--bg-input); }
.settings-modal button:not(.settings-tab):not(.modal-close) { color: var(--text-main); background: var(--bg-input); border-color: var(--border-color); border-radius: 3px; font-size: 12px; }
.settings-modal button:not(.settings-tab):not(.modal-close):hover { background: var(--bg-hover); filter: none; }
.settings-modal button.primary { color: white !important; background: var(--accent-color) !important; border-color: var(--accent-color) !important; }
.settings-modal button.primary:hover { background: color-mix(in srgb, var(--accent-color) 88%, white) !important; }
.settings-modal button.danger { color: #ef4444 !important; background: transparent !important; border-color: #ef4444 !important; }

.form-grid { display: grid; gap: 0 14px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.settings-divider { height: 1px; margin: 22px 0; background: var(--border-color); }
.model-form > button, .model-form > label, .model-form > small { max-width: 720px; }
.settings-modal .check { display: flex; align-items: center; gap: 8px; }
.settings-modal .check input { width: auto; margin: 0; accent-color: var(--accent-color); }
.settings-modal input[type="range"] { padding: 0; accent-color: var(--accent-color); }
.settings-modal .field-hint { color: var(--text-muted); }
.settings-modal .voice-settings { margin: 5px 0 17px; padding: 14px 15px 4px; border-color: var(--border-color); border-radius: 3px; }
.settings-modal .voice-settings legend { color: var(--text-main); }
.settings-modal .empty-note { color: var(--text-muted); border-color: var(--border-color); }
.settings-modal .selected-provider { color: var(--text-main); background: var(--bg-input); border-color: var(--border-color); }
.form-actions { margin-top: 8px; }

.sound-option { display: flex; min-height: 72px; align-items: center; gap: 12px; margin-bottom: 10px; padding: 14px 18px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; }
.sound-option > div { flex: 1; }
.sound-option strong, .sound-option small { display: block; }
.sound-option strong { margin-bottom: 4px; color: var(--text-main); font-size: 13px; }
.sound-option small { color: var(--text-muted); font-size: 11px; }
.switch { position: relative; width: 46px; height: 24px; flex: 0 0 auto; margin: 0 !important; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 20px; cursor: pointer; transition: .18s ease; }
.switch span::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; content: ""; background: var(--text-muted); border-radius: 50%; transition: .18s ease; }
.switch input:checked + span { background: var(--accent-color); border-color: var(--accent-color); }
.switch input:checked + span::after { transform: translateX(22px); background: white; }
.sound-levels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-top: 20px; }
.settings-modal .sound-slider { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 0; padding: 14px 16px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; }
.sound-slider span { color: var(--text-main); font-size: 12px; }
.sound-slider output { min-width: 29px; color: var(--accent-color); text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }
.settings-modal .sound-slider input { grid-column: 1 / -1; width: 100%; margin: 4px 0 0; }
.sound-slider:has(input:disabled) { opacity: .42; }

@media (max-width: 850px) {
  .settings-overlay { padding: 10px; }
  .settings-modal { width: 100%; min-width: 0; height: calc(100vh - 20px); min-height: 0; }
  .log-panel { top: 0; height: auto; }
}

@media (max-width: 560px) {
  .game-actions { top: 8px; right: 8px; }
  .game-action { width: 38px; height: 38px; padding: 8px; }
  .settings-overlay { padding: 0; }
  .settings-modal { height: 100%; border: 0; border-radius: 0; }
  .settings-modal .settings-head { min-height: 62px; padding-left: 16px; }
  .settings-tabs { padding: 0 4px; }
  .settings-tab { padding: 12px 3px; font-size: 10px; letter-spacing: .04em; }
  .settings-modal .settings-section { padding: 20px 16px 28px; }
  .two-columns, .three-columns { grid-template-columns: 1fr; }
  .catalog-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-intro { align-items: flex-start; }
  .section-intro.section-title { flex-wrap: wrap; }
  .section-intro.section-title > button { margin-left: 0; }
  .sound-levels { grid-template-columns: 1fr; }
  .seating-overlay { padding: 8px; }
  .seating-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: calc(100vh - 100px); padding: 12px; overflow-y: auto; }
  .inventory-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; }
  .seating-head { min-height: 68px; padding: 12px 14px; }
  .seating-head small { display: none; }
}

/* v45: start screen, lobby, auth modal, create-room modal, exit-room button */
.screen-overlay {
  position: fixed;
  z-index: 250;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0a0705;
  overflow-y: auto;
}
.screen-overlay::before {
  content: "";
  position: fixed;
  inset: -6%;
  background: url("/static/assets/backgrounds/phon.png") center/cover no-repeat;
  filter: blur(7px) saturate(108%);
  z-index: -2;
  pointer-events: none;
}
.screen-overlay::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  z-index: -1;
  pointer-events: none;
}
.screen-overlay.hidden { display: none; }
.screen-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 32px 28px 30px;
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
  text-align: center;
}
.screen-card h1 {
  margin: 0;
  color: var(--text-main);
  font-size: 28px;
  letter-spacing: .04em;
}
.app-logo {
  position: absolute;
  bottom: calc(100% + 56px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  white-space: nowrap;
  font-family: "Unbounded", "Inter", sans-serif;
  font-weight: 800;
  font-size: 54px;
  line-height: 1;
  letter-spacing: .02em;
  text-align: center;
  color: #ffffff;
  -webkit-text-stroke: 3px #6366f1;
  paint-order: stroke fill;
  text-shadow: 0 0 2px #6366f1, 0 0 4px #6366f1;
}
.screen-stack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(420px, 100%);
}
.screen-tagline {
  margin: -8px 0 6px;
  color: var(--text-muted);
  font-size: 13px;
}
.screen-field {
  display: grid;
  gap: 6px;
  text-align: left;
  color: var(--text-muted);
  font-size: 12px;
}
.screen-field input {
  width: 100%;
  padding: 9px 10px;
  color: var(--text-main);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 5px;
}
.screen-field input:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.screen-button {
  width: 100%;
  padding: 11px;
  color: var(--text-main);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  font-size: 14px;
}
.screen-button.primary {
  color: white;
  background: var(--accent-color);
  border-color: var(--accent-color);
}

.overlay-modal {
  position: fixed;
  z-index: 310;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 7, 6, .76);
  backdrop-filter: blur(5px);
}
.overlay-modal.hidden { display: none; }
.modal-card {
  width: min(360px, 100%);
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 16px;
}
.modal-body {
  display: grid;
  gap: 12px;
  padding: 18px;
}
.modal-body label {
  display: grid;
  gap: 5px;
  color: var(--text-muted);
  font-size: 12px;
}
.modal-body input {
  width: 100%;
  padding: 9px 10px;
  color: var(--text-main);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 5px;
}
.modal-body button {
  width: 100%;
  padding: 11px;
  border-radius: 5px;
}

.lobby-layout {
  width: min(900px, 100%);
  height: min(560px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.lobby-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 18px;
}
.lobby-head strong {
  flex: 1;
}
.lobby-back {
  padding: 7px 12px;
  color: var(--text-main);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 5px;
}
.rooms-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  gap: 10px;
  align-content: start;
  scrollbar-color: var(--border-color) var(--bg-input);
  scrollbar-width: thin;
}
.rooms-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.room-card {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 7px;
  cursor: default;
}
.room-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.room-card-head strong {
  color: var(--text-main);
  font-size: 15px;
}
.room-card-badge {
  padding: 2px 9px;
  color: white;
  background: var(--accent-color);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.room-card-meta {
  color: var(--text-muted);
  font-size: 12px;
}

#workspace.hidden { display: none; }
.game-actions.hidden { display: none; }

.field-error {
  display: block;
  margin: -6px 0 6px;
  color: #ef4444;
  font-size: 12px;
  font-weight: 500;
}
.field-error.hidden { display: none; }
.overlay-modal input.invalid,
.screen-field input.invalid {
  border-color: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, .18);
}

.floating-toolbar {
  position: fixed;
  z-index: 260;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}
.floating-toolbar.hidden { display: none; }
.floating-toolbar .game-action svg { width: 21px; height: 21px; }
body:not(.light-theme) .theme-icon-sun { display: none; }
body.light-theme .theme-icon-moon { display: none; }

#settingsPanel.no-room .settings-tab[data-tab="base"],
#settingsPanel.no-room .settings-tab[data-tab="characters"],
#settingsPanel.no-room .settings-tab[data-tab="room"],
#settingsPanel.no-room .tab-panel[data-panel="base"],
#settingsPanel.no-room .tab-panel[data-panel="characters"],
#settingsPanel.no-room .tab-panel[data-panel="room"] {
  display: none !important;
}
#settingsPanel.no-room .settings-tabs {
  grid-template-columns: 1fr;
}

.context-saves-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}
.context-saves-form label { display: flex; flex-direction: column; gap: 6px; }
.context-saves-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}
.context-saves-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 16px 8px;
}
.context-save-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}
.context-save-item-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.context-save-item-info strong { font-size: 14px; color: var(--text-main); }
.context-save-item-info small { color: var(--text-muted); font-size: 11px; }
.context-saves-form .field-hint { color: var(--text-muted); }
.context-save-item-actions { display: flex; gap: 8px; flex-shrink: 0; }
.context-save-item-actions button {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-modal);
  color: var(--text-main);
  font-size: 12px;
  cursor: pointer;
}
.context-save-item-actions button:hover { background: var(--bg-hover); }
.context-save-item-actions button.context-save-delete {
  color: #c84d45;
  border-color: rgba(200, 77, 69, .5);
}
.context-save-item-actions button.context-save-delete:hover {
  background: rgba(200, 77, 69, .12);
}
