:root {
  color-scheme: dark;
  --ink: #111111;
  --ink-2: #171717;
  --panel: rgba(247, 247, 242, 0.91);
  --panel-strong: #ffffff;
  --line: rgba(255, 255, 255, 0.14);
  --line-dark: rgba(17, 17, 17, 0.12);
  --text: #f8faf7;
  --text-dark: #151515;
  --muted: #9ca3af;
  --muted-dark: #60646c;
  --green: #2ad49b;
  --green-dark: #0f7a5c;
  --amber: #f59e0b;
  --rose: #e85d75;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--ink);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  color: var(--text);
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #111111 0%, #181512 42%, #121a16 100%);
  background-size: 42px 42px, 42px 42px, auto;
}

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

button {
  cursor: pointer;
}

#sceneCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1440px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 0 2px 18px;
}

.brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.edge-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  max-width: 260px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #d1d5db;
  background: rgba(17, 17, 17, 0.72);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.icon-btn {
  min-width: 74px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(17, 17, 17, 0.72);
  font-size: 12px;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.control-panel,
.chat-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.control-panel {
  min-height: calc(100vh - 94px);
  padding: 16px;
}

.chat-panel {
  display: flex;
  min-height: calc(100vh - 94px);
  flex-direction: column;
  padding: 18px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.mode-btn {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  color: #d7ded9;
  background: transparent;
  font-size: 13px;
  font-weight: 800;
}

.mode-btn.active {
  color: #07120e;
  background: var(--green);
}

label {
  display: grid;
  gap: 8px;
  margin-top: 15px;
  color: #dfe7e2;
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  transition: border 0.2s, box-shadow 0.2s, background 0.2s;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 58px;
  max-height: 180px;
  resize: none;
  padding: 14px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(42, 212, 155, 0.76);
  box-shadow: 0 0 0 4px rgba(42, 212, 155, 0.14);
  background: rgba(0, 0, 0, 0.42);
}

.primary-btn,
.send-btn,
.stop-btn,
.prompt-row button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-btn,
.send-btn {
  color: #06110d;
  background: linear-gradient(135deg, var(--green), #a3e635);
}

.primary-btn {
  width: 100%;
  height: 44px;
  margin-top: 16px;
}

.provider-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.provider-box summary {
  color: #dfe7e2;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.provider-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.status {
  min-height: 44px;
  margin-top: 14px;
  padding: 11px 12px;
  border: 1px solid rgba(245, 158, 11, 0.22);
  border-radius: 8px;
  color: #fde68a;
  background: rgba(245, 158, 11, 0.1);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.status[data-type="error"] {
  border-color: rgba(232, 93, 117, 0.4);
  color: #fecdd3;
  background: rgba(232, 93, 117, 0.12);
}

.status[data-type="success"] {
  border-color: rgba(42, 212, 155, 0.36);
  color: #bbf7d0;
  background: rgba(42, 212, 155, 0.1);
}

.chat-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: 44px;
  line-height: 1.02;
  letter-spacing: 0;
}

.prompt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 0;
}

.prompt-row button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  color: #e5e7eb;
  background: rgba(255, 255, 255, 0.065);
  font-size: 12px;
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 360px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.message {
  width: fit-content;
  max-width: min(84%, 820px);
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
}

.message.user {
  align-self: flex-end;
  color: #07120e;
  background: var(--green);
}

.message.assistant {
  align-self: flex-start;
  color: var(--text-dark);
  background: var(--panel-strong);
}

.message.system {
  align-self: center;
  color: #d1d5db;
  background: rgba(255, 255, 255, 0.08);
  font-size: 13px;
}

.message strong {
  color: var(--green-dark);
}

.message em {
  color: var(--muted-dark);
}

.message code {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(17, 17, 17, 0.08);
  font-size: 0.92em;
  font-family: "SF Mono", "Fira Code", monospace;
}

.generated-image {
  display: block;
  width: min(100%, 520px);
  margin-top: 12px;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-width: 34px;
}

.typing i {
  width: 7px;
  height: 7px;
  background: var(--green-dark);
  animation: bounce 0.9s infinite alternate;
}

.typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing i:nth-child(3) {
  animation-delay: 0.3s;
}

.citations {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.citations.hidden {
  display: none;
}

.citations-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: #e5e7eb;
  font-size: 12px;
}

.citations-head span {
  color: var(--amber);
  font-weight: 800;
}

.citation-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.citation {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  min-height: 78px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #f3f4f6;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.18);
}

.citation-index {
  color: var(--green);
  font-weight: 800;
}

.citation-body {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.citation-body strong,
.citation-body small,
.citation-body em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-body strong {
  color: #ffffff;
  font-size: 12px;
}

.citation-body small {
  color: var(--amber);
  font-size: 11px;
}

.citation-body em {
  color: #d1d5db;
  font-size: 11px;
  font-style: normal;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 78px;
  gap: 10px;
  margin-top: 12px;
}

.send-btn,
.stop-btn {
  min-height: 58px;
  padding: 0 14px;
}

.stop-btn {
  color: #ffffff;
  background: var(--rose);
}

.stop-btn.hidden {
  display: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

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

@media (max-width: 980px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding: 12px 0;
  }

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

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

  .control-panel,
  .chat-panel {
    min-height: auto;
  }

  h1 {
    font-size: 34px;
  }

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

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

  .send-btn,
  .stop-btn {
    min-height: 46px;
  }
}
