@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Orbitron:wght@500;600;700&display=swap");

:root {
  --bg-1: #f3efe7;
  --bg-2: #d7e7df;
  --ink: #1a1a1a;
  --muted: #5b5b5b;
  --panel: #fdfcf8;
  --panel-shadow: rgba(28, 35, 32, 0.12);
  --accent: #f07c5c;
  --accent-2: #20786e;
  --accent-3: #f2c14f;
  --border: rgba(26, 26, 26, 0.15);
  --grid: rgba(26, 26, 26, 0.07);
}

body.theme-console {
  --bg-1: #0b1220;
  --bg-2: #0f1b2b;
  --ink: #e3f3ef;
  --muted: #9db4b0;
  --panel: #0f1724;
  --panel-shadow: rgba(0, 0, 0, 0.45);
  --accent: #45f3ff;
  --accent-2: #8b6bff;
  --accent-3: #ffb45e;
  --border: rgba(69, 243, 255, 0.18);
  --grid: rgba(69, 243, 255, 0.08);
  font-family: "Manrope", "Space Grotesk", "Helvetica Neue", "Noto Sans", sans-serif;
  background: radial-gradient(circle at top, #111c2d 0%, var(--bg-1) 38%, var(--bg-2) 100%);
}

body.theme-console .logo {
  font-family: "Orbitron", "Fraunces", "Georgia", serif;
}

body.theme-console .topbar {
  background: linear-gradient(120deg, #0d1826, #0f1b2b 50%, #101f32 90%);
  border-bottom: 1px solid var(--border);
}

body.theme-console .btn {
  color: #081b22;
  box-shadow: 0 8px 18px rgba(69, 243, 255, 0.22);
}

body.theme-console .btn:hover {
  box-shadow: 0 12px 26px rgba(69, 243, 255, 0.28);
}

body.theme-console .btn.ghost {
  border-color: rgba(69, 243, 255, 0.25);
  color: var(--ink);
}

body.theme-console .tool-btn:hover {
  background: rgba(69, 243, 255, 0.12);
  border-color: rgba(69, 243, 255, 0.4);
}

body.theme-console .tool-btn.active {
  background: rgba(139, 107, 255, 0.18);
  border-color: rgba(139, 107, 255, 0.5);
}

body.theme-console .sidebar,
body.theme-console .inspector,
body.theme-console .canvas-toolbar {
  background: rgba(12, 20, 34, 0.92);
  border-color: rgba(69, 243, 255, 0.2);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

body.theme-console .panel-title,
body.theme-console .hint,
body.theme-console .muted-text {
  color: var(--muted);
}

body.theme-console .zoom-value,
body.theme-console .chip {
  background: rgba(12, 18, 30, 0.9);
  color: var(--muted);
  border-color: rgba(69, 243, 255, 0.2);
}

body.theme-console .field input,
body.theme-console .field textarea,
body.theme-console .field select {
  background: rgba(10, 16, 27, 0.85);
  color: var(--ink);
  border-color: rgba(69, 243, 255, 0.25);
}

body.theme-console .field input:focus,
body.theme-console .field textarea:focus,
body.theme-console .field select:focus {
  outline: 2px solid rgba(69, 243, 255, 0.45);
  border-color: rgba(69, 243, 255, 0.6);
}

body.theme-console .canvas {
  background: linear-gradient(150deg, #0b1220 0%, #0e1726 100%);
  border-color: rgba(69, 243, 255, 0.2);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  background-image: linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px),
    radial-gradient(circle at 20% 20%, rgba(69, 243, 255, 0.12), transparent 45%);
}

body.theme-console .connections path {
  stroke: rgba(232, 240, 255, 0.65);
}

body.theme-console .connections marker path {
  fill: rgba(232, 240, 255, 0.65);
}

body.theme-console .connections path.edge.selected {
  stroke: var(--accent);
}

body.theme-console .node {
  --node-fill: #15253a;
  --node-stroke: rgba(69, 243, 255, 0.55);
}

body.theme-console .node-shape {
  color: #e8f0ff;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
}

body.theme-console .node.selected {
  box-shadow: 0 0 0 3px rgba(69, 243, 255, 0.35);
}

body.theme-console .node.connect-source .node-shape {
  box-shadow: 0 0 0 3px rgba(255, 180, 94, 0.45);
}

body.theme-console .node.type-terminator {
  --node-fill: #14362b;
  --node-stroke: rgba(109, 255, 136, 0.6);
}

body.theme-console .node.type-process {
  --node-fill: #16263b;
  --node-stroke: rgba(69, 243, 255, 0.55);
}

body.theme-console .node.type-decision {
  --node-fill: #2b2316;
  --node-stroke: rgba(255, 180, 94, 0.65);
}

body.theme-console .node.type-gate {
  --node-fill: #241a38;
  --node-stroke: rgba(139, 107, 255, 0.65);
}

body.theme-console .node.type-note {
  --node-fill: #2f2a1b;
  --node-stroke: rgba(255, 180, 94, 0.65);
}

body.theme-console .inline-edit {
  background: #0b1220;
  color: var(--ink);
  border-color: rgba(69, 243, 255, 0.45);
}

body.theme-console .empty-hint {
  background: rgba(12, 18, 30, 0.9);
  color: var(--muted);
  border-color: rgba(69, 243, 255, 0.2);
}

body.embed .topbar {
  padding: 12px 18px;
}

body.embed .workspace {
  padding: 12px 16px 18px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Helvetica Neue", "Noto Sans", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #ffffff 0%, var(--bg-1) 38%, var(--bg-2) 100%);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.6s ease;
}

.topbar {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 26px;
  background: linear-gradient(120deg, #fff2df, #f9f7f0 30%, #e8f2ea 80%);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.logo {
  font-family: "Fraunces", "Georgia", serif;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}

.tagline {
  font-size: 0.95rem;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  border: none;
  background: var(--accent);
  color: #1d0e0a;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(240, 124, 92, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(240, 124, 92, 0.3);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
  box-shadow: none;
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.85rem;
  box-shadow: none;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 260px;
  gap: 18px;
  padding: 18px 22px 24px;
}

.sidebar,
.inspector {
  background: var(--panel);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 18px 40px var(--panel-shadow);
  border: 1px solid rgba(26, 26, 26, 0.08);
  animation: riseIn 0.6s ease;
}

.panel-title {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 14px;
}

.tool-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s ease, border 0.2s ease, transform 0.2s ease;
  animation: stagger 0.4s ease both;
  animation-delay: calc(var(--i) * 0.06s);
}

.tool-btn:hover {
  background: rgba(240, 124, 92, 0.12);
  border-color: rgba(240, 124, 92, 0.4);
}

.tool-btn.active {
  background: rgba(32, 120, 110, 0.18);
  border-color: rgba(32, 120, 110, 0.5);
  transform: translateX(2px);
}

.tool-icon {
  width: 28px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ink);
  border-radius: 6px;
  position: relative;
}

.tool-icon.pointer {
  border: none;
  width: 24px;
  height: 24px;
}

.tool-icon.pointer::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 10px solid var(--ink);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  transform: rotate(-20deg);
}

.tool-icon.connect {
  border: none;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: linear-gradient(var(--ink), var(--ink)) center/18px 2px no-repeat;
}

.tool-icon.connect::before,
.tool-icon.connect::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink);
  top: 10px;
}

.tool-icon.connect::before {
  left: 2px;
}

.tool-icon.connect::after {
  right: 2px;
}

.tool-icon.shape.start {
  border-radius: 999px;
}

.tool-icon.shape.decision {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.tool-icon.shape.gate {
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.tool-icon.shape.note {
  border-style: dashed;
  border-color: var(--muted);
}

.tool-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.canvas-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border-radius: 14px;
  padding: 10px 16px;
  border: 1px solid rgba(26, 26, 26, 0.08);
  box-shadow: 0 12px 24px rgba(28, 35, 32, 0.08);
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.view-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.zoom-value {
  min-width: 56px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #ffffff;
  font-size: 0.85rem;
  color: var(--muted);
}

.status {
  font-weight: 600;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
}

.canvas {
  position: relative;
  flex: 1;
  min-height: 520px;
  background: linear-gradient(150deg, #fefbf6 0%, #f2f7f4 100%);
  border-radius: 22px;
  border: 1px solid rgba(26, 26, 26, 0.08);
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 20px 40px rgba(28, 35, 32, 0.12);
  background-image: linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px),
    radial-gradient(circle at 20% 20%, rgba(240, 124, 92, 0.15), transparent 45%);
  background-size: 40px 40px, 40px 40px, auto;
}

.canvas.connecting {
  cursor: crosshair;
}

.canvas.panning {
  cursor: grabbing;
}

.connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  transform-origin: 0 0;
  overflow: visible;
}

.connections path {
  fill: none;
  stroke: #2c2c2c;
  stroke-width: 2.2px;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: stroke;
}

.connections marker path {
  fill: #2c2c2c;
}

.connections path.edge {
  transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

.connections path.edge.selected {
  stroke: var(--accent-2);
  stroke-width: 3px;
}

.connections path.edge.draft {
  stroke-dasharray: 8 6;
  opacity: 0.7;
}

.node-layer {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.node {
  position: absolute;
  user-select: none;
  cursor: grab;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.node:active {
  cursor: grabbing;
}

.node.selected {
  box-shadow: 0 0 0 3px rgba(32, 120, 110, 0.4);
  border-radius: 16px;
}

.node.connect-source .node-shape {
  box-shadow: 0 0 0 3px rgba(240, 124, 92, 0.45);
}

.node-shape {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px 14px;
  font-weight: 600;
  border: 2px solid var(--node-stroke, #2b2b2b);
  background: var(--node-fill, #f8e8d7);
  color: var(--ink);
  border-radius: 14px;
  box-shadow: 0 10px 20px rgba(26, 26, 26, 0.1);
}

.node.type-terminator {
  --node-fill: #d1e7dd;
  --node-stroke: #2c2c2c;
}

.node.type-terminator .node-shape {
  border-radius: 999px;
}

.node.type-process {
  --node-fill: #e7f0ff;
  --node-stroke: #2c2c2c;
}

.node.type-decision {
  --node-fill: #ffe8cc;
  --node-stroke: #2c2c2c;
}

.node.type-decision .node-shape {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  border-radius: 0;
}

.node.type-gate {
  --node-fill: #e9d5ff;
  --node-stroke: #2c2c2c;
}

.node.type-gate .node-shape {
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.node.type-note {
  --node-fill: #fff3c4;
  --node-stroke: #2c2c2c;
}

.node.type-note .node-shape {
  border-style: dashed;
}

.inline-edit {
  position: absolute;
  inset: 10px;
  border: 1px solid var(--accent-2);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  background: #ffffff;
}

.empty-hint {
  position: absolute;
  right: 24px;
  bottom: 24px;
  background: rgba(253, 252, 248, 0.9);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--muted);
  border: 1px dashed rgba(26, 26, 26, 0.2);
}

.inspector-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-size: 0.85rem;
  color: var(--muted);
}

.field input,
.field textarea,
.field select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 90px;
}

.inspector-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.muted-text {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.85rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 12px 18px;
  background: #1c1c1c;
  color: #fff;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

#fileInput {
  display: none;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 200px minmax(0, 1fr);
    grid-template-rows: auto auto;
  }

  .inspector {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 1;
  }

  .tool-list {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .canvas-wrap {
    order: 2;
  }

  .inspector {
    order: 3;
  }
}

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

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

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