:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-soft: #fbfdff;
  --surface: #ffffff;
  --surface-hover: #f8fbff;
  --line: #d9e2ef;
  --text: #142033;
  --muted: #66748a;
  --blue: #2563eb;
  --button-bg: #ffffff;
  --button-hover: #f8fbff;
  --image-bg: #edf2f7;
  --map-bg: #ffffff;
  --chip-bg: #f7fbff;
  --chip-border: #bfd2f2;
  --chip-text: #1d4ed8;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080d18;
  --panel: #101827;
  --panel-soft: #0c1422;
  --surface: #111c2d;
  --surface-hover: #17263c;
  --line: #26364e;
  --text: #e7edf8;
  --muted: #9aa9bd;
  --blue: #8bb8ff;
  --button-bg: #111c2d;
  --button-hover: #17263c;
  --image-bg: #182436;
  --map-bg: #0a101c;
  --chip-bg: #12223a;
  --chip-border: #31517c;
  --chip-text: #9cc5ff;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(68vw, 520px);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 60px;
  object-fit: contain;
}

.status,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.theme-toggle {
  width: 54px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.theme-toggle-track {
  position: relative;
  width: 42px;
  height: 22px;
  border-radius: 999px;
  background: linear-gradient(135deg, #dbeafe, #fef3c7);
  transition: background 160ms ease;
}

.theme-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.28);
  transition: transform 160ms ease, background 160ms ease;
}

html[data-theme="dark"] .theme-toggle-track {
  background: linear-gradient(135deg, #1e3a8a, #4c1d95);
}

html[data-theme="dark"] .theme-toggle-thumb {
  transform: translateX(20px);
  background: #dbeafe;
}

.search-button {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover,
.search-button:hover {
  border-color: #93b4f8;
  background: var(--button-hover);
}

.search-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.search-button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.theme-toggle:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.layout {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(510px, 3fr);
}

.map-pane {
  min-width: 0;
  padding: 14px;
}

.map-stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--map-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.leaflet-map {
  width: 100%;
  height: 100%;
  background: var(--map-bg);
}

.leaflet-container {
  width: 100%;
  height: 100%;
  background: var(--map-bg);
  font: inherit;
  touch-action: none;
}

.leaflet-tile {
  image-rendering: auto;
}

.leaflet-control-attribution,
.leaflet-control-zoom {
  display: none;
}

.selection-ring {
  pointer-events: none;
}

#glMapCanvas,
#mapCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#glMapCanvas {
  pointer-events: none;
}

#mapCanvas {
  background: transparent;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: contain;
}

#mapCanvas.is-panning {
  cursor: grabbing;
}

.detail-pane {
  min-width: 0;
  overflow: auto;
  padding: 14px;
  border-left: 1px solid var(--line);
  background: var(--panel-soft);
}

.work-detail,
.neighbors-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.neighbors-section {
  margin-top: 14px;
}

.hero-work {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.poster {
  width: 100%;
  max-height: min(48vh, 430px);
  aspect-ratio: 3 / 2;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--image-bg);
}

.work-copy h2 {
  margin: 0 0 12px;
  font-size: 18px;
  line-height: 1.35;
}

.work-meta {
  display: grid;
  gap: 7px;
  font-size: 15px;
  line-height: 1.45;
}

.work-meta div {
  overflow-wrap: anywhere;
}

.work-meta span {
  display: inline-block;
  min-width: 54px;
  color: var(--muted);
  margin-right: 8px;
}

.actress-links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  vertical-align: middle;
}

.actress-search {
  min-height: 28px;
  padding: 2px 8px;
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-text);
  font: inherit;
  line-height: 1.25;
  cursor: pointer;
}

.actress-search:hover {
  background: var(--surface-hover);
  border-color: #93b4f8;
}

.actress-search:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  outline-offset: 2px;
}

h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.search-panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.search-field {
  display: grid;
  gap: 7px;
}

.search-field span {
  color: var(--muted);
  font-size: 13px;
}

.search-field input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
}

.search-field input:focus {
  border-color: #93b4f8;
  outline: 3px solid rgba(37, 99, 235, 0.14);
}

.search-results {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.search-result-card {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.search-result-card:hover {
  border-color: #93b4f8;
  background: var(--surface-hover);
}

.search-thumb {
  width: 84px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--image-bg);
}

.search-result-copy {
  min-width: 0;
}

.search-code {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.search-result-copy h4 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-copy p,
.search-empty {
  margin: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.neighbors {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.neighbor-card {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.neighbor-card:hover {
  border-color: #93b4f8;
  background: var(--surface-hover);
}

.neighbor-thumb {
  width: 84px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--image-bg);
}

.placeholder {
  background: var(--image-bg);
}

.image-link {
  display: inline-flex;
}

.neighbor-copy {
  min-width: 0;
}

.neighbor-copy h4 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.neighbor-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .topbar {
    height: auto;
    gap: 10px;
  }

  .brand-link {
    flex-basis: auto;
    max-width: min(62vw, 420px);
  }

  .layout {
    height: auto;
    min-height: calc(100vh - 72px);
    grid-template-columns: 1fr;
  }

  .map-pane {
    height: 45vh;
  }

  .detail-pane {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  body.is-searching .layout {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 72px);
  }

  body.is-searching,
  body.is-search-selecting {
    overflow-anchor: none;
  }

  body.is-searching .detail-pane {
    order: 1;
    border-top: 0;
  }

  body.is-searching .map-pane {
    order: 2;
    height: 45vh;
  }

  body.is-searching .neighbors-section {
    display: none;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 6px 12px;
  }

  .search-button {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
  }

  .theme-toggle {
    width: 50px;
    height: 30px;
  }

  .brand-logo {
    max-height: 60px;
  }

  .poster {
    max-height: 38vh;
  }

  .neighbor-card {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .neighbor-thumb,
  .search-thumb {
    width: 76px;
  }

  .search-result-card {
    grid-template-columns: 76px minmax(0, 1fr);
  }
}
