:root {
  --bg: #14161c;
  --panel: #1c1f27;
  --panel2: #252935;
  --line: #313646;
  --text: #e7e9ee;
  --muted: #9aa1b2;
  --accent: #ff6b4a;
  --accent2: #4ab3ff;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
body { display: grid; grid-template-columns: 290px 1fr; height: 100vh; }
body.chat-on { grid-template-columns: 290px 1fr 320px; }

#sidebar, #chat { background: var(--panel); overflow-y: auto; border-right: 1px solid var(--line); }
#chat { border-right: none; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
#chat[hidden] { display: none; }

.brand { display: flex; gap: 10px; align-items: center; padding: 14px 14px 8px; }
.brand .logo { font-size: 30px; }
.brand h1 { font-size: 17px; margin: 0; }
.brand small { color: var(--muted); font-size: 11px; }

section { padding: 8px 14px 12px; border-bottom: 1px solid var(--line); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 6px 0 8px; }
h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; opacity: 0.7; }

.scene-group-title { font-size: 11px; color: var(--muted); margin: 8px 0 4px; display: flex; align-items: center; gap: 6px; }
.badge { background: var(--panel2); border-radius: 8px; padding: 0 6px; font-size: 10px; }
.scene-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.scene-list li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; }
.scene-list li:hover { background: var(--panel2); }
.scene-list li.active { background: #33263a; outline: 1px solid var(--accent); }
.scene-list li small { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene-list li.empty { color: var(--muted); cursor: default; font-style: italic; }
.scene-list li.empty:hover { background: none; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.grid button { text-align: left; }
button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 8px; cursor: pointer; font: inherit; font-size: 12.5px;
}
button:hover { border-color: #4b5268; }
button.active { background: #3a2a2a; border-color: var(--accent); color: #fff; }
button:disabled { opacity: 0.5; cursor: wait; }

.slider { display: grid; grid-template-columns: 80px 1fr 40px; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.slider output { text-align: right; color: var(--text); }
input[type='range'] { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 8px; cursor: pointer; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; min-height: 16px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.hint.keys { line-height: 1.9; }
kbd {
  display: inline-block; min-width: 18px; padding: 0 4px; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; background: var(--panel2); font: 11px ui-monospace, monospace; text-align: center; color: var(--text);
}

#viewport { position: relative; overflow: hidden; }
#viewport canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
#hud {
  position: absolute; top: 12px; left: 14px; pointer-events: none; max-width: 60%;
  background: rgba(20, 22, 28, 0.62); padding: 8px 12px; border-radius: 10px; backdrop-filter: blur(4px);
}
#scene-title { font-size: 20px; font-weight: 700; }
#scene-desc { font-size: 13px; opacity: 0.9; }
.hint-bar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(20, 22, 28, 0.78);
  padding: 6px 14px; border-radius: 16px; font-size: 12px; pointer-events: none; max-width: 92%; text-align: center;
}
#stats { position: absolute; top: 12px; right: 14px; font: 11px ui-monospace, monospace; background: rgba(20, 22, 28, 0.7); padding: 4px 8px; border-radius: 6px; }
#toast {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff;
  padding: 8px 16px; border-radius: 8px; opacity: 0; transition: opacity 0.3s; pointer-events: none; font-weight: 600;
}
#toast.show { opacity: 1; }

#chat header { padding: 14px; border-bottom: 1px solid var(--line); }
#chat header h2 { margin: 0; }
#chat header small { color: var(--muted); font-size: 11px; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 8px 10px; border-radius: 10px; line-height: 1.4; font-size: 13px; max-width: 95%; white-space: pre-wrap; }
.msg.user { background: #2f3b57; align-self: flex-end; }
.msg.bot { background: var(--panel2); align-self: flex-start; }
.msg.error { background: #4a2323; }
.msg .load { margin-top: 6px; }
.msg.pending::after { content: ' ⏳'; }
#chat-form { padding: 10px 12px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
#chat-form .check { margin-top: 0; }
textarea {
  width: 100%; resize: vertical; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; font: inherit;
}
#chat-send { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

@media (max-width: 1100px) {
  body, body.chat-on { grid-template-columns: 250px 1fr; }
  #chat { position: fixed; right: 0; top: 0; bottom: 0; width: 300px; transform: translateX(270px); transition: transform 0.2s; z-index: 5; }
  #chat:hover, #chat:focus-within { transform: none; }
}
