:root {
  color-scheme: light;
  --ink: #25302b;
  --muted: #6b746f;
  --line: #d9ded8;
  --panel: #ffffff;
  --wash: #f5f7f3;
  --accent: #23746d;
  --accent-strong: #164f4a;
  --amber: #d89a3d;
  --sage: #dfe9df;
  --shadow: 0 16px 45px rgba(37, 48, 43, 0.1);
}

* {
  box-sizing: border-box;
}

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  min-height: 36px;
  padding: 0 12px;
  font: inherit;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(18px);
}

.topbar h1,
.scene-heading h2,
.sidebar h2,
.study-section h3,
.detail-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 20px;
}

.brand-block {
  min-width: 154px;
}

.global-search {
  flex: 1 1 420px;
  max-width: 560px;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 3px 10px;
  box-shadow: 0 8px 20px rgba(37, 48, 43, 0.04);
}

.global-search span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.global-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.global-search input::placeholder {
  color: #9aa39d;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.mode-switch {
  display: flex;
  gap: 6px;
}

.mode-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.mode-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  text-decoration: none;
  font-size: 14px;
}

.mode-link:hover,
.mode-link:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 65px);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 16px;
  background: #eef3ec;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.sidebar h2 {
  font-size: 15px;
}

#scene-count {
  color: var(--muted);
  font-size: 13px;
}

.scene-list {
  display: grid;
  gap: 8px;
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.category-tab,
.track-pill {
  min-height: 28px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
}

.category-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.scene-item {
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  text-align: left;
}

.scene-item.active {
  border-color: var(--accent);
  background: #fff;
}

.scene-item strong {
  font-size: 13px;
}

.scene-item span {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  padding: 18px 20px 22px;
  display: grid;
  gap: 14px;
}

.home-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 0.5fr);
  gap: 22px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96) 0%, rgba(250, 247, 239, 0.95) 48%, rgba(237, 246, 242, 0.95) 100%),
    #fff;
  box-shadow: var(--shadow);
  padding: 20px;
}

.home-copy h2,
.rail-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.home-copy h2 {
  max-width: 680px;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.05;
}

.home-copy p:last-child {
  max-width: 680px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.library-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  min-height: 74px;
  border: 1px solid rgba(217, 222, 216, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 11px 12px;
}

.metric strong {
  display: block;
  font-size: 25px;
  line-height: 1.05;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.scene-rail,
.expansion-panel {
  display: grid;
  gap: 10px;
}

.rail-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.rail-header h2 {
  font-size: 18px;
}

.track-filter {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.track-pill.active {
  background: #2f4051;
  border-color: #2f4051;
  color: #fff;
}

.scene-cards {
  display: grid;
  grid-auto-columns: minmax(150px, 176px);
  grid-auto-flow: column;
  grid-template-columns: none;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.scene-card {
  display: grid;
  grid-template-rows: 86px auto auto auto;
  gap: 3px;
  min-height: 164px;
  overflow: hidden;
  padding: 0 0 10px;
  background: #fff;
  text-align: left;
}

.scene-card img {
  display: block;
  width: 100%;
  height: 86px;
  border-bottom: 1px solid var(--line);
  object-fit: cover;
}

.scene-card span,
.scene-card strong,
.scene-card small {
  padding: 0 10px;
}

.scene-card span {
  margin-top: 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.scene-card strong {
  font-size: 14px;
  line-height: 1.2;
}

.scene-card small {
  color: var(--muted);
  font-size: 12px;
}

.scene-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(35, 116, 109, 0.12);
}

.expansion-tracks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.expansion-track {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.expansion-track div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.expansion-track strong {
  font-size: 14px;
}

.expansion-track span {
  border-radius: 999px;
  background: #eef3ec;
  color: var(--accent-strong);
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
}

.expansion-track p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.scene-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.scene-heading h2 {
  font-size: 24px;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  max-width: 680px;
  font-size: 13px;
}

.scene-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.scene-stats span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.visual-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 14px;
  align-items: start;
}

.scene-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.scene-stage img {
  display: block;
  width: 100%;
  height: auto;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
}

.hit-svg,
.label-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hit-area {
  fill: rgba(35, 116, 109, 0.001);
  stroke: transparent;
  stroke-width: 0.2;
  cursor: default;
  pointer-events: all;
}

.hit-area:hover,
.hit-area.active {
  fill: rgba(35, 116, 109, 0.001);
  stroke: transparent;
}

.label-layer {
  pointer-events: none;
}

.hotspot {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hotspot-label {
  display: none;
  position: absolute;
  top: 0;
  left: 50%;
  max-width: 130px;
  border: 1px solid rgba(35, 116, 109, 0.2);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--accent-strong);
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
  white-space: normal;
  line-height: 1.2;
  box-shadow: 0 6px 18px rgba(37, 48, 43, 0.1);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 4px));
  transition: opacity 140ms ease, transform 140ms ease;
}

.hotspot.fixed-label .hotspot-label,
.hotspot.show-label .hotspot-label {
  display: block;
  opacity: 1;
  transform: translate(-50%, calc(-100% - 8px));
}

.hotspot.fixed-label .hotspot-label {
  position: static;
  transform: translateY(0);
  pointer-events: auto;
}

.hotspot.fixed-label {
  cursor: pointer;
  pointer-events: auto;
}

.hotspot.suppressed-label .hotspot-label,
.review .hotspot .hotspot-label {
  display: none;
  opacity: 0;
}

.hotspot.active .hotspot-dot {
  background: var(--accent);
  transform: scale(1.25);
}

.detail-card,
.study-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(37, 48, 43, 0.06);
}

.detail-card {
  min-height: 136px;
  padding: 14px;
  position: sticky;
  top: 78px;
}

.detail-card h3 {
  font-size: 20px;
  line-height: 1.15;
  margin-bottom: 8px;
}

.detail-card p {
  font-size: 13px;
  line-height: 1.42;
}

.detail-card p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.study-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.study-section {
  padding: 12px;
}

.study-section h3 {
  font-size: 15px;
}

.study-section.wide {
  grid-column: 1 / -1;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfa;
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.phrase-list,
.sentence-list {
  display: grid;
  gap: 6px;
}

.phrase,
.sentence {
  border-left: 2px solid var(--sage);
  padding-left: 8px;
  font-size: 12px;
  line-height: 1.35;
}

.phrase strong {
  display: block;
}

.phrase span,
.sentence {
  color: var(--muted);
}

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

.print .sidebar,
.print .topbar,
.print .detail-card,
.print .scene-stats,
.print #toggle-labels {
  display: none;
}

.print .layout,
.print .visual-panel,
.print .study-grid {
  display: block;
}

.print .workspace {
  padding: 0;
}

@media (max-width: 980px) {
  .layout,
  .visual-panel,
  .study-grid,
  .home-panel,
  .expansion-tracks {
    grid-template-columns: 1fr;
  }

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

  .scene-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-card {
    position: static;
  }

  .library-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  body {
    background: #fff;
    overflow-x: hidden;
  }

  button,
  .mode-link {
    min-height: 32px;
    padding: 0 9px;
    font-size: 13px;
  }

  .topbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 54px;
    padding: 8px 10px;
  }

  .topbar .eyebrow {
    display: none;
  }

  .topbar h1 {
    font-size: 15px;
    line-height: 1.2;
  }

  .brand-block {
    min-width: 0;
  }

  .global-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    min-height: 34px;
    padding: 2px 8px;
  }

  .global-search span {
    display: none;
  }

  .global-search input {
    font-size: 13px;
  }

  .mode-switch {
    gap: 4px;
    max-width: 100%;
    overflow-x: auto;
  }

  .mode-button[data-mode="print"] {
    display: none;
  }

  .layout {
    display: block;
    min-height: 0;
  }

  .sidebar {
    display: none;
  }

  .workspace {
    padding: 6px;
    gap: 7px;
    min-width: 0;
  }

  .home-panel {
    gap: 12px;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(37, 48, 43, 0.08);
  }

  .home-copy h2 {
    font-size: 24px;
  }

  .home-copy p:last-child {
    font-size: 12px;
    line-height: 1.4;
  }

  .library-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .metric {
    min-height: 52px;
    padding: 7px;
  }

  .metric strong {
    font-size: 18px;
  }

  .metric span {
    font-size: 10px;
  }

  .scene-rail,
  .expansion-panel {
    gap: 7px;
  }

  .rail-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .rail-header h2 {
    font-size: 15px;
  }

  .track-filter {
    justify-content: flex-start;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .track-pill {
    white-space: nowrap;
  }

  .scene-cards {
    display: grid;
    grid-auto-columns: 136px;
    grid-auto-flow: column;
    grid-template-columns: none;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 3px;
    -webkit-overflow-scrolling: touch;
  }

  .scene-card {
    grid-template-rows: 72px auto auto auto;
    min-height: 144px;
  }

  .scene-card img {
    height: 72px;
  }

  .scene-card span {
    font-size: 10px;
  }

  .scene-card strong {
    font-size: 13px;
  }

  .scene-card small {
    font-size: 11px;
  }

  .scene-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .scene-heading .eyebrow,
  .scene-stats {
    display: none;
  }

  .scene-heading h2 {
    font-size: 18px;
  }

  .subtitle {
    max-width: none;
    font-size: 11px;
    line-height: 1.35;
  }

  .visual-panel,
  .study-grid,
  .columns {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .visual-panel {
    gap: 8px;
  }

  .scene-stage {
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(37, 48, 43, 0.08);
    min-width: 0;
  }

  .detail-card {
    min-height: 0;
    padding: 8px;
    position: static;
  }

  .detail-card .eyebrow {
    font-size: 10px;
  }

  .detail-card h3 {
    font-size: 18px;
  }

  .detail-card p {
    font-size: 12px;
  }

  .study-grid {
    gap: 8px;
  }

  .study-section {
    padding: 10px;
    min-width: 0;
  }

  .study-section:not(:first-child) {
    display: none;
  }

  .section-title {
    margin-bottom: 8px;
  }

  #toggle-labels {
    display: none;
  }

  .chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    max-height: 116px;
    overflow-y: auto;
    padding: 0 2px 2px 0;
    -webkit-overflow-scrolling: touch;
  }

  .chip {
    flex: 0 1 auto;
    min-height: 30px;
    white-space: nowrap;
  }

  .hotspot.fixed-label .hotspot-label {
    display: none;
  }

  .hotspot.show-label .hotspot-label,
  .hotspot.fixed-label.show-label .hotspot-label {
    display: block;
    opacity: 1;
    transform: translate(-50%, calc(-100% - 8px));
  }

  .hotspot-label {
    max-width: 112px;
    padding: 3px 6px;
    font-size: 11px;
  }

  .expansion-tracks {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .expansion-track {
    padding: 9px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .sidebar,
  .detail-card,
  #toggle-labels {
    display: none;
  }

  .layout,
  .visual-panel,
  .study-grid {
    display: block;
  }

  .workspace {
    padding: 0;
  }

  .study-section,
  .scene-stage {
    box-shadow: none;
    break-inside: avoid;
    margin-bottom: 12px;
  }
}
