/* Stories — Pathwoven, ported into Tree of Destiny and restyled to the
   Plum design system. Same selectors as the original build; only the
   declarations changed, plus the three screens were un-absolutized
   so they flow in the page like Training and Analyse do. No custom
   palette, no decorative textures, no drop shadows — plum.css tokens
   only. */

#screen-stories input, #screen-stories select, #screen-stories textarea { font-family: var(--body); }
#screen-stories .hidden { display: none !important; }

/* Button variants plum.css doesn't define. Keep plum.css's own .btn /
   .btn-primary pill shape and sizing — only add color for these three. */
.btn-ghost{ background: transparent; border-color: transparent; color: var(--stone); }
.btn-ghost:hover{ border-color: var(--line); color: var(--ink); }
.btn-danger{ background: transparent; border-color: var(--signal); color: var(--signal); }
.btn-danger:hover{ background: var(--signal); color: #fff; }
.btn-sm{ padding: 7px 14px; font-size: 12.5px; min-height: 36px; }
.btn:disabled{ opacity: .4; cursor: default; }

/* ================= LIBRARY ================= */
.library-hero{
  padding: 8px 0 28px;
  border-bottom: 1px solid var(--line);
}
.library-hero h1{ font-size: clamp(1.75rem, 4vw, 2.6rem); max-width: 720px; }
.library-hero h1 em{ font-style: italic; color: var(--plum-ink); font-weight: 500; }
.library-hero p{ max-width: 560px; margin-top: 12px; }
.library-hero-actions{ margin-top: 22px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.claim-lookup{ display: flex; gap: 8px; align-items: center; }
.claim-lookup input{
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 16px; font-size: 13.5px; color: var(--ink); min-height: 44px; min-width: 180px;
}
.claim-lookup input:focus{ outline: none; border-color: var(--plum); }
.library-body{ padding: 32px 0 60px; }
.library-body h2{ font-size: 15px; color: var(--stone); font-weight: 600; letter-spacing: .3px; margin-bottom: 18px; }
.project-grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px,1fr));
  gap: 16px;
}
.project-card{
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px 18px;
  position: relative;
}
.project-card:hover{ border-color: var(--plum); }
.project-card .branch-mark{
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--plum-wash); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--plum-ink); font-size: 13px; margin-bottom: 16px;
}
.project-card h3{ font-size: 18px; margin-bottom: 6px; word-break: break-word; }
.project-card .meta{ font-size: 12px; color: var(--faint); font-family: var(--mono); }
.project-card .card-actions{ margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.empty-state{
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 46px 28px; text-align: center; color: var(--stone);
}
.empty-state h3{ font-size: 19px; margin-bottom: 8px; }
.empty-state p{ font-size: 13.5px; max-width: 340px; margin: 0 auto 18px; }

/* ================= BUILDER ================= */
#screen-builder{
  display: flex; flex-direction: column;
  height: 74vh; min-height: 480px;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.app-header{
  height: 56px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--mist);
  overflow-x: auto;
}
.app-header .btn{ white-space: nowrap; flex: none; }
.app-header .project-name-input{
  background: transparent; border: 1px solid transparent; color: var(--ink);
  font-family: var(--display); font-size: 17px; font-weight: 700; padding: 5px 8px; border-radius: 6px;
  min-width: 120px;
}
.app-header .project-name-input:hover, .app-header .project-name-input:focus{ border-color: var(--line); outline: none; }
.app-header .stat{ font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.app-header .spacer{ flex: 1; }

.builder-body{ flex: 1; display: flex; min-height: 0; }
.sidebar{
  width: 240px; flex: none; border-right: 1px solid var(--line); background: var(--paper);
  display: flex; flex-direction: column; padding: 14px;
  overflow-y: auto;
}
.sidebar .sb-title{ font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--faint); margin: 16px 0 8px; font-weight: 600; }
.sidebar .sb-title:first-child{ margin-top: 0; }
.node-list-item{
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--stone); border: 1px solid transparent;
}
.node-list-item:hover{ background: var(--mist); color: var(--ink); }
.node-list-item .dot{ width: 6px; height: 6px; border-radius: 50%; background: var(--line); flex: none; }
.node-list-item.is-start .dot{ background: var(--plum); }
.node-list-item span.label{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.canvas-wrapper{ flex: 1; position: relative; overflow: auto; background: var(--mist); }
.canvas-world{ position: relative; width: 3600px; height: 2600px; }
svg.connectors{ position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }

.node-card{
  position: absolute; width: 254px;
  background: var(--paper); color: var(--ink);
  border-radius: 14px; border: 1px solid var(--line);
  z-index: 2;
}
.node-card.is-start{ box-shadow: 0 0 0 2px var(--plum); }
.node-card .drag-handle{
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: var(--mist); border-bottom: 1px solid var(--line);
  border-radius: 14px 14px 0 0; cursor: grab; user-select: none;
}
.node-card .drag-handle:active{ cursor: grabbing; }
.node-card .grip{ color: var(--faint); font-size: 12px; letter-spacing: 1px; }
.node-card .start-badge{
  font-size: 9.5px; font-family: var(--mono); letter-spacing: .5px;
  background: var(--plum-wash); color: var(--plum-ink); padding: 2px 7px; border-radius: 20px; font-weight: 600;
}
.node-card .hd-spacer{ flex: 1; }
.icon-btn{
  width: 24px; height: 24px; border-radius: 6px; border: none; background: transparent;
  color: var(--faint); display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.icon-btn:hover{ background: var(--line); color: var(--ink); }
.node-card .thumb{ width: 100%; height: 140px; object-fit: contain; background: var(--mist); display: block; }
.node-card .body-pad{ padding: 12px 12px 10px; }
.header-input{
  width: 100%; border: none; background: transparent; font-family: var(--display);
  font-size: 15.5px; font-weight: 700; color: var(--ink); padding: 2px 0; border-bottom: 1px dashed transparent;
}
.header-input:focus{ outline: none; border-bottom: 1px dashed var(--plum); }
.hyperlink-cap{ font-size: 10.5px; color: var(--plum); font-family: var(--mono); margin-top: 2px; display: flex; align-items: center; gap: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider-label{ font-size: 9.5px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--faint); margin: 12px 0 6px; font-weight: 600; }
.option-row{ display: flex; align-items: center; gap: 6px; margin-bottom: 6px; position: relative; }
.option-letter{
  width: 18px; height: 18px; border-radius: 5px; background: var(--plum-wash); color: var(--plum-ink);
  font-family: var(--mono); font-size: 10px; display: flex; align-items: center; justify-content: center; flex: none; font-weight: 600;
}
.option-input{
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--paper); border-radius: 6px;
  padding: 6px 7px; font-size: 12.5px; color: var(--ink);
}
.option-input:focus{ outline: none; border-color: var(--plum); }
.option-target{
  width: 30px; flex: none; border: 1px solid var(--line); background: var(--paper); border-radius: 6px;
  padding: 6px 2px; font-size: 15px; color: var(--ink); text-align: center;
}
.option-row .port-out{ width: 8px; height: 8px; border-radius: 50%; background: var(--plum); flex: none; margin-left: 1px; }
.option-row.linked .port-out{ background: var(--good); }
.option-remove{ width: 18px; height: 18px; flex: none; border: none; background: transparent; color: var(--faint); font-size: 13px; border-radius: 4px; }
.option-remove:hover{ background: var(--signal); color: #fff; }
.add-option-btn{
  width: 100%; margin-top: 4px; border: 1px dashed var(--line); background: transparent;
  border-radius: 6px; padding: 7px; font-size: 12px; color: var(--stone); font-weight: 600;
}
.add-option-btn:hover{ border-color: var(--plum); color: var(--plum); }
.port-in{ position: absolute; left: -6px; top: 50%; transform: translateY(-50%); width: 10px; height: 10px; border-radius: 50%; background: var(--paper); border: 2px solid var(--plum); }
.end-note{ font-size: 11px; color: var(--faint); font-style: italic; margin-top: 8px; }

/* ================= MODAL ================= */
.modal-overlay{
  position: fixed; inset: 0; background: rgba(33,29,32,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fadeIn .12s ease;
}
@keyframes fadeIn{ from{ opacity: 0; } to{ opacity: 1; } }
.modal-box{
  width: 420px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; animation: popIn .14s ease;
}
@keyframes popIn{ from{ opacity: 0; transform: translateY(6px) scale(.98); } to{ opacity: 1; transform: none; } }
.modal-box h3{ font-size: 19px; margin-bottom: 16px; }
.field{ margin-bottom: 14px; }
.field label{ display: block; font-size: 11.5px; color: var(--stone); margin-bottom: 6px; font-weight: 600; letter-spacing: .3px; }
.field input[type=text], .field input[type=url]{
  width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 7px;
  padding: 9px 10px; color: var(--ink); font-size: 13.5px;
}
.field input:focus{ outline: none; border-color: var(--plum); }
.field .hint{ font-size: 11px; color: var(--faint); margin-top: 5px; line-height: 1.5; }
.modal-actions{ display: flex; gap: 9px; margin-top: 20px; flex-wrap: wrap; }
.modal-thumb-row{ display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.modal-thumb{ width: 64px; height: 64px; border-radius: 8px; object-fit: cover; background: var(--mist); border: 1px solid var(--line); flex: none; }
.modal-thumb.empty::after{ content: '⬚'; color: var(--faint); }
.modal-thumb.empty{ display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 11px; }

/* ================= PLAYER ================= */
#screen-player{ display: flex; justify-content: center; padding: 24px 0 40px; }
.story-card{
  width: 100%; max-width: 620px; height: fit-content;
  background: var(--paper); color: var(--ink); border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line);
}
.crumbs{ display: flex; gap: 6px; padding: 12px 18px; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--mist); }
.crumb{ font-family: var(--mono); font-size: 10.5px; color: var(--stone); background: var(--paper); border: 1px solid var(--line);
  padding: 4px 9px; border-radius: 20px; white-space: nowrap; flex: none; }
.crumb:hover{ border-color: var(--plum); color: var(--plum); }
.crumb.current{ background: var(--plum); color: #fff; border-color: var(--plum); }
.story-banner{ width: 100%; height: 320px; object-fit: contain; background: var(--mist); display: block; }
.story-body{ padding: 30px 32px 26px; }
.story-body h1{ font-size: 28px; line-height: 1.2; }
.story-body h1 a{ color: inherit; text-decoration: underline; text-decoration-color: var(--plum); text-underline-offset: 5px; }
.paths-label{ font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--faint); margin: 24px 0 12px; font-weight: 600; }
.signpost{
  width: 100%; text-align: left; display: flex; align-items: center; gap: 14px;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 13px 15px; margin-bottom: 9px; font-size: 14.5px; color: var(--ink); font-weight: 500;
  transition: border-color .12s ease, transform .1s ease, background .12s ease;
}
.signpost:hover{ border-color: var(--plum); background: var(--plum-wash); transform: translateX(3px); }
.signpost .sp-letter{
  width: 26px; height: 26px; border-radius: 7px; background: var(--plum-wash); color: var(--plum-ink);
  font-family: var(--mono); font-size: 12px; font-weight: 700; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.the-end{ text-align: center; padding: 30px 0 8px; }
.the-end .flourish{ color: var(--plum); font-size: 12px; letter-spacing: 5px; font-family: var(--mono); margin-bottom: 8px; }
.the-end h2{ font-size: 24px; font-style: italic; font-weight: 500; }
.notice{ font-size: 12.5px; color: var(--signal); background: var(--signal-wash); border: 1px solid var(--signal); padding: 9px 12px; border-radius: 8px; margin-top: 10px; }
.player-footer{ display: flex; justify-content: space-between; align-items: center; padding: 14px 32px 22px; border-top: 1px solid var(--line); background: var(--mist); }
.player-footer .left-btns{ display: flex; gap: 8px; }
.txt-btn{ background: none; border: none; color: var(--stone); font-size: 12.5px; font-weight: 600; padding: 6px 4px; cursor: pointer; }
.txt-btn:hover{ color: var(--plum); }

@media (max-width: 720px){
  .sidebar{ width: 0; padding: 0; overflow: hidden; border: none; }
  .story-body{ padding: 22px 18px; }
  .story-banner{ height: 220px; }
  .app-header{ height: auto; flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .app-header .project-name-input{ flex: 1; min-width: 0; font-size: 15px; }
  .app-header .stat{ display: none; }
  #screen-builder{ height: 82vh; }
}
