:root {
  color-scheme: dark;
  --bg: #090c11;
  --panel: rgba(16, 20, 27, 0.92);
  --panel-strong: #11161d;
  --ink: #eef4f8;
  --muted: #9aa4af;
  --line: rgba(255, 255, 255, 0.1);
  --accent: #5eead4;
  --accent-strong: #2dd4bf;
  --danger: #ef4444;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

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

.file-picker {
  position: fixed;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

button,
input,
select,
textarea,
.canvas-node,
.asset-card,
.progress-panel {
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease,
    transform 180ms ease;
}

.home-gate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  min-height: 100vh;
  overflow: hidden;
  background: #050607;
}

.home-gate[hidden],
.key-gate[hidden],
.canvas-app[hidden],
.progress-panel[hidden] {
  display: none;
}

.home-circuit,
.home-vignette {
  position: absolute;
  inset: 0;
}

.home-circuit {
  z-index: 0;
}

.home-vignette {
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 0 34%, rgba(0, 0, 0, 0.34) 66%, rgba(0, 0, 0, 0.82) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 28%, rgba(0, 0, 0, 0.18));
}

.home-core {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  gap: 34px;
  width: min(760px, calc(100vw - 36px));
  text-align: center;
}

.home-core h1 {
  margin: 0;
  color: #f7fbff;
  font-size: clamp(38px, 7vw, 92px);
  font-weight: 920;
  line-height: 1;
  text-shadow:
    0 0 28px rgba(94, 234, 212, 0.24),
    0 14px 60px rgba(0, 0, 0, 0.6);
}

.enter-creation {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-width: min(280px, calc(100vw - 70px));
  min-height: 78px;
  padding: 0 42px;
  border: 1px solid rgba(94, 234, 212, 0.5);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 44%),
    rgba(9, 18, 20, 0.9);
  color: #f7fffd;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 44px rgba(94, 234, 212, 0.18),
    0 28px 90px rgba(0, 0, 0, 0.54);
  cursor: pointer;
  overflow: hidden;
}

.enter-creation::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: inherit;
}

.enter-creation::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 42%;
  background: linear-gradient(90deg, transparent, rgba(94, 234, 212, 0.34), transparent);
  animation: home-button-current 2.6s ease-in-out infinite;
}

.enter-creation span {
  position: relative;
  z-index: 1;
  font-size: 21px;
  font-weight: 900;
}

.enter-creation:hover {
  border-color: rgba(94, 234, 212, 0.9);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 64px rgba(94, 234, 212, 0.28),
    0 34px 100px rgba(0, 0, 0, 0.62);
  transform: translateY(-2px);
}

.enter-creation:disabled {
  opacity: 0.66;
  cursor: wait;
}

@keyframes home-button-current {
  0% {
    left: -48%;
    opacity: 0;
  }

  18%,
  78% {
    opacity: 1;
  }

  100% {
    left: 106%;
    opacity: 0;
  }
}

.key-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent),
    var(--bg);
}

.key-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-message {
  min-height: 18px;
  color: rgba(94, 234, 212, 0.86);
  font-size: 12px;
  font-weight: 760;
}

.login-message.is-error {
  color: #fecaca;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.node-label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 92px;
  resize: vertical;
  padding: 10px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.12);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.primary-button,
.ghost-button,
.link-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
}

.primary-button {
  min-height: 40px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #06221f;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled {
  opacity: 0.58;
  cursor: wait;
}

.ghost-button,
.link-button,
.icon-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
}

.ghost-button,
.link-button {
  min-height: 38px;
  padding: 0 12px;
  gap: 8px;
  text-decoration: none;
}

.link-button {
  min-height: 32px;
  color: var(--accent);
  font-size: 12px;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.ghost-button:hover,
.link-button:hover,
.icon-button:hover {
  border-color: rgba(94, 234, 212, 0.36);
  color: var(--accent);
}

.canvas-app {
  position: relative;
  display: block;
  width: 100vw;
  height: 100vh;
}

.app-topbar {
  position: absolute;
  inset: 12px 12px auto 12px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 0;
  padding: 0;
  border-bottom: 0;
  background: transparent;
  pointer-events: none;
}

.app-topbar > div:first-child,
.topbar-actions {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 27, 0.9);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.app-topbar .eyebrow {
  display: none;
}

.app-topbar h1 {
  margin: 0;
  padding: 0 6px;
  font-size: 16px;
  line-height: 1;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.busy {
  border-color: rgba(94, 234, 212, 0.36);
  color: var(--accent);
}

.status-pill.error {
  border-color: rgba(239, 68, 68, 0.48);
  color: #fecaca;
}

.workspace {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.asset-library {
  position: absolute;
  left: 12px;
  top: 66px;
  bottom: 12px;
  z-index: 35;
  display: grid;
  align-content: start;
  gap: 12px;
  width: clamp(260px, 24vw, 320px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: auto;
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
}

.asset-library.is-collapsed {
  pointer-events: none;
  transform: translateX(-12px);
  opacity: 0;
  visibility: hidden;
}

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

.library-head div {
  display: grid;
  gap: 4px;
}

.library-head span,
.upload-box span,
.asset-meta,
.node-muted {
  color: var(--muted);
  font-size: 12px;
}

.upload-box {
  display: grid;
  gap: 6px;
  min-height: 92px;
  padding: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
}

.upload-box input {
  width: 100%;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
}

.asset-grid {
  display: grid;
  gap: 10px;
}

.asset-card {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.asset-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.04);
}

.asset-actions,
.node-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.canvas-shell,
.canvas-viewport {
  min-width: 0;
  min-height: 0;
}

.canvas-shell {
  width: 100%;
  height: 100%;
}

.canvas-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background:
    radial-gradient(circle at 30% 20%, rgba(94, 234, 212, 0.06), transparent 26%),
    var(--bg);
}

.canvas-viewport.is-panning {
  cursor: grabbing;
}

.canvas-viewport.is-drop-target::after {
  content: "";
  position: absolute;
  inset: 74px 14px 14px;
  z-index: 24;
  border: 1px dashed rgba(94, 234, 212, 0.62);
  border-radius: 8px;
  background: rgba(94, 234, 212, 0.06);
  pointer-events: none;
}

.canvas-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.46;
  background-image:
    linear-gradient(rgba(94, 234, 212, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(94, 234, 212, 0.12) 1px, transparent 1px);
  background-position: var(--canvas-grid-x, 0) var(--canvas-grid-y, 0);
  background-size: var(--canvas-grid-size, 48px) var(--canvas-grid-size, 48px);
}

.canvas-world {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
  will-change: transform;
}

.canvas-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  gap: 8px;
  place-items: center;
  width: min(460px, calc(100% - 40px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 27, 0.74);
  color: var(--muted);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.canvas-empty[hidden] {
  display: none;
}

.canvas-empty strong {
  color: var(--ink);
}

.canvas-controls {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 27, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.canvas-toolbar {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 28;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 28px);
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(18, 18, 18, 0.72);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(16px);
}

.local-stats,
.toolbar-button {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.local-stats {
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.06);
}

.toolbar-button {
  padding: 0 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.toolbar-button:hover {
  background: rgba(255, 255, 255, 0.09);
}

.canvas-controls span {
  min-width: 46px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-align: right;
}

.canvas-node {
  position: absolute;
  width: 312px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 27, 0.95);
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: text;
  touch-action: none;
}

.canvas-node.image-node {
  width: 286px;
}

.node-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  cursor: grab;
}

.node-head:active {
  cursor: grabbing;
}

.node-head strong {
  font-size: 13px;
}

.node-body {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.node-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.image-preview {
  display: grid;
  place-items: center;
  min-height: 200px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%);
  background-color: rgba(255, 255, 255, 0.03);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.image-preview img {
  width: 100%;
  max-height: 340px;
  object-fit: contain;
}

.progress-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: grid;
  gap: 12px;
  width: min(420px, calc(100vw - 36px));
  max-height: min(520px, calc(100vh - 36px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 27, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.api-panel {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(8px);
}

.api-panel[hidden] {
  display: none;
}

.image-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
}

.image-editor-modal[hidden] {
  display: none;
}

.image-editor-shell {
  display: grid;
  grid-template-rows: auto auto minmax(280px, 1fr) auto;
  gap: 12px;
  width: min(1120px, calc(100vw - 28px));
  height: min(820px, calc(100vh - 28px));
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 20px;
  background: rgba(14, 14, 14, 0.98);
  box-shadow: 0 34px 100px rgba(0, 0, 0, 0.68);
}

.image-editor-head,
.image-editor-foot,
.image-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-editor-head,
.image-editor-foot {
  justify-content: space-between;
}

.image-editor-head div {
  display: grid;
  gap: 3px;
}

.image-editor-head strong {
  font-size: 16px;
}

.image-editor-head span {
  color: rgba(255, 255, 255, 0.48);
  font-size: 12px;
}

.image-editor-toolbar {
  flex-wrap: wrap;
  padding: 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.image-editor-toolbar button {
  min-width: 42px;
  height: 38px;
  padding: 0 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 900;
  cursor: pointer;
}

.image-editor-toolbar button:hover,
.image-editor-toolbar button.is-selected {
  background: rgba(255, 95, 87, 0.2);
  color: #fff;
}

.image-editor-stage {
  position: relative;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  overflow: hidden;
  touch-action: none;
}

.image-editor-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.image-editor-text-input {
  position: absolute;
  z-index: 4;
  width: min(320px, 70%);
  height: auto;
  min-height: 42px;
  padding: 4px 8px;
  border: 2px solid rgba(255, 95, 87, 0.82);
  border-radius: 10px;
  background: rgba(8, 8, 8, 0.78);
  color: #ff5f57;
  font-weight: 900;
  outline: none;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.36);
}

.image-editor-foot {
  justify-content: flex-end;
}

.api-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  background: rgba(18, 18, 18, 0.98);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.58);
}

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

.api-head div {
  display: grid;
  gap: 4px;
}

.api-head strong {
  font-size: 16px;
}

.api-head span {
  color: rgba(255, 255, 255, 0.48);
  font-size: 12px;
}

.account-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.account-card span,
.settings-model-title {
  color: rgba(255, 255, 255, 0.46);
  font-size: 12px;
  font-weight: 820;
}

.account-card strong {
  color: #f6f6f6;
  font-size: 18px;
}

.account-card em {
  color: rgba(255, 255, 255, 0.56);
  font-size: 12px;
  font-style: normal;
}

.settings-model-list {
  display: grid;
  gap: 8px;
}

.settings-model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.055);
}

.settings-model-row strong {
  min-width: 0;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-model-row em {
  flex: 0 0 auto;
  color: rgba(255, 255, 255, 0.54);
  font-size: 12px;
  font-style: normal;
  font-weight: 760;
}

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

.progress-head div {
  display: grid;
  gap: 3px;
}

.progress-head strong {
  font-size: 14px;
}

.progress-head span {
  color: var(--muted);
  font-size: 12px;
}

.progress-list {
  display: grid;
  gap: 10px;
  overflow: auto;
}

.progress-job {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.progress-job.done {
  border-color: rgba(94, 234, 212, 0.28);
}

.progress-job.error {
  border-color: rgba(239, 68, 68, 0.42);
}

.progress-job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 850;
}

.progress-job-top span,
.progress-message {
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transition: width 240ms ease;
}

.progress-job.error .progress-fill {
  background: var(--danger);
}

@media (max-width: 820px) {
  .app-topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    inset: 10px 10px auto 10px;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    max-width: 100%;
  }

  .asset-library {
    left: 10px;
    right: 10px;
    top: 108px;
    bottom: 10px;
    z-index: 25;
    width: auto;
  }

  .canvas-node,
  .canvas-node.image-node {
    width: min(312px, calc(100vw - 32px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Flow canvas redesign */
.app-topbar {
  display: none;
}

.canvas-viewport {
  background: #070707;
}

.canvas-grid {
  opacity: 1;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.17) 1.4px, transparent 1.5px);
  background-size: var(--canvas-grid-size, 58px) var(--canvas-grid-size, 58px);
  background-position: var(--canvas-grid-x, 0) var(--canvas-grid-y, 0);
}

.canvas-empty {
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.22);
  font-size: clamp(26px, 4vw, 60px);
  font-weight: 850;
}

.canvas-empty span {
  display: none;
}

.canvas-empty strong {
  color: inherit;
}

.canvas-controls {
  gap: 6px;
  padding: 6px;
  opacity: 0.32;
  border-radius: 12px;
  background: rgba(18, 18, 18, 0.68);
}

.canvas-controls:hover {
  opacity: 0.9;
}

.connection-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 0;
}

.connection-path {
  fill: none;
  stroke: rgba(255, 255, 255, 0.72);
  stroke-width: 4;
  stroke-linecap: round;
}

.connection-plus circle,
.connection-plus path {
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 3;
}

.connection-plus circle {
  fill: #101010;
}

.canvas-node {
  width: var(--node-width, 420px);
  min-height: var(--node-min-height, 220px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.canvas-node.image-node,
.canvas-node.text-node,
.canvas-node.generator-node,
.canvas-node.video-node,
.canvas-node.audio-node,
.canvas-node.agent-node {
  width: var(--node-width, 420px);
}

.canvas-node.is-active .flow-image-preview,
.canvas-node.is-active .text-node-input,
.canvas-node.is-active .media-placeholder,
.canvas-node.is-active .composer-panel {
  border-color: rgba(255, 255, 255, 0.48);
}

.node-kicker {
  position: absolute;
  left: 6px;
  top: -34px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: rgba(255, 255, 255, 0.48);
  font-size: 18px;
  font-weight: 760;
  cursor: grab;
}

.node-kicker:active {
  cursor: grabbing;
}

.node-close {
  position: absolute;
  left: -13px;
  top: -13px;
  z-index: 12;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid rgba(10, 10, 10, 0.72);
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.48), transparent 24%),
    #ff5f57;
  color: rgba(82, 18, 16, 0.96);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.16),
    0 8px 20px rgba(0, 0, 0, 0.44),
    0 0 18px rgba(255, 95, 87, 0.18);
  cursor: pointer;
}

.node-close:hover {
  background: #ff453a;
  color: #fff;
  transform: scale(1.06);
}

.node-handles {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.node-handle {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: #101010;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  pointer-events: auto;
  transform: translateY(-50%);
}

.node-handle-left {
  left: -56px;
}

.node-handle-right {
  right: -56px;
}

.text-node-input,
.flow-image-preview,
.media-placeholder,
.composer-panel {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(35, 35, 35, 0.96);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 22px 60px rgba(0, 0, 0, 0.34);
}

.text-node-input {
  display: block;
  min-height: var(--node-min-height, 240px);
  padding: 18px 20px;
  border-radius: 16px;
  color: #f4f4f4;
  font-size: 20px;
  font-weight: 720;
  resize: none;
}

.flow-image-preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: var(--node-min-height, 290px);
  border-radius: 16px;
  cursor: grab;
  overflow: hidden;
}

.flow-image-preview:active {
  cursor: grabbing;
}

.flow-image-preview img {
  width: 100%;
  height: 100%;
  min-height: inherit;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.flow-image-preview span,
.media-placeholder span,
.reference-thumb {
  color: rgba(255, 255, 255, 0.22);
  font-size: 42px;
}

.media-placeholder {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: var(--node-min-height, 220px);
  border-radius: 16px;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
}

.media-placeholder em {
  color: rgba(255, 255, 255, 0.42);
  font-size: 13px;
  font-style: normal;
}

.image-tools {
  position: absolute;
  left: 50%;
  bottom: -46px;
  z-index: 8;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 16px);
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  background: rgba(13, 13, 13, 0.88);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
  opacity: 0.16;
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.canvas-node.is-active .image-tools,
.canvas-node:hover .image-tools {
  opacity: 1;
}

.image-tool-button {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.075);
  color: rgba(255, 255, 255, 0.78);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

.image-tool-button:hover,
.image-tool-button.is-selected {
  background: rgba(255, 95, 87, 0.18);
  color: #fff;
}

.image-tool-button.feed-button {
  min-width: 72px;
  background: rgba(255, 255, 255, 0.88);
  color: #0a0a0a;
}

.composer-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(130px, 1fr) auto;
  gap: 14px;
  min-height: var(--node-min-height, 360px);
  padding: 18px 20px 18px;
  border-radius: 24px;
  background: rgba(16, 16, 16, 0.96);
  overflow: visible;
}

.composer-panel > :not(.water-progress):not(.settings-popover) {
  position: relative;
  z-index: 2;
}

.water-progress {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
}

.water-progress[hidden] {
  display: none;
}

.water-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 8%;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.34), transparent 22%),
    linear-gradient(180deg, rgba(83, 198, 255, 0.44), rgba(25, 117, 255, 0.52));
  box-shadow: inset 0 16px 36px rgba(255, 255, 255, 0.16);
  opacity: 0.72;
  transition: height 520ms ease;
}

.water-fill::before,
.water-fill::after {
  content: "";
  position: absolute;
  left: -12%;
  right: -12%;
  top: -14px;
  height: 28px;
  border-radius: 50%;
  background: rgba(157, 224, 255, 0.55);
  animation: water-wave 2.8s ease-in-out infinite;
}

.water-fill::after {
  top: -18px;
  opacity: 0.46;
  animation-delay: -1.4s;
}

.water-progress.done .water-fill {
  background:
    radial-gradient(circle at 20% 16%, rgba(255, 255, 255, 0.42), transparent 24%),
    linear-gradient(180deg, rgba(94, 234, 212, 0.5), rgba(20, 184, 166, 0.58));
}

.water-progress.error .water-fill {
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.28), transparent 22%),
    linear-gradient(180deg, rgba(248, 113, 113, 0.52), rgba(220, 38, 38, 0.58));
}

.water-label {
  position: absolute;
  top: 18px;
  right: 68px;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  font-weight: 850;
  backdrop-filter: blur(10px);
}

@keyframes water-wave {
  0%,
  100% {
    transform: translateX(-3%) scaleY(1);
  }

  50% {
    transform: translateX(3%) scaleY(0.72);
  }
}

.composer-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.reference-drop {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: min(270px, 62%);
  min-height: 78px;
  padding: 3px 12px 3px 3px;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}

.reference-drop:hover {
  border-color: rgba(255, 255, 255, 0.56);
  background: rgba(255, 255, 255, 0.055);
}

.reference-drop.is-pending {
  border-color: rgba(94, 234, 212, 0.46);
}

.reference-drop.is-pending .reference-thumb {
  position: relative;
}

.reference-drop.is-pending .reference-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.18), transparent);
  animation: reference-loading 1.1s ease-in-out infinite;
}

.reference-thumb {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border: 1px dashed rgba(255, 255, 255, 0.24);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.reference-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.reference-meta strong {
  color: rgba(255, 255, 255, 0.84);
  font-size: 13px;
  font-weight: 850;
}

.reference-meta em {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.42);
  font-size: 12px;
  font-style: normal;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes reference-loading {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

.composer-expand {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.84);
  font-size: 22px;
  cursor: pointer;
}

.source-chip {
  justify-self: start;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 15px;
  font-weight: 760;
}

.composer-prompt {
  min-height: 130px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #f4f4f4;
  font-size: 24px;
  font-weight: 760;
  line-height: 1.35;
  resize: none;
  box-shadow: none;
}

.composer-prompt:focus {
  box-shadow: none;
}

.composer-prompt::placeholder {
  color: rgba(255, 255, 255, 0.42);
}

.composer-controls {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  min-width: 0;
}

.generation-type,
.compact-select,
.composer-setting,
.composer-model,
.cost-chip {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: #f6f6f6;
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}

.generation-type {
  padding-right: 4px;
}

.compact-select {
  position: relative;
}

.compact-select select,
.composer-model {
  min-width: 0;
  height: 44px;
  padding: 0 30px 0 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  appearance: none;
  box-shadow: none;
}

.compact-select span {
  position: absolute;
  right: 4px;
  color: rgba(255, 255, 255, 0.54);
  pointer-events: none;
}

.composer-model {
  width: clamp(118px, 18vw, 150px);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-setting {
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.cost-chip {
  color: #fff;
}

.send-button {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-left: auto;
  border: 0;
  border-radius: 50%;
  background: #f3f4f6;
  color: #090b12;
  font-size: 34px;
  font-weight: 800;
  cursor: pointer;
}

.settings-popover {
  position: absolute;
  right: 52px;
  bottom: 80px;
  z-index: 30;
  display: grid;
  gap: 14px;
  width: min(480px, calc(100% - 40px));
  max-height: min(520px, calc(100vh - 120px));
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 20px;
  background: rgba(18, 18, 18, 0.98);
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.58);
  overflow: auto;
}

.model-group {
  display: grid;
  gap: 8px;
}

.model-group > strong {
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
}

.model-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.model-option {
  display: grid;
  gap: 5px;
  min-height: 62px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.055);
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  text-align: left;
}

.model-option strong {
  overflow: hidden;
  color: #f6f6f6;
  font-size: 13px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-option span {
  color: rgba(255, 255, 255, 0.48);
  font-size: 12px;
  font-weight: 760;
}

.model-option.is-selected {
  border-color: rgba(94, 234, 212, 0.46);
  background: rgba(94, 234, 212, 0.12);
}

.segment-group {
  display: grid;
  gap: 8px;
}

.segment-group strong {
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
}

.segment-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 0;
  padding: 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.segment-group.is-ratio .segment-buttons {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segment-button {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.44);
  font-size: 15px;
  font-weight: 760;
  cursor: pointer;
}

.segment-button em {
  font-style: normal;
}

.ratio-icon {
  display: block;
  width: var(--ratio-w, 24px);
  height: var(--ratio-h, 18px);
  border: 2px solid currentColor;
  border-radius: 3px;
}

.segment-button.is-selected {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.canvas-menu {
  position: absolute;
  z-index: 60;
  display: grid;
  gap: 4px;
  width: 250px;
  margin: 0;
  padding: 16px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 24px;
  background: rgba(19, 19, 19, 0.98);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.62);
}

.canvas-menu[hidden] {
  display: none;
}

.canvas-menu button {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #f5f5f5;
  font-size: 18px;
  font-weight: 760;
  text-align: left;
  cursor: pointer;
}

.canvas-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.canvas-menu span {
  width: 22px;
  color: rgba(255, 255, 255, 0.48);
  text-align: center;
}

@media (max-width: 820px) {
  .canvas-toolbar {
    left: 10px;
    right: 10px;
    top: 10px;
    justify-content: space-between;
  }

  .local-stats,
  .toolbar-button {
    font-size: 12px;
  }

  .canvas-node,
  .canvas-node.image-node,
  .canvas-node.text-node,
  .canvas-node.generator-node,
  .canvas-node.video-node,
  .canvas-node.audio-node,
  .canvas-node.agent-node {
    width: min(var(--node-width, 420px), calc(100vw - 36px));
  }

  .composer-panel {
    border-radius: 22px;
    padding: 14px;
  }

  .composer-controls {
    gap: 10px;
    flex-wrap: wrap;
  }

  .composer-prompt {
    font-size: 20px;
  }

  .compact-select,
  .composer-setting,
  .composer-model,
  .cost-chip {
    font-size: 16px;
  }

  .settings-popover {
    right: 14px;
    left: 14px;
    bottom: 72px;
    width: auto;
    padding: 14px;
    border-radius: 20px;
  }

  .segment-group.is-ratio .segment-buttons {
    grid-template-columns: repeat(4, minmax(52px, 1fr));
  }

  .node-handle-left {
    left: -22px;
  }

  .node-handle-right {
    right: -22px;
  }
}

@media (pointer: coarse) {
  input,
  select {
    min-height: 44px;
  }

  .toolbar-button,
  .ghost-button,
  .primary-button,
  .link-button {
    min-height: 44px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .canvas-menu {
    width: min(300px, calc(100vw - 24px));
    padding: 12px;
  }

  .canvas-menu button {
    min-height: 58px;
    font-size: 17px;
  }

  .node-close {
    left: -15px;
    top: -15px;
    width: 30px;
    height: 30px;
    font-size: 20px;
  }

  .node-handle {
    width: 46px;
    height: 46px;
    font-size: 28px;
  }

  .send-button {
    width: 62px;
    height: 62px;
  }

  .compact-select,
  .composer-setting,
  .composer-model,
  .cost-chip {
    min-height: 48px;
  }

  .image-tools {
    bottom: -56px;
    gap: 8px;
    padding: 8px;
  }

  .image-tool-button {
    min-width: 44px;
    height: 44px;
    font-size: 16px;
  }

  .image-tool-button.feed-button {
    min-width: 86px;
  }
}
