:root {
  --ink: #0b1f2a;
  --ink-soft: #123141;
  --paper: #f8f4ee;
  --accent: #ffb700;
  --accent-2: #ff6b6b;
  --accent-3: #3dc9b0;
  --panel: #f3ede3;
  --shadow: 0 18px 40px rgba(11, 31, 42, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #fff8e4 0%, #f1e6d4 45%, #e8dbc8 100%);
}

.page {
  height: 100vh;
  display: grid;
  grid-template-rows: 5vh 92vh 3vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 28px;
  background: linear-gradient(120deg, #0b1f2a 0%, #123a4a 60%, #0f2a37 100%);
  color: #f6f0e7;
  overflow: hidden;
}

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

.logo {
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
  background: var(--accent);
  color: #0b1f2a;
  padding: 8px 10px;
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.title {
  font-size: 18px;
  font-weight: 600;
}

.subtitle {
  font-size: 12px;
  opacity: 0.7;
}

.header-meta {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}

.main {
  display: flex;
  min-height: 0;
  --panel-width: 15%;
}

.panel {
  flex: 0 0 var(--panel-width);
  min-width: 220px;
  padding: 24px 22px;
  background: var(--panel);
  border-right: 2px solid rgba(11, 31, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
  font-family: "Fraunces", "Times New Roman", serif;
}

.selection-info {
  min-height: 18px;
  font-size: 12px;
  color: rgba(11, 31, 42, 0.6);
  margin-top: -6px;
}

.control label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  color: rgba(11, 31, 42, 0.65);
}

select,
button {
  font-family: inherit;
}

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(11, 31, 42, 0.2);
  background: #fff;
}

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(11, 31, 42, 0.2);
  background: #fff;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.type-select {
  position: relative;
  margin-bottom: 0;
}

#nodeTypeDisplay {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(11, 31, 42, 0.2);
  background: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.type-options {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid rgba(11, 31, 42, 0.2);
  border-radius: 12px;
  padding: 6px;
  margin: 0;
  display: grid;
  gap: 4px;
  box-shadow: var(--shadow);
  z-index: 5;
  list-style: none;
}

.type-options[hidden] {
  display: none;
}

.type-select.is-open {
  margin-bottom: var(--type-list-space, 0px);
}

.type-options button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.type-options button:hover,
.type-options button:focus {
  background: rgba(11, 31, 42, 0.08);
}

.type-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.type-dot-accent {
  background: var(--accent);
}

.type-dot-warn {
  background: var(--accent-2);
}

.type-dot-info {
  background: var(--accent-3);
}

.segmented {
  display: flex;
  gap: 8px;
}

.segmented button {
  flex: 1;
  border-radius: 999px;
  border: 1px solid rgba(11, 31, 42, 0.2);
  padding: 8px 10px;
  background: transparent;
  cursor: pointer;
}

.segmented button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.legend {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  font-size: 14px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
}

.dot.accent {
  background: var(--accent);
}

.dot.warn {
  background: var(--accent-2);
}

.dot.info {
  background: var(--accent-3);
}

.button-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, 1fr);
}

.button-grid button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(11, 31, 42, 0.2);
  background: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.button-grid button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.add-node {
  display: grid;
  gap: 10px;
}

.add-node button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(11, 31, 42, 0.2);
  background: #fff;
  cursor: pointer;
}

.add-edge {
  display: grid;
  gap: 10px;
}

.add-edge button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(11, 31, 42, 0.2);
  background: #fff;
  cursor: pointer;
}

.debug-toggle {
  margin-top: auto;
}

.debug-toggle label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: rgba(11, 31, 42, 0.7);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.button-row-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.add-node button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.add-edge button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.edge-selected {
  stroke: #ff6b6b;
  stroke-width: 4;
}

.node-list {
  display: grid;
  gap: 8px;
  max-height: 160px;
  overflow: auto;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(11, 31, 42, 0.12);
  background: rgba(255, 255, 255, 0.7);
}

.node-list-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.node-list-item.is-active {
  font-weight: 600;
}

.node-list-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.node-list-meta {
  font-size: 11px;
  color: rgba(11, 31, 42, 0.6);
}

.canvas {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 183, 0, 0.08), transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(61, 201, 176, 0.12), transparent 45%),
    linear-gradient(120deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.2));
  overflow: hidden;
}

.resizer {
  flex: 0 0 8px;
  cursor: col-resize;
  background: linear-gradient(180deg, rgba(11, 31, 42, 0.12), rgba(11, 31, 42, 0));
  border-left: 1px solid rgba(11, 31, 42, 0.08);
  border-right: 1px solid rgba(11, 31, 42, 0.08);
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

.canvas::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(11, 31, 42, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(11, 31, 42, 0.06) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

#graph {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

.canvas-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(11, 31, 42, 0.1);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 1;
}

.tab-button {
  border: 1px solid rgba(11, 31, 42, 0.2);
  background: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}

.tab-button.is-active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.canvas-panels {
  position: relative;
  flex: 1 1 auto;
  overflow: auto;
  z-index: 1;
}

.tab-panel {
  width: 100%;
  height: 100%;
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.export-output,
.data-output {
  border: none;
  padding: 16px;
  font-family: "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  background: #fff;
  color: var(--ink);
  resize: none;
}

.node-card {
  transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

.is-selected .node-card {
  stroke: #0b1f2a;
  stroke-width: 4;
}

.is-selected .node-label {
  font-weight: 700;
}

.node-description {
  pointer-events: none;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  font-size: 12px;
  background: #0b1f2a;
  color: #f6f0e7;
  line-height: 1;
}

.footer #status.status-warning {
  color: #ffd166;
}

.footer #status.status-error {
  color: #ff8a8a;
}

.footer #status.status-info {
  color: #f6f0e7;
}

.footer-meta {
  opacity: 0.6;
}

.debug-overlay {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 11px;
  color: #0b1f2a;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(11, 31, 42, 0.2);
  box-shadow: 0 8px 20px rgba(11, 31, 42, 0.2);
  transform: translate(8px, 8px);
  max-width: 240px;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .page {
    grid-template-rows: 8vh 86vh 6vh;
  }

  .main {
    flex-direction: column;
  }

  .panel,
  .canvas {
    width: 100%;
  }

  .panel {
    min-width: auto;
    border-right: none;
    border-bottom: 2px solid rgba(11, 31, 42, 0.08);
  }

  .resizer {
    display: none;
  }
}

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

.page {
  animation: rise 0.6s ease-out;
}
