:root {
  color-scheme: light;
  --bg: #ece7df;
  --paper: #fbf8f3;
  --panel: rgba(252, 249, 245, 0.9);
  --sidebar: #1f2520;
  --sidebar-line: rgba(255, 255, 255, 0.08);
  --ink: #1f1b18;
  --muted: #6c6259;
  --line: rgba(53, 38, 27, 0.12);
  --accent: #b95d2c;
  --accent-soft: rgba(185, 93, 44, 0.12);
  --sage: #425646;
  --shadow: 0 24px 60px rgba(34, 24, 17, 0.12);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background: linear-gradient(180deg, #efe9e1 0%, #e7ded4 100%);
  font-family: "IBM Plex Sans", "Noto Sans SC", "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.page-backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at top left, rgba(185, 93, 44, 0.14), transparent 28rem),
    radial-gradient(circle at bottom right, rgba(66, 86, 70, 0.14), transparent 24rem);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(480px, 100%);
  padding: 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-card .eyebrow {
  margin-bottom: 8px;
}

.auth-card h1,
.chat-header h2,
.empty-state h3,
.assistant-summary h3 {
  margin: 0;
  font-family: "IBM Plex Serif", "Source Han Serif SC", serif;
  letter-spacing: -0.02em;
}

.auth-card h1 {
  line-height: 1.18;
}

.auth-copy {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: center;
}

.auth-form,
.composer,
.context-grid,
.sidebar-actions {
  display: grid;
  gap: 16px;
}

.auth-form {
  margin-top: 24px;
  gap: 14px;
}

.auth-form .primary-button {
  margin-top: 2px;
}

.auth-form .status-text {
  margin: -2px 0 0;
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: center;
}

label {
  display: grid;
  gap: 8px;
}

label span,
.composer-field span {
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  padding: 14px 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

textarea {
  resize: vertical;
  min-height: 110px;
  font-family: "IBM Plex Mono", "Consolas", monospace;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(185, 93, 44, 0.7);
  box-shadow: 0 0 0 4px rgba(185, 93, 44, 0.1);
  transform: translateY(-1px);
}

.primary-button,
.ghost-button,
.conversation-item {
  border: 0;
  border-radius: 16px;
}

.primary-button {
  padding: 14px 18px;
  color: #fff9f4;
  background: linear-gradient(135deg, #a64b20, #ce7341);
  box-shadow: 0 14px 28px rgba(166, 75, 32, 0.18);
}

.ghost-button {
  padding: 11px 14px;
  color: inherit;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}

.ghost-button.compact {
  padding: 8px 12px;
}

.status-text,
.muted {
  color: var(--muted);
}

.status-text:empty {
  display: none;
}

.workspace {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  color: #f0ece5;
  background:
    radial-gradient(circle at top, rgba(185, 93, 44, 0.18), transparent 14rem),
    linear-gradient(180deg, #1e241f 0%, #171c18 100%);
  border-right: 1px solid var(--sidebar-line);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.sidebar-top {
  display: grid;
  gap: 14px;
}

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

.conversation-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.conversation-item {
  width: 100%;
  padding: 14px;
  color: #f2ede6;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  display: grid;
  gap: 6px;
}

.conversation-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.conversation-item strong {
  font-size: 0.96rem;
}

.conversation-item p,
.conversation-item span,
.sidebar-empty span,
.profile-card p,
.message-head p {
  margin: 0;
  color: rgba(242, 237, 230, 0.7);
  font-size: 0.88rem;
}

.conversation-item.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 700;
}

.sync-badge.pending {
  color: #f7d4bd;
  background: rgba(185, 93, 44, 0.18);
}

.sync-badge.failed {
  color: #ffd6d1;
  background: rgba(170, 72, 63, 0.24);
}

.sidebar-empty,
.profile-card {
  padding: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px;
}

.sidebar-bottom {
  display: grid;
  gap: 14px;
}

.profile-card {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.profile-card strong {
  display: block;
}

.chat-pane {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 24px clamp(18px, 4vw, 38px);
  gap: 18px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.chat-header-main {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 14px;
  color: var(--sage);
  background: rgba(66, 86, 70, 0.12);
  border: 1px solid rgba(66, 86, 70, 0.14);
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
}

.pill.subtle {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(185, 93, 44, 0.16);
}

.pill.subtle.danger {
  color: #a94b42;
  background: rgba(169, 75, 66, 0.12);
  border-color: rgba(169, 75, 66, 0.16);
}

.empty-state {
  padding: 28px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid var(--line);
  border-radius: 24px;
}

.empty-state p {
  margin: 14px 0 0;
  max-width: 48rem;
  color: var(--muted);
  line-height: 1.8;
}

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

.message-card {
  max-width: 860px;
  min-width: 0;
  padding: 22px;
  border-radius: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.message-card.user {
  justify-self: end;
  width: min(100%, 760px);
  background: rgba(255, 255, 255, 0.88);
}

.message-card.assistant {
  justify-self: start;
  width: min(100%, 860px);
  background: rgba(251, 248, 243, 0.96);
}

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

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 700;
}

.user-avatar {
  color: #fff6f0;
  background: linear-gradient(135deg, #8f411b, #b85d2b);
}

.assistant-avatar {
  color: #f4efe7;
  background: linear-gradient(135deg, #32473a, #47614f);
}

.message-body,
.assistant-grid {
  min-width: 0;
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.message-body.compact {
  gap: 12px;
}

.assistant-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.user-section,
.assistant-section,
.snippet-shell,
.test-case {
  min-width: 0;
  padding: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(53, 38, 27, 0.09);
  border-radius: 18px;
}

.assistant-summary {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.assistant-reply {
  margin-top: 18px;
}

.reply-text {
  min-width: 0;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.8;
}

.reply-text :where(h1, h2, h3, h4, h5, h6, p, ul, ol, blockquote, hr) {
  margin: 0;
}

.reply-text > :where(h1, h2, h3, h4, h5, h6, p, ul, ol, blockquote, hr, pre, .code-block-shell) + :where(h1, h2, h3, h4, h5, h6, p, ul, ol, blockquote, hr, pre, .code-block-shell) {
  margin-top: 0.38rem;
}

.reply-text :where(h1, h2, h3, h4, h5, h6) {
  line-height: 1.35;
  font-weight: 700;
}

.reply-text h1 {
  font-size: 1.2rem;
}

.reply-text h2 {
  font-size: 1.12rem;
}

.reply-text h3,
.reply-text h4,
.reply-text h5,
.reply-text h6 {
  font-size: 1rem;
}

.reply-text :where(ul, ol) {
  padding-left: 1.05rem;
}

.reply-text li {
  margin: 0;
  line-height: 1.7;
}

.user-section .reply-text {
  line-height: 1.45;
}

.user-section .reply-text > :where(h1, h2, h3, h4, h5, h6, p, ul, ol, blockquote, hr, pre, .code-block-shell) + :where(h1, h2, h3, h4, h5, h6, p, ul, ol, blockquote, hr, pre, .code-block-shell) {
  margin-top: 0 !important;
}

.user-section .reply-text :where(h1, h2, h3, h4, h5, h6, p, ul, ol, li, blockquote, hr) {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

.user-section .reply-text :where(ul, ol) {
  padding-left: 0.95rem;
  margin-left: 0 !important;
}

.user-section .reply-text li + li {
  margin-top: 0 !important;
}

.user-section .reply-text h1,
.user-section .reply-text h2,
.user-section .reply-text h3,
.user-section .reply-text h4,
.user-section .reply-text h5,
.user-section .reply-text h6 {
  line-height: 1.2;
}

.reply-text pre {
  width: 100%;
  max-width: 100%;
  margin-top: 0;
  padding: 14px;
  color: #f4eee7;
  background: #181b19;
  border-radius: 16px;
  overflow: auto;
}

.reply-text code {
  padding: 0.15em 0.38em;
  background: rgba(24, 27, 25, 0.08);
  border-radius: 8px;
  font-family: "IBM Plex Mono", "Consolas", monospace;
  font-size: 0.94em;
}

.reply-text pre code {
  padding: 0;
  background: transparent;
}

.code-block-shell {
  position: relative;
  min-width: 0;
  max-width: 100%;
  margin: 0;
}

.code-copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  min-width: 54px;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: #f4eee7;
  background: rgba(255, 255, 255, 0.08);
  font: 600 0.78rem/1 "IBM Plex Sans", "Source Han Sans SC", sans-serif;
  cursor: pointer;
}

.code-copy-button:hover,
.code-copy-button.copied {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.16);
}

.pending-steps ul {
  margin: 0;
  padding-left: 18px;
}

.assistant-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.assistant-section h4,
.user-section h4,
.snippet-head h4,
.test-case h5 {
  margin: 0 0 10px;
}

.assistant-section p,
.assistant-section ul,
.test-case p {
  margin: 0;
}

.assistant-section ul {
  padding-left: 18px;
}

.message-card.assistant.pending {
  border-style: dashed;
}

.message-card.assistant.error {
  border-color: rgba(170, 72, 63, 0.2);
  background: rgba(255, 247, 245, 0.96);
}

.pending-shell {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(53, 38, 27, 0.09);
  border-radius: 18px;
}

.pending-copy strong,
.pending-copy p {
  display: block;
  margin: 0;
}

.pending-copy p {
  margin-top: 6px;
  color: var(--muted);
}

.pending-eta {
  display: inline-block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.loading-dots span {
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #a64b20, #ce7341);
  border-radius: 999px;
  animation: pulse-dot 1s infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.skeleton-grid {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.skeleton-grid span {
  display: block;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(216, 206, 194, 0.56) 0%,
    rgba(255, 255, 255, 0.92) 50%,
    rgba(216, 206, 194, 0.56) 100%
  );
  background-size: 220% 100%;
  animation: skeleton-shift 1.5s infinite linear;
}

.skeleton-grid span:nth-child(1) {
  width: 88%;
}

.skeleton-grid span:nth-child(2) {
  width: 96%;
}

.skeleton-grid span:nth-child(3) {
  width: 72%;
}

.error-panel {
  border-color: rgba(170, 72, 63, 0.16);
  background: rgba(255, 243, 240, 0.86);
}

.snippet-shell {
  margin-top: 18px;
  background: #171918;
  color: #f2eee7;
}

.snippet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "IBM Plex Mono", "Consolas", monospace;
  line-height: 1.6;
}

.test-case-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.composer {
  padding: 20px;
  background: rgba(252, 249, 245, 0.94);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  gap: 14px;
}

.composer-field {
  display: grid;
  gap: 10px;
}

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

.composer-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
  border-radius: 16px;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.composer-panel-head:hover {
  border-color: rgba(185, 93, 44, 0.28);
  background: rgba(255, 255, 255, 0.92);
  transform: translateY(-1px);
}

.composer-panel-title {
  font-size: 0.92rem;
  font-weight: 700;
}

.panel-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 0;
  line-height: 1;
  position: relative;
}

.panel-toggle::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid currentColor;
  transition: transform 220ms ease;
}

.composer-panel-body {
  display: block;
  overflow: hidden;
  max-height: 1000px;
  opacity: 1;
  transform: translateY(0);
  transition:
    max-height 260ms ease,
    opacity 180ms ease,
    transform 220ms ease;
}

.composer-panel.collapsed .composer-panel-body {
  max-height: 0;
  opacity: 0;
  transform: translateY(-6px);
}

.composer-panel.collapsed .panel-toggle::before {
  transform: rotate(180deg);
}

.composer textarea[name="problemStatement"] {
  min-height: 132px;
}

.composer textarea[name="code"] {
  min-height: 240px;
}

.composer textarea[name="notes"] {
  min-height: 120px;
}

.composer.compact textarea[name="problemStatement"] {
  min-height: 70px;
}

.composer.compact textarea[name="code"] {
  min-height: 110px;
}

.composer.compact textarea[name="notes"] {
  min-height: 68px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.composer-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.runtime-picker {
  position: relative;
}

.runtime-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-weight: 700;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.runtime-trigger:hover {
  border-color: rgba(185, 93, 44, 0.3);
  background: rgba(255, 255, 255, 0.94);
  transform: translateY(-1px);
}

.runtime-chevron {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid currentColor;
  transition: transform 180ms ease;
}

.runtime-trigger[aria-expanded="true"] .runtime-chevron {
  transform: rotate(180deg);
}

.runtime-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  z-index: 12;
  min-width: 132px;
  padding: 8px;
  background: rgba(252, 249, 245, 0.98);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 6px;
}

.runtime-menu[hidden] {
  display: none !important;
}

.runtime-option {
  width: 100%;
  padding: 10px 12px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 700;
}

.runtime-option:hover,
.runtime-option.active {
  border-color: rgba(185, 93, 44, 0.24);
  background: rgba(185, 93, 44, 0.12);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 30;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 14, 12, 0.42);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  padding: 28px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.mobile-only {
  display: none;
}

@keyframes pulse-dot {
  0%,
  80%,
  100% {
    transform: scale(0.75);
    opacity: 0.45;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes skeleton-shift {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -20% 0;
  }
}

@media (max-width: 1080px) {
  .assistant-grid,
  .test-case-grid {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 88vw);
    transform: translateX(-100%);
    transition: transform 180ms ease;
    z-index: 20;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-flex;
  }

  .chat-pane {
    padding: 18px;
  }

  .chat-header,
  .composer-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-buttons {
    width: 100%;
  }

  .runtime-picker,
  .runtime-trigger,
  #send-button {
    width: 100%;
  }

  .runtime-menu {
    left: 0;
    right: 0;
  }

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