/* The path tree window (site/prereqPathTree.js): a tutor's prerequisites
   drawn as a tree with arrows, and "Which course did you take?" at each
   choice. A centred window on a computer, a full-height sheet on a phone.
   Colours: the site's tokens (style.css), plus a violet for overlapping
   courses, set for both themes here. */

:root,
[data-theme="dark"] {
  --pt-violet-text: #c4b5fd;
  --pt-violet-bg: rgba(139, 92, 246, 0.16);
  --pt-violet-border: rgba(167, 139, 250, 0.55);
  --pt-line: rgba(148, 163, 184, 0.55);
}

[data-theme="light"] {
  --pt-violet-text: #5b21b6;
  --pt-violet-bg: #ede9fe;
  --pt-violet-border: #a78bfa;
  --pt-line: #94a3b8;
}

.pt-root {
  position: fixed;
  inset: 0;
  z-index: 5200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.pt-root[hidden] {
  display: none;
}

/* In tutor setup: laid over the part of the frame on screen (top and height
   set by the script). */
.pt-root--framed {
  bottom: auto;
}

.pt-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(var(--shadow-rgb), 0.54);
  opacity: 0;
  transition: opacity 220ms ease;
}

.pt-window {
  position: relative;
  width: min(760px, 100%);
  max-height: min(88dvh, 100%);
  height: min(88dvh, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 18px 48px rgba(var(--shadow-rgb), 0.35);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 220ms ease, transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.pt-root.is-open .pt-backdrop { opacity: 1; }
.pt-root.is-open .pt-window { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .pt-backdrop,
  .pt-window { transition: none; }
}

.pt-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 12px 20px;
  border-bottom: 1px solid var(--border);
}

.pt-head__titles {
  min-width: 0;
  flex: 1 1 auto;
}

.pt-head__title {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.pt-head__lead {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.pt-head__hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.pt-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.pt-close:focus-visible,
.pt-ok:focus-visible,
.pt-continue:focus-visible,
.pt-legend__summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pt-body {
  --pt-indent: 26px;
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 14px 16px 28px 16px;
  container-type: inline-size;
  container-name: pt;
}

/* ---- legend, in the top right corner ---- */
/* Computer: its own column beside the tree, never over a card. */
.pt-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
  align-items: start;
  gap: 0 14px;
}

.pt-tree-host {
  min-width: 0;
}

.pt-legend {
  font-size: 0.8rem;
}

.pt-legend--side {
  position: sticky;
  top: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.pt-legend__summary {
  margin: 0;
  font-weight: 700;
}

/* Phone: a "Colours" button in the header's corner; its list opens over the tree. */
.pt-legend--corner {
  display: none;
  position: relative;
  flex: 0 0 auto;
  align-self: center;
}

.pt-legend--corner .pt-legend__summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}

.pt-legend--corner .pt-legend__summary::-webkit-details-marker {
  display: none;
}

.pt-legend--corner .pt-legend__list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 3;
  width: max-content;
  max-width: min(260px, 80vw);
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(var(--shadow-rgb), 0.3);
}


.pt-legend__list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.pt-legend__item {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.25;
}

.pt-legend__swatch {
  flex: 0 0 auto;
  width: 16px;
  height: 12px;
  border-radius: 4px;
  border: 2px solid var(--border);
  background: var(--surface-2);
}

.pt-legend__item--root .pt-legend__swatch { background: var(--info-bg); border-color: var(--accent); }
.pt-legend__item--prereq .pt-legend__swatch { background: var(--success-bg); border-color: var(--success-border); }
.pt-legend__item--question .pt-legend__swatch { background: var(--warning-bg); border-color: var(--warning-border); }
.pt-legend__item--antireq .pt-legend__swatch { background: var(--pt-violet-bg); border-color: var(--pt-violet-border); }
.pt-legend__item--repeat .pt-legend__swatch { background: var(--surface-2); border-color: var(--border); opacity: 0.7; }
.pt-legend__item--other .pt-legend__swatch { background: transparent; border-style: dashed; border-color: var(--pt-line); }

/* ---- the tree ---- */
.pt-tree,
.pt-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pt-children {
  padding-left: var(--pt-indent);
}

.pt-node {
  position: relative;
  min-width: 0;
}

.pt-children > .pt-node {
  padding-top: 12px;
}

/* The rail down from the parent, and the arrow into each child. */
.pt-children > .pt-node::before {
  content: '';
  position: absolute;
  left: calc(var(--pt-indent) * -1 + 10px);
  top: 0;
  bottom: 0;
  border-left: 2px solid var(--pt-line);
}

.pt-children > .pt-node:last-child::before {
  bottom: auto;
  height: 34px;
}

.pt-children > .pt-node::after {
  content: '';
  position: absolute;
  left: calc(var(--pt-indent) * -1 + 10px);
  top: 33px;
  width: calc(var(--pt-indent) - 12px);
  border-top: 2px solid var(--pt-line);
}

.pt-children > .pt-node > .pt-card::before,
.pt-children > .pt-node > .pt-question::before {
  content: '';
  position: absolute;
  left: -9px;
  top: 16px;
  border-style: solid;
  border-width: 5px 0 5px 7px;
  border-color: transparent transparent transparent var(--pt-line);
}

.pt-card {
  position: relative;
  min-height: 44px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 9px 12px;
  border: 2px solid var(--success-border);
  border-radius: var(--radius-md);
  background: var(--success-bg);
  overflow-wrap: anywhere;
}

.pt-card__name {
  min-width: 0;
  flex: 1 1 14rem;
  font-weight: 600;
  line-height: 1.3;
}

.pt-card__tag {
  flex: 0 1 auto;
  font-size: 0.78rem;
  color: var(--muted);
}

.pt-card__same,
.pt-card__from,
.pt-card__loading {
  flex: 1 0 100%;
  font-size: 0.78rem;
  color: var(--muted);
}

.pt-node--root > .pt-card {
  border-color: var(--accent);
  background: var(--info-bg);
}

.pt-node--antireq > .pt-card {
  border-color: var(--pt-violet-border);
  background: var(--pt-violet-bg);
}

.pt-node--antireq > .pt-card .pt-card__tag {
  color: var(--pt-violet-text);
}

.pt-node.is-repeat > .pt-card {
  border-color: var(--border);
  background: var(--surface-2);
  opacity: 0.72;
}

.pt-node.is-other > .pt-card {
  border-style: dashed;
  border-color: var(--pt-line);
  background: transparent;
}

/* ---- a course card is a switch: pressed off, it is left off the list ---- */
.pt-card.is-removable {
  cursor: pointer;
  -webkit-user-select: text;
  user-select: text;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.pt-card.is-removable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pt-card__mark {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  background: rgba(var(--shadow-rgb), 0.08);
  transition: color 160ms ease, background-color 160ms ease;
}

.pt-card__mark-on,
.pt-card.is-removed .pt-card__mark-off {
  display: none;
}

.pt-card.is-removed .pt-card__mark-on {
  display: block;
}

@media (hover: hover) {
  .pt-card.is-removable:hover .pt-card__mark {
    color: var(--danger-text);
    background: var(--danger-bg);
  }

  .pt-card.is-removed:hover .pt-card__mark {
    color: var(--accent);
    background: var(--info-bg);
  }
}

.pt-card.is-removed,
.pt-node.is-repeat > .pt-card.is-removed {
  opacity: 0.48;
  border-style: dashed;
  border-color: var(--border);
  background: transparent;
}

.pt-card.is-removed .pt-card__name {
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .pt-card.is-removable,
  .pt-card__mark { transition: none; }
}

/* Deep lines keep their place: a card says where it comes from. */
.pt-card__from {
  display: none;
}

/* ---- a choice ---- */
.pt-question {
  position: relative;
  padding: 12px 12px 14px;
  border: 2px solid var(--warning-border);
  border-radius: var(--radius-md);
  background: var(--warning-bg);
}

.pt-question.is-active {
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.25);
}

.pt-question.is-answered {
  border-style: dashed;
}

.pt-question__title {
  margin: 0;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pt-question__hint {
  margin: 2px 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.pt-options {
  display: grid;
  gap: 6px;
}

.pt-option {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.pt-option input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.pt-option.is-picked {
  border-color: var(--accent);
  background: var(--info-bg);
}

.pt-option.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.pt-option__names {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  line-height: 1.3;
}

.pt-option__course {
  min-width: 0;
}

.pt-option__school {
  margin-left: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.pt-option__and {
  color: var(--muted);
  font-size: 0.85rem;
}

.pt-option--none {
  font-style: italic;
}

.pt-continue,
.pt-ok {
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--action);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.pt-continue {
  margin-top: 12px;
}

.pt-continue:disabled,
.pt-ok:disabled {
  background: var(--control-disabled-bg);
  color: var(--muted);
  cursor: not-allowed;
}

/* ---- the bottom bar ---- */
.pt-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.pt-foot__status {
  margin: 0;
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.pt-ok {
  flex: 0 0 auto;
  min-width: 96px;
}

.pt-loading {
  margin: 32px auto;
}

/* ---- phones (narrow windows) ---- */
@media (max-width: 640px) {
  .pt-root {
    align-items: flex-end;
    padding: 0;
  }

  .pt-window {
    width: 100%;
    height: 94dvh;
    max-height: 100%;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    transform: translateY(40px);
  }

  .pt-root--framed .pt-window {
    height: 100%;
  }

  .pt-head {
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 12px 10px 16px;
  }

  .pt-head__titles {
    flex: 1 1 100%;
    order: 3;
  }

  .pt-head__title {
    font-size: 1rem;
  }

  .pt-head__lead {
    font-size: 0.82rem;
  }

  .pt-body {
    --pt-indent: 14px;
    grid-template-columns: minmax(0, 1fr);
    padding: 10px 12px 24px;
  }

  .pt-legend--side { display: none; }

  /* The corner: the Colours button, then the close button. */
  .pt-legend--corner {
    display: block;
    margin-left: auto;
  }

  .pt-card,
  .pt-question {
    padding-left: 10px;
    padding-right: 10px;
  }

  /* Four levels in, lines stop moving right and say where they come from. */
  .pt-node.is-deep > .pt-children {
    padding-left: 0;
  }

  .pt-node.is-deep > .pt-children > .pt-node::before,
  .pt-node.is-deep > .pt-children > .pt-node::after,
  .pt-node.is-deep > .pt-children > .pt-node > .pt-card::before,
  .pt-node.is-deep > .pt-children > .pt-node > .pt-question::before {
    display: none;
  }

  .pt-node.is-deep .pt-card__from {
    display: block;
  }

  .pt-foot {
    flex-wrap: wrap;
  }

  .pt-ok {
    flex: 1 0 100%;
  }
}
