@import "tailwindcss";

/* ── Template modal ──────────────────────────────────────────────────────────── */

.cn-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 24, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}

.cn-modal {
  background: #0e1120;
  border: 1px solid #1e2340;
  border-radius: 12px;
  width: 100%;
  max-width: 780px;
  overflow: hidden;
}

.cn-modal__header {
  position: relative;
  padding: 28px 32px 20px;
  border-bottom: 1px solid #1e2340;
}

.cn-modal__title {
  font-size: 18px;
  font-weight: 700;
  color: #e2e8f0;
  margin: 0 0 6px;
}

.cn-modal__sub {
  font-size: 13px;
  color: #4a5570;
  margin: 0;
}

.cn-modal__close {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid #1e2340;
  border-radius: 5px;
  color: #3a4060;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}

.cn-modal__close:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
  color: #ef4444;
}

.cn-modal__templates {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 20px 24px;
}

.cn-template-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: #13162a;
  border: 1px solid #1e2340;
  border-radius: 8px;
  padding: 16px 18px;
  text-align: left;
  cursor: pointer;
  transition: all 0.12s;
  width: 100%;
}

.cn-template-card:hover {
  border-color: #3b82f6;
  background: #161a30;
}

.cn-template-card__name {
  font-size: 15px;
  font-weight: 700;
  color: #e2e8f0;
}

.cn-template-card__tagline {
  font-size: 11px;
  font-weight: 600;
  color: #3b82f6;
  letter-spacing: 0.04em;
}

.cn-template-card__desc {
  font-size: 12px;
  color: #4a5570;
  line-height: 1.5;
  margin-top: 4px;
}

.cn-template-card__meta {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.cn-template-card__meta span {
  font-size: 10px;
  color: #2a3050;
  font-family: monospace;
}

.cn-modal__footer {
  padding: 16px 32px;
  border-top: 1px solid #1e2340;
  text-align: right;
}

.cn-modal__skip {
  font-size: 12px;
  color: #3a4060;
  text-decoration: none;
  transition: color 0.12s;
}

.cn-modal__skip:hover {
  color: #8892b0;
}

/* ── Auth layout ─────────────────────────────────────────────────────────────── */

.auth-body {
  margin: 0;
  min-height: 100vh;
  background: #0a0d18;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.auth-wrap {
  width: 100%;
  max-width: 380px;
  padding: 24px;
}

.auth-card {
  background: #0e1120;
  border: 1px solid #1e2340;
  border-radius: 10px;
  padding: 32px;
}

.auth-logo {
  font-size: 18px;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 4px;
}

.auth-sub {
  font-size: 13px;
  color: #4a5570;
  margin: 0 0 24px;
}

.auth-notice {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 5px;
  padding: 8px 12px;
  font-size: 13px;
  color: #10b981;
  margin-bottom: 16px;
}

.auth-alert {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 5px;
  padding: 8px 12px;
  font-size: 13px;
  color: #ef4444;
  margin-bottom: 16px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.auth-field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #4a5570;
}

.auth-field input {
  background: #090c18;
  border: 1px solid #1e2340;
  border-radius: 5px;
  padding: 9px 12px;
  font-size: 14px;
  color: #c8d0e0;
  outline: none;
  transition: border-color 0.12s;
}

.auth-field input:focus {
  border-color: #3b82f6;
}

.auth-card input[type="submit"] {
  width: 100%;
  margin-top: 8px;
  background: #3b82f6;
  border: none;
  border-radius: 5px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: background 0.12s;
}

.auth-card input[type="submit"]:hover {
  background: #2563eb;
}

/* ── Canvas app shell ──────────────────────────────────────────────────────── */

.cn-body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #0a0d18;
}

.cn-app {
  position: fixed;
  inset: 0;
  display: flex;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  color: #c8d0e0;
  background: #0a0d18;
  overflow: hidden;
}

/* ── Palette ────────────────────────────────────────────────────────────────── */

.cn-palette {
  position: absolute;
  top: 0; left: 0;
  width: 200px;
  height: 100%;
  background: #0e1120;
  border-right: 1px solid #1e2340;
  overflow-y: auto;
  padding: 0 8px 16px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: #2a2f45 transparent;
}

.cn-palette__logo {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #e2e8f0;
  padding: 14px 6px 10px;
  border-bottom: 1px solid #1e2340;
  margin-bottom: 6px;
}

.cn-palette__section {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #3a4060;
  padding: 10px 6px 3px;
  margin: 0;
}

.cn-palette__btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #8892b0;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cn-palette__btn:hover {
  background: #161930;
  border-color: #2a2f45;
  color: #c8d0e0;
}

.cn-palette__btn::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cn-palette__btn--source::before     { background: #ef4444; }
.cn-palette__btn--transform::before  { background: #8b5cf6; }
.cn-palette__btn--branch::before     { background: #ec4899; }
.cn-palette__btn--modulation::before { background: #10b981; }

/* ── Top bar ─────────────────────────────────────────────────────────────────── */

.cn-topbar {
  position: absolute;
  top: 0; left: 200px; right: 0;
  height: 44px;
  background: #0e1120;
  border-bottom: 1px solid #1e2340;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  z-index: 20;
  overflow: hidden;
}

.cn-topbar__name {
  font-weight: 600;
  font-size: 13px;
  color: #e2e8f0;
  flex-shrink: 0;
}

.cn-topbar__api {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  flex: 1;
}

.cn-topbar__api-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #3a4060;
  flex-shrink: 0;
}

.cn-topbar__api-url {
  font-size: 11px;
  font-family: "SF Mono", "Fira Code", monospace;
  color: #4fc3f7;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cn-topbar__api-url:hover { text-decoration: underline; }

.cn-save-status {
  margin-left: auto;
  font-size: 11px;
  color: #3a4060;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.cn-topbar__snapshot {
  font-size: 11px;
  background: #1e2340;
  border: 1px solid #2a3050;
  border-radius: 4px;
  color: #8892b0;
  padding: 3px 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.12s;
}

.cn-topbar__snapshot:hover {
  background: #2a3050;
  color: #c8d0e0;
}

.cn-topbar__history {
  font-size: 11px;
  color: #3a4060;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: all 0.12s;
}

.cn-topbar__history:hover {
  background: #1e2340;
  color: #8892b0;
}

/* ── History panel ───────────────────────────────────────────────────────────── */

.cn-history {
  position: absolute;
  top: 44px;
  right: 0;
  width: 260px;
  height: calc(100vh - 44px);
  background: #0e1120;
  border-left: 1px solid #1e2340;
  z-index: 25;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cn-history__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #1e2340;
  flex-shrink: 0;
}

.cn-history__title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #4a5570;
}

.cn-history__close {
  color: #2a3050;
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
  transition: color 0.12s;
}

.cn-history__close:hover { color: #8892b0; }

.cn-history__list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: #2a2f45 transparent;
}

.cn-history__empty {
  font-size: 12px;
  color: #2a3050;
  text-align: center;
  margin-top: 24px;
  font-style: italic;
}

.cn-history__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 5px;
  border: 1px solid #1e2340;
  margin-bottom: 6px;
  background: #13162a;
}

.cn-history__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cn-history__time {
  font-size: 12px;
  color: #8892b0;
}

.cn-history__nodes {
  font-size: 10px;
  color: #2a3050;
  font-family: monospace;
}

.cn-history__restore {
  font-size: 10px;
  background: transparent;
  border: 1px solid #2a3050;
  border-radius: 3px;
  color: #4a5570;
  padding: 3px 8px;
  cursor: pointer;
  transition: all 0.12s;
  flex-shrink: 0;
}

.cn-history__restore:hover {
  border-color: #10b981;
  color: #10b981;
}

.cn-topbar__logout {
  font-size: 11px;
  color: #3a4060;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: all 0.12s;
}

.cn-topbar__logout:hover {
  background: #1e2340;
  color: #8892b0;
}

/* ── Canvas area ─────────────────────────────────────────────────────────────── */

.cn-canvas {
  position: absolute;
  top: 44px; left: 200px; right: 0; bottom: 0;
  overflow: hidden;
  cursor: grab;
  background-color: #0a0d18;
  background-image:
    radial-gradient(circle, #1e2340 1.5px, transparent 1.5px);
  background-size: 28px 28px;
}

.cn-canvas:active { cursor: grabbing; }

/* ── World (transform container) ────────────────────────────────────────────── */

.cn-world {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ── SVG edges ───────────────────────────────────────────────────────────────── */

.cn-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 5;
}

.cn-edge {
  fill: none;
  stroke: #2a4070;
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: stroke;
  cursor: pointer;
}

.cn-edge--temp {
  stroke: #4fc3f7;
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
  opacity: 0.8;
  pointer-events: none;
}

.cn-edge--selected {
  stroke: #4fc3f7;
  stroke-width: 2.5;
  opacity: 1;
}

.cn-edge-del {
  pointer-events: all;
  cursor: pointer;
}

.cn-edge-del__circle {
  fill: #0e1120;
  stroke: #ef4444;
  stroke-width: 1.5;
}

.cn-edge-del__icon {
  fill: #ef4444;
  font-size: 13px;
  font-family: system-ui, sans-serif;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.cn-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: stroke;
  cursor: pointer;
}

/* ── Zoom indicator ──────────────────────────────────────────────────────────── */

.cn-zoom {
  position: absolute;
  bottom: 12px; right: 12px;
  background: #0e1120;
  border: 1px solid #1e2340;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: monospace;
  color: #3a4060;
  z-index: 20;
  pointer-events: none;
  letter-spacing: 0.04em;
}

/* ── Nodes ───────────────────────────────────────────────────────────────────── */

.cn-node {
  position: absolute;
  width: 220px;
  user-select: none;
}

.cn-node__card {
  margin: 0 10px;
  background: #13162a;
  border: 1px solid #1e2340;
  border-radius: 7px;
  overflow: hidden;
  transition: border-color 0.12s;
}

.cn-node:hover .cn-node__card {
  border-color: #2a3050;
}

.cn-node__header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #0e1120;
  border-bottom: 1px solid #1e2340;
  cursor: grab;
}

.cn-node__header:active { cursor: grabbing; }

.cn-node__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cn-node__kind {
  flex: 1;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #4a5570;
}

.cn-node__del {
  width: 16px;
  height: 16px;
  border: none;
  background: transparent;
  color: #2a3050;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.12s;
  flex-shrink: 0;
}

.cn-node__del:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.cn-node__body {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cn-node__label {
  font-size: 13px;
  font-weight: 500;
  color: #c8d0e0;
  min-height: 18px;
  outline: none;
  border-radius: 3px;
  padding: 1px 3px;
  cursor: text;
  word-break: break-word;
  line-height: 1.4;
  transition: background 0.1s;
}

.cn-node__label:focus { background: #090c18; }

.cn-node__label:empty::before {
  content: attr(placeholder);
  color: #2a3050;
  pointer-events: none;
}

.cn-node__desc {
  font-size: 11px;
  color: #4a5570;
  min-height: 14px;
  outline: none;
  border-radius: 3px;
  padding: 1px 3px;
  cursor: text;
  word-break: break-word;
  line-height: 1.5;
  transition: background 0.1s;
}

.cn-node__desc:focus { background: #090c18; color: #8892b0; }

.cn-node__desc:empty::before {
  content: attr(placeholder);
  color: #1e2340;
  pointer-events: none;
  font-style: italic;
}

.cn-node__hint {
  font-size: 10px;
  color: #2d6b50;
  line-height: 1.5;
  font-style: italic;
  padding: 1px 3px;
  user-select: none;
}

/* ── Ports ───────────────────────────────────────────────────────────────────── */

.cn-node__inputs,
.cn-node__outputs {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.cn-node__inputs  { left: 0; }
.cn-node__outputs { right: 0; }

.cn-port {
  display: flex;
  align-items: center;
}

.cn-port__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #2a3050;
  background: #0a0d18;
  transition: all 0.12s;
  flex-shrink: 0;
}

.cn-port--out .cn-port__dot {
  cursor: crosshair;
}

.cn-port--out:hover .cn-port__dot,
.cn-port--in:hover .cn-port__dot {
  background: #1e2a40;
  transform: scale(1.35);
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.15);
}

/* ── Mod port ────────────────────────────────────────────────────────────────── */

.cn-port--mod .cn-port__dot {
  border-radius: 3px; /* diamond-ish to distinguish from regular ports */
}

/* ── Mod edge ────────────────────────────────────────────────────────────────── */

.cn-edge--mod {
  stroke: #10b981;
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
  opacity: 0.55;
}

/* ── Modulation controls ─────────────────────────────────────────────────────── */

.cn-node__mod {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid #181e35;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cn-node__mod-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.cn-node__mod-label {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #10b981;
  flex-shrink: 0;
  width: 22px;
}

.cn-node__mod-slider {
  flex: 1;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: #1e2340;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.cn-node__mod-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  cursor: pointer;
}

.cn-node__mod-slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  border: none;
  cursor: pointer;
}

.cn-node__mod-val {
  font-size: 10px;
  font-family: monospace;
  color: #10b981;
  width: 14px;
  text-align: right;
  flex-shrink: 0;
}

.cn-node__mod-date {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid #1e2340;
  color: #3a4060;
  font-size: 10px;
  padding: 2px 3px;
  outline: none;
  cursor: pointer;
  color-scheme: dark;
}

.cn-node__mod-date:focus {
  border-color: #10b981;
  color: #8892b0;
}

/* ── Zoom level adaptations ──────────────────────────────────────────────────── */

/* medium: hide description and modulation */
[data-zoom-level="medium"] .cn-node__desc { display: none; }
[data-zoom-level="medium"] .cn-node__mod  { display: none; }

/* overview: collapse nodes to pill */
[data-zoom-level="overview"] .cn-node__desc,
[data-zoom-level="overview"] .cn-node__label { display: none; }
[data-zoom-level="overview"] .cn-node__mod    { display: none; }

[data-zoom-level="overview"] .cn-node__body { padding: 2px 6px; }

[data-zoom-level="overview"] .cn-node__card {
  border-radius: 4px;
}

[data-zoom-level="overview"] .cn-edge {
  stroke-width: 1;
  stroke: #1e2f50;
}

[data-zoom-level="overview"] .cn-node__del { display: none; }
