:root{
  --bg: #f6f7f9;
  --panel: rgba(255,255,255,0.86);
  --panel2: rgba(255,255,255,0.70);
  --text: #111218;
  --muted: rgba(20,20,30,0.56);
  --line: rgba(20,20,30,0.18);
  --line2: rgba(20,20,30,0.10);
  --topbar-h: 56px;
}

*{ box-sizing:border-box; }

html,
body{
  height:100%;
}

body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* Top bar */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line2);
  background: linear-gradient(to bottom, rgba(255,255,255,0.92), rgba(255,255,255,0.72));
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand .title{
  font-size:16px;
  letter-spacing:0.3px;
  line-height:1.2;
}

.brand .subtitle{
  font-size:12px;
  color: var(--muted);
  margin-top:2px;
  line-height:1.4;
}

.controls{
  display:flex;
  gap:10px;
}

/* Buttons */
.btn{
  border: 1px solid rgba(20,20,30,0.18);
  background: rgba(255,255,255,0.84);
  color: rgba(15,15,20,0.86);
  padding: 8px 12px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}

.btn:hover{
  background: rgba(255,255,255,0.96);
}

.btn.primary{
  background: rgba(255,255,255,0.96);
  border-color: rgba(20,20,30,0.22);
}

.btnSmall{
  padding: 6px 10px;
  font-size: 12px;
}

.hidden{
  display:none !important;
}

/* Layout */
.layout{
  display:grid;
  grid-template-columns: 1fr 360px;
  height: calc(100vh - 56px);
}

.graphPanel{
  position:relative;
  border-right: 1px solid var(--line2);
  background:
    radial-gradient(circle at 30% 20%, rgba(20,20,30,0.08), transparent 45%),
    radial-gradient(circle at 80% 60%, rgba(20,20,30,0.06), transparent 50%),
    linear-gradient(to bottom, rgba(255,255,255,0.52), rgba(255,255,255,0.20));
}

.graph{
  position:absolute;
  inset:0;
}

.sidePanel{
  background: rgba(255,255,255,0.62);
  overflow:auto;
  padding: 14px;
}

.panelBlock{
  background: rgba(255,255,255,0.82);
  border: 1px solid var(--line2);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.06);
}

/* Headings */
h2,
h3{
  margin:0 0 10px 0;
  font-weight:650;
  letter-spacing:0.2px;
  color: rgba(15,15,20,0.92);
}

h2{
  font-size: 16px;
  line-height: 1.25;
}

h3{
  font-size: 15px;
  line-height: 1.25;
}

/* Body text / hint system */
.hint{
  margin: 0 0 10px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.hint strong{
  color: rgba(20,20,30,0.78);
  font-weight: 650;
}

.hint a{
  color: rgba(15,15,20,0.82);
  text-decoration: none;
  border-bottom: 1px solid rgba(20,20,30,0.18);
}

.hint a:hover{
  border-bottom-color: rgba(20,20,30,0.34);
}

/* Submission rules */
.submissionRules{
  margin: 2px 0 14px 0;
  padding-top: 2px;
}

.submissionRules .hint{
  margin-bottom: 6px;
}

/* This handles both structures:
   1) <ul class="hint">
   2) <ul class="hintList">
*/
.submissionRules ul,
.hintList{
  margin: 0 0 0 18px;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.submissionRules li,
.hintList li{
  margin: 0 0 4px 0;
  padding-left: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.submissionRules li::marker,
.hintList li::marker{
  color: rgba(20,20,30,0.82);
  font-size: 0.95em;
}

/* Form */
.form{
  margin-top: 2px;
}

.form label{
  display:grid;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.form input,
.form textarea,
.form select{
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(20,20,30,0.14);
  background: rgba(255,255,255,0.92);
  color: rgba(15,15,20,0.86);
  padding: 10px;
  outline:none;
  font: inherit;
  line-height: 1.35;
}

.form textarea{
  resize: vertical;
  min-height: 84px;
}

.form input::placeholder,
.form textarea::placeholder{
  color: rgba(20,20,30,0.36);
}

.form input:focus,
.form textarea:focus,
.form select:focus{
  border-color: rgba(20,20,30,0.26);
  background: rgba(255,255,255,0.98);
}

.formRow{
  display:flex;
  gap:8px;
  margin-top:8px;
}

.status{
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* Chips UI */
.chipsRow{
  display:flex;
  gap:10px;
  align-items:center;
}

.chips{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:8px;
}

.chip{
  display:inline-flex;
  gap:8px;
  align-items:center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(20,20,30,0.16);
  background: rgba(20,20,30,0.04);
  color: rgba(15,15,20,0.76);
  font-size: 13px;
  line-height: 1.2;
}

.chip button{
  border:none;
  background:transparent;
  color: rgba(15,15,20,0.48);
  cursor:pointer;
  padding:0;
}

.chip button:hover{
  color: rgba(15,15,20,0.86);
}

/* Legend */
.legend{
  display:flex;
  flex-direction:column;
  gap:10px;
  font-size:13px;
  color: rgba(20,20,24,0.72);
}

.legendRow{
  display:grid;
  grid-template-columns: 60px auto;
  align-items:center;
  column-gap:12px;
}

.legendIndent{
  margin-left:18px;
  border-left: 1px solid rgba(0,0,0,0.12);
  padding-left:14px;
  display:flex;
  flex-direction:column;
  gap:8px;
}

.labelSample{
  display:inline-block;
  padding:0;
  background: rgba(255,255,255,0.65);
  color: rgba(20,20,24,0.78);
  font-size:12px;
  line-height:1.2;
  letter-spacing:0.2px;
}

.lineSample{
  width:48px;
  height:0;
  border-top: 3px solid rgba(120,120,120,0.6);
}

.lineSample.weak{
  border-top-style: dashed;
  border-top-width: 2px;
  opacity: 0.4;
}

.lineSample.blue{ border-color: #4c7fff; }
.lineSample.red{ border-color: #e05252; border-top-style: dashed; }
.lineSample.gray{ border-color: #777; border-top-style: dotted; }
.lineSample.purple{ border-color: #7a5cff; border-top-style: dashed; }
.lineSample.orange{ border-color: #f59e0b; border-top-width: 4px; }

.lineSample.thick{ border-top-width: 4px; }
.lineSample.thin{ border-top-width: 2px; }
.lineSample.rel-primary{ border-top-color: rgba(20,20,30,0.38); }
.lineSample.rel-icw{ border-top-color: rgba(20,20,30,0.18); }
.lineSample.rel-agrees{ border-top-color: #2f6fff; }
.lineSample.rel-disagrees{ border-top-color: #e24b4b; }
.lineSample.rel-asks{ border-top-color: #7a7a86; }
.lineSample.rel-co{ border-top-color: #8b5cf6; }
.lineSample.rel-extends{ border-top-color: #f59e0b; }

/* Optional old line helpers */
.line{
  width: 26px;
  height: 2px;
  display:inline-block;
  margin-right:8px;
  vertical-align:middle;
  background: rgba(20,20,30,0.14);
}

.linePrimary{ background: rgba(20,20,30,0.26); }
.lineOther{ background: rgba(20,20,30,0.14); }

/* Preview bubble */
.previewBubble{
  position:absolute;
  z-index:50;
  width: min(560px, 46vw);
  max-height: min(620px, 62vh);
  overflow: visible;
  border-radius: 14px;
  border: 1px solid rgba(20,20,30,0.16);
  background: rgba(255,255,255,0.94);
  box-shadow: 0 18px 44px rgba(0,0,0,0.12);
  backdrop-filter: blur(10px);
  display:flex;
  flex-direction:column;
  min-height:0;
}

.previewHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(20,20,30,0.10);
  position: relative;
  z-index: 3;
}

.previewLabel{
  font-size: 13px;
  font-weight: 700;
  line-height: 1.22;
  color: rgba(15,15,20,0.90);
  min-width: 0;
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#previewClose{
  position: relative;
  z-index: 4;
  pointer-events:auto;
  flex: 0 0 auto;
}

.previewFrame{
  width:100%;
  height: 360px;
  min-height: 220px;
  border:0;
  background: rgba(20,20,30,0.04);
  pointer-events:auto;
  flex: 1 1 auto;
}

.previewMeta{
  padding: 10px;
  font-size: 12px;
  color: rgba(20,20,30,0.62);
  border-top: 1px solid rgba(20,20,30,0.10);
  display:grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  align-items:start;
  flex: 0 0 auto;
  min-height: 0;
  pointer-events:auto;
}

.previewMeta a{
  color: rgba(15,15,20,0.86);
  text-decoration:none;
  border-bottom: 1px solid rgba(20,20,30,0.22);
  white-space: nowrap;
  pointer-events:auto;
}

.previewMeta a:hover{
  border-bottom-color: rgba(20,20,30,0.42);
}

.previewMetaLeft{
  min-width:0;
}

.previewMetaRight{
  text-align:right;
}

.previewContext{
  grid-column: 1 / -1;
  max-height: 140px;
  overflow: auto;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(20,20,30,0.06);
  color: rgba(20,20,30,0.70);
  line-height: 1.45;
  white-space: pre-wrap;
  -webkit-overflow-scrolling: touch;
}

#preview{
  pointer-events:auto;
}

.previewBubble::before{
  pointer-events:none;
}

.previewBubble.noIframe .previewFrame{
  display:none;
}

/* Node label strip */
.node-bg{
  fill: rgba(255,255,255,0.78);
}

.node-label{
  text-anchor: middle;
  dominant-baseline: middle;
  text-align: center;
  fill: rgba(40,40,40,0.95);
  font-size: 13px;
  font-weight: 500;
  paint-order: stroke;
  stroke: rgba(255,255,255,0.9);
  stroke-width: 4px;
  stroke-linejoin: miter;
}

.node-handle{
  fill: rgba(40,40,40,0.55);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.2px;
  paint-order: stroke;
  stroke: rgba(255,255,255,0.9);
  stroke-width: 2px;
  stroke-linejoin: miter;
}

.node.isPinned .node-box{
  fill: rgba(245,245,248,0.98);
}

/* Mobile */
@media (max-width: 980px){
  .layout{
    grid-template-columns: 1fr;
  }

  .sidePanel{
    height: 42vh;
  }

  .graphPanel{
    height: calc(58vh - 56px);
    border-right:none;
    border-bottom: 1px solid var(--line2);
  }

  .previewBubble{
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    bottom: 12px !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    max-height: calc(100vh - var(--topbar-h) - 24px) !important;
    overflow: visible;
  }

  .previewFrame{
    height: 44vh;
    min-height: 240px;
  }

  .previewContext{
    max-height: 22vh;
  }
}