:root {
  color-scheme: dark;
  --bg: #07080c;
  --bg-2: #10131a;
  --panel: rgba(18, 22, 31, 0.92);
  --panel-2: rgba(30, 35, 48, 0.86);
  --line: rgba(255, 255, 255, 0.11);
  --line-red: rgba(255, 67, 91, 0.42);
  --red: #ff435b;
  --red-2: #b9152e;
  --cyan: #63d6e8;
  --gold: #f2c15f;
  --text: #f4f7fb;
  --soft: #c6cedb;
  --muted: #8893a3;
  --ok: #7ce38b;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 67, 91, 0.08), transparent 260px),
    linear-gradient(90deg, rgba(99, 214, 232, 0.08), transparent 36%, rgba(242, 193, 95, 0.05)),
    var(--bg);
  letter-spacing: 0;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1500px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 18px 0 56px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 12px 0;
  background: rgba(7, 8, 12, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 260px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-red);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(185, 21, 46, 0.9), rgba(99, 214, 232, 0.16));
  color: #fff;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
  font-size: 12px;
}

.topnav {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.topnav a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--soft);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.03);
}

.topnav a.nav-auth {
  border-color: var(--line-red);
  color: var(--text);
  background: rgba(185, 21, 46, 0.22);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.45fr);
  gap: 14px;
  align-items: stretch;
  padding: 16px 0 14px;
}

.module-console,
.status-panel,
.panel,
.floating-chat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
}

.module-console {
  min-height: 460px;
  display: grid;
  align-content: space-between;
  gap: 22px;
  padding: clamp(22px, 4vw, 42px);
  border-color: rgba(255, 67, 91, 0.25);
}

.panel-head {
  display: grid;
  gap: 10px;
}

.panel-head.compact {
  gap: 6px;
}

.kicker {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 760px;
  color: var(--text);
  font-size: clamp(34px, 5vw, 68px);
  line-height: 1;
}

h2 {
  font-size: 20px;
}

p {
  color: var(--soft);
  line-height: 1.68;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.module-tile {
  min-height: 112px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
}

.module-tile.active,
.module-tile:hover,
.module-tile:focus-visible {
  border-color: var(--line-red);
  background: rgba(255, 67, 91, 0.12);
}

.module-tile strong,
.module-tile span {
  display: block;
}

.module-tile span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.assistant-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 39;
  width: 64px;
  height: 56px;
  border: 1px solid var(--line-red);
  border-radius: 999px;
  color: var(--text);
  background: linear-gradient(135deg, rgba(185, 21, 46, 0.95), rgba(18, 22, 31, 0.98));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  font-weight: 900;
  cursor: pointer;
}

.floating-chat {
  position: fixed;
  right: 22px;
  bottom: 88px;
  z-index: 40;
  width: min(420px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 132px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  overflow: hidden;
  transition: opacity 160ms ease, transform 160ms ease, visibility 160ms ease;
}

.floating-chat.is-closed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
}

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 67, 91, 0.08);
}

.chat-close {
  flex: none;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 0 9px;
  color: var(--soft);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  cursor: pointer;
}

.chat-log {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 14px;
  overflow: auto;
}

.message {
  display: grid;
  gap: 6px;
  max-width: 92%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.message.user {
  justify-self: end;
  border-color: rgba(99, 214, 232, 0.35);
  background: rgba(99, 214, 232, 0.09);
}

.message.pending {
  opacity: 0.72;
}

.message strong {
  font-size: 14px;
}

.message p {
  color: var(--soft);
  font-size: 14px;
}

.message small {
  color: var(--muted);
  line-height: 1.5;
}

.message-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.message-actions a {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
}

.ask-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.ask-box input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.24);
  outline: none;
}

.ask-box input:focus {
  border-color: var(--cyan);
}

.ask-box button,
.prompt-row button {
  min-height: 42px;
  border: 1px solid var(--line-red);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(185, 21, 46, 0.42);
  cursor: pointer;
}

.prompt-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.prompt-row.compact {
  padding: 0 12px 10px;
}

.prompt-row.compact button {
  min-height: 32px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.status-panel {
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.status-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.status-grid dt {
  color: var(--muted);
  font-size: 12px;
}

.status-grid dd {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr) minmax(260px, 0.55fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  padding: 18px;
}

.panel.wide {
  grid-column: span 2;
}

.workspace-shell {
  margin: 0 0 14px;
}

.auth-page {
  min-height: calc(100vh - 96px);
  display: grid;
  align-items: center;
  padding: 36px 0;
}

.auth-panel {
  width: min(720px, 100%);
  display: grid;
  gap: 16px;
  margin: 0 auto;
  border-color: rgba(255, 67, 91, 0.24);
}

.auth-panel h1 {
  max-width: 680px;
  font-size: clamp(34px, 5vw, 58px);
}

.auth-card.solo {
  width: min(520px, 100%);
}

.auth-switch {
  color: var(--muted);
  font-size: 13px;
}

.auth-switch a {
  color: var(--text);
  text-decoration-color: var(--line-red);
}

.auth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.action-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  color: var(--soft);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.04);
}

.action-button.primary {
  border-color: var(--line-red);
  color: var(--text);
  background: rgba(185, 21, 46, 0.36);
}

.workspace-standalone {
  display: grid;
  gap: 14px;
  padding-top: 16px;
}

.workspace-hero {
  min-height: 360px;
}

.workspace-panel {
  display: grid;
  gap: 14px;
  border-color: rgba(255, 67, 91, 0.22);
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.auth-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.auth-card input {
  min-width: 0;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 0 11px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.24);
  outline: none;
}

.auth-card input:focus {
  border-color: var(--cyan);
}

.auth-card button,
.workspace-account button,
.workspace-actions button {
  min-height: 38px;
  border: 1px solid var(--line-red);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(185, 21, 46, 0.36);
  cursor: pointer;
}

.workspace-private {
  display: grid;
  gap: 14px;
}

.workspace-account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.workspace-account h3 {
  margin: 4px 0;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.workspace-modules {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.workspace-module,
.character-row {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.workspace-module.ready {
  border-color: rgba(124, 227, 139, 0.42);
}

.workspace-module.locked {
  opacity: 0.74;
}

.workspace-module span,
.workspace-module small,
.character-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.workspace-characters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.auth-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.auth-status[data-level="ok"] {
  color: var(--ok);
}

.auth-status[data-level="error"] {
  color: var(--red);
}

.callback-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.callback-panel {
  width: min(680px, 100%);
}

.market-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.market-row {
  width: 100%;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.market-row:hover,
.market-row:focus-visible {
  border-color: var(--line-red);
}

.market-row strong,
.market-row small {
  display: block;
}

.market-row small {
  margin-top: 4px;
  color: var(--muted);
}

.market-row b {
  color: var(--gold);
  white-space: nowrap;
}

.knowledge-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 14px 0 0;
  list-style: none;
}

.knowledge-list li {
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.knowledge-list strong,
.knowledge-list span {
  display: block;
}

.knowledge-list span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.source-table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
}

.source-table th,
.source-table td {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.source-table th {
  width: 90px;
  color: var(--muted);
  font-weight: 700;
}

.source-table td {
  color: var(--soft);
  overflow-wrap: anywhere;
}

@media (max-width: 1180px) {
  .workbench,
  .section-grid {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  }

  .status-panel {
    grid-column: 1 / -1;
  }

  .panel.wide {
    grid-column: span 1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw - 20px, 760px);
    padding-bottom: 28px;
  }

  .topbar,
  .workbench,
  .section-grid {
    grid-template-columns: 1fr;
  }

  .topnav {
    justify-content: flex-start;
  }

  h1 {
    font-size: 36px;
  }

  .module-console,
  .floating-chat {
    min-height: auto;
  }

  .module-grid,
  .market-list,
  .auth-grid,
  .workspace-modules,
  .workspace-characters {
    grid-template-columns: 1fr;
  }

  .workspace-account {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-log {
    max-height: 430px;
  }

  .floating-chat {
    right: 10px;
    bottom: 76px;
    width: calc(100vw - 20px);
    height: min(560px, calc(100vh - 104px));
  }

  .assistant-launcher {
    right: 14px;
    bottom: 14px;
  }
}
