:root {
  --sidebar-width: 280px;
  --bg: #121212;
  --panel: #171717;
  --panel-2: #202020;
  --line: #303030;
  --text: #f5f5f5;
  --muted: #9a9a9a;
  --faint: #6e6e6e;
  --red: #ff4747;
  --green: #72d9a3;
  --cyan: #21d5ef;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
}

body.is-viewer-open {
  overflow: hidden;
  overscroll-behavior: none;
}

button,
textarea,
select {
  font: inherit;
  color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns 180ms ease;
}

.app.is-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #161616;
  border-right: 1px solid var(--line);
  transform: translateX(0);
  transition: transform 180ms ease, border-color 180ms ease;
}

.app.is-collapsed .sidebar {
  border-right: 0;
  transform: translateX(-100%);
}

.project-head {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 92px;
  padding: 16px 12px;
  border-bottom: 1px solid var(--line);
}

.logo {
  width: 64px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #fff;
  border: 1px solid rgba(255, 214, 166, 0.56);
  border-radius: 8px;
  background: linear-gradient(180deg, #ff9a32 0%, #f36b14 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 22px rgba(243, 107, 20, 0.22);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1;
}

.project-meta {
  position: relative;
  display: grid;
  gap: 7px;
  min-width: 0;
}

.project-title-input {
  width: 150px;
  min-width: 0;
  border: 0;
  border-radius: 4px;
  color: var(--text);
  background: transparent;
  padding: 0;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
  outline: none;
}

.project-title-input:hover,
.project-title-input:focus {
  background: #242424;
  box-shadow: 0 0 0 4px #242424;
}

.canvas-picker {
  position: relative;
  width: max-content;
}

.canvas-switch,
.muted-select,
.tab,
.book-btn,
.search-btn,
.collapse-btn,
#closeInspector,
.sidebar-restore {
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
}

.canvas-switch {
  width: max-content;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
}

.canvas-switch[aria-expanded="true"] {
  color: #fff;
}

.canvas-switch::after,
.muted-select::after {
  content: "";
  display: inline-block;
  margin-left: 6px;
  border: 4px solid transparent;
  border-top-color: currentColor;
  transform: translateY(2px);
}

.canvas-switch[aria-expanded="true"]::after {
  transform: translateY(-2px) rotate(180deg);
}

.canvas-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 9px);
  z-index: 30;
  display: none;
  width: 180px;
  overflow: visible;
  border: 1px solid #3c3c3c;
  border-radius: 8px;
  background: #222;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.44);
}

.canvas-menu.is-open {
  display: block;
}

.canvas-menu-list {
  display: grid;
  max-height: 220px;
  overflow: visible;
  padding: 6px;
  gap: 2px;
}

.canvas-menu button {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  padding: 8px 9px;
  text-align: left;
  font-size: 13px;
  font-weight: 800;
}

.canvas-menu-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  border-radius: 6px;
}

.canvas-menu-item:hover,
.canvas-menu-item.is-active {
  background: #343434;
}

.canvas-select-btn {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.canvas-rename-input {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid #5a5a5a;
  border-radius: 6px;
  color: var(--text);
  background: #1b1b1b;
  padding: 0 8px;
  font-size: 13px;
  font-weight: 800;
  outline: none;
}

.canvas-more-btn {
  position: relative;
  width: 28px !important;
  height: 30px;
  opacity: 0;
  padding: 0 !important;
}

.canvas-menu-item:hover .canvas-more-btn,
.canvas-menu-item.is-actions-open .canvas-more-btn {
  opacity: 1;
}

.canvas-more-btn::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: -7px 0 0 currentColor, 7px 0 0 currentColor;
  transform: translate(-50%, -50%);
}

.canvas-more-btn:hover {
  background: #444 !important;
}

.canvas-action-menu {
  position: absolute;
  right: 4px;
  top: calc(100% + 4px);
  z-index: 40;
  display: none;
  width: 128px;
  padding: 5px;
  border: 1px solid #404040;
  border-radius: 8px;
  background: #262626;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.42);
}

.canvas-menu-item.is-actions-open .canvas-action-menu {
  display: grid;
  gap: 2px;
}

.canvas-action-menu button {
  padding: 7px 8px;
  font-size: 12px;
}

.canvas-action-menu button:hover {
  background: #3a3a3a;
}

.canvas-action-menu button[data-canvas-delete] {
  color: #ff8b8b;
}

.canvas-action-menu button[data-canvas-delete]:hover {
  color: #fff;
  background: #7a2626;
}

.canvas-add-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid #343434 !important;
  border-radius: 0 !important;
}

.canvas-add-btn span {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #111;
  background: #f0f0f0;
  font-size: 16px;
  line-height: 1;
}

.tab-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
}

.tab {
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.tab.is-active {
  background: #3a3a3a;
}

.book-btn,
.search-btn,
.collapse-btn,
.sidebar-restore {
  display: grid;
  place-items: center;
}

.book-btn {
  margin-left: auto;
  width: 30px;
  height: 30px;
}

.book-btn::before,
.search-btn::before,
.collapse-btn::before,
.sidebar-restore::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
}

.book-btn::before {
  border-radius: 2px;
}

.panel-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  padding: 14px;
}

.section-filter {
  display: grid;
  grid-template-columns: 1fr auto 30px;
  align-items: center;
  gap: 8px;
  margin-bottom: 30px;
}

.muted-select {
  padding: 0;
  color: var(--muted);
  text-align: left;
  font-size: 13px;
}

.section-filter .muted-select:nth-child(2) {
  color: var(--text);
}

.search-btn::before {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  box-shadow: 8px 8px 0 -6px currentColor;
}

.empty-state {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.empty-state p {
  margin: 0;
  color: #f1f1f1;
  font-weight: 700;
}

.empty-state span {
  color: var(--muted);
  line-height: 1.55;
}

.node-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: #4a4a4a transparent;
}

.node-list::-webkit-scrollbar {
  width: 6px;
}

.node-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #4a4a4a;
}

.node-list::-webkit-scrollbar-track {
  background: transparent;
}

.node-list-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #1d1d1d;
  text-align: left;
}

.list-thumb {
  width: 34px;
  height: 34px;
  overflow: hidden;
  border-radius: 6px;
  background: url("assets/node-thumb.png") center / cover;
}

.list-thumb img,
.list-thumb video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.node-list-item strong,
.node-list-item span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
}

.node-list-item span {
  color: var(--muted);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 54px;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.collapse-btn {
  width: 34px;
  height: 30px;
  border-radius: 8px;
}

.collapse-btn::before,
.sidebar-restore::before {
  width: 13px;
  height: 13px;
  border-right: 0;
  border-top: 0;
  transform: rotate(45deg);
}

.sidebar-restore {
  position: absolute;
  z-index: 12;
  left: 12px;
  bottom: 17px;
  width: 34px;
  height: 30px;
  border-radius: 8px;
  background: rgba(32, 32, 32, 0.9);
  opacity: 0;
  pointer-events: none;
}

.sidebar-restore::before {
  transform: rotate(-135deg);
}

.app.is-collapsed .sidebar-restore {
  opacity: 1;
  pointer-events: auto;
}

.board-shell {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  background: #121212;
}

.canvas-board {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.045) 0 1px, transparent 1.6px) var(--grid-x, 0px) var(--grid-y, 0px) / var(--grid-size, 16px) var(--grid-size, 16px),
    #131313;
  cursor: default;
}

.canvas-board.is-pan-ready {
  cursor: grab;
}

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

.selection-box {
  position: absolute;
  z-index: 6;
  display: none;
  border: 1px dashed rgba(238, 238, 238, 0.88);
  background: rgba(238, 238, 238, 0.12);
  box-shadow: none;
  pointer-events: none;
}

.selection-box.is-visible {
  display: block;
}

.canvas-board.is-dropping-media {
  outline: 1px solid rgba(114, 217, 163, 0.75);
  outline-offset: -1px;
}

.canvas-board::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 52% 55%, rgba(255, 255, 255, 0.04), transparent 20%),
    radial-gradient(circle at 62% 44%, rgba(80, 120, 255, 0.035), transparent 28%);
  pointer-events: none;
}

.world {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  will-change: transform;
}

.nodes-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.edge-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.guide-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.align-guide {
  position: absolute;
  display: none;
  pointer-events: none;
}

.align-guide.is-visible {
  display: block;
}

.align-guide.vertical {
  border-left: 1px dashed rgba(114, 217, 163, 0.95);
  filter: drop-shadow(0 0 5px rgba(114, 217, 163, 0.6));
}

.align-guide.horizontal {
  border-top: 1px dashed rgba(114, 217, 163, 0.95);
  filter: drop-shadow(0 0 5px rgba(114, 217, 163, 0.6));
}

.edge-line,
.edge-flow,
.edge-hit {
  fill: none;
  stroke-linecap: round;
  shape-rendering: geometricPrecision;
  vector-effect: non-scaling-stroke;
}

.edge-group {
  pointer-events: auto;
}

.edge-line {
  stroke: rgba(238, 238, 238, 0.72);
  stroke-width: 2;
  pointer-events: none;
}

.edge-flow {
  stroke: #d8f3ff;
  stroke-width: 3;
  stroke-dasharray: 16 42;
  animation: edgePulse 1.05s linear infinite;
  filter: drop-shadow(0 0 10px rgba(114, 211, 255, 0.9));
  opacity: 0;
  pointer-events: none;
}

.edge-hit {
  stroke: transparent;
  stroke-width: 18;
  pointer-events: stroke;
  cursor: pointer;
}

.edge-group:hover .edge-line,
.edge-group.is-temp .edge-line,
.edge-group.is-generating .edge-line {
  stroke: rgba(72, 174, 255, 0.88);
  stroke-width: 3;
  filter: drop-shadow(0 0 8px rgba(60, 170, 255, 0.72));
}

.edge-group:hover .edge-flow,
.edge-group.is-temp .edge-flow,
.edge-group.is-generating .edge-flow {
  opacity: 1;
}

@keyframes edgePulse {
  to {
    stroke-dashoffset: -58;
  }
}

.add-menu {
  position: absolute;
  z-index: 7;
  display: none;
  width: 240px;
  padding: 14px 16px;
  border: 1px solid #3b3b3b;
  border-radius: 14px;
  background: #262626;
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.36);
  user-select: none;
}

.add-menu * {
  user-select: none;
}

.add-menu.is-open {
  display: grid;
  gap: 10px;
}

.add-menu-title {
  color: var(--muted);
  font-size: 14px;
}

.add-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

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

.menu-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #4a4a4a;
  flex: 0 0 auto;
}

.menu-icon::before,
.menu-icon::after {
  content: "";
  position: absolute;
  border: 2px solid #fff;
}

.menu-icon.image::before {
  width: 17px;
  height: 14px;
  border-radius: 3px;
}

.menu-icon.image::after {
  right: 8px;
  top: 8px;
  width: 6px;
  height: 6px;
  border-left: 0;
  border-bottom: 0;
  transform: rotate(45deg);
}

.menu-icon.video::before {
  width: 16px;
  height: 18px;
  border-radius: 3px;
}

.menu-icon.video::after {
  right: 7px;
  width: 7px;
  height: 7px;
  border-left: 0;
  border-bottom: 0;
  transform: rotate(45deg);
}

.menu-icon.text::before {
  content: "T";
  width: auto;
  height: auto;
  border: 0;
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
}

.menu-icon.text::after {
  display: none;
}

.context-menu {
  position: absolute;
  z-index: 11;
  display: none;
  min-width: 110px;
  padding: 6px;
  border: 1px solid #3a3a3a;
  border-radius: 9px;
  background: #262626;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
}

.context-menu.is-open {
  display: block;
}

.context-menu button {
  width: 100%;
  height: 34px;
  border: 0;
  border-radius: 7px;
  color: var(--text);
  background: transparent;
  text-align: left;
  padding: 0 10px;
}

.context-menu button:hover {
  background: rgba(255, 255, 255, 0.1);
}

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

.context-menu.is-edge-menu #copyNodeBtn {
  display: none;
}

.context-menu.is-edge-menu #reversePromptBtn {
  display: none;
}

.context-menu.is-edge-menu #editImageBtn {
  display: none;
}

#deleteNodeBtn {
  color: #ffb4b4;
}

#deleteNodeBtn:hover {
  background: rgba(255, 71, 71, 0.16);
}

.top-actions {
  position: absolute;
  z-index: 8;
  top: 16px;
  right: 18px;
  display: flex;
  align-items: center;
}

.login-btn {
  height: 36px;
  min-width: 68px;
  padding: 0 18px;
  border: 1px solid #333;
  border-radius: 10px;
  color: #fff;
  background: #050505;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
}

.login-btn:hover {
  border-color: #555;
  background: #111;
}

.login-btn.is-signed-in {
  min-width: 72px;
  max-width: 180px;
  border-color: #4a4a4a;
  background: #181818;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canvas-node {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(280px * var(--s, 1));
  min-height: calc(170px * var(--s, 1));
  overflow: visible;
  border: 1px solid #3a3a3a;
  border-radius: calc(10px * var(--s, 1));
  color: var(--text);
  background: rgba(29, 29, 29, 0.94);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
  user-select: none;
  cursor: move;
  pointer-events: auto;
  will-change: transform, width, min-height;
}

.connector {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: calc(20px * var(--s, 1));
  height: calc(20px * var(--s, 1));
  border: 1px solid #9e9e9e;
  border-radius: 50%;
  color: #d8d8d8;
  background: rgba(36, 36, 36, 0.92);
  transform: translateY(-50%);
  cursor: crosshair;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 120ms ease;
}

.canvas-node:hover .connector,
.canvas-node.is-active .connector,
.canvas-node.is-connecting .connector,
.canvas-node.is-connect-target .connector,
.connector:hover {
  opacity: 1;
}

.connector::before,
.connector::after {
  content: "";
  position: absolute;
  width: calc(8px * var(--s, 1));
  height: 1px;
  background: currentColor;
}

.connector::after {
  transform: rotate(90deg);
}

.connector.left {
  left: calc(-24px * var(--s, 1));
}

.connector.right {
  right: calc(-24px * var(--s, 1));
}

.canvas-node.is-active {
  border-color: rgba(255, 255, 255, 0.68);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2), 0 24px 70px rgba(0, 0, 0, 0.42);
}

.canvas-node.is-selected {
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 24px 70px rgba(0, 0, 0, 0.42);
}

.canvas-node.is-active.is-selected {
  border-color: rgba(255, 255, 255, 0.74);
}

.inline-panel {
  position: absolute;
  width: 660px;
  min-height: 226px;
  padding: 14px;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  background: #262626;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  color: var(--text);
  pointer-events: auto;
}

.inline-generate-btn {
  position: relative;
  z-index: 5;
  pointer-events: auto;
  touch-action: manipulation;
}

.inline-generate-btn.is-running {
  color: #181818;
  background: #dededb;
}

.inline-generate-btn.is-paused {
  color: #102219;
  background: #72d9a3;
}

.inline-panel.is-expanded {
  position: absolute;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(980px, calc(100vw - 96px));
  height: min(880px, calc(100vh - 96px));
  min-height: min(560px, calc(100vh - 96px));
  max-height: calc(100vh - 96px);
  overflow: hidden;
  padding: 20px;
  transform-origin: center center;
  box-shadow: 0 30px 120px rgba(0, 0, 0, 0.62);
}

.panel-expand-btn {
  position: absolute;
  right: 14px;
  top: 14px;
  width: 36px;
  height: 36px;
  border: 1px solid #444;
  border-radius: 8px;
  color: #d8d8d8;
  background: rgba(24, 24, 24, 0.82);
}

.panel-expand-btn::before,
.panel-expand-btn::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: currentColor;
}

.panel-expand-btn::before {
  right: 9px;
  top: 8px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}

.panel-expand-btn::after {
  left: 9px;
  bottom: 8px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.inline-panel.is-expanded .panel-expand-btn::before {
  right: 17px;
  top: 16px;
}

.inline-panel.is-expanded .panel-expand-btn::after {
  left: 17px;
  bottom: 16px;
}

.inline-prompt {
  position: relative;
  width: 100%;
  min-height: 96px;
  border: 1px solid rgba(220, 220, 220, 0.32);
  border-radius: 8px;
  color: #d8d8d8;
  background: transparent;
  resize: none;
  line-height: 1.55;
  padding: 16px 52px 16px 18px;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

.inline-prompt::selection,
.inline-prompt *::selection {
  color: #ffffff !important;
  background: rgba(220, 220, 220, 0.56) !important;
  -webkit-text-fill-color: #ffffff !important;
}

.inline-panel .inline-prompt::selection,
.inline-panel .inline-prompt *::selection,
.prompt-chip::selection,
.prompt-chip *::selection,
textarea.inline-prompt::selection {
  color: #ffffff !important;
  background: rgba(220, 220, 220, 0.56) !important;
  -webkit-text-fill-color: #ffffff !important;
}

.inline-prompt:focus {
  border-color: rgba(245, 245, 245, 0.68);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.inline-prompt:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.inline-panel.is-expanded .inline-prompt {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 56px;
  font-size: 15px;
  scrollbar-width: thin;
  scrollbar-color: #6a6a68 #2a2a29;
}

.inline-panel.is-expanded .inline-prompt::-webkit-scrollbar {
  width: 10px;
}

.inline-panel.is-expanded .inline-prompt::-webkit-scrollbar-track {
  background: #2a2a29;
}

.inline-panel.is-expanded .inline-prompt::-webkit-scrollbar-thumb {
  border: 2px solid #2a2a29;
  border-radius: 8px;
  background: #6a6a68;
}

.inline-panel.is-expanded .reference-strip,
.inline-panel.is-expanded .inline-controls {
  flex: 0 0 auto;
}

.mention-menu {
  position: absolute;
  left: 14px;
  top: 96px;
  z-index: 25;
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow-x: hidden;
  overflow-y: auto;
  margin-top: 0;
  padding: 8px;
  border: 1px solid #3d3d3d;
  border-radius: 10px;
  background: #1b1b1b;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
}

.inline-panel.is-expanded .mention-menu {
  margin-top: 0;
}

.mention-menu.is-open {
  display: grid;
}

.mention-menu button {
  display: grid;
  grid-template-columns: 42px auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  height: 52px;
  border: 1px solid #3f3f3f;
  border-radius: 8px;
  color: var(--text);
  background: #252525;
  padding: 5px 8px 5px 5px;
  text-align: left;
}

.mention-menu button:hover {
  border-color: #6b6b6b;
  background: #2f2f2f;
}

.mention-menu img,
.mention-menu video,
.mention-menu .video-thumb-placeholder,
.mention-menu .audio-thumb-placeholder {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  object-fit: cover;
  background: #111;
}

.mention-menu span {
  font-size: 12px;
  font-weight: 800;
}

.mention-empty {
  display: block;
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
}

.mention-strip {
  position: absolute;
  left: 18px;
  top: 18px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 210px;
  min-height: 44px;
  margin: 0;
  pointer-events: auto;
}

.mention-strip button {
  position: relative;
  width: 66px;
  height: 54px;
  overflow: hidden;
  border: 1px solid #565656;
  border-radius: 8px;
  background: #151515;
  padding: 0;
}

.mention-strip button::after {
  content: attr(data-index);
  position: absolute;
  right: -2px;
  top: -2px;
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  font-size: 10px;
  line-height: 1;
  opacity: 1;
}

.mention-strip button:hover::after {
  opacity: 1;
}

.mention-strip img,
.mention-strip video,
.mention-strip .audio-thumb-placeholder {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.inline-panel:has(.mention-strip) .inline-prompt {
  padding-top: 68px;
  padding-left: 0;
}

.inline-panel.is-expanded .mention-strip {
  left: 24px;
  top: 24px;
}

.inline-panel.is-expanded:has(.mention-strip) .inline-prompt {
  padding-top: 72px;
  padding-left: 0;
}

.prompt-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-inline: 4px;
  padding: 2px 7px 2px 3px;
  border: 1px solid #3d3d3d;
  border-radius: 999px;
  color: #fff;
  background: #1d1d1d;
  vertical-align: middle;
  font-size: 15px;
  font-weight: 800;
  cursor: text;
  white-space: nowrap;
}

.prompt-chip img,
.prompt-chip video,
.prompt-chip .audio-thumb-placeholder {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  object-fit: cover;
}

.reference-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  min-height: 56px;
  margin: 0 44px 8px 0;
}

.reference-strip > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.reference-strip > div {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.reference-thumb {
  position: relative;
  display: block;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
}

.reference-strip img,
.reference-strip video,
.video-thumb-placeholder,
.audio-thumb-placeholder,
.text-thumb-placeholder {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border: 1px solid #454545;
  border-radius: 10px;
  object-fit: cover;
  background: #111;
  cursor: zoom-in;
}

.video-thumb-placeholder {
  position: relative;
  display: block;
  background: linear-gradient(135deg, #151515, #2a2a2a);
}

.audio-thumb-placeholder {
  display: grid;
  place-items: center;
  color: #f2f2f2;
  background: linear-gradient(135deg, #182033, #302345);
  font-size: 11px;
  font-weight: 800;
}

.text-thumb-placeholder {
  display: grid;
  place-items: center;
  color: #eeeeec;
  background: #20201f;
  font-size: 12px;
  font-weight: 800;
}

.audio-thumb-placeholder::before {
  content: "♪";
}

.video-thumb-placeholder::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 12px solid rgba(255, 255, 255, 0.78);
  transform: translate(-35%, -50%);
}

.reference-thumb button {
  position: absolute;
  right: -4px;
  top: -4px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  color: #fff;
  background: rgba(10, 10, 10, 0.86);
  cursor: pointer;
}

.reference-thumb button::before,
.reference-thumb button::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 1.5px;
  border-radius: 999px;
  background: currentColor;
}

.reference-thumb button::before {
  transform: rotate(45deg);
}

.reference-thumb button::after {
  transform: rotate(-45deg);
}

.reference-thumb button:hover {
  background: #f04444;
  border-color: #f04444;
}

.inline-controls {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(110px, 0.8fr) minmax(120px, 1fr) minmax(96px, 0.7fr) 40px;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: #f1f1f1;
  font-size: 13px;
}

.inline-controls.is-video {
  grid-template-columns: minmax(130px, 1fr) minmax(120px, 1fr) minmax(120px, 1fr) minmax(120px, 1fr) 40px;
}

.inline-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.inline-controls select {
  height: 34px;
  border: 1px solid #444;
  border-radius: 8px;
  color: var(--text);
  background: #181818;
  padding: 0 9px;
  color-scheme: dark;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.inline-controls select:focus {
  border-color: #6a6a6a;
  background: #181818;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.inline-controls option {
  color: var(--text);
  background: #181818;
}

.native-select-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.custom-select {
  position: relative;
  min-width: 0;
}

.custom-select [data-select-toggle] {
  position: relative;
  width: 100%;
  height: 34px;
  border: 1px solid #444;
  border-radius: 8px;
  color: var(--text);
  background: #181818;
  padding: 0 30px 0 9px;
  text-align: left;
  font-weight: 700;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.custom-select [data-select-toggle]::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-65%) rotate(45deg);
  opacity: 0.8;
}

.custom-select.is-open [data-select-toggle] {
  border-color: #6a6a6a;
  background: #1f1f1f;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.custom-options {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: none;
  max-height: 188px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid #414141;
  border-radius: 8px;
  background: #1b1b1b;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.42);
  scrollbar-width: none;
}

.custom-options::-webkit-scrollbar,
.mention-menu::-webkit-scrollbar,
.reference-strip > div::-webkit-scrollbar {
  display: none;
}

.mention-menu,
.reference-strip > div {
  scrollbar-width: none;
}

.custom-select.is-open .custom-options {
  display: grid;
  gap: 3px;
}

/* The expanded panel keeps its controls pinned to the bottom of the viewport.
   Open their menus upward so every option remains inside the visible panel. */
.inline-panel.is-expanded .custom-options {
  top: auto;
  bottom: calc(100% + 6px);
  max-height: min(188px, calc(100vh - 180px));
  overscroll-behavior: contain;
}

.custom-options [data-select-option] {
  width: 100%;
  height: 30px;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  padding: 0 8px;
  text-align: left;
  font-weight: 700;
}

.custom-options [data-select-option]:hover,
.custom-options [data-select-option].is-selected {
  background: #303030;
}

.inline-controls button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  color: #111;
  background: #d8d8d8;
  font-weight: 900;
  align-self: end;
}

.node-preview {
  height: var(--node-h);
  border-radius: inherit;
  background: url("assets/node-thumb.png") center / cover;
}

.canvas-node.has-image .node-preview {
  height: var(--node-h);
  border-radius: inherit;
  background: transparent;
}

.canvas-node.has-image .node-preview img,
.canvas-node.has-image .node-preview video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  user-select: none;
}

.canvas-node.has-image .node-preview img {
  -webkit-user-drag: none;
  pointer-events: none;
}

.canvas-node.has-image .node-preview video {
  object-fit: contain;
  background: #000;
}

.view-image-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: calc(38px * var(--s, 1));
  height: calc(38px * var(--s, 1));
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 50%;
  color: #fff;
  background: rgba(0, 0, 0, 0.46);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 120ms ease, background 120ms ease;
  cursor: pointer;
}

.canvas-node.has-image:hover .view-image-btn {
  opacity: 1;
}

.view-image-btn::before {
  content: "";
  width: calc(18px * var(--s, 1));
  height: calc(11px * var(--s, 1));
  border: calc(2px * var(--s, 1)) solid currentColor;
  border-radius: 999px / 70%;
}

.view-image-btn::after {
  content: "";
  position: absolute;
  width: calc(6px * var(--s, 1));
  height: calc(6px * var(--s, 1));
  border-radius: 50%;
  background: currentColor;
}

.view-video-btn::before {
  width: 0;
  height: 0;
  margin-left: calc(3px * var(--s, 1));
  border-top: calc(9px * var(--s, 1)) solid transparent;
  border-bottom: calc(9px * var(--s, 1)) solid transparent;
  border-left: calc(14px * var(--s, 1)) solid currentColor;
  border-radius: 0;
}

.view-video-btn::after {
  display: none;
}

.canvas-node.has-image .node-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
}

.node-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: block;
  padding: calc(12px * var(--s, 1));
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.72), transparent);
}

.node-body strong {
  display: block;
  font-size: calc(14px * var(--s, 1));
  line-height: 1.2;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
}

.node-error {
  display: -webkit-box;
  margin: calc(7px * var(--s, 1)) 0 0;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #ffd2d2;
  font-size: calc(11px * var(--s, 1));
  line-height: 1.35;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
}

.node-text-output {
  display: block;
  margin: calc(7px * var(--s, 1)) 0 0;
  overflow: hidden;
  color: #d7efe8;
  font-size: calc(11px * var(--s, 1));
  line-height: 1.42;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
  white-space: pre-wrap;
}

.canvas-node.is-text {
  overflow: visible;
  background: #181818;
  user-select: text;
  -webkit-user-select: text;
}

.canvas-node.is-text .node-preview {
  display: none;
}

.canvas-node.is-text .node-body {
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(18px * var(--s, 1));
  border-radius: inherit;
  background: #181818;
}

.canvas-node.is-text .node-body strong {
  flex: 0 0 auto;
  padding-right: calc(42px * var(--s, 1));
  padding-bottom: calc(13px * var(--s, 1));
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  font-size: calc(15px * var(--s, 1));
  text-shadow: none;
  user-select: none;
  -webkit-user-select: none;
}

.canvas-node.is-text .node-text-output {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: calc(14px * var(--s, 1));
  padding-right: calc(8px * var(--s, 1));
  overflow: auto;
  color: #eeeeec;
  font-size: calc(14px * var(--s, 1));
  line-height: 1.75;
  overflow-wrap: anywhere;
  text-shadow: none;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  outline: none;
}

.canvas-node.is-text .node-text-output.is-empty {
  color: #8d8d8a;
}

.canvas-node.is-text .node-text-output::selection,
.canvas-node.is-text .node-text-output *::selection {
  color: #ffffff !important;
  background: rgba(220, 220, 220, 0.56) !important;
  -webkit-text-fill-color: #ffffff !important;
}

.canvas-node.is-text .node-text-output:focus-visible {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.text-node-expand {
  position: absolute;
  right: calc(10px * var(--s, 1));
  top: calc(10px * var(--s, 1));
  z-index: 4;
  width: calc(34px * var(--s, 1));
  height: calc(34px * var(--s, 1));
  padding: 0;
  border: 1px solid #444;
  border-radius: calc(8px * var(--s, 1));
  color: #d8d8d8;
  background: rgba(24, 24, 24, 0.88);
  user-select: none;
  -webkit-user-select: none;
}

.text-node-expand::before,
.text-node-expand::after,
.text-viewer-toggle::before,
.text-viewer-toggle::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: currentColor;
}

.text-node-expand::before {
  right: 7px;
  top: 6px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}

.text-node-expand::after {
  left: 7px;
  bottom: 6px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.text-node-expand:hover {
  color: #fff;
  border-color: #666;
  background: #2b2b2b;
}

.text-node-resize {
  position: absolute;
  right: 5px;
  bottom: 5px;
  z-index: 4;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: nwse-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.text-node-resize::before,
.text-node-resize::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  border-right: 2px solid rgba(255, 255, 255, 0.62);
  border-bottom: 2px solid rgba(255, 255, 255, 0.62);
}

.text-node-resize::before {
  width: 10px;
  height: 10px;
}

.text-node-resize::after {
  width: 5px;
  height: 5px;
}

.text-node-resize:hover {
  background: rgba(255, 255, 255, 0.08);
}

.node-progress {
  width: calc(118px * var(--s, 1));
  height: calc(5px * var(--s, 1));
  margin-top: calc(8px * var(--s, 1));
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
}

.node-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38d5ff, #7cffb2, #ffe06c, #ff7ad9);
  background-size: 180% 100%;
  box-shadow: 0 0 calc(14px * var(--s, 1)) rgba(96, 218, 255, 0.55);
  animation: node-progress-flow 1.2s linear infinite;
}

@keyframes node-progress-flow {
  from {
    background-position: 0 0;
  }

  to {
    background-position: 180% 0;
  }
}

.bottom-left {
  position: fixed;
  z-index: 70;
  left: calc(var(--sidebar-width) + 22px);
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - var(--sidebar-width) - 44px);
  color: var(--text);
  font-size: 13px;
  pointer-events: auto;
}

#zoomLabel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #fff;
  background: rgba(18, 18, 18, 0.9);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.75);
  white-space: nowrap;
}

.app.is-collapsed .bottom-left {
  left: 58px;
}

.canvas-action-btn {
  height: 30px;
  border: 1px solid #3b3b3b;
  border-radius: 8px;
  color: #d8d8d8;
  background: rgba(34, 34, 34, 0.92);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.canvas-action-btn.is-active {
  border-color: rgba(114, 217, 163, 0.7);
  color: #111;
  background: var(--green);
}

.api-config-btn {
  position: absolute;
  z-index: 9;
  right: 18px;
  bottom: 18px;
  width: 44px;
  height: 34px;
  border: 1px solid #3c3c3c;
  border-radius: 8px;
  color: #fff;
  background: #111;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.36);
}

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

.api-modal {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(4px);
}

.api-modal.is-open {
  display: grid;
}

.api-dialog {
  width: min(720px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid #3b3b3b;
  border-radius: 8px;
  background: #202020;
  box-shadow: 0 24px 78px rgba(0, 0, 0, 0.46);
}

.api-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 8px;
}

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

.api-dialog-head strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

#closeApiModal {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: #303030;
}

.api-section {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  border-top: 1px solid #303030;
}

.api-section h2 {
  margin: 0;
  font-size: 15px;
}

.api-section label {
  display: grid;
  gap: 7px;
  color: #d8d8d8;
  font-size: 12px;
  font-weight: 700;
}

.api-section input {
  width: 100%;
  height: 38px;
  border: 1px solid #3d3d3d;
  border-radius: 8px;
  color: var(--text);
  background: #111;
  padding: 0 10px;
}

.api-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px 18px;
  border-top: 1px solid #303030;
  color: var(--muted);
  font-size: 12px;
}

.api-actions .is-error {
  color: #ff8585;
}

.api-actions button {
  height: 38px;
  border: 0;
  border-radius: 8px;
  color: #111;
  background: #f2f2f2;
  padding: 0 16px;
  font-weight: 900;
}

.auth-modal {
  position: absolute;
  z-index: 24;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.auth-modal.is-open {
  display: grid;
}

.auth-dialog {
  width: min(420px, calc(100vw - 48px));
  border: 1px solid #3b3b3b;
  border-radius: 14px;
  background: #202020;
  box-shadow: 0 24px 78px rgba(0, 0, 0, 0.48);
}

.auth-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 10px;
}

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

.auth-dialog-head strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

#closeAuthModal {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: #303030;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 18px 14px;
}

.auth-tabs button {
  height: 36px;
  border: 1px solid #3d3d3d;
  border-radius: 8px;
  color: var(--text);
  background: #151515;
  font-weight: 800;
}

.auth-tabs button.is-active {
  border-color: #f2f2f2;
  background: #f2f2f2;
  color: #111;
}

.account-panel {
  display: none;
  gap: 8px;
  margin: 0 18px 14px;
  padding: 14px;
  border: 1px solid #3a3a3a;
  border-radius: 10px;
  background: #181818;
}

.account-panel span,
.account-panel strong {
  display: block;
}

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

.account-panel strong {
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 16px;
}

.auth-modal.is-account .auth-tabs,
.auth-modal.is-account .auth-form {
  display: none;
}

.auth-modal.is-account .account-panel {
  display: grid;
}

.account-name-form {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.account-name-form label,
.account-name-form p {
  color: var(--muted);
  font-size: 12px;
}

.account-name-form > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.account-name-form input,
.account-name-form button {
  height: 38px;
  border: 1px solid #454545;
  border-radius: 8px;
}

.account-name-form input {
  min-width: 0;
  color: var(--text);
  background: #111;
  padding: 0 10px;
}

.account-name-form button {
  color: #111;
  background: #ededed;
  padding: 0 12px;
  font-weight: 800;
}

.account-name-form p {
  min-height: 16px;
  margin: 0;
}

.account-name-form p.is-error {
  color: #ff9d9d;
}

.auth-form {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: #d8d8d8;
  font-size: 12px;
  font-weight: 700;
}

.auth-form input {
  width: 100%;
  height: 42px;
  border: 1px solid #3d3d3d;
  border-radius: 8px;
  color: var(--text);
  background: #111;
  padding: 0 12px;
  outline: none;
}

.auth-form input:focus {
  border-color: #777;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: #ff9d9d;
  font-size: 12px;
}

.auth-submit {
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: #111;
  background: #f2f2f2;
  font-weight: 900;
}

.auth-secondary {
  display: none;
  height: 38px;
  border: 1px solid #444;
  border-radius: 8px;
  color: #f2f2f2;
  background: transparent;
  font-weight: 800;
}

.auth-secondary.is-visible {
  display: block;
}

.account-actions {
  display: grid;
  gap: 8px;
  padding: 0 18px 18px;
}

.auth-modal.is-account .auth-secondary {
  display: block;
  width: 100%;
}

.permission-modal {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
}

.permission-modal.is-open {
  display: grid;
}

.permission-dialog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(1180px, calc(100vw - 48px));
  max-height: min(760px, calc(100vh - 48px));
  border: 1px solid #444;
  border-radius: 8px;
  background: #202020;
  box-shadow: 0 24px 78px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.permission-dialog-head,
.permission-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

.permission-dialog-head {
  border-bottom: 1px solid #353535;
}

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

.permission-dialog-head strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
}

#closePermissionModal,
.permission-actions button,
.permission-save-btn,
.permission-delete-btn,
.permission-clear-usage-btn,
.permission-create-form button {
  height: 34px;
  border: 1px solid #494949;
  border-radius: 6px;
  color: var(--text);
  background: #2a2a2a;
  padding: 0 12px;
  font-weight: 800;
}

#closePermissionModal {
  width: 34px;
  padding: 0;
}

.permission-table-wrap {
  overflow: auto;
}

.permission-create-form {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(180px, 0.7fr) 130px auto;
  align-items: end;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid #353535;
  background: #242424;
}

.permission-create-form label {
  display: grid;
  gap: 6px;
  color: #aaa;
  font-size: 12px;
}

.permission-create-form input,
.permission-create-form select {
  width: 100%;
  height: 36px;
  border: 1px solid #494949;
  border-radius: 6px;
  color: var(--text);
  background: #171717;
  padding: 0 10px;
}

.permission-create-form button {
  background: #ededed;
  color: #171717;
}

.permission-table {
  width: 100%;
  border-collapse: collapse;
  color: #e8e8e8;
  font-size: 13px;
}

.permission-table th,
.permission-table td {
  height: 48px;
  border-bottom: 1px solid #343434;
  padding: 8px 10px;
  text-align: center;
  white-space: nowrap;
}

.permission-table th:first-child,
.permission-table td:first-child {
  min-width: 220px;
  text-align: left;
}

.permission-user-email {
  display: block;
  margin-top: 3px;
  color: #888;
  font-size: 11px;
  font-weight: 500;
}

.permission-table thead th {
  position: sticky;
  z-index: 1;
  top: 0;
  color: #aaa;
  background: #191919;
  font-size: 12px;
}

.permission-table select {
  height: 32px;
  border: 1px solid #444;
  border-radius: 6px;
  color: var(--text);
  background: #151515;
  padding: 0 8px;
}

.permission-display-name-input {
  width: 120px;
  height: 32px;
  border: 1px solid #444;
  border-radius: 6px;
  color: var(--text);
  background: #151515;
  padding: 0 8px;
  outline: none;
}

.permission-display-name-input:focus {
  border-color: #777;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 8%);
}

.permission-moyu-usage {
  min-width: 288px;
  text-align: right !important;
}

.permission-moyu-usage span {
  display: block;
}

.permission-moyu-editor {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.permission-moyu-currency {
  margin: 0 !important;
  color: #f2f2f2 !important;
  font-size: 13px !important;
}

.permission-moyu-amount-input {
  width: 92px;
  height: 28px;
  border: 1px solid #444;
  border-radius: 6px;
  color: #f2f2f2;
  background: #151515;
  padding: 0 7px;
  outline: none;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.permission-moyu-amount-input:focus {
  border-color: #777;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 8%);
}

.permission-moyu-usage span {
  margin-top: 3px;
  color: #888;
  font-size: 11px;
}

.permission-moyu-usage span.is-paused {
  color: #ffb86b;
}

.permission-save-usage-btn,
.permission-clear-usage-btn {
  height: 24px;
  margin-top: 0;
  padding: 0 8px;
  font-size: 11px;
}

.permission-save-usage-btn {
  color: #d8e7ff;
  border-color: #465c7a;
  background: #24354d;
}

.permission-clear-usage-btn {
  color: #bfe7ca;
  border-color: #3f624b;
  background: #203329;
}

.permission-save-usage-btn:disabled,
.permission-clear-usage-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.permission-table tr[data-spend-paused="true"] {
  background: rgba(133, 76, 28, 0.16);
}

.permission-table input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: #f2f2f2;
}

.permission-table tr[data-primary-admin="true"] {
  background: #252525;
}

.permission-managed-state {
  display: inline-flex;
  align-items: center;
  height: 24px;
  border: 1px solid #3f624b;
  border-radius: 6px;
  color: #bce9c8;
  background: #203329;
  padding: 0 8px;
  font-size: 12px;
}

.permission-managed-state.is-unmanaged {
  border-color: #70583d;
  color: #ffd39c;
  background: #382c20;
}

.permission-row-actions {
  display: flex;
  gap: 6px;
}

.permission-delete-btn {
  color: #ffb2b2;
  border-color: #6a3d3d;
}

.permission-actions {
  border-top: 1px solid #353535;
}

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

.permission-status-error {
  color: #ff9d9d !important;
}

@media (max-width: 720px) {
  .permission-modal {
    padding: 10px;
  }

  .permission-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .permission-create-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}

.image-viewer {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: none;
  grid-template-rows: auto 1fr;
  gap: 16px;
  padding: 18px;
  background: rgba(16, 16, 16, 0.18);
  backdrop-filter: blur(2px);
  overscroll-behavior: contain;
  touch-action: none;
  user-select: none;
}

.image-viewer.is-open {
  display: grid;
}

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

.image-viewer-head div {
  display: flex;
  gap: 8px;
}

.image-viewer-head button {
  height: 34px;
  border: 1px solid #3d3d3d;
  border-radius: 8px;
  color: var(--text);
  background: #242424;
  padding: 0 12px;
  font-weight: 800;
}

#viewerImage {
  grid-row: 2;
  align-self: center;
  justify-self: center;
  width: auto;
  height: auto;
  max-width: calc(100vw - 36px);
  max-height: calc(100vh - 86px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: none;
  transform: none;
  cursor: default;
}

#viewerVideo {
  display: none;
  grid-row: 2;
  align-self: center;
  justify-self: center;
  width: auto;
  height: auto;
  max-width: calc(100vw - 36px);
  max-height: calc(100vh - 86px);
  object-fit: contain;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  transform: none;
}

.image-editor {
  position: fixed;
  z-index: 96;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(8, 8, 8, 0.82);
  backdrop-filter: blur(5px);
  overscroll-behavior: contain;
}

.image-editor.is-open {
  display: grid;
}

.image-editor-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1220px, calc(100vw - 36px));
  height: min(900px, calc(100vh - 36px));
  border: 1px solid #414141;
  border-radius: 16px;
  overflow: hidden;
  background: #1c1c1c;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.58);
}

.image-editor-head,
.image-editor-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #222;
}

.image-editor-head {
  justify-content: space-between;
  border-bottom: 1px solid #343434;
}

.image-editor-head strong,
.image-editor-head span {
  display: block;
}

.image-editor-head span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.image-editor-head span.is-error {
  color: #ff9d9d;
}

.image-editor-head button,
.image-editor-tools button {
  min-height: 36px;
  border: 1px solid #454545;
  border-radius: 8px;
  color: var(--text);
  background: #292929;
  padding: 0 12px;
  font-weight: 800;
}

.image-editor-tools button.is-active {
  border-color: #f0f0f0;
  background: #e8e8e8;
  color: #111;
}

.image-editor-tools button.is-primary {
  border-color: #f4f4f4;
  background: #f4f4f4;
  color: #111;
}

.image-editor-tools button:disabled {
  opacity: 0.45;
}

.image-editor-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 14px;
  overflow: auto;
  background-color: #111;
  background-image: linear-gradient(45deg, #191919 25%, transparent 25%), linear-gradient(-45deg, #191919 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #191919 75%), linear-gradient(-45deg, transparent 75%, #191919 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

#imageEditorCanvas {
  display: block;
  max-width: calc(min(1220px, 100vw - 36px) - 28px);
  max-height: calc(min(900px, 100vh - 36px) - 150px);
  width: auto;
  height: auto;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  cursor: crosshair;
  touch-action: none;
}

.image-editor-tools {
  flex-wrap: wrap;
  border-top: 1px solid #343434;
}

.image-editor-tools label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ccc;
  font-size: 12px;
  font-weight: 800;
}

.image-editor-tools input[type="color"] {
  width: 42px;
  height: 34px;
  border: 1px solid #444;
  border-radius: 7px;
  padding: 2px;
  background: #111;
}

.image-editor-size input {
  width: 150px;
}

.image-editor-size output {
  min-width: 24px;
  text-align: right;
}

.image-editor-spacer {
  flex: 1 1 20px;
}

@media (max-width: 720px) {
  .image-editor {
    padding: 8px;
  }

  .image-editor-dialog {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
  }

  .image-editor-size input {
    width: 92px;
  }
}

.text-viewer {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(10, 10, 10, 0.72);
  backdrop-filter: blur(4px);
  overscroll-behavior: contain;
}

.text-viewer.is-open {
  display: grid;
}

.text-viewer-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1320px, calc(100vw - 48px));
  height: min(920px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid #555;
  border-radius: 8px;
  background: #181818;
  box-shadow: 0 32px 110px rgba(0, 0, 0, 0.62);
}

.text-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 18px 0 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.text-viewer-head strong {
  font-size: 20px;
}

.text-viewer-toggle {
  position: relative;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid #444;
  border-radius: 8px;
  color: #e2e2df;
  background: #242424;
}

.text-viewer-toggle::before {
  right: 17px;
  top: 16px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}

.text-viewer-toggle::after {
  left: 17px;
  bottom: 16px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.text-viewer-toggle:hover {
  color: #fff;
  border-color: #666;
  background: #303030;
}

.text-viewer-content {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 28px 34px 44px;
  color: #eeeeec;
  font-size: 18px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  scrollbar-width: thin;
  scrollbar-color: #686866 #242423;
}

.text-viewer-content::selection,
.text-viewer-content *::selection {
  color: #fff;
  background: rgba(220, 220, 220, 0.56);
}

.text-viewer-content::-webkit-scrollbar {
  width: 10px;
}

.text-viewer-content::-webkit-scrollbar-track {
  background: #242423;
}

.text-viewer-content::-webkit-scrollbar-thumb {
  border: 2px solid #242423;
  border-radius: 8px;
  background: #686866;
}

.inspector {
  position: absolute;
  z-index: 9;
  display: none;
  top: 74px;
  right: 18px;
  gap: 14px;
  width: 340px;
  padding: 16px;
  border: 1px solid #373737;
  border-radius: 12px;
  background: rgba(26, 26, 26, 0.96);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  transform: translateX(390px);
  transition: transform 180ms ease;
}

.inspector.is-open {
  transform: translateX(0);
}

.inspector-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

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

.inspector-head strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

#closeInspector {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #2a2a2a;
}

.inspector label {
  display: grid;
  gap: 8px;
  color: #d7d7d7;
  font-size: 12px;
  font-weight: 700;
}

textarea,
select {
  width: 100%;
  border: 1px solid #383838;
  border-radius: 8px;
  color: var(--text);
  background: #101010;
}

textarea {
  min-height: 105px;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
}

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

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.generate-action {
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: #111;
  background: #f3f3f3;
  font-weight: 800;
}

.result-preview {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid #333;
  border-radius: 8px;
  background: #161616;
}

.result-preview img {
  width: 80px;
  height: 48px;
  border-radius: 5px;
  object-fit: cover;
}

.result-preview strong,
.result-preview span {
  display: block;
  font-size: 12px;
}

.result-preview span {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 760px) {
  .app,
  .app.is-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    transform: translateX(0);
    transition: transform 180ms ease;
  }

  .app.is-collapsed .sidebar {
    transform: translateX(-100%);
  }

  .inspector {
    left: 12px;
    right: 12px;
    width: auto;
    transform: translateY(110%);
  }

  .inspector.is-open {
    transform: translateY(0);
  }

  .bottom-left,
  .app.is-collapsed .bottom-left {
    left: 12px;
    right: 12px;
    max-width: none;
    gap: 8px;
    overflow-x: auto;
  }
}
