:root {
  color-scheme: dark;
  --bg: #0c1116;
  --bg-soft: #121a22;
  --bg-elevated: #17212b;
  --text: #f5f7fa;
  --muted: #b4beca;
  --accent: #33d6a6;
  --accent-strong: #00b382;
  --warning: #f5a524;
  --danger: #ef5f6b;
  --line: rgba(255, 255, 255, 0.08);
  --glow: rgba(51, 214, 166, 0.2);
  --shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --font: "Sora", "Space Grotesk", "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", "Menlo", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 20% -10%, rgba(51, 214, 166, 0.18), transparent 60%),
    radial-gradient(900px 500px at 80% 0%, rgba(245, 165, 36, 0.15), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

.main {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 32px 0 64px;
}

.shell {
  background: linear-gradient(160deg, rgba(18, 26, 34, 0.8), rgba(18, 26, 34, 0.6));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

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

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

.brand img {
  width: 44px;
  height: 44px;
}

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.nav {
  display: flex;
  gap: 12px;
  position: relative;
  align-items: center;
}

.nav a {
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--muted);
  transition: all 0.2s ease;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(51, 214, 166, 0.1);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.avatar-menu {
  position: absolute;
  right: 0;
  top: 56px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-width: 180px;
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  padding: 8px;
  z-index: 30;
}

.avatar-menu.open {
  display: flex;
}

.avatar-menu button {
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: left;
  font-size: 0.95rem;
}

.avatar-menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.nav a.active,
.nav a:hover {
  color: var(--text);
  border-color: rgba(51, 214, 166, 0.5);
  box-shadow: 0 0 0 2px rgba(51, 214, 166, 0.15) inset;
}

.section-title {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.section-subtitle {
  margin: 0;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(18, 26, 34, 0.7);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

.status-dot.ready {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-top: 28px;
}

.chat-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  background: rgba(12, 17, 22, 0.8);
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 8px;
}

.message {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(18, 26, 34, 0.8);
  border: 1px solid var(--line);
}

.message.user {
  border-color: rgba(51, 214, 166, 0.35);
  box-shadow: 0 0 0 1px rgba(51, 214, 166, 0.2);
}

.message.tool {
  border-color: rgba(88, 161, 255, 0.35);
  box-shadow: 0 0 0 1px rgba(88, 161, 255, 0.2);
  background: rgba(12, 18, 28, 0.8);
}

.message.tool-call {
  border-color: rgba(245, 165, 36, 0.35);
  box-shadow: 0 0 0 1px rgba(245, 165, 36, 0.2);
  background: rgba(28, 20, 12, 0.75);
}

.message.tool-result {
  border-color: rgba(51, 214, 166, 0.35);
  box-shadow: 0 0 0 1px rgba(51, 214, 166, 0.2);
  background: rgba(12, 24, 20, 0.75);
}

.message .meta {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.message > p {
  margin: 8px 0 0;
  line-height: 1.5;
}

.markdown-body {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
  overflow-x: auto;
}

.markdown-body p {
  margin: 0 0 0.5rem 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 0.6rem 0 0.4rem;
}

.markdown-body pre {
  background: rgba(12, 18, 24, 0.85);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  overflow: auto;
}

.markdown-body code {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.85em;
  font-family: var(--mono);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  border: 1px solid var(--line);
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  background: rgba(18, 26, 34, 0.6);
}

.markdown-body thead th {
  background: rgba(51, 214, 166, 0.12);
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.35rem 0 0.35rem 1.2rem;
  padding-left: 1rem;
}

.tool-calls {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed rgba(255, 255, 255, 0.12);
  display: grid;
  gap: 10px;
}

.tool-calls-title {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tool-call-card {
  background: rgba(10, 14, 18, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.tool-call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tool-call-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.tool-call-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(51, 214, 166, 0.15);
  color: #6fe9c1;
  border: 1px solid rgba(51, 214, 166, 0.35);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tool-call-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tool-call-detail {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(14, 20, 26, 0.7);
  padding: 8px 10px;
}

.tool-call-section {
  border-color: rgba(88, 161, 255, 0.35);
  background: rgba(10, 22, 36, 0.7);
}

.tool-result-section {
  border-color: rgba(51, 214, 166, 0.35);
  background: rgba(12, 28, 22, 0.75);
}

.tool-call-summary {
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  list-style: none;
}

.tool-call-summary::-webkit-details-marker {
  display: none;
}

.tool-call-summary::after {
  content: '▸';
  display: inline-block;
  margin-left: 6px;
  transition: transform 0.2s ease;
}

.tool-call-detail[open] .tool-call-summary::after {
  transform: rotate(90deg);
}

.tool-call-pre {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cfe7dc;
}

.tool-event-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.tool-event-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.tool-event-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tool-event-badge.call {
  background: rgba(245, 165, 36, 0.18);
  color: #ffd18a;
  border: 1px solid rgba(245, 165, 36, 0.4);
}

.tool-event-badge.result {
  background: rgba(51, 214, 166, 0.18);
  color: #8ef4d1;
  border: 1px solid rgba(51, 214, 166, 0.4);
}

.tool-event-details {
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 14, 18, 0.7);
  padding: 8px 10px;
}

.tool-event-details.call {
  border-color: rgba(245, 165, 36, 0.35);
  background: rgba(36, 24, 12, 0.7);
}

.tool-event-details.result {
  border-color: rgba(51, 214, 166, 0.35);
  background: rgba(12, 26, 20, 0.7);
}

.tool-event-summary {
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  list-style: none;
}

.tool-event-summary::-webkit-details-marker {
  display: none;
}

.tool-event-summary::after {
  content: '▸';
  display: inline-block;
  margin-left: 6px;
  transition: transform 0.2s ease;
}

.tool-event-details[open] .tool-event-summary::after {
  transform: rotate(90deg);
}

.tool-event-pre {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cfe7dc;
}

.compose {
  margin-top: 20px;
  display: grid;
  gap: 12px;
}

textarea,
input,
select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.btn-row {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.95rem;
}

.btn-primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  color: #04110d;
  box-shadow: 0 12px 30px rgba(0, 179, 130, 0.3);
}

.linear-wipe {
  text-align: center;
  display: inline-block;
  background: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.9) 20%,
    rgba(51, 214, 166, 0.9) 40%,
    rgba(0, 179, 130, 0.9) 60%,
    rgba(255, 255, 255, 0.9) 80%
  );
  background-size: 200% auto;
  color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shine 1s linear infinite;
}

@keyframes shine {
  to {
    background-position: 200% center;
  }
}

.btn-primary.is-loading {
  opacity: 0.65;
  cursor: wait;
  box-shadow: none;
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.aside-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  background: rgba(18, 26, 34, 0.7);
  display: grid;
  gap: 16px;
}

.aside-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.aside-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(51, 214, 166, 0.12);
  color: var(--accent);
  font-size: 0.75rem;
  border: 1px solid rgba(51, 214, 166, 0.3);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.modal.open {
  display: flex;
}

.modal-card {
  width: min(620px, 95vw);
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 8px;
}

.modal-card p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.warning-box {
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245, 165, 36, 0.4);
  background: rgba(245, 165, 36, 0.08);
  padding: 12px;
  color: #fbd38d;
  font-size: 0.9rem;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-top: 16px;
}

.form-field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.list {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.tool-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(12, 17, 22, 0.7);
}

.tool-item h4 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.tool-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  transition: all 0.2s ease;
}

.slider::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.2s ease;
}

.toggle input:checked + .slider {
  background: rgba(51, 214, 166, 0.6);
}

.toggle input:checked + .slider::after {
  transform: translateX(18px);
}

.footer-note {
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  header {
    flex-direction: column;
    align-items: flex-start;
  }

  .grid {
    grid-template-columns: 1fr;
  }

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #04110d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1rem;
  text-transform: uppercase;
  margin-right: 4px;
  box-shadow: 0 0 10px rgba(51, 214, 166, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.1);
}
