/* =========================================================================
   Talehaven - the five embedded demos.
   Mechanics are hand written; the chrome below is the same visual language
   as the rest of the page, so nothing looks like a borrowed widget.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. Shared shell
   ------------------------------------------------------------------------- */

.demo {
  --demo-surface: var(--white);
  --demo-line: var(--hairline);
  --demo-ink: var(--ink);
  --demo-muted: var(--ink-soft);

  position: relative;
  margin-top: clamp(2rem, 1.4rem + 2vw, 3rem);
  background: var(--demo-surface);
  border: 1px solid var(--demo-line);
  border-radius: var(--radius-frame);
  overflow: hidden;
  color: var(--demo-ink);
  box-shadow: var(--shadow-frame);
}

.demo--dark {
  --demo-surface: var(--soot);
  --demo-line: var(--hairline-on-dark);
  --demo-ink: var(--white);
  --demo-muted: var(--ink-on-dark);
}

.demo__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--demo-line);
  background: inherit;
}

.demo__label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: var(--step-label);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--demo-muted);
}

.demo__label::before {
  content: '';
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--crimson);
  flex: none;
}

.demo__tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.demo__tool {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.1rem;
  padding: 0 0.75rem;
  border: 1px solid var(--demo-line);
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.demo__tool:hover {
  border-color: var(--demo-ink);
}

.demo--dark .demo__tool:hover {
  background: rgba(255, 255, 255, 0.1);
}

.demo:not(.demo--dark) .demo__tool:hover {
  background: rgba(29, 29, 29, 0.06);
}

.demo__tool[aria-pressed='true'],
.demo__tool--active {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--white);
}

.demo__hint {
  padding: 0.75rem 1.1rem;
  border-top: 1px solid var(--demo-line);
  font-size: 0.82rem;
  color: var(--demo-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.9rem;
}

.demo__hint strong {
  color: var(--demo-ink);
  font-weight: 800;
}

/* -------------------------------------------------------------------------
   2. Adventure - scene switching
   ------------------------------------------------------------------------- */

.adventure {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.6fr);
  min-height: 25rem;
}

.adventure__scenes {
  border-right: 1px solid var(--demo-line);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.adventure__scene-btn {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid transparent;
  border-radius: var(--radius-chip);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.adventure__scene-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.demo:not(.demo--dark) .adventure__scene-btn:hover {
  background: rgba(29, 29, 29, 0.05);
}

.adventure__scene-btn[aria-current='true'] {
  background: rgba(185, 76, 76, 0.16);
  border-color: var(--crimson);
}

.adventure__num {
  width: 1.75rem;
  height: 1.75rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-size: 0.75rem;
  font-weight: 800;
  flex: none;
  opacity: 0.6;
}

.adventure__scene-btn[aria-current='true'] .adventure__num {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--white);
  opacity: 1;
}

.adventure__scene-name {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.3;
}

.adventure__scene-kind {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--demo-muted);
  margin-top: 0.15rem;
}

.adventure__pane {
  padding: clamp(1.2rem, 1rem + 1vw, 1.9rem);
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.adventure__pane[data-swap='true'] .adventure__swap {
  opacity: 0;
  transform: translateY(8px);
}

.adventure__swap {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  transition: opacity var(--t-mid) var(--ease), transform var(--t-mid) var(--ease);
}

.adventure__title {
  font-size: clamp(1.25rem, 1.1rem + 0.8vw, 1.6rem);
  font-weight: 800;
  letter-spacing: -0.015em;
}

.adventure__text {
  font-size: var(--step-small);
  line-height: 1.65;
  color: var(--demo-muted);
  max-width: 54ch;
}

.adventure__attached-label {
  font-size: var(--step-label);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--demo-muted);
}

.adventure__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--demo-line);
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
}

.demo:not(.demo--dark) .chip {
  background: rgba(29, 29, 29, 0.04);
}

.chip__icon {
  width: 1rem;
  height: 1rem;
  flex: none;
  color: var(--crimson);
}

.demo--dark .chip__icon {
  color: var(--sage);
}

.adventure__spread {
  margin-top: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.mini-card {
  border: 1px solid var(--demo-line);
  border-radius: var(--radius-chip);
  padding: 0.85rem 0.95rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.mini-card__art {
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  border-radius: 8px;
  background: var(--sage);
  color: var(--ink);
  display: grid;
  place-items: center;
}

.mini-card__art svg {
  width: 1.6rem;
  height: 1.6rem;
}

.mini-card > span:last-child {
  min-width: 0;
}

.mini-card__name {
  display: block;
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.25;
}

.mini-card__meta {
  display: block;
  font-size: 0.74rem;
  color: var(--demo-muted);
  margin-top: 0.2rem;
  line-height: 1.4;
}

/* -------------------------------------------------------------------------
   3. Board - draggable canvas with connections
   ------------------------------------------------------------------------- */

.board {
  position: relative;
  height: clamp(24rem, 46vw, 32rem);
  background-color: var(--demo-surface);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: 28px 28px;
  overflow: hidden;
  touch-action: pan-y;
}

.board__links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.board__link {
  stroke: var(--sage);
  stroke-width: 1.8;
  fill: none;
  stroke-dasharray: 5 5;
  opacity: 0.85;
}

.board__node {
  position: absolute;
  width: 13.5rem;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-chip);
  border: 1px solid var(--hairline-on-dark);
  background: var(--bark);
  color: var(--white);
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: box-shadow var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.board__node:hover {
  border-color: var(--sage);
}

.board__node[data-dragging='true'] {
  cursor: grabbing;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  border-color: var(--sage);
  z-index: 3;
}

.board__node[data-kind='note'] {
  background: var(--sage);
  color: var(--ink);
  border-color: rgba(29, 29, 29, 0.25);
  width: 12rem;
}

.board__node[data-kind='image'] {
  padding: 0;
  overflow: hidden;
  width: 11rem;
}

.board__kind {
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 800;
  opacity: 0.72;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.board__kind svg {
  width: 0.85rem;
  height: 0.85rem;
}

.board__name {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.25;
}

.board__meta {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.76rem;
  line-height: 1.45;
  opacity: 0.78;
}

.board__thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--sage);
  display: grid;
  place-items: center;
  color: var(--ink);
}

.board__thumb svg {
  width: 56%;
  height: 56%;
}

.board__caption {
  padding: 0.6rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
}

/* -------------------------------------------------------------------------
   4. Map - token, zoom, reveal
   ------------------------------------------------------------------------- */

.map {
  position: relative;
  height: clamp(24rem, 46vw, 32rem);
  overflow: hidden;
  background: #cdcdbe;
  touch-action: pan-y;
}

.map__viewport {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  transition: transform var(--t-mid) var(--ease);
}

.map__svg {
  width: 100%;
  height: 100%;
  display: block;
}

.map__token {
  position: absolute;
  width: 2.75rem;
  height: 2.75rem;
  margin: -1.375rem 0 0 -1.375rem;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: var(--crimson);
  color: var(--white);
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.32);
  z-index: 3;
}

.map__token[data-dragging='true'] {
  cursor: grabbing;
  transform: scale(1.08);
}

.map__token:focus-visible {
  outline: 3px solid var(--white);
  outline-offset: 2px;
}

/* An <svg> keeps its own aspect ratio unless both sides are pinned, so
   inset alone let the fog grow taller than the map and the revealed circle
   landed below the token. */
.map__fog {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.map__svg {
  width: 100%;
  height: 100%;
}

.map__zoom {
  position: absolute;
  right: 0.9rem;
  bottom: 0.9rem;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.map__zoom button {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
}

.map__zoom button:hover {
  background: var(--white);
}

.map__scale {
  position: absolute;
  left: 0.9rem;
  bottom: 0.9rem;
  z-index: 4;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-pill);
  background: rgba(26, 18, 18, 0.82);
  color: var(--white);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* -------------------------------------------------------------------------
   5. Document - editable fragment
   ------------------------------------------------------------------------- */

.doc {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.doc__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.7rem 1.1rem;
  border-bottom: 1px solid var(--demo-line);
}

.doc__btn {
  min-width: 2.2rem;
  height: 2.2rem;
  padding: 0 0.6rem;
  border: 1px solid var(--demo-line);
  border-radius: 8px;
  background: transparent;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.doc__btn:hover {
  background: rgba(29, 29, 29, 0.06);
  border-color: var(--ink);
}

.doc__btn svg {
  width: 1rem;
  height: 1rem;
}

.doc__sep {
  width: 1px;
  margin: 0.25rem 0.4rem;
  background: var(--demo-line);
}

.doc__sheet {
  padding: clamp(1.4rem, 1rem + 1.5vw, 2.5rem);
  min-height: 20rem;
  max-width: 68ch;
  outline: none;
  line-height: 1.68;
  font-size: var(--step-small);
}

.doc__sheet:focus-visible {
  outline: none;
  box-shadow: inset 3px 0 0 var(--crimson);
}

.doc__sheet h3 {
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: -0.015em;
  margin: 0 0 0.75rem;
}

.doc__sheet p {
  margin: 0 0 0.9rem;
}

.doc__sheet ul {
  list-style: none;
  margin: 0 0 0.9rem;
  padding: 0;
}

.doc__sheet li {
  position: relative;
  padding-left: 1.35rem;
  margin-bottom: 0.35rem;
}

.doc__sheet li::before {
  content: '';
  position: absolute;
  left: 0.15rem;
  top: 0.62em;
  width: 0.45rem;
  height: 0.45rem;
  background: var(--crimson);
  border-radius: 1px;
  transform: rotate(45deg);
}

.doc__sheet mark {
  background: rgba(180, 185, 76, 0.4);
  color: inherit;
  padding: 0.05em 0.2em;
  border-radius: 4px;
}

/* -------------------------------------------------------------------------
   6. NPC builder
   ------------------------------------------------------------------------- */

.npc {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.npc__form {
  padding: clamp(1.2rem, 1rem + 1vw, 1.8rem);
  border-right: 1px solid var(--demo-line);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field__label {
  font-size: var(--step-label);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--demo-muted);
}

.field input,
.field textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-chip);
  background: var(--white);
  font-size: 0.9rem;
  resize: none;
  transition: border-color var(--t-fast) var(--ease);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--crimson);
  box-shadow: 0 0 0 3px rgba(185, 76, 76, 0.16);
}

.field__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.field__chip {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.field__chip:hover {
  border-color: var(--ink);
  background: rgba(29, 29, 29, 0.05);
}

.field__chip[aria-pressed='true'] {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--white);
}

.demo--dark .field__chip {
  border-color: var(--hairline-on-dark);
}

.demo--dark .field__chip:hover {
  border-color: var(--white);
  background: rgba(255, 255, 255, 0.1);
}

.npc__preview {
  padding: clamp(1.2rem, 1rem + 1vw, 1.8rem);
  background: var(--surface-sunken);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* A light card inside a dark frame: its ink has to be set back to the page
   ink, otherwise it inherits white from the frame and vanishes. */
.npc-card {
  color: var(--ink);
  background: var(--white);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.npc-card__top {
  display: flex;
  gap: 0.9rem;
  padding: 1rem;
  background: var(--sage);
  align-items: center;
}

.npc-card__avatar {
  width: 3.5rem;
  height: 3.5rem;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--white);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.npc-card__avatar svg {
  width: 100%;
  height: 100%;
}

.npc-card__name {
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.npc-card__role {
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 0.15rem;
  color: rgba(29, 29, 29, 0.72);
}

.npc-card__body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.npc-card__row {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: 0.6rem;
  font-size: 0.84rem;
  line-height: 1.5;
}

.npc-card__key {
  font-size: var(--step-label);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding-top: 0.15rem;
}

.npc-card__value[data-empty='true'] {
  color: var(--grey);
  font-style: italic;
}

.npc-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 1rem 1rem;
}

.npc-card__tag {
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-pill);
  background: rgba(180, 185, 76, 0.4);
  font-size: 0.72rem;
  font-weight: 800;
}

.npc__where {
  font-size: 0.8rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* -------------------------------------------------------------------------
   7. Poll card (team section)
   ------------------------------------------------------------------------- */

.poll {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1rem;
}

.poll__row {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr) 2.5rem;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.82rem;
}

.poll__date {
  font-weight: 800;
}

.poll__bar {
  display: block;
  height: 0.6rem;
  border-radius: var(--radius-pill);
  background: rgba(29, 29, 29, 0.1);
  overflow: hidden;
}

/* A span is inline by default, so width and height were being dropped and
   the bar measured zero. Every bar, ring and rule on this page is a span. */
.poll__fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--crimson);
  width: 0;
  transition: width var(--t-slow) var(--ease);
}

/* The date that wins is the answer the card exists to give, so it is marked
   rather than just slightly differently coloured. */
.poll__row--best {
  position: relative;
  margin-inline: -0.5rem;
  padding: 0.3rem 0.5rem;
  border-radius: 0.5rem;
  background: var(--tint-olive);
}

.poll__row--best .poll__date {
  font-weight: 900;
}

.poll__row--best .poll__fill {
  background: var(--olive);
}

/* On its own grid row the badge doubled the height of the winning line and
   the card looked broken. It belongs beside the bar. */
.poll__row--best {
  grid-template-columns: 5.5rem minmax(0, 1fr) auto 2.5rem;
}

.poll__win {
  white-space: nowrap;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.poll__count {
  text-align: right;
  font-weight: 700;
  color: var(--ink-soft);
}

/* -------------------------------------------------------------------------
   8. Demo responsive
   ------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .adventure,
  .npc {
    grid-template-columns: minmax(0, 1fr);
  }

  .adventure__scenes {
    border-right: 0;
    border-bottom: 1px solid var(--demo-line);
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .adventure__scene-btn {
    flex: none;
    width: 13rem;
  }

  .npc__form {
    border-right: 0;
    border-bottom: 1px solid var(--demo-line);
  }

  .adventure__spread {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 620px) {
  .board,
  .map {
    height: 24rem;
  }

  .board__node {
    width: 11rem;
    font-size: 0.92em;
  }

  .demo__bar {
    flex-wrap: wrap;
  }
}
