:root {
  color-scheme: light;
  --bg: #f7f6f3;
  --bg-soft: #f2efe9;
  --panel: #ffffff;
  --panel-soft: #fbfaf7;
  --stroke: rgba(19, 24, 33, 0.12);
  --stroke-strong: rgba(19, 24, 33, 0.2);
  --text: #141922;
  --muted: #5d6573;
  --accent: #dfb400;
  --accent-soft: rgba(223, 180, 0, 0.16);
  --accent-blue: #2f5ea8;
  --shadow: 0 14px 34px rgba(13, 17, 24, 0.08);
  --mono: "IBM Plex Sans", "Segoe UI", sans-serif;
  --serif: "Merriweather", "Iowan Old Style", "Palatino", serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  font-family: var(--serif);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(223, 180, 0, 0.09), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(47, 94, 168, 0.08), transparent 58%),
    linear-gradient(180deg, var(--bg), var(--bg-soft));
  overflow-x: hidden;
  overflow-y: hidden;
}

.bg-orb {
  position: fixed;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  filter: blur(65px);
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
}

.orb-1 {
  background: #eed28b;
  top: -170px;
  left: -160px;
}

.orb-2 {
  background: #b7cae8;
  bottom: -190px;
  right: -150px;
}

.glass {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px) saturate(118%);
}

.topbar {
  position: relative;
  z-index: 10;
  width: min(1480px, 96vw);
  margin: 14px auto 10px;
  padding: 12px 16px;
  border-radius: 16px;
  border-top: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-wrap {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: #fffaf0;
  display: grid;
  place-items: center;
}

.logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.title {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.08;
}

.tagline {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5f6674;
  text-decoration: none;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 8px 11px;
}

.nav-btn:hover {
  color: #273246;
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--stroke);
}

.nav-btn.active {
  color: #111722;
  border-color: rgba(223, 180, 0, 0.56);
  background: var(--accent-soft);
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1480px, 96vw);
  margin: 0 auto 14px;
  display: grid;
  gap: 14px;
  grid-template-columns: 320px minmax(0, 1fr);
  align-items: start;
  height: calc(100dvh - 102px);
}

.panel {
  border-radius: 18px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--stroke);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rooms-panel {
  position: relative;
  top: auto;
  max-height: none;
  height: 100%;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.panel-title {
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1.15;
}

.panel-subtitle {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.new-chat-btn {
  border: 1px solid rgba(223, 180, 0, 0.6);
  background: var(--accent-soft);
  color: #6f5300;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.new-chat-btn:hover {
  background: rgba(223, 180, 0, 0.24);
}

.glass-input {
  width: 100%;
  height: 40px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: #fff;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}

.glass-input:focus {
  outline: none;
  border-color: rgba(47, 94, 168, 0.38);
  box-shadow: 0 0 0 3px rgba(47, 94, 168, 0.12);
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
  max-height: none;
  flex: 1 1 auto;
  overflow: auto;
  padding-right: 2px;
}

.room-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.15s ease;
}

.room-card:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 94, 168, 0.32);
  box-shadow: 0 7px 16px rgba(14, 18, 24, 0.07);
}

.room-card.active {
  border-color: rgba(223, 180, 0, 0.72);
  background: linear-gradient(180deg, #fffdf4, #fffaf0);
  box-shadow: 0 9px 18px rgba(111, 83, 0, 0.12);
}

.room-title {
  font-size: 16px;
  line-height: 1.3;
  margin-bottom: 4px;
}

.room-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
}

.room-preview {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.4;
  color: #434c5b;
}

.chat-panel {
  min-width: 0;
  min-height: 0;
  max-height: none;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  overflow: hidden;
}

.chat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.breadcrumbs {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.chat-status {
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: #fff;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5c6472;
}

.chat-header {
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(251, 250, 247, 0.96));
  padding: 12px;
  min-height: 0;
}

.article-kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: #7a5d00;
  margin-bottom: 4px;
}

#room-title {
  font-size: clamp(22px, 2.1vw, 30px);
  line-height: 1.16;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.context-strip {
  display: grid;
  gap: 6px;
}

#context-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.context-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(20, 25, 34, 0.09);
  overflow: hidden;
}

.context-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #efcc4f);
  transition: width 0.25s ease;
}

.chat-stream {
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.66);
  padding: 12px;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  width: fit-content;
  max-width: min(86ch, 100%);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  padding: 10px 12px;
}

.message.assistant {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
  max-width: min(72ch, 100%);
  border-color: rgba(47, 94, 168, 0.28);
  background: linear-gradient(180deg, rgba(237, 244, 255, 0.96), rgba(245, 249, 255, 0.98));
}

.message.system {
  align-self: center;
  border-style: dashed;
  background: rgba(252, 248, 230, 0.96);
}

.message-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
}

.message-role {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: #5a6270;
}

.message-time {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  color: #697180;
}

.message-status {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #8a6400;
}

.message-body {
  font-size: 19px;
  line-height: 1.58;
  white-space: normal;
  word-break: break-word;
}

.message-body p {
  margin: 0 0 11px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.typing-caret {
  display: inline-block;
  margin-left: 2px;
  color: #2f5ea8;
  font-family: var(--mono);
  animation: lc-blink 0.9s steps(1, end) infinite;
}

@keyframes lc-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.message-body .chat-h {
  margin: 13px 0 8px;
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.25;
  color: #111722;
}

.message-body .chat-h2 {
  font-size: 21px;
}

.message-body .chat-h3 {
  font-size: 18px;
}

.message-body .chat-h4 {
  font-size: 16px;
}

.message-body .chat-list {
  margin: 0 0 11px 1.2em;
  padding-left: 0.2em;
}

.message-body .chat-list li {
  margin: 0 0 5px;
}

.message-body blockquote {
  margin: 0 0 11px;
  padding: 7px 11px;
  border-left: 3px solid rgba(47, 94, 168, 0.35);
  background: rgba(47, 94, 168, 0.08);
  border-radius: 8px;
  color: #2c394f;
}

.message-body code {
  font-family: var(--mono);
  font-size: 0.92em;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid rgba(19, 24, 33, 0.14);
  background: rgba(19, 24, 33, 0.06);
}

.message-body .chat-divider {
  border: 0;
  border-top: 1px solid rgba(19, 24, 33, 0.18);
  margin: 10px 0 12px;
}

.message-steps,
.message-terms {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.step-chip {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #4b5463;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: #fff;
  padding: 4px 8px;
}

.term-chip {
  font-family: var(--mono);
  font-size: 11px;
  color: #2f5ea8;
  border-radius: 999px;
  border: 1px solid rgba(47, 94, 168, 0.2);
  background: rgba(47, 94, 168, 0.08);
  padding: 4px 8px;
}

.message-sources {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sources-head {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5b6473;
}

.sources-legend {
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.45;
  color: #667080;
}

.sources-note {
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.45;
  color: #7a5d00;
}

.source-card {
  border: 1px solid var(--stroke);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.98);
  padding: 9px 10px;
}

.source-tier-a {
  border-color: rgba(47, 94, 168, 0.38);
}

.source-tier-b {
  border-color: rgba(47, 94, 168, 0.26);
}

.source-tier-c {
  border-color: var(--stroke);
}

.source-tier-d {
  border-color: rgba(137, 107, 0, 0.22);
  background: rgba(255, 252, 242, 0.98);
}

.source-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.source-link {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.source-link:hover .source-title {
  text-decoration: underline;
}

.source-icon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: rgba(19, 24, 33, 0.09);
}

.source-title {
  font-family: var(--mono);
  font-size: 12px;
  color: #2f5ea8;
}

.source-rank {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5a6270;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 3px 7px;
  background: #fff;
}

.source-meta {
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.source-badge {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #5a6270;
  border: 1px solid rgba(19, 24, 33, 0.12);
  border-radius: 999px;
  padding: 3px 7px;
  background: rgba(255, 255, 255, 0.94);
}

.source-badge-tier {
  color: #2f5ea8;
  border-color: rgba(47, 94, 168, 0.28);
  background: rgba(47, 94, 168, 0.08);
}

.source-badge-tier-a {
  color: #245286;
  border-color: rgba(36, 82, 134, 0.32);
  background: rgba(36, 82, 134, 0.09);
}

.source-badge-tier-b {
  color: #2f5ea8;
  border-color: rgba(47, 94, 168, 0.28);
  background: rgba(47, 94, 168, 0.08);
}

.source-badge-tier-c {
  color: #5a6270;
  border-color: rgba(19, 24, 33, 0.12);
  background: rgba(255, 255, 255, 0.94);
}

.source-badge-tier-d {
  color: #7a5d00;
  border-color: rgba(137, 107, 0, 0.3);
  background: rgba(255, 245, 214, 0.86);
}

.source-summary {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  color: #4a5362;
}

.composer {
  border-radius: 14px;
  border: 1px solid rgba(223, 180, 0, 0.3);
  background: rgba(255, 251, 241, 0.96);
  padding: 8px;
  gap: 6px;
}

.composer-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  align-items: end;
  gap: 8px;
}

#chat-input {
  width: 100%;
  resize: none;
  min-height: 46px;
  max-height: 220px;
  overflow-y: hidden;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.45;
}

#chat-input:focus {
  outline: none;
  border-color: rgba(47, 94, 168, 0.42);
  box-shadow: 0 0 0 3px rgba(47, 94, 168, 0.12);
}

#chat-input::placeholder {
  color: #717a89;
}

#send-btn {
  width: 46px;
  height: 46px;
  border-radius: 11px;
  border: 1px solid var(--stroke-strong);
  background: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.2s ease, background-color 0.2s ease;
}

#send-btn svg {
  width: 20px;
  height: 20px;
  fill: #566071;
}

#send-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(223, 180, 0, 0.7);
  background: #fffef9;
}

#send-btn:disabled,
#chat-input:disabled {
  opacity: 0.68;
  cursor: not-allowed;
}

.composer-note {
  font-family: var(--mono);
  font-size: 12px;
  color: #7a5d00;
}

.share-wrap {
  position: relative;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: #fff;
  color: #495362;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 10px;
  cursor: pointer;
}

.share-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.share-btn.shared {
  border-color: rgba(223, 180, 0, 0.75);
  color: #7a5d00;
}

.share-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 150px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.99);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 8;
}

.share-item {
  border: none;
  background: transparent;
  text-decoration: none;
  text-align: left;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: #3f4857;
  cursor: pointer;
}

.share-item:hover {
  background: rgba(19, 24, 33, 0.05);
}

.empty-state {
  padding: 14px;
  border-radius: 12px;
  border: 1px dashed rgba(19, 24, 33, 0.2);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.rooms-hint {
  margin-top: 4px;
  border-radius: 10px;
  border: 1px dashed rgba(19, 24, 33, 0.18);
  padding: 8px 10px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  color: #4f5867;
}

.rooms-hint.muted {
  color: var(--muted);
}

.older-hint {
  align-self: center;
  border-radius: 999px;
  border: 1px dashed rgba(19, 24, 33, 0.17);
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 9px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #596171;
}

.older-hint.loading {
  border-color: rgba(223, 180, 0, 0.5);
  color: #7a5d00;
}

@media (max-width: 1180px) {
  body {
    overflow-y: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .rooms-panel {
    order: 2;
    position: static;
    max-height: none;
    height: auto;
  }

  .rooms-list {
    max-height: 42vh;
    flex: 0 0 auto;
  }

  .chat-panel {
    order: 1;
    min-height: 78vh;
    height: auto;
  }
}

@media (max-width: 760px) {
  .topbar {
    width: min(96vw, 100%);
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 9px;
  }

  .brand {
    width: 100%;
  }

  .title {
    font-size: 32px;
  }

  .tagline {
    font-size: 11px;
  }

  .nav {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .nav-btn {
    font-size: 10px;
    padding: 6px 9px;
  }

  .layout {
    width: min(96vw, 100%);
    margin-bottom: 20px;
    gap: 10px;
  }

  .panel {
    padding: 12px;
    border-radius: 14px;
  }

  .chat-top {
    flex-wrap: wrap;
  }

  .chat-tools {
    width: 100%;
    justify-content: flex-end;
  }

  #room-title {
    font-size: 26px;
    -webkit-line-clamp: 3;
  }

  .chat-stream {
    padding: 10px;
    min-height: 320px;
  }

  .message,
  .message.user {
    max-width: 100%;
  }

  .message-body {
    font-size: 18px;
  }

  .composer-shell {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  #send-btn {
    width: 44px;
    height: 44px;
  }
}
