:root {
  color-scheme: dark;
  --bg: #080808;
  --panel: #141414;
  --panel-2: #1d1b1a;
  --line: #303030;
  --muted: #9a9a9a;
  --text: #f5f5f5;
  --soft: #c7c7c7;
  --accent: #ff3933;
  --accent-2: #ff5a4f;
  --blue: #2f86ff;
  --danger-bg: #351314;
  --radius: 8px;
  --sidebar: 248px;
  --topbar: 56px;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  display: flex; flex-direction: column;
  background: #101010; border-right: 1px solid var(--line); z-index: 50;
}
.brand {
  height: 54px; display: flex; align-items: center; gap: 4px;
  padding: 0 12px; border: 0; background: transparent; text-align: left;
}
.brand-rp { color: var(--accent); font-weight: 900; font-size: 23px; }
.brand-title { font-weight: 800; font-size: 15px; }
.version-pill { margin-left: auto; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: #dcdcdc; background: #1d1d1d; font-size: 11px; }
.side-tabs { display: grid; grid-template-columns: 1fr; border-bottom: 1px solid var(--line); }
.side-tabs button { height: 48px; border: 0; background: transparent; font-weight: 800; }
.side-tabs button.active { border-bottom: 2px solid #fff; }
.side-block { padding: 14px 10px; border-bottom: 1px solid #242424; }
.side-title { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.icon-button, .round-button, .avatar-button { border: 1px solid var(--line); background: #171717; border-radius: 8px; min-width: 34px; height: 34px; }
.icon-button:hover, .round-button:hover, .avatar-button:hover { border-color: #555; }
.side-list { display: grid; gap: 8px; overflow: auto; max-height: calc(100vh - 270px); }
.empty-text { color: var(--muted); font-size: 13px; margin: 8px 0; }
.room-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 8px; align-items: center; padding: 8px; border-radius: 8px; background: #161616; border: 1px solid transparent; }
.room-row:hover { border-color: #393939; }
.room-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #2a2422; display: grid; place-items: center; color: var(--accent); font-weight: 900; }
.room-name { font-size: 13px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.delete-room { border: 0; background: transparent; color: #aaa; padding: 5px; }
.live-panel { margin-top: auto; border-top: 1px solid var(--line); }
.live-panel h3 { margin: 0 0 8px; font-size: 13px; display: flex; justify-content: space-between; }
.live-user { display: flex; gap: 8px; align-items: center; padding: 8px; border: 1px solid #2a2a2a; border-radius: 8px; background: #171717; }
.live-avatar { width: 26px; height: 26px; border-radius: 50%; background: #3a2a55; display: grid; place-items: center; }
.side-balance { margin-top: auto; padding: 12px 8px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.7; }

.content-shell { grid-column: 2; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 40; height: var(--topbar); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: rgba(8,8,8,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.page-title { font-size: 18px; font-weight: 900; display: flex; gap: 10px; align-items: center; }
.back-button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: #111; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.avatar-button { width: 36px; height: 36px; border-radius: 50%; color: #8c67ff; background: radial-gradient(circle at 50% 35%, #6545b8, #1b1628 70%); }
.profile-menu { position: fixed; top: 52px; right: 14px; width: 260px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #1a1a1a; box-shadow: 0 18px 50px rgba(0,0,0,.5); z-index: 80; }
.profile-menu h3 { margin: 0 0 10px; }
.menu-muted { color: var(--muted); font-size: 13px; }
.menu-stack { display: grid; gap: 10px; margin-top: 14px; }
.check-row { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: #171717; }

.view-root { flex: 1; min-width: 0; }
.view-container { width: min(100%, 1180px); margin: 0 auto; padding: 28px 36px 90px; }
.panel { border: 1px solid var(--line); border-radius: 8px; background: linear-gradient(180deg, #151515, #101010); padding: 20px; }
.api-panel { display: grid; gap: 12px; }
.field-label { display: block; color: #b9c8ff; font-size: 12px; font-weight: 800; margin-bottom: 7px; }
.field, .textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #050505;
  min-height: 44px; padding: 0 14px; outline: none;
}
.field:focus, .textarea:focus, select:focus { border-color: #666; }
.textarea { padding: 12px 14px; resize: vertical; min-height: 110px; line-height: 1.55; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > .grow { flex: 1 1 auto; }
.button { min-height: 42px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px; background: #171717; font-weight: 800; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.secondary { background: #fff; color: #111; border-color: #fff; }
.button.danger { background: var(--danger-bg); border-color: #703030; color: #ff8c84; }
.button.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.hint { color: var(--muted); font-size: 13px; }
.warning-text { color: var(--accent-2); font-size: 13px; font-weight: 800; }
.hero { margin-top: 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: linear-gradient(135deg, #2b2422, #151515); }
.hero h1 { margin: 0 0 8px; font-size: 26px; }
.library-head { display: flex; align-items: center; justify-content: space-between; margin: 30px 0 14px; }
.library-head h2 { margin: 0; font-size: 22px; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0 10px; }
.chip { border: 1px solid #444; border-radius: 999px; background: transparent; padding: 10px 16px; font-weight: 800; white-space: nowrap; }
.chip.active { background: var(--accent); border-color: var(--accent); }
.notice { border: 1px solid #5a2929; background: #2b1212; color: #ffd9d6; padding: 14px 16px; border-radius: 8px; margin: 16px 0; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 20px; }
.story-card { min-width: 0; }
.story-cover { width: 100%; aspect-ratio: 3 / 4; border-radius: 8px; background: #2a2523; border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); object-fit: cover; margin-bottom: 10px; }
.story-title { font-size: 15px; font-weight: 900; line-height: 1.35; min-height: 40px; }
.story-meta { color: var(--muted); font-size: 13px; margin: 6px 0; }
.story-actions { display: flex; gap: 6px; margin-top: 10px; }
.blurred { filter: blur(5px); pointer-events: none; user-select: none; opacity: .55; }

.builder { width: min(100%, 980px); margin: 0 auto; padding: 28px 28px 120px; }
.builder h1 { margin: 0 0 24px; font-size: 26px; }
.form-section { border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 16px; background: #101010; }
.form-section h2 { margin: 0 0 14px; font-size: 18px; }
.required::before { content: "* "; color: var(--accent); }
.form-grid { display: grid; gap: 14px; }
.profile-preview { white-space: pre-wrap; color: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #080808; }
.bottom-bar { position: fixed; left: var(--sidebar); right: 0; bottom: 0; min-height: 72px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 34px; background: rgba(8,8,8,.92); border-top: 1px solid var(--line); z-index: 70; backdrop-filter: blur(12px); }

.chat-page { height: calc(100vh - var(--topbar)); display: grid; grid-template-rows: 1fr auto; }
.chat-scroll { overflow-y: auto; padding: 32px 24px 22px; }
.chat-inner { width: min(100%, 820px); margin: 0 auto; display: grid; gap: 22px; }
.message { line-height: 1.8; white-space: pre-wrap; color: #ddd; }
.message.user { justify-self: end; background: #2b2b2b; border-radius: 999px; padding: 12px 18px; color: #fff; }
.suggestions { display: grid; justify-items: end; gap: 10px; }
.suggestion { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.suggestion button { border: 0; background: #2b2b2b; border-radius: 999px; padding: 11px 17px; font-weight: 800; }
.chat-compose { position: sticky; bottom: 0; padding: 14px 24px 18px; background: linear-gradient(180deg, transparent, #080808 22%); }
.compose-box { width: min(100%, 820px); margin: 0 auto; border: 1px solid var(--line); border-radius: 8px; background: #050505; display: grid; grid-template-columns: 1fr 46px; align-items: end; padding: 10px; }
.compose-box textarea { min-height: 42px; max-height: 180px; resize: none; border: 0; background: transparent; outline: none; padding: 10px; line-height: 1.45; }
.send-button { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 18px; }

.modal-backdrop { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.72); backdrop-filter: blur(9px); z-index: 1000; padding: 22px; }
.auth-modal { width: min(100%, 560px); max-height: calc(100vh - 44px); overflow: auto; border: 1px solid #3a3a3a; border-radius: 8px; background: #20201f; padding: 22px; box-shadow: 0 24px 80px rgba(0,0,0,.65); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 25px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; }
.tabs button { min-height: 44px; border: 1px solid var(--line); border-radius: 8px; background: #111; font-weight: 900; }
.tabs button.active { background: var(--accent); border-color: var(--accent); }
.auth-form { display: grid; gap: 12px; }
.password-line { display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 8px; }
.password-line .field { min-width: 0; height: 44px; }
.password-line .button { height: 44px; min-height: 44px; padding: 0 10px; white-space: nowrap; }
.code-line { display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, .9fr); gap: 8px; }
.terms { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 9px; background: #181818; }
.terms label { display: flex; gap: 8px; align-items: center; font-weight: 800; font-size: 13px; }
.link-button { border: 0; background: transparent; color: #ddd; text-decoration: underline; padding: 8px; font-weight: 800; }

#toast-root { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(760px, calc(100vw - 32px)); display: grid; gap: 10px; z-index: 20000; pointer-events: none; }
.toast { pointer-events: auto; border: 1px solid #86506a; background: #351522; color: #f5dce7; border-radius: 8px; padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 12px; max-height: 36vh; overflow: auto; white-space: pre-wrap; box-shadow: 0 18px 60px rgba(0,0,0,.45); }
.toast.info { border-color: #33658f; background: #102236; color: #d7ebff; }
.toast.success { border-color: #276b45; background: #10291c; color: #d8ffe7; }
.toast-actions { display: flex; gap: 6px; align-self: start; }
.toast-actions button { border: 1px solid rgba(255,255,255,.6); background: transparent; border-radius: 8px; padding: 6px 10px; font-weight: 800; }

@media (max-width: 760px) {
  :root { --sidebar: 0px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content-shell { grid-column: 1; }
  .view-container, .builder { padding-left: 18px; padding-right: 18px; }
  .bottom-bar { left: 0; }
  .row { flex-direction: column; align-items: stretch; }
  .code-line, .password-line { grid-template-columns: 1fr; }
}
