:root {
  --bg: #050505;
  --panel: #202020;
  --panel-soft: #151515;
  --paper: #f3f1ec;
  --paper-2: #e5e1da;
  --text: #f8f5f0;
  --muted: #9a958b;
  --accent: #ffffff;
  --line: rgba(255, 255, 255, 0.08);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.06), transparent 24%),
    linear-gradient(180deg, #0b0b0b 0%, #040404 100%);
  color: var(--text);
  font-family: "Unbounded", sans-serif;
}

button, input, textarea, select {
  font: inherit;
}

button, select {
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 284px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #252525 0%, #1f1f1f 100%);
  border-right: 1px solid var(--line);
  padding: 18px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  transition: transform 0.25s ease;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 35;
}

body.sidebar-open .sidebar-overlay {
  opacity: 1;
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 2px 4px;
}

.burger {
  width: 42px;
  height: 42px;
  border: 0;
  background: transparent;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.global-burger {
  display: none;
  flex-shrink: 0;
}

.burger span {
  width: 24px;
  height: 2px;
  background: #fff;
  border-radius: 999px;
}

.brand-name {
  font-family: "Rubik Mono One", sans-serif;
  font-size: clamp(1.6rem, 4vw, 2rem);
  letter-spacing: 0.02em;
}

.menu {
  display: grid;
  gap: 12px;
}

.menu-card {
  border: 0;
  padding: 18px 20px;
  border-radius: 14px;
  background: var(--paper);
  color: #101010;
  font-weight: 800;
  font-size: 1.02rem;
  text-align: left;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.03);
}

.menu-card.ghost {
  background: #0c0c0c;
  color: #fff;
}

.menu-card.active {
  outline: 2px solid rgba(255, 255, 255, 0.15);
}

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

.access-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  width: 100%;
  overflow: hidden;
}

.access-code-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.access-code-row input {
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border-radius: 12px;
  padding: 10px 12px;
}

.mini-button {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--paper);
  color: #111;
  font-weight: 700;
}

.section-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 245px;
  overflow: auto;
  padding-right: 4px;
}

.history-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.chat-list-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-open-button {
  all: unset;
  display: block;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 0;
}

.chat-delete {
  all: unset;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: #ffb2b2;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  align-self: center;
}

.chat-delete:hover {
  color: #ffd8d8;
  background: rgba(255, 86, 86, 0.2);
}

.history-item strong,
.history-item span {
  display: block;
}

.history-item strong {
  font-size: 0.95rem;
}

.history-item span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.72rem;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  gap: 12px;
}

.topbar-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
}

.status-badge {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: #e5dfd3;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.view {
  display: none;
  flex: 1;
  padding: 0 28px 28px;
}

.view.active {
  display: flex;
  flex-direction: column;
}

.view-chat.active {
  min-height: 0;
  overflow: hidden;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  text-align: center;
  min-height: 32vh;
  animation: rise 0.55s ease;
}

.hero h1 {
  margin: 0;
  font-size: clamp(3rem, 5vw, 5.4rem);
  font-weight: 800;
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.chat-stream {
  width: min(920px, 100%);
  margin: 12px auto 0;
  display: grid;
  gap: 18px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  padding-bottom: 20px;
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(760px, 82vw);
  border-radius: 24px;
  padding: 18px 20px;
  position: relative;
}

.message.user .bubble {
  background: #656565;
  color: #fff;
  border-top-right-radius: 8px;
  font-weight: 700;
}

.message.assistant .bubble {
  background: transparent;
  border: 1px solid var(--line);
  border-top-left-radius: 8px;
  width: min(760px, 82vw);
  min-width: 0;
}

.assistant-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-weight: 700;
}

.assistant-head .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fff 0%, #bbb 100%);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.25);
}

.assistant-body {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.message-body {
  color: inherit;
  min-width: 0;
  width: 100%;
}

.message-body h1,
.message-body h2,
.message-body h3,
.message-body p,
.message-body ul,
.message-body ol,
.message-body blockquote {
  margin: 0 0 12px;
}

.message-body ul,
.message-body ol {
  padding-left: 20px;
}

.message-body p,
.message-body li,
.message-body blockquote,
.message-body pre,
.message-body code,
.message-body strong,
.message-body em {
  word-break: break-word;
}

.assistant-json {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  overflow: auto;
}

.assistant-raw {
  display: grid;
  gap: 10px;
}

.assistant-raw-toggle {
  cursor: pointer;
  user-select: none;
  list-style: none;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.07);
  color: #ebe5dc;
  font-size: 0.74rem;
  width: fit-content;
}

.assistant-raw-toggle::-webkit-details-marker {
  display: none;
}

.message-body pre {
  margin: 14px 0 0;
  max-width: 100%;
}

.message-body code:not(pre code) {
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 8px;
}

.message-body blockquote {
  padding: 12px 14px;
  border-left: 3px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 14px;
  color: #e8e2d6;
}

.code-block {
  margin-top: 14px;
  background: #0d1117;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
}

.code-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-wrap: wrap;
}

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

.code-action {
  border: 0;
  border-radius: 10px;
  background: #f3f1ec;
  color: #111;
  padding: 8px 10px;
  font-size: 0.74rem;
  font-weight: 700;
}

.code-block pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: #edf2f7;
  max-width: 100%;
}

.code-block code {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  color: inherit;
  font-family: Consolas, "Courier New", monospace;
  white-space: pre;
}

.katex-display {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0 10px;
}

.katex {
  max-width: 100%;
}

.message-body .katex-display > .katex {
  display: inline-block;
  min-width: max-content;
}

.assistant-media,
.assistant-links,
.assistant-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.assistant-media img,
.assistant-media video,
.assistant-media audio {
  max-width: min(100%, 420px);
  border-radius: 18px;
  background: #111;
}

.assistant-link,
.meta-chip {
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.07);
  color: #ebe5dc;
  text-decoration: none;
  font-size: 0.74rem;
}

.composer-wrap {
  width: min(920px, 100%);
  margin: auto auto 0;
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding-top: 14px;
  padding-bottom: 4px;
  background:
    linear-gradient(180deg, rgba(5, 5, 5, 0) 0%, rgba(5, 5, 5, 0.82) 18%, rgba(5, 5, 5, 0.98) 100%);
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}

.settings-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-toggle {
  display: none;
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 700;
  justify-content: space-between;
  align-items: center;
}

.settings-panel {
  display: block;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  background: var(--paper);
  color: #111;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
}

.pill select,
.pill input {
  border: 0;
  background: transparent;
  min-width: 0;
  width: auto;
  font-weight: 700;
}

.composer {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, var(--paper) 0%, #efede7 100%);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.send-button {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 0;
  background: #fff;
  color: #111;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
}

.composer-field {
  flex: 1;
  min-width: 0;
}

.composer textarea {
  width: 100%;
  resize: none;
  border: 0;
  background: transparent;
  min-height: 42px;
  color: #111;
  font-weight: 700;
  outline: none;
}

.hint {
  margin: 10px 4px 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 24px;
  backdrop-filter: blur(12px);
}

.panel h2 {
  margin: 0;
  font-size: 1.5rem;
}

.panel-copy {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.history-content {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.history-card {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.history-card h3,
.history-card p {
  margin: 0;
}

.history-card p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.6;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
  }
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .global-burger {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    max-width: 340px;
    padding: 14px;
    gap: 16px;
    z-index: 40;
    transform: translateX(-100%);
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    pointer-events: auto;
  }

  .topbar,
  .view {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions,
  .topbar-main {
    justify-content: space-between;
  }

  .access-code-row {
    grid-template-columns: 1fr;
  }

  .access-code-row .mini-button {
    width: 100%;
  }

  .hero {
    min-height: 24vh;
  }

  .hero h1 {
    font-size: 2.5rem;
  }

  .settings-toggle {
    display: inline-flex;
    margin-bottom: 10px;
  }

  .settings-panel {
    display: none;
  }

  body.chat-settings-open .settings-panel {
    display: block;
  }

  .settings-row,
  .settings-inline {
    flex-direction: column;
    align-items: stretch;
  }

  .pill {
    width: 100%;
    justify-content: space-between;
  }

  .bubble {
    max-width: 100%;
  }
}
