:root {
  --bg: #f5f2eb;
  --surface: rgba(255, 252, 246, 0.74);
  --surface-strong: rgba(255, 255, 255, 0.86);
  --surface-soft: rgba(251, 248, 240, 0.72);
  --line: rgba(24, 31, 30, 0.08);
  --line-strong: rgba(24, 31, 30, 0.14);
  --text: #131918;
  --text-soft: #6a736f;
  --accent: #154c56;
  --accent-soft: rgba(21, 76, 86, 0.09);
  --warm: #b7744b;
  --shadow: 0 18px 60px rgba(16, 22, 21, 0.06);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 14% 16%, rgba(183, 116, 75, 0.1), transparent 22%),
    radial-gradient(circle at 84% 12%, rgba(21, 76, 86, 0.08), transparent 20%),
    linear-gradient(180deg, #faf7f1 0%, var(--bg) 100%);
  color: var(--text);
  font-family: "Noto Sans SC", "Manrope", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(24, 31, 30, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 31, 30, 0.022) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.28), transparent 85%);
  pointer-events: none;
}

.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(48px);
  opacity: 0.42;
  pointer-events: none;
  animation: floatAmbient 14s ease-in-out infinite;
}

.ambient-a {
  width: 260px;
  height: 260px;
  top: 82px;
  right: 10%;
  background: rgba(21, 76, 86, 0.14);
}

.ambient-b {
  width: 320px;
  height: 320px;
  left: 8%;
  bottom: 10%;
  background: rgba(183, 116, 75, 0.12);
  animation-delay: -5s;
}

.app-shell {
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  padding: 30px 24px 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 10px;
  animation: riseIn 620ms cubic-bezier(0.22, 1, 0.36, 1);
}

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

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #174f59, #0e3138);
  box-shadow: 0 0 0 5px rgba(21, 76, 86, 0.08);
}

.eyebrow {
  display: block;
  margin-bottom: 6px;
  color: var(--text-soft);
  font-family: "Manrope", sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.brand-copy h1,
.canvas-head h2 {
  margin: 0;
  font-family: "Manrope", "Noto Sans SC", sans-serif;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-copy h1 {
  font-size: 1rem;
  letter-spacing: -0.04em;
}

.mode-switch {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid rgba(24, 31, 30, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.36);
}

.mode-pill,
.segment,
.quiet-btn,
.primary-btn,
.secondary-btn,
.link-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.mode-pill {
  min-width: 76px;
  padding: 8px 15px;
  border-radius: 999px;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.mode-pill.is-active {
  background: #141918;
  color: #faf8f2;
  box-shadow: 0 8px 20px rgba(20, 25, 24, 0.12);
}

.stage {
  position: relative;
  margin-top: 12px;
  padding: 18px 18px 32px;
  border: 1px solid rgba(24, 31, 30, 0.08);
  border-radius: 32px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.64), rgba(255, 252, 246, 0.76));
  box-shadow: 0 20px 70px rgba(16, 22, 21, 0.05);
  backdrop-filter: blur(22px);
  overflow: hidden;
  animation: riseIn 760ms cubic-bezier(0.22, 1, 0.36, 1);
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top right, rgba(21, 76, 86, 0.06), transparent 26%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 34%);
  pointer-events: none;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  pointer-events: none;
}

.control-bar,
.composer,
.request-preview,
.image-form,
.image-preview {
  position: relative;
  z-index: 1;
}

.control-bar {
  padding: 16px 16px 18px;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.34)),
    rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 16px 38px rgba(16, 22, 21, 0.035);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.field {
  min-width: 0;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-soft);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

.field-head label {
  margin-bottom: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(24, 31, 30, 0.08);
  border-radius: 16px;
  outline: none;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font: inherit;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

input {
  height: 46px;
  padding: 0 15px;
}

select {
  height: 46px;
  padding: 0 40px 0 15px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(24, 31, 30, 0.5) 50%),
    linear-gradient(135deg, rgba(24, 31, 30, 0.5) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 18px,
    calc(100% - 12px) 18px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

textarea {
  min-height: 126px;
  padding: 14px;
  resize: vertical;
  line-height: 1.8;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(21, 76, 86, 0.22);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 4px rgba(21, 76, 86, 0.06);
}

.segmented-control {
  display: flex;
  gap: 6px;
}

.provider-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.segment {
  flex: 1 1 0;
  min-width: 0;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 700;
}

.segment.is-active {
  background: #141918;
  color: #faf8f2;
  box-shadow: 0 10px 20px rgba(20, 25, 24, 0.08);
}

.segment[data-unavailable="true"] {
  color: rgba(106, 115, 111, 0.58);
  background: rgba(245, 241, 235, 0.42);
  box-shadow: inset 0 0 0 1px rgba(24, 31, 30, 0.04);
}

.segment[data-unavailable="true"]:not(.is-active) {
  opacity: 0.78;
}

.input-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.base-url-switch {
  width: fit-content;
}

.field-base-url .base-url-switch .segment {
  height: 34px;
  padding: 0 12px;
  font-size: 0.76rem;
}

.field-base-url .field-head {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.base-url-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
}

.base-url-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  height: 46px;
  padding: 0 12px;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 16px;
  background: rgba(247, 243, 236, 0.84);
  color: rgba(19, 25, 24, 0.72);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

#baseUrl[readonly] {
  color: rgba(19, 25, 24, 0.82);
  background: rgba(247, 243, 236, 0.74);
  cursor: default;
}

#modelSelect:disabled {
  color: rgba(106, 115, 111, 0.9);
  background: rgba(247, 243, 236, 0.72);
  cursor: not-allowed;
}

#modelSelect:disabled + .quiet-btn {
  opacity: 0.78;
}

.quiet-btn,
.secondary-btn {
  height: 46px;
  padding: 0 15px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.64);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 700;
}

.primary-btn {
  height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  background: #141918;
  color: #faf8f2;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: 0 10px 22px rgba(20, 25, 24, 0.1);
}

.mode-pill:hover,
.segment:hover,
.quiet-btn:hover,
.secondary-btn:hover,
.primary-btn:hover,
.link-btn:hover {
  transform: translateY(-1px);
}

.toolbar-footer {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(24, 31, 30, 0.05);
}

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

.toolbar-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.toolbar-status span:first-child {
  color: var(--accent);
  font-size: 0.95rem;
}

.meta-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(24, 31, 30, 0.06);
  color: var(--text-soft);
}

.meta-live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(24, 31, 30, 0.28);
}

.meta-live[data-kind="success"] {
  color: #1c6d4c;
}

.meta-live[data-kind="success"]::before {
  background: #2f9d69;
}

.meta-live[data-kind="error"] {
  color: #9a4a3a;
}

.meta-live[data-kind="error"]::before {
  background: #c7634c;
}

.meta-live[data-kind="warning"] {
  color: #8a6230;
}

.meta-live[data-kind="warning"]::before {
  background: #c18a3f;
}

.meta-live[data-kind="loading"]::before {
  background: var(--accent);
  animation: pulseDot 1.2s ease-in-out infinite;
}

.meta-copy {
  opacity: 0.78;
}

.toolbar-note {
  margin: 0;
  color: rgba(106, 115, 111, 0.82);
  font-size: 0.82rem;
  line-height: 1.7;
}

.toolbar-actions,
.composer-actions {
  display: flex;
  gap: 10px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none !important;
  box-shadow: none !important;
}

.mode-panel {
  display: none;
  position: relative;
  z-index: 1;
}

.mode-panel.is-visible {
  display: block;
}

.canvas-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 34px 8px 0;
  margin-bottom: 20px;
}

.canvas-caption {
  display: block;
  margin-bottom: 10px;
  color: rgba(106, 115, 111, 0.74);
  font-family: "Manrope", sans-serif;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.canvas-head h2 {
  font-size: 1.56rem;
}

.canvas-note,
.request-endpoint {
  color: var(--text-soft);
  font-size: 0.84rem;
}

.request-endpoint {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
}

.conversation-surface {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 500px;
  padding: 92px 26px 28px;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.62)),
    radial-gradient(circle at top, rgba(21, 76, 86, 0.035), transparent 42%);
  animation: riseIn 900ms cubic-bezier(0.22, 1, 0.36, 1);
}

.surface-hint {
  position: absolute;
  top: 24px;
  left: 24px;
  color: rgba(24, 31, 30, 0.34);
  font-family: "Manrope", sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.surface-hint.is-hidden {
  opacity: 0.18;
}

.message-stack {
  margin-top: auto;
}

.message {
  display: flex;
  gap: 12px;
}

.message + .message {
  margin-top: 18px;
}

.message.user {
  flex-direction: row-reverse;
}

.message-mark {
  width: 30px;
  height: 30px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: rgba(21, 76, 86, 0.08);
  color: var(--accent);
  font-family: "Manrope", sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
}

.message.user .message-mark {
  background: rgba(183, 116, 75, 0.1);
  color: var(--warm);
}

.message-body {
  max-width: min(62%, 660px);
  padding: 15px 16px;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(16px);
}

.message-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.message-title strong {
  font-size: 0.9rem;
}

.message-title span {
  color: var(--text-soft);
  font-size: 0.76rem;
}

.message-body p {
  margin: 10px 0 0;
  color: #202827;
  line-height: 1.78;
}

.message.is-error .message-body {
  border-color: rgba(183, 116, 75, 0.18);
  background: rgba(255, 247, 242, 0.72);
}

.composer {
  display: grid;
  gap: 12px;
  margin-top: 20px;
  padding: 18px 18px 16px;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.3);
  animation: riseIn 980ms cubic-bezier(0.22, 1, 0.36, 1);
}

.composer-footer,
.request-head,
.image-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.link-btn {
  padding: 0;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.84rem;
}

.link-btn:hover {
  color: var(--text);
}

.request-preview {
  margin-top: 28px;
  padding: 18px 8px 0;
  border-top: 1px solid rgba(24, 31, 30, 0.05);
  animation: riseIn 1060ms cubic-bezier(0.22, 1, 0.36, 1);
}

.request-preview.is-collapsed .request-preview-body {
  display: none;
}

.debug-toggle-btn {
  width: 100%;
  height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(24, 31, 30, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.34);
  color: var(--text-soft);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: left;
}

.debug-toggle-btn[aria-expanded="true"] {
  color: var(--text);
  background: rgba(255, 255, 255, 0.54);
}

.request-preview-body {
  margin-top: 18px;
}

.request-head-secondary {
  margin-top: 18px;
}

.request-head strong {
  display: block;
  font-size: 0.98rem;
}

pre,
code {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
}

pre {
  margin-top: 14px;
  padding: 16px 18px;
  overflow: auto;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 18px;
  background: rgba(250, 247, 239, 0.44);
  color: #17332e;
  font-size: 0.8rem;
  line-height: 1.9;
}

.image-stage {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
}

.image-form {
  padding: 18px;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.28);
  animation: riseIn 820ms cubic-bezier(0.22, 1, 0.36, 1);
}

.image-preview {
  position: relative;
  min-height: 460px;
  border: 1px solid rgba(24, 31, 30, 0.06);
  border-radius: 24px;
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.06)),
    linear-gradient(180deg, #e7e1d6 0%, #d7d1c6 100%);
  animation: riseIn 920ms cubic-bezier(0.22, 1, 0.36, 1);
}

.generated-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview.has-image .preview-glow {
  opacity: 0.16;
}

.image-preview.has-image .preview-copy {
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 252, 246, 0.72);
  backdrop-filter: blur(12px);
}

.image-request-preview {
  margin-top: 26px;
}

.preview-glow {
  position: absolute;
  inset: 16% 12%;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(21, 76, 86, 0.18), transparent 45%),
    radial-gradient(circle at 65% 40%, rgba(183, 116, 75, 0.22), transparent 28%);
  filter: blur(24px);
  animation: breathe 8s ease-in-out infinite;
}

.preview-copy {
  position: absolute;
  left: 26px;
  bottom: 24px;
  display: grid;
  gap: 8px;
}

.preview-copy strong {
  font-family: "Manrope", sans-serif;
  font-size: 1rem;
}

.preview-copy span {
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.7;
}

@keyframes floatAmbient {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, -14px, 0) scale(1.04);
  }
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(0.96);
    opacity: 0.72;
  }
  50% {
    transform: scale(1.04);
    opacity: 1;
  }
}

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

@keyframes pulseDot {
  0%,
  100% {
    transform: scale(0.9);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.15);
    opacity: 1;
  }
}

@media (max-width: 1040px) {
  .control-grid,
  .image-stage {
    grid-template-columns: 1fr 1fr;
  }

  .field-head {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .base-url-switch {
    width: 100%;
  }

  .field-base-url .base-url-switch .segment {
    flex: 0 1 auto;
  }

  .base-url-shell {
    grid-template-columns: 1fr;
  }

  .base-url-tag {
    width: fit-content;
    min-width: 0;
  }
}

@media (max-width: 920px) {
  .app-shell {
    padding: 20px 14px 36px;
  }

  .topbar,
  .toolbar-footer,
  .canvas-head,
  .composer-footer,
  .request-head,
  .image-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .stage {
    padding: 18px;
  }

  .control-grid,
  .image-stage {
    grid-template-columns: 1fr;
  }

  .toolbar-actions,
  .composer-actions {
    width: 100%;
  }

  .toolbar-topline,
  .toolbar-status,
  .field-head,
  .base-url-shell {
    flex-direction: column;
    align-items: stretch;
    display: flex;
  }

  .base-url-shell {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar-actions .secondary-btn,
  .toolbar-actions .primary-btn,
  .composer-actions .secondary-btn,
  .composer-actions .primary-btn {
    flex: 1 1 0;
  }

  .conversation-surface {
    min-height: 360px;
    padding: 76px 16px 16px;
  }

  .surface-hint {
    left: 16px;
    top: 18px;
  }

  .message-body {
    max-width: 100%;
  }

  .image-preview {
    min-height: 300px;
  }
}
