:root {
  --canvas: #111714;
  --paper: #fffefa;
  --paper-soft: #f1f5ed;
  --ink: #171f1b;
  --muted: #68746d;
  --line: #d9ddd2;
  --primary: #4e7f69;
  --primary-dark: #315f50;
  --shadow: 0 20px 58px rgba(5, 12, 9, 0.34);
  --neutral: #7c8580;
  --red: #c85f6b;
  --orange: #cb7656;
  --yellow: #c5a245;
  --green: #63966b;
  --teal: #4f907f;
  --blue: #5f82bd;
  --purple: #8370ad;
  --pink: #bd6f95;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
.link-tool {
  align-items: center;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  height: 42px;
  justify-content: center;
  min-width: 42px;
  padding: 0 14px;
  text-decoration: none;
}

button:hover,
.link-tool:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button svg,
.link-tool svg {
  fill: none;
  height: 20px;
  pointer-events: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 20px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.secondary,
.link-tool.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

button.secondary:hover,
.link-tool.secondary:hover {
  background: var(--paper-soft);
}

.review-shell {
  min-height: 100vh;
}

.review-map {
  background: rgba(255, 254, 250, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  box-shadow: var(--shadow);
  left: 18px;
  max-height: calc(100dvh - 104px);
  overflow: auto;
  padding: 16px;
  position: fixed;
  top: 74px;
  transform: translateX(-116%);
  transition: transform 170ms ease;
  width: min(330px, calc(100vw - 36px));
  z-index: 8;
}

.review-map.open {
  transform: translateX(0);
}

.review-shell.tree-hidden .review-map {
  transform: translateX(-116%);
}

.map-head {
  margin-bottom: 14px;
}

.map-head h1 {
  font-size: 24px;
  letter-spacing: 0;
  margin: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
  margin: 0 0 5px;
  text-transform: uppercase;
}

.map-content {
  display: grid;
  gap: 10px;
}

.tree-empty {
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 150px;
  padding: 18px;
  text-align: center;
}

.album-node {
  background: rgba(255, 254, 250, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.album-row,
.unit-row,
.frame-row {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  min-height: 44px;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}

.album-row:hover,
.unit-row:hover,
.frame-row:hover {
  background: var(--paper-soft);
}

.node-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-meta {
  color: var(--muted);
  font-size: 12px;
}

.expander {
  color: var(--muted);
}

.unit-children,
.frame-list {
  display: grid;
}

.frame-row {
  grid-template-columns: 18px minmax(0, 1fr) auto;
  min-height: 38px;
  padding-left: 18px;
}

.frame-row.active {
  background: #edf5f0;
  color: var(--primary-dark);
  font-weight: 760;
}

.frame-row.visited .visit-dot {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.76);
}

.visit-dot {
  border: 1px solid var(--line);
  border-radius: 999px;
  height: 10px;
  width: 10px;
}

.visit-dot[data-color="neutral"],
.frame-tag-dot[data-color="neutral"],
.filter-dot[data-color="neutral"] {
  background: var(--neutral);
}

.visit-dot[data-color="red"],
.frame-tag-dot[data-color="red"],
.filter-dot[data-color="red"] {
  background: var(--red);
}

.visit-dot[data-color="orange"],
.frame-tag-dot[data-color="orange"],
.filter-dot[data-color="orange"] {
  background: var(--orange);
}

.visit-dot[data-color="yellow"],
.frame-tag-dot[data-color="yellow"],
.filter-dot[data-color="yellow"] {
  background: var(--yellow);
}

.visit-dot[data-color="green"],
.frame-tag-dot[data-color="green"],
.filter-dot[data-color="green"] {
  background: var(--green);
}

.visit-dot[data-color="teal"],
.frame-tag-dot[data-color="teal"],
.filter-dot[data-color="teal"] {
  background: var(--teal);
}

.visit-dot[data-color="blue"],
.frame-tag-dot[data-color="blue"],
.filter-dot[data-color="blue"] {
  background: var(--blue);
}

.visit-dot[data-color="purple"],
.frame-tag-dot[data-color="purple"],
.filter-dot[data-color="purple"] {
  background: var(--purple);
}

.visit-dot[data-color="pink"],
.frame-tag-dot[data-color="pink"],
.filter-dot[data-color="pink"] {
  background: var(--pink);
}

.review-main {
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.stage {
  align-items: center;
  background: #111714;
  display: flex;
  height: 100vh;
  height: 100dvh;
  justify-content: center;
  overflow: hidden;
  position: relative;
  touch-action: none;
  user-select: none;
  width: 100%;
}

.stage-image {
  display: block;
  max-height: calc(100% - 40px);
  max-width: calc(100% - 40px);
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
}

.stage-empty {
  color: #c9d6d0;
  padding: 24px;
  text-align: center;
}

.stage-note-card {
  background: rgba(255, 254, 250, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  max-height: min(72vh, 760px);
  max-width: min(580px, calc(100% - 56px));
  min-height: min(360px, calc(100vh - 180px));
  overflow: auto;
  padding: 28px 30px;
  width: min(540px, calc(100% - 56px));
}

.stage-note-card h2 {
  font-size: 24px;
  letter-spacing: 0;
  margin: 0 0 18px;
}

.stage-note-body {
  font-size: 17px;
  line-height: 1.68;
}

.stage-note-body h1,
.stage-note-body h2,
.stage-note-body h3 {
  letter-spacing: 0;
  margin: 0.5em 0;
}

.stage-note-body p {
  margin: 0 0 0.9em;
}

.stage-note-body code {
  background: #edf2ef;
  border-radius: 4px;
  padding: 1px 4px;
}

.viewer-tools {
  display: flex;
  gap: 8px;
  left: 18px;
  position: fixed;
  top: 18px;
  z-index: 10;
}

.icon-tool {
  background: rgba(255, 254, 250, 0.9);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: 0 10px 28px rgba(5, 12, 9, 0.2);
  color: var(--ink);
  min-width: 42px;
  padding: 0;
}

.icon-tool:hover {
  background: #fff;
  border-color: #fff;
}

.color-filter {
  align-items: center;
  background: rgba(255, 254, 250, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(5, 12, 9, 0.2);
  display: flex;
  gap: 6px;
  left: 50%;
  max-width: min(620px, calc(100vw - 196px));
  overflow-x: auto;
  padding: 6px;
  position: fixed;
  top: 18px;
  transform: translateX(-50%);
  z-index: 9;
}

.color-filter[hidden] {
  display: none;
}

.filter-button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--ink);
  gap: 7px;
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
}

.filter-button:hover,
.filter-button.active {
  background: #fff;
  border-color: var(--line);
}

.filter-dot {
  border-radius: 999px;
  height: 12px;
  width: 12px;
}

.filter-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.all-filter {
  min-width: auto;
}

.image-rail {
  bottom: 96px;
  display: flex;
  gap: 8px;
  left: 50%;
  max-width: min(620px, calc(100vw - 40px));
  overflow-x: auto;
  padding: 8px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 5;
}

.image-thumb {
  background: rgba(255, 254, 250, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  height: 60px;
  min-height: 60px;
  overflow: hidden;
  padding: 0;
  width: 90px;
}

.image-thumb.active {
  border-color: #b4d6c9;
  box-shadow: 0 0 0 3px rgba(180, 214, 201, 0.38);
}

.image-thumb img {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.frame-nav {
  display: none;
}

.frame-nav-button {
  background: rgba(255, 254, 250, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(5, 12, 9, 0.22);
  color: var(--ink);
  font-size: 34px;
  height: 56px;
  line-height: 1;
  padding: 0;
  width: 56px;
}

.sticky-note {
  background: rgba(255, 254, 250, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(5, 12, 9, 0.24);
  height: 42px;
  min-height: 42px;
  min-width: 42px;
  overflow: hidden;
  padding: 0;
  position: fixed;
  right: 22px;
  top: 22px;
  transition:
    border-radius 140ms ease,
    height 140ms ease,
    opacity 140ms ease,
    padding 140ms ease,
    width 140ms ease;
  width: 42px;
  z-index: 8;
}

.sticky-note:not(.note-open) {
  cursor: pointer;
}

.sticky-note::before {
  background: var(--primary);
  border-radius: 999px;
  content: "";
  height: 16px;
  left: 13px;
  position: absolute;
  top: 13px;
  width: 16px;
}

.sticky-note.note-open {
  border-radius: 8px;
  height: min(62vh, 560px);
  max-height: calc(100vh - 132px);
  max-width: min(420px, calc(100vw - 48px));
  min-height: 260px;
  min-width: 280px;
  overflow: auto;
  padding: 24px 18px 18px;
  resize: both;
  width: min(340px, 28vw);
}

.sticky-note.note-open::before {
  display: none;
}

.sticky-note h2 {
  font-size: 18px;
  letter-spacing: 0;
  margin: 0 0 10px;
}

.sticky-note > .eyebrow,
.sticky-note h2,
.note-body {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.sticky-note.note-open > .eyebrow,
.sticky-note.note-open h2,
.sticky-note.note-open .note-body {
  opacity: 1;
  pointer-events: auto;
}

.note-body {
  font-size: 14px;
  line-height: 1.55;
}

.note-body h1,
.note-body h2,
.note-body h3 {
  letter-spacing: 0;
  margin: 0.45em 0;
}

.note-body p {
  margin: 0 0 0.8em;
}

.note-body code {
  background: #edf2ef;
  border-radius: 4px;
  padding: 1px 4px;
}

.playbar {
  align-items: center;
  background: rgba(255, 254, 250, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  bottom: 22px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  left: 50%;
  min-height: 62px;
  padding: 10px 12px 10px 16px;
  position: fixed;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 44px));
  z-index: 8;
}

.now-playing {
  min-width: 0;
}

.now-playing strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.frame-line {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 12px minmax(0, 1fr);
}

.frame-tag-dot {
  border-radius: 999px;
  height: 12px;
  width: 12px;
}

.audio-actions {
  display: flex;
  gap: 8px;
}

.audio-actions button {
  min-width: 48px;
  padding: 0;
}

.audio-actions .autoplay-button {
  min-width: 58px;
  padding: 0 12px;
}

.autoplay-button.active {
  background: var(--primary);
  color: #fff;
}

.speed-actions {
  background: rgba(255, 254, 250, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  display: flex;
  gap: 4px;
  padding: 4px;
}

.speed-button {
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  min-height: 32px;
  padding: 0 10px;
}

.speed-button:hover,
.speed-button.active {
  background: var(--primary);
  color: #fff;
}

.auth-gate {
  align-items: center;
  background: rgba(17, 23, 20, 0.78);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 100;
}

.auth-card {
  background: rgba(255, 254, 250, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 380px;
  padding: 20px;
  width: 100%;
}

.auth-card h2 {
  font-size: 26px;
  letter-spacing: 0;
  margin: 0;
}

.auth-card label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 760;
  gap: 7px;
}

.auth-card input {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  padding: 0 12px;
  width: 100%;
}

.auth-message {
  background: #fff0ec;
  border: 1px solid #e7beb6;
  border-radius: 8px;
  color: #9e4b46;
  padding: 10px 12px;
}

.auth-switch {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.auth-switch:hover {
  background: var(--paper-soft);
}

@media (max-width: 760px) {
  .stage {
    align-items: center;
    height: 100svh;
    min-height: 100svh;
    padding: calc(184px + var(--safe-top)) 12px calc(138px + var(--safe-bottom));
  }

  @supports (height: 100dvh) {
    .stage {
      height: 100dvh;
      min-height: 100dvh;
    }
  }

  .viewer-tools {
    left: 12px;
    top: calc(12px + var(--safe-top));
  }

  .icon-tool {
    height: 46px;
    min-width: 46px;
  }

  .color-filter {
    left: 12px;
    max-width: calc(100vw - 24px);
    top: calc(66px + var(--safe-top));
    transform: none;
    width: calc(100vw - 24px);
  }

  .review-map {
    left: 12px;
    max-height: calc(100dvh - 92px - var(--safe-top) - var(--safe-bottom));
    top: calc(70px + var(--safe-top));
    width: calc(100vw - 24px);
    z-index: 11;
  }

  .map-head h1 {
    font-size: 22px;
  }

  .stage-image {
    max-height: 100%;
    max-width: 100%;
  }

  .stage-note-card {
    max-height: 100%;
    max-width: calc(100vw - 28px);
    min-height: min(220px, 100%);
    padding: 22px;
    width: calc(100vw - 28px);
  }

  .frame-nav {
    display: flex;
    justify-content: space-between;
    left: 12px;
    pointer-events: none;
    position: fixed;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 6;
  }

  .frame-nav-button {
    pointer-events: auto;
  }

  .sticky-note {
    right: 14px;
    top: calc(12px + var(--safe-top));
  }

  .sticky-note.note-open {
    height: 56vh;
    max-height: 56vh;
    min-height: 220px;
    width: min(320px, calc(100vw - 28px));
  }

  .playbar {
    align-items: center;
    bottom: calc(12px + var(--safe-bottom));
    display: grid;
    gap: 8px 10px;
    grid-template-areas:
      "now audio"
      "speed speed";
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 10px;
    width: calc(100vw - 24px);
  }

  .now-playing {
    grid-area: now;
  }

  .audio-actions {
    display: grid;
    grid-area: audio;
    grid-template-columns: 52px 46px 46px;
  }

  .audio-actions button,
  .audio-actions .autoplay-button {
    min-width: 0;
    padding: 0;
  }

  .speed-actions {
    grid-area: speed;
    justify-content: stretch;
    width: 100%;
  }

  .speed-button {
    flex: 1;
  }

  .image-rail {
    bottom: auto;
    max-width: calc(100vw - 24px);
    top: calc(116px + var(--safe-top));
  }
}
