/* Concept Map Builder — styles */

:root {
  --ink: #17212b;
  --ink-soft: #5a6b7b;
  --line: #cfd8e3;
  --paper: #f4f7fa;
  --card: #ffffff;
  --accent: #0b6bcb;
  --accent-soft: #e4effb;
  --danger: #b3261e;
  --node-fill: #ffffff;
  --node-border: #4a6785;
  --link-stroke: #6b7c91;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(23, 33, 43, .12), 0 6px 18px rgba(23, 33, 43, .08);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}

.screen { height: 100%; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ buttons */

.btn {
  font: inherit;
  font-size: .875rem;
  padding: .45rem .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #eef3f8; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #095ab0; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-quiet:hover { background: #e7edf4; }
.btn-icon { width: 2.1rem; padding: .45rem 0; text-align: center; font-size: 1rem; line-height: 1; }

.mode-switch { display: flex; }
.mode-switch .btn-mode:first-child { border-radius: 8px 0 0 8px; }
.mode-switch .btn-mode:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.btn-mode.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------- start screen */

#start-screen {
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  overflow: auto;
}

.start-card {
  width: min(620px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2rem 2.25rem 2.25rem;
}

.start-card h1 { margin: 0 0 .35rem; font-size: 1.65rem; }
.lede { margin: 0 0 1.5rem; color: var(--ink-soft); line-height: 1.5; }

.field-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
  margin-bottom: .35rem;
}

.start-card input[type="text"],
.start-card textarea {
  width: 100%;
  font: inherit;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfdfe;
  margin-bottom: 1.1rem;
  resize: vertical;
}
.start-card textarea { line-height: 1.55; margin-bottom: .4rem; }
.start-card input:focus, .start-card textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }

.hint { font-size: .8rem; color: var(--ink-soft); margin: 0 0 1.25rem; }
.error-text { color: var(--danger); font-size: .875rem; margin: .8rem 0 0; }
.start-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ----------------------------------------------------------------- toolbar */

#editor { display: flex; flex-direction: column; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .55rem .9rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 5;
}

.toolbar-group { display: flex; align-items: center; gap: .4rem; }
.toolbar-right { margin-left: auto; }
.toolbar-title { flex: 0 1 auto; gap: .6rem; }

#map-title {
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  width: min(260px, 34vw);
  padding: .35rem .5rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}
#map-title:hover:not([readonly]) { border-color: var(--line); }
#map-title:focus { border-color: var(--accent); outline: 3px solid var(--accent-soft); background: #fff; }
#map-title[readonly] { cursor: default; }

.save-status { font-size: .75rem; color: var(--ink-soft); min-width: 5.5rem; }
.save-status.is-error { color: var(--danger); font-weight: 600; }
.zoom-level { font-size: .78rem; color: var(--ink-soft); min-width: 3rem; text-align: center; }

.badge {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .3rem .55rem;
  border-radius: 999px;
  background: #fff4d6;
  border: 1px solid #e8cf92;
  color: #7a5a12;
}

/* ------------------------------------------------------------------ canvas */

.canvas {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  background-color: var(--paper);
  background-image: radial-gradient(#d6dfe9 1px, transparent 1px);
  background-size: 22px 22px;
  cursor: default;
  touch-action: none;
  user-select: none;
}
.canvas:focus { outline: none; }
.canvas.is-panning { cursor: grabbing; }
.canvas.mode-link { cursor: crosshair; }

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

/* The SVG is a big fixed sheet offset by 50000 so world coordinates can be
   negative; #links-root shifts everything back into place. */
.links-layer {
  position: absolute;
  left: -50000px;
  top: -50000px;
  pointer-events: none;
  overflow: visible;
}
.nodes-layer, .labels-layer { position: absolute; left: 0; top: 0; }

/* nodes */
.node {
  position: absolute;
  transform: translate(-50%, -50%);
  /* The layers have no width of their own, so size to the text and only wrap
     once the box would get too wide to read. */
  width: max-content;
  min-width: 74px;
  max-width: 190px;
  padding: .55rem .8rem;
  /* A coloured node sets the -local variables inline; selection styling below
     still wins because it sets border-color outright. */
  background: var(--node-fill-local, var(--node-fill));
  border: 2px solid var(--node-border-local, var(--node-border));
  color: var(--node-text-local, var(--ink));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: .9rem;
  line-height: 1.35;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  cursor: grab;
  pointer-events: auto;
}
.node.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.node.is-link-source { border-color: #0e8a5f; box-shadow: 0 0 0 3px #d3f2e5, var(--shadow); }
.node.is-editing { cursor: text; user-select: text; background: #fffdf3; }
.node.is-empty::after { content: "…"; color: var(--ink-soft); }
.node:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.canvas.mode-link .node { cursor: crosshair; }
.canvas.mode-link .node:hover { border-color: #0e8a5f; }
.is-readonly .node { cursor: default; }

/* links */
.link-hit { stroke: transparent; stroke-width: 18; fill: none; pointer-events: stroke; cursor: pointer; }
.link-line { stroke: var(--link-stroke); stroke-width: 2; fill: none; pointer-events: none; }
.link-group.is-selected .link-line { stroke: var(--accent); stroke-width: 3; }
.arrow-head { fill: var(--link-stroke); }
.arrow-head-selected { fill: var(--accent); }
.rubber-band { stroke: #0e8a5f; stroke-width: 2; stroke-dasharray: 6 5; fill: none; pointer-events: none; }
.is-readonly .link-hit { cursor: default; }

/* link labels */
.link-label {
  position: absolute;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 160px;
  padding: .12rem .38rem;
  background: rgba(255, 255, 255, .94);
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: .78rem;
  color: var(--ink-soft);
  text-align: center;
  overflow-wrap: break-word;
  cursor: grab;          /* dragging a label bends its link */
  pointer-events: auto;
}
.link-label.is-bending { cursor: grabbing; background: #fff; border-color: var(--accent); }
.is-readonly .link-label { cursor: default; }
.link-label.is-selected { border-color: var(--accent); color: var(--ink); }
.link-label.is-editing { border-color: var(--accent); background: #fffdf3; cursor: text; user-select: text; }
.link-label.is-placeholder { color: #8a99a8; font-style: italic; }
.link-label:empty::before { content: "label"; color: #9aa8b6; font-style: italic; }
/* Viewers shouldn't see the "label" affordance on unlabelled links. */
.is-readonly .link-label:empty::before { content: ""; }

/* overlays */
.empty-hint {
  position: absolute;
  inset: auto 0 auto 0;
  top: 45%;
  text-align: center;
  color: var(--ink-soft);
  font-size: 1rem;
  pointer-events: none;
  margin: 0;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 1.1rem;
  transform: translateX(-50%);
  background: #17212b;
  color: #fff;
  font-size: .85rem;
  padding: .55rem .9rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: none;
  max-width: 90%;
}

.help-bar {
  display: flex;
  gap: 1.1rem;
  flex-wrap: wrap;
  padding: .45rem .9rem;
  background: var(--card);
  border-top: 1px solid var(--line);
  font-size: .74rem;
  color: var(--ink-soft);
  flex: 0 0 auto;
}
.help-bar strong { color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------ context menu */

.context-menu {
  position: fixed;
  z-index: 40;
  min-width: 190px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: .3rem;
}
.context-menu > button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: .85rem;
  padding: .45rem .6rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.context-menu > button:hover { background: var(--accent-soft); }
.context-menu > button.is-danger { color: var(--danger); }
.context-menu > button.is-danger:hover { background: #fdeceb; }
.context-menu hr { border: 0; border-top: 1px solid var(--line); margin: .3rem .2rem; }

/* colour swatches */
.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  padding: .4rem .5rem .5rem;
  max-width: 210px;
}

.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(23, 33, 43, .25);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.swatch:hover { transform: scale(1.12); }
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch.is-current { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }

/* "no colour" reads as a white circle with a diagonal line through it */
.swatch.is-none {
  background:
    linear-gradient(to bottom right, transparent calc(50% - 1px), #b3261e calc(50% - 1px),
      #b3261e calc(50% + 1px), transparent calc(50% + 1px)),
    #fff;
}

.swatch-picker { overflow: hidden; background: conic-gradient(#ff8787, #ffd43b, #69db7c, #4dabf7, #da77f2, #ff8787); }
.swatch-picker::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-picker::-webkit-color-swatch { border: 0; opacity: 0; }
.swatch-picker::-moz-color-swatch { border: 0; opacity: 0; }

/* -------------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(23, 33, 43, .45);
  padding: 1rem;
}

.modal-card {
  width: min(560px, 100%);
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.6rem 1.75rem;
}
.modal-card h2 { margin: 0 0 1.2rem; font-size: 1.2rem; }

.link-row { margin-bottom: 1.35rem; }
.link-row label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .35rem; }
.link-input { display: flex; gap: .4rem; }
.link-input input {
  flex: 1;
  font: inherit;
  font-size: .82rem;
  padding: .45rem .55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fb;
  color: var(--ink-soft);
}
.link-row .hint { margin: .35rem 0 0; }
.modal-actions { display: flex; justify-content: flex-end; }

.loading-screen { display: grid; place-items: center; color: var(--ink-soft); }

@media (max-width: 720px) {
  .toolbar { gap: .5rem; }
  #map-title { width: 40vw; }
  .help-bar { display: none; }
}
