:root {
  color-scheme: dark;
  --bg: #05070c;
  --panel: rgba(7, 11, 18, 0.48);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(255, 255, 255, 0.18);
  --line-bright: rgba(127, 255, 232, 0.38);
  --text: #f8fbff;
  --text-dark: #10141c;
  --muted: #aab6c8;
  --muted-dark: #566070;
  --cyan: #58f4ff;
  --mint: #2df4a8;
  --lime: #b6ff6a;
  --pink: #ff5bd7;
  --amber: #ffd166;
  --red: #ff5b73;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(88, 244, 255, 0.45) rgba(255, 255, 255, 0.08);
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.08);
}

*::-webkit-scrollbar-thumb {
  background: rgba(88, 244, 255, 0.45);
  border-radius: 999px;
}

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

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(88, 244, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(182, 255, 106, 0.055) 1px, transparent 1px),
    radial-gradient(circle at 20% 15%, rgba(88, 244, 255, 0.16), transparent 26%),
    radial-gradient(circle at 88% 30%, rgba(255, 91, 215, 0.14), transparent 24%),
    radial-gradient(circle at 48% 98%, rgba(182, 255, 106, 0.11), transparent 24%),
    #05070c;
  background-size: 48px 48px, 48px 48px, auto, auto, auto, auto;
}

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

button {
  cursor: pointer;
}

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

.light-ribbon {
  position: fixed;
  inset: auto -12vw 6vh -12vw;
  z-index: 0;
  height: 34vh;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(88, 244, 255, 0.18), rgba(182, 255, 106, 0.16), rgba(255, 91, 215, 0.12), transparent);
  filter: blur(26px);
  transform: rotate(-6deg);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  padding: 0 4px 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.brand::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 99px;
  background: var(--mint);
  box-shadow: 0 0 24px var(--mint), 0 0 44px var(--cyan);
}

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

.edge-pill,
.icon-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(5, 7, 12, 0.58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(4px);
}

.edge-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  max-width: 270px;
  padding: 0 13px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.icon-btn {
  min-width: 64px;
  height: 36px;
  font-size: 12px;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 350px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  perspective: 1400px;
}

.control-panel,
.chat-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.018)),
    var(--panel);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.11);
  backdrop-filter: saturate(130%) blur(4px);
}

.control-panel {
  height: calc(100dvh - 84px);
  min-height: 640px;
  overflow-y: auto;
  padding: 16px;
  transform: rotateY(2deg);
  transform-origin: right center;
}

.chat-panel {
  display: flex;
  height: calc(100dvh - 84px);
  min-height: 640px;
  flex-direction: column;
  padding: 18px;
  transform: rotateY(-1.1deg);
  transform-origin: left center;
  overflow: hidden;
}

.panel-kicker {
  margin-bottom: 12px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
}

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

.mode-btn {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: #dbe8f2;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.mode-btn.active {
  color: #04100e;
  background: linear-gradient(135deg, var(--cyan), var(--mint) 48%, var(--lime));
  box-shadow: 0 0 24px rgba(45, 244, 168, 0.26);
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  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, transform 0.2s;
}

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

select {
  cursor: pointer;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(88, 244, 255, 0.82);
  box-shadow: 0 0 0 4px rgba(88, 244, 255, 0.12), 0 0 24px rgba(45, 244, 168, 0.12);
  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: #04100e;
  background: linear-gradient(135deg, var(--cyan), var(--mint) 48%, var(--lime));
  box-shadow: 0 12px 36px rgba(45, 244, 168, 0.24);
}

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

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

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

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

.provider-note code {
  color: var(--cyan);
  font-family: "SF Mono", "Fira Code", monospace;
}

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

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--mint);
}

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

.status[data-type="error"] {
  border-color: rgba(255, 91, 115, 0.42);
  color: #ffd1d7;
  background: rgba(255, 91, 115, 0.12);
}

.status[data-type="success"] {
  border-color: rgba(45, 244, 168, 0.4);
  color: #caffde;
  background: rgba(45, 244, 168, 0.11);
}

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

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #edf7ff;
  font-size: 12px;
}

.history-head button,
.canvas-toolbar button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  font-size: 12px;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 7px;
  max-height: 240px;
  margin-top: 10px;
  overflow-y: auto;
}

.history-item {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 54px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  color: #eaf7ff;
  background: rgba(0, 0, 0, 0.2);
  text-align: left;
}

.history-item.active {
  border-color: rgba(88, 244, 255, 0.58);
  background: rgba(88, 244, 255, 0.12);
}

.history-item span,
.history-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  font-size: 12px;
  font-weight: 800;
}

.history-item small {
  color: var(--muted);
  font-size: 11px;
}

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

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

h1 {
  margin: 0;
  color: var(--text);
  font-size: 50px;
  line-height: 1.02;
  letter-spacing: 0;
  text-shadow: 0 0 28px rgba(88, 244, 255, 0.16);
}

.hero-note {
  max-width: 380px;
  margin: 0;
  color: #cfdae8;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
  text-align: right;
}

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

.prompt-row button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  color: #eef7ff;
  background: rgba(255, 255, 255, 0.075);
  font-size: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.prompt-row button:hover,
.icon-btn:hover,
.primary-btn:hover,
.send-btn:hover {
  transform: translateY(-1px);
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(88, 244, 255, 0.07), transparent 36%),
    rgba(0, 0, 0, 0.045);
}

.messages.hidden,
.composer.hidden,
.canvas-panel.hidden,
.chat-tools.hidden,
.citations.hidden {
  display: none;
}

.message {
  width: fit-content;
  max-width: min(86%, 860px);
  padding: 13px 15px;
  border-radius: 8px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.2);
}

.message.assistant {
  max-height: 46vh;
  overflow-y: auto;
}

.message.user {
  align-self: flex-end;
  color: #04100e;
  background: linear-gradient(135deg, var(--mint), var(--lime));
}

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

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

.message a {
  color: #005b73;
  font-weight: 800;
  text-decoration-color: rgba(0, 91, 115, 0.45);
  text-underline-offset: 3px;
}

.message strong {
  color: #06735c;
}

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

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

.inline-citation {
  display: inline-flex;
  align-items: center;
  margin-left: 2px;
}

.generated-image {
  display: block;
  width: min(100%, 540px);
  margin-top: 12px;
  border: 1px solid rgba(16, 20, 28, 0.14);
  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: #06735c;
  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.075);
}

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

.canvas-panel {
  flex: 1;
  min-height: 0;
  margin-top: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  color: #edf7ff;
}

.canvas-toolbar > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.canvas-toolbar button {
  padding: 0 11px;
}

.canvas-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  height: calc(100% - 52px);
  min-height: 430px;
}

#codeEditor {
  height: 100%;
  min-height: 430px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  resize: none;
  font: 13px/1.55 "SF Mono", "Fira Code", Consolas, monospace;
  tab-size: 2;
  background: rgba(0, 0, 0, 0.48);
}

#canvasFrame {
  width: 100%;
  height: 100%;
  min-height: 430px;
  border: 0;
  background: #05070c;
}

.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: 82px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: #f3f8ff;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.2);
}

.citation-index {
  color: var(--mint);
  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: #d5e0ee;
  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: 60px;
  padding: 0 14px;
}

.stop-btn {
  color: #ffffff;
  background: linear-gradient(135deg, var(--red), var(--pink));
}

.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: 1060px) {
  .app-shell {
    width: min(100% - 20px, 820px);
    padding: 12px 0;
  }

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

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

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

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

  .hero-note {
    max-width: none;
    text-align: left;
  }

  h1 {
    font-size: 38px;
  }

  .messages {
    min-height: 360px;
    max-height: 62dvh;
  }

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

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

  #codeEditor,
  #canvasFrame {
    min-height: 360px;
  }

  #codeEditor {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 14px, 460px);
  }

  .top-actions,
  .edge-pill,
  .icon-btn {
    width: 100%;
  }

  .top-actions {
    align-items: stretch;
  }

  .edge-pill,
  .icon-btn {
    justify-content: center;
  }

  .control-panel,
  .chat-panel {
    padding: 12px;
  }

  .mode-btn {
    min-height: 38px;
    font-size: 11px;
  }

  h1 {
    font-size: 31px;
  }

  .message {
    max-width: 94%;
  }

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

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