:root {
  color-scheme: dark;
  --bg: #000;
  --sidebar: rgba(8, 8, 12, 0.38);
  --sidebar-border: rgba(255, 255, 255, 0.12);
  --hover: rgba(255, 255, 255, 0.1);
  --active: rgba(255, 255, 255, 0.16);
  --composer: #2b2b2b;
  --composer-border: #3a3a3a;
  --text: #f4f4f4;
  --muted: #b4b4b4;
  --subtle: #7f7f7f;
  --line: #242424;
  --user-bubble: #303030;
  --learny-bubble: rgba(20, 20, 22, 0.86);
  --error: #ff6b6b;
  --ready: #d8d8d8;
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 0;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid #d8d8d8;
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  isolation: isolate;
}

.star-field {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #000;
  pointer-events: none;
  contain: paint;
}

.star-field::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 45%, transparent 0 42%, rgba(0, 0, 0, 0.42) 78%, rgba(0, 0, 0, 0.82) 100%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.44), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.44));
}

.star {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: rgba(255, 255, 255, var(--opacity));
  box-shadow: 0 0 var(--glow) rgba(210, 224, 255, var(--glow-opacity));
  opacity: var(--opacity);
  transform: translate3d(0, 0, 0);
  animation: starDrift var(--duration) linear var(--delay) infinite alternate;
  backface-visibility: hidden;
  will-change: transform;
}

.sidebar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 10px 8px;
  border-right: 1px solid var(--sidebar-border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.025)),
    var(--sidebar);
  box-shadow:
    inset -1px 0 rgba(255, 255, 255, 0.07),
    inset 0 1px rgba(255, 255, 255, 0.08),
    18px 0 60px rgba(0, 0, 0, 0.38);
  overflow: hidden;
  backdrop-filter: blur(34px) saturate(1.45);
  -webkit-backdrop-filter: blur(34px) saturate(1.45);
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: -40% -26%;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 255, 255, 0.12), transparent 0 18%, transparent 36%),
    radial-gradient(circle at 82% 72%, rgba(255, 255, 255, 0.055), transparent 0 38%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.085), transparent 45%, rgba(255, 255, 255, 0.035));
  filter: blur(22px);
  opacity: 0.64;
  pointer-events: none;
  transform: translate3d(0, 0, 0);
}

.sidebar > * {
  position: relative;
  z-index: 1;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 0 4px 2px 8px;
}

.sidebar-header strong {
  font-size: 1.3rem;
  font-weight: 700;
}

.sidebar-toggle,
.add-chat-button,
.send-button {
  display: inline-grid;
  place-items: center;
}

.sidebar-toggle {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.sidebar-toggle:hover,
.add-chat-button:hover {
  background: var(--hover);
}

.sidebar-nav {
  display: grid;
  gap: 2px;
}

.nav-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 0 9px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 120ms ease;
}

.nav-item:hover {
  background: var(--hover);
}

.nav-item.active {
  background: var(--active);
}

.nav-icon {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1;
}

.nav-item span:last-child {
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chats-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  margin-top: 8px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
}

.panel-heading p {
  margin: 0;
  color: var(--subtle);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
}

.add-chat-button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1;
}

.chat-search {
  position: relative;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 34px;
  margin: 0 5px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.105), rgba(255, 255, 255, 0.045)),
    rgba(255, 255, 255, 0.035);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.08),
    0 10px 30px rgba(0, 0, 0, 0.18);
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.chat-search:focus-within {
  border-color: rgba(255, 255, 255, 0.24);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06)),
    rgba(255, 255, 255, 0.055);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 12px 34px rgba(0, 0, 0, 0.22);
}

.chat-search-icon {
  position: relative;
  width: 13px;
  height: 13px;
  border: 1.7px solid var(--subtle);
  border-radius: 50%;
  opacity: 0.86;
}

.chat-search-icon::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: -4px;
  width: 6px;
  height: 1.7px;
  border-radius: 999px;
  background: var(--subtle);
  transform: rotate(45deg);
  transform-origin: left center;
}

.chat-search input {
  min-width: 0;
  height: 30px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.8rem;
}

.chat-search input::placeholder {
  color: rgba(180, 180, 180, 0.68);
}

.chat-search input::-webkit-search-cancel-button {
  appearance: none;
}

.chat-list {
  display: grid;
  align-content: start;
  gap: 2px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.chat-list,
.chat-log {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.chat-list::-webkit-scrollbar,
.chat-log::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.chat-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 3px 4px 3px 8px;
  border-radius: var(--radius);
  color: var(--muted);
}

.chat-item:hover,
.chat-item.active {
  background: rgba(255, 255, 255, 0.09);
}

.chat-open-button {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.chat-title {
  overflow: hidden;
  color: #e7e7e7;
  font-size: 0.79rem;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-meta {
  overflow: hidden;
  color: var(--subtle);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-chat-button {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: transparent;
  color: var(--subtle);
  opacity: 0;
  transform: translateX(4px);
  transition: opacity 140ms ease, transform 140ms ease, background 140ms ease, color 140ms ease;
}

.chat-item:hover .delete-chat-button,
.delete-chat-button:focus-visible {
  opacity: 1;
  transform: translateX(0);
}

.delete-chat-button:hover {
  background: rgba(255, 107, 107, 0.12);
  color: #ff8f8f;
}

.empty-chat-list {
  padding: 8px;
  color: var(--subtle);
  font-size: 0.78rem;
}

.main-area {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: transparent;
  isolation: isolate;
}

.top-bar,
.chat-panel {
  position: relative;
  z-index: 2;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.26);
  font-size: 0.76rem;
  backdrop-filter: blur(12px);
}

.connection-pill span {
  width: 9px;
  height: 9px;
  border: 1px solid #a8a8a8;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

.connection-pill.checking span {
  border-color: #a8a8a8;
  border-top-color: transparent;
}

.connection-pill.online span {
  border-color: #7edc89;
  background: #7edc89;
  box-shadow: 0 0 12px rgba(126, 220, 137, 0.5);
  animation: none;
}

.connection-pill.offline span {
  border-color: var(--error);
  background: transparent;
  box-shadow: 0 0 10px rgba(255, 107, 107, 0.42);
  animation: none;
}

.connection-pill strong {
  font-weight: 550;
}

.chat-panel {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.chat-log {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: min(820px, calc(100vw - 320px));
  min-height: 0;
  max-height: 100%;
  margin: 0 auto;
  padding: 42px 0 26px;
  padding-bottom: 22px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 40%;
  display: grid;
  width: min(680px, 100%);
  transform: translate(-50%, -50%);
  place-items: center;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.empty-state.hidden {
  opacity: 0;
}

.empty-state h1 {
  margin: 0;
  color: #f1f1f1;
  font-size: 3.22rem;
  font-weight: 500;
  line-height: 1.2;
}

.message {
  display: grid;
  gap: 6px;
  width: 100%;
  animation: messageIn 160ms ease both;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 16px;
  color: var(--subtle);
  font-size: 0.68rem;
}

.source {
  display: none;
}

.message.user .message-meta {
  justify-content: flex-end;
  padding-right: 4px;
}

.message.learny .message-meta {
  padding-left: 4px;
}

.bubble {
  max-width: min(680px, 76%);
  margin: 0;
  color: #f4f4f4;
  font-size: 0.95rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bubble-text,
.thought-time {
  display: block;
}

.message.user .bubble {
  justify-self: end;
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--user-bubble);
}

.message.learny .bubble {
  justify-self: start;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: var(--learny-bubble);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(12px);
}

.message.learny .thought-time {
  max-height: 0;
  margin-top: 0;
  color: var(--subtle);
  font-size: 0.72rem;
  line-height: 1.35;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-2px);
  transition: opacity 160ms ease, transform 160ms ease, max-height 160ms ease, margin-top 160ms ease;
}

.message.learny .bubble:hover .thought-time,
.message.learny .bubble:focus-within .thought-time {
  max-height: 24px;
  margin-top: 8px;
  opacity: 1;
  transform: translateY(0);
}

.message.typing .bubble {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 28px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ready);
  animation: typingDot 900ms ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 140ms;
}

.typing-dot:nth-child(3) {
  animation-delay: 280ms;
}

.composer-zone {
  width: min(760px, calc(100vw - 332px));
  margin: 0 auto 36px;
  flex: 0 0 auto;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 6px;
  min-height: 54px;
  padding: 6px 6px 6px 16px;
  border: 1px solid var(--composer-border);
  border-radius: 28px;
  background: var(--composer);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.send-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--text);
  font-size: 1rem;
}

.composer input {
  min-width: 0;
  height: 38px;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
}

.composer input::placeholder {
  color: #a7a7a7;
}

.send-button {
  background: #676767;
  color: #141414;
  font-weight: 850;
  transition: background 120ms ease, transform 120ms ease;
}

.send-button:hover {
  background: #f4f4f4;
}

.send-button:active {
  transform: scale(0.96);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

@keyframes typingDot {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  50% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

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

@keyframes starDrift {
  from {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(var(--travel-x), var(--travel-y), 0);
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .chat-log,
  .composer-zone {
    width: min(760px, calc(100vw - 28px));
  }

  .top-bar {
    padding: 0 14px;
  }
}

@media (max-width: 560px) {
  .main-area {
    grid-template-rows: 42px minmax(0, 1fr);
  }

  .empty-state {
    top: 36%;
  }

  .composer-zone {
    margin-bottom: 16px;
  }

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

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
