.bjj {
  --lv: #46524b;
  --lv-0: #46524b;
  --lv-1: #e5534b;
  --lv-2: #e8a33d;
  --lv-3: #b8d64a;
  --lv-4: #4fdc8a;
  max-width: 72rem;
}

/* The map page is wider than other pages; keep the header lined up with it. */
.bjj-site .site-header {
  max-width: 72rem;
}

.bjj .lv-0 { --lv: var(--lv-0); }
.bjj .lv-1 { --lv: var(--lv-1); }
.bjj .lv-2 { --lv: var(--lv-2); }
.bjj .lv-3 { --lv: var(--lv-3); }
.bjj .lv-4 { --lv: var(--lv-4); }

.bjj button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.bjj h2 {
  margin: 0;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
}

.muted {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Toolbar */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.5rem 0 1rem;
}

.edit-link {
  padding: 0.4rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.edit-link:hover {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.seg {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.seg button {
  padding: 0.35rem 0.85rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 0.875rem;
}

.seg button[aria-pressed="true"] {
  background: var(--line);
  color: var(--fg);
}

/* Layout: map with the panel beside it on wide screens, as a bottom sheet on narrow ones */

.layout {
  display: grid;
  gap: 1.5rem;
  align-items: start;
}

/* Wide screens: the board runs the full width of the window, with the panel floating
   over its right side. From 1200px the insights move into a column beside the board and
   scroll on their own, so the page itself barely needs to. */
@media (min-width: 900px) {
  .bjj-site {
    overflow-x: clip;
  }

  .workspace {
    width: calc(100vw - 2rem);
    margin-left: calc(50% - 50vw + 1rem);
  }

  .layout {
    position: relative;
    display: block;
    height: calc(100dvh - 4rem);
    min-height: 34rem;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
  }
}

@media (min-width: 1200px) {
  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 21rem;
    gap: 1rem;
    height: calc(100dvh - 4rem);
    min-height: 34rem;
  }

  .workspace .layout {
    height: auto;
    min-height: 0;
  }

  .workspace .insights {
    grid-template-columns: 1fr;
    align-content: start;
    min-height: 0;
    margin-top: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* The map */

.map {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 2.75rem;
  padding: 0 1.5rem 1rem;
}

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

.edge {
  fill: none;
  stroke: var(--lv);
  stroke-width: 1.5;
  opacity: 0.4;
  transition: opacity 0.15s;
}

.edge.lv-0 {
  stroke-dasharray: 3 4;
  opacity: 0.25;
}

.edge.faded {
  opacity: 0.05;
}

.edge.in {
  opacity: 0.35;
}

.edge.out {
  opacity: 1;
  stroke-width: 2.25;
}

marker path {
  fill: var(--lv);
}

.col-head {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
}

.cell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-height: 4rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--lv);
  border-radius: 10px;
  background: color-mix(in srgb, var(--lv) 9%, var(--panel));
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.cell:hover {
  border-color: var(--lv);
}

.cell.selected {
  border-color: var(--lv);
  box-shadow: 0 0 0 1px var(--lv), 0 0 24px color-mix(in srgb, var(--lv) 30%, transparent);
}

.cell.neutral {
  justify-self: center;
  width: min(100%, 16rem);
  margin-bottom: 0.5rem;
}

.cell-name {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.25;
}

.cell-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.often {
  color: var(--accent);
  font-weight: 600;
}

.cell-subs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 0.2rem;
}

.dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--lv);
  vertical-align: middle;
}

/* Panel */

.panel {
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  outline: none;
}

@media (min-width: 900px) {
  .panel {
    position: absolute;
    top: 1rem;
    right: 1rem;
    bottom: 1rem;
    z-index: 5;
    width: 24rem;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgb(0 0 0 / 0.5);
  }

  body:not(.panel-open) .panel {
    display: none;
  }
}

/* The board (board.ts) */

.map.board {
  position: absolute;
  inset: 0;
  display: block;
  padding: 0;
  overflow: hidden;
  background-color: var(--inset);
  background-image: radial-gradient(circle, var(--line) 1.2px, transparent 1.4px);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.map.board.panning {
  cursor: grabbing;
}

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

.board-edges {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

.branch {
  fill: none;
  stroke: var(--lv);
  stroke-width: 2;
  opacity: 0.55;
}

.board .edge {
  stroke-width: 1.75;
}

.board .edge.out {
  stroke-width: 2.75;
}

.node {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--lv);
  border-radius: 12px;
  background: color-mix(in srgb, var(--lv) 10%, var(--panel));
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.node:hover,
.node.selected {
  border-color: var(--lv);
}

.node.selected {
  box-shadow: 0 0 0 1px var(--lv), 0 0 32px color-mix(in srgb, var(--lv) 35%, transparent);
}

.node.neutral {
  border-left-width: 1px;
  border-top: 4px solid var(--lv);
  align-items: center;
  text-align: center;
}

.node .cell-name {
  font-size: 1.1rem;
}

.node .cell-meta {
  font-size: 0.8rem;
}

.node.sub {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0.45rem;
  padding: 0 0.7rem;
  border-left-width: 1px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg);
  font-size: 0.9rem;
  white-space: nowrap;
}

.dragging .node {
  cursor: grabbing;
  transition: none;
}

.board-controls {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.board-controls button {
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.7rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--fg);
  font-size: 0.85rem;
}

.board-controls button:hover {
  background: var(--line);
}

.board-hint {
  position: absolute;
  top: 0.75rem;
  left: 1rem;
  z-index: 4;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  pointer-events: none;
}

@media (max-width: 899px) {
  .panel {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    max-height: 75dvh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    box-shadow: 0 -12px 40px rgb(0 0 0 / 0.6);
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 0.2s, visibility 0.2s;
  }

  .panel-open .panel {
    transform: none;
    visibility: visible;
  }

  /* Room to scroll the bottom of the page above the open sheet. */
  .panel-open .bjj {
    padding-bottom: 75dvh;
  }

  .map {
    gap: 0.5rem 2rem;
    padding: 0 1rem 1rem;
  }

  .bjj.page {
    padding-inline: 0.75rem;
  }

  .bjj > .eyebrow,
  .bjj > h1,
  .bjj > .lede,
  .bjj > .toolbar {
    margin-inline: 0.75rem;
  }
}

.panel-empty {
  margin: 0;
  color: var(--muted);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.panel-head .eyebrow {
  margin-bottom: 0.25rem;
}

.close {
  width: 2rem;
  height: 2rem;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: none;
  font-size: 1.2rem;
  line-height: 1;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--lv) 22%, transparent);
  color: color-mix(in srgb, var(--lv) 70%, var(--fg));
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill.lv-0 {
  background: none;
  border: 1px dashed var(--lv);
  color: var(--muted);
}

.often-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.often-toggle input {
  accent-color: var(--accent);
  width: 1.1rem;
  height: 1.1rem;
}

.group h3,
.add h3 {
  margin: 1.5rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.group:first-of-type h3 {
  margin-top: 1.25rem;
}

.moves {
  margin: 0;
  padding: 0;
  list-style: none;
}

.move {
  padding: 0.65rem 0 0.65rem 0.7rem;
  border-left: 3px solid var(--lv);
  margin-top: 0.5rem;
}

.move-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.move-name {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
}

.move-meta {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.badge {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0 0.35rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
  vertical-align: 0.1em;
}

.goto {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent) !important;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.rate {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  margin-top: 0.5rem;
}

.rate button {
  padding: 0.45rem 0.1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--inset);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.rate button[aria-pressed="true"] {
  border-color: var(--lv);
  background: color-mix(in srgb, var(--lv) 25%, transparent);
  color: var(--fg);
  font-weight: 600;
}

.note {
  margin-top: 0.4rem;
  font-size: 0.82rem;
}

.note summary {
  color: var(--muted);
  cursor: pointer;
}

.bjj textarea,
.bjj input:not([type="checkbox"]),
.bjj select {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--inset);
  color: var(--fg);
  font: inherit;
  font-size: 16px; /* stops iOS zooming in on focus */
}

.note-text {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.remove {
  margin-top: 0.4rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--lv-1) !important;
  font-size: 0.8rem;
}

.add {
  margin-top: 1rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--line);
}

.add label {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.85rem;
}

.add button[type="submit"] {
  margin-top: 0.85rem;
  padding: 0.5rem 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* Insights */

.insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.insights .card {
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.insights h2 {
  margin-bottom: 0.75rem;
}

.focus {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.92rem;
}

.focus li + li {
  margin-top: 0.6rem;
}

.chain {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.chain li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0 0.35rem 1rem;
  border-left: 2px solid var(--line);
}

.dist {
  display: flex;
  height: 0.75rem;
  gap: 2px;
  overflow: hidden;
  border-radius: 999px;
}

.dist span {
  background: var(--lv);
}

.legend {
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
}

.legend li {
  display: grid;
  grid-template-columns: 1rem 1fr auto;
  align-items: center;
  gap: 0 0.5rem;
  padding: 0.3rem 0;
}

.legend span {
  font-family: var(--mono);
  color: var(--muted);
}

.legend small {
  grid-column: 2 / -1;
  color: var(--muted);
  font-size: 0.8rem;
}

.recent {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
}

.recent li {
  display: grid;
  grid-template-columns: 3.75rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}

.recent .goto {
  text-align: left;
}

.when,
.change {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.sync-status {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 20;
  max-width: calc(100% - 2rem);
  margin: 0;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.sync-status:empty {
  display: none;
}

.sync-status.warn {
  border-color: var(--lv-2);
  color: var(--lv-2);
}

/* Above the bottom sheet on narrow screens. */
@media (max-width: 899px) {
  .panel-open .sync-status {
    bottom: auto;
    top: 1rem;
  }
}
