:root {
  --bg: #000000;
  --fg: #ffffff;
  --muted: #b8b8b8;
  --panel: rgba(12, 12, 12, 0.92);
  --edge: #ffffff;
  --node-border: rgba(255, 255, 255, 0.24);
  --node-shadow: 0 8px 20px rgba(0, 0, 0, 0.7);
  --error: #ff7a7a;
  --header-clearance: 126px;
  --footer-clearance: 92px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.app-header {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  pointer-events: none;
}

.app-header-image {
  display: block;
  width: min(380px, 62vw);
  height: auto;
}

.page {
  position: relative;
  min-height: 100vh;
  background: var(--bg);
}

.lookup-form {
  display: grid;
  gap: 8px;
}

.lookup-form--hidden {
  display: none;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-row input {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  padding: 0 12px;
  background: #080808;
  color: var(--fg);
  font-size: 0.95rem;
}

.input-row button {
  min-height: 40px;
  border: 1px solid #ffffff;
  border-radius: 8px;
  padding: 0 14px;
  color: #000000;
  background: #ffffff;
  font-weight: 600;
  cursor: pointer;
}

.meta,
.error {
  margin: 10px 0 0;
  font-size: 0.9rem;
}

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

.error {
  color: var(--error);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.page--start {
  display: grid;
  place-items: center;
}

.page--graph {
  padding-top: calc(var(--header-clearance) + 44px);
  padding-bottom: var(--footer-clearance);
}

.page--detail {
  padding-top: calc(var(--header-clearance) + 28px);
  padding-bottom: calc(var(--footer-clearance) + 28px);
  display: grid;
  place-items: start center;
}

.book-detail-shell {
  width: min(920px, calc(100vw - 28px));
}

.cover-modal-content--standalone {
  margin: 0;
}

.start-screen {
  width: min(92vw, 520px);
}

.lookup-form--start {
  gap: 10px;
}

.input-row--start-input {
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

.input-row--start-input input {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  padding: 0 14px;
  background: #070707;
  color: #ffffff;
  font-size: 1.05rem;
}

.input-row--start-input input::placeholder {
  color: #cfcfcf;
}

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

.start-action-button {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 9px;
  padding: 0 10px;
  background: #f5f5f5;
  color: #0a0a0a;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: lowercase;
  cursor: pointer;
}

.start-action-button--secondary {
  background: #0f0f0f;
  color: #ffffff;
}

.scanner-slot {
  position: relative;
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  background: #040404;
  overflow: hidden;
}

.scanner-viewport {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #000000;
}

.scanner-viewport video,
.scanner-viewport canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner-guide {
  position: absolute;
  inset: 12% 10%;
  border: 2px solid rgba(255, 95, 95, 0.96);
  border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  z-index: 30;
}

.scanner-guide::before,
.scanner-guide::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  border-top: 2px dashed rgba(255, 66, 66, 0.92);
}

.scanner-guide::before {
  top: 36%;
}

.scanner-guide::after {
  top: 64%;
}

.scanner-guide-label {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 220px;
  font-size: 0.7rem;
  line-height: 1.18;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  color: #fff7ec;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 31;
  letter-spacing: 0.01em;
}

.keepa-import-status {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #e5e5e5;
  font-size: 0.9rem;
}

.keepa-import-status[hidden] {
  display: none;
}

.keepa-import-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: keepa-import-spin 0.8s linear infinite;
}

@keyframes keepa-import-spin {
  to {
    transform: rotate(360deg);
  }
}

.graph-top-actions {
  position: fixed;
  top: calc(var(--header-clearance) - 18px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.graph-action-button {
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(10, 10, 10, 0.86);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.graph-action-button--share svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

.graph-stage {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background: #000000;
  --node-w: 164px;
  --node-h: 246px;
}

.page--graph .graph-stage {
  min-height: calc(100vh - var(--header-clearance) - var(--footer-clearance));
}

.app-footer {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
}

.app-footer-link {
  width: 78px;
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  padding: 5px 8px;
  background: transparent;
  color: #ffffff;
  font-size: 0.78rem;
  line-height: 1;
  text-align: center;
  text-transform: lowercase;
  cursor: pointer;
}

.footer-modal {
  width: min(560px, calc(100vw - 28px));
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 12px;
  padding: 14px 14px 12px;
  background: #070707;
  color: #ffffff;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.82);
}

.footer-modal::backdrop {
  background: rgba(0, 0, 0, 0.76);
}

.footer-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.footer-modal-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.footer-modal-close {
  min-height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 7px;
  padding: 4px 9px;
  background: #111111;
  color: #ffffff;
  font-size: 0.8rem;
  cursor: pointer;
}

.footer-modal-content p {
  margin: 0 0 10px;
  color: #dddddd;
  font-size: 0.9rem;
  line-height: 1.45;
}

.footer-modal-content p:last-child {
  margin-bottom: 0;
}

.graph-edges {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.graph-nodes {
  position: absolute;
  inset: 0;
}

.graph-edge {
  stroke: var(--edge);
  stroke-width: 1.3;
  opacity: 0.92;
}

.graph-ring {
  fill: none;
  stroke: rgba(255, 255, 255, 0.16);
  stroke-width: 1;
  stroke-dasharray: 5 5;
}

.graph-node {
  position: absolute;
  width: var(--node-w);
  transform: translate(-50%, -50%);
  cursor: pointer;
  touch-action: none;
}

.graph-cover {
  width: var(--node-w);
  height: var(--node-h);
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--node-border);
  box-shadow: var(--node-shadow);
  display: block;
  background: #151515;
  transform: scale(var(--cover-scale, 1));
  transform-origin: center center;
  transition: transform 0s linear;
  will-change: transform;
}

.graph-cover-fallback {
  width: var(--node-w);
  height: var(--node-h);
  border-radius: 8px;
  border: 1px solid var(--node-border);
  box-shadow: var(--node-shadow);
  background: #0d0d0d;
  color: #f2f2f2;
  display: grid;
  place-items: center;
  padding: 8px;
  text-align: center;
  font-size: 0.65rem;
  line-height: 1.25;
  transform: scale(var(--cover-scale, 1));
  transform-origin: center center;
  transition: transform 0s linear;
  will-change: transform;
}

.graph-node[data-depth="0"] .graph-cover,
.graph-node[data-depth="0"] .graph-cover-fallback {
  outline: 2px solid rgba(255, 255, 255, 0.72);
}

.graph-node--center {
  z-index: 4;
}

.graph-node--center .graph-cover,
.graph-node--center .graph-cover-fallback {
  --cover-scale: 1.5;
}

.graph-node:hover {
  z-index: 12;
}

.graph-node:hover .graph-cover,
.graph-node:hover .graph-cover-fallback {
  --cover-scale: 3;
  transition: transform 0.5s linear;
}

.graph-node--drag-ready {
  cursor: grab;
  z-index: 12;
}

.graph-node--dragging {
  cursor: grabbing;
  z-index: 16;
}

.graph-node--dragging .graph-cover,
.graph-node--dragging .graph-cover-fallback {
  --cover-scale: 3;
  transition: transform 0s linear;
}

.graph-node--drop-target .graph-cover,
.graph-node--drop-target .graph-cover-fallback {
  --cover-scale: 1.5;
  transition: transform 0.12s linear, box-shadow 0.12s linear;
  box-shadow:
    var(--node-shadow),
    0 0 0 1px rgba(255, 255, 255, 1),
    0 0 0 2px rgba(255, 255, 255, 0.9),
    0 0 0 3px rgba(255, 255, 255, 0.8),
    0 0 0 4px rgba(255, 255, 255, 0.7),
    0 0 0 5px rgba(255, 255, 255, 0.6),
    0 0 0 6px rgba(255, 255, 255, 0.5),
    0 0 0 7px rgba(255, 255, 255, 0.4),
    0 0 0 8px rgba(255, 255, 255, 0.3),
    0 0 0 9px rgba(255, 255, 255, 0.2),
    0 0 0 10px rgba(255, 255, 255, 0.1);
}

.graph-node--dragging.graph-node--drop-target .graph-cover,
.graph-node--dragging.graph-node--drop-target .graph-cover-fallback {
  --cover-scale: 1.5;
}

.graph-node--snapping-center {
  z-index: 14;
}

.graph-node--snapping-center .graph-cover,
.graph-node--snapping-center .graph-cover-fallback {
  --cover-scale: 1.5;
  transition: transform 0.18s ease-out;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--muted);
  padding: 12px 14px;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: 8px;
}

.cover-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
}

.cover-modal.is-open {
  display: block;
}

.cover-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.cover-modal-content {
  position: relative;
  width: min(760px, calc(100vw - 28px));
  margin: 6vh auto 0;
  background: #050505;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.8);
}

.cover-modal-close {
  position: absolute;
  right: 10px;
  top: 8px;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: #111111;
  color: #ffffff;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}

.cover-modal-media-wrap {
  display: grid;
  place-items: center;
  margin-top: 10px;
  margin-bottom: 0;
}

.cover-modal-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.cover-modal-layout {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.cover-modal-image {
  width: min(280px, 100%);
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #111111;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.65);
}

.cover-modal-image--missing {
  opacity: 0.45;
}

.cover-modal-amazon-button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #111111;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}

.cover-modal-recenter {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  padding: 7px 12px;
  background: #111111;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.cover-modal-share {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #111111;
  color: #ffffff;
  cursor: pointer;
}

.cover-modal-share svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.cover-modal-text-wrap {
  padding-top: 14px;
}

.cover-modal-title {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: #ffffff;
  line-height: 1.35;
}

.cover-modal-attributes {
  margin: 0;
  display: grid;
  gap: 9px;
}

.cover-modal-attributes div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.cover-modal-attributes dt {
  color: #a9a9a9;
  font-size: 0.8rem;
  font-weight: 600;
}

.cover-modal-attributes dd {
  margin: 0;
  color: #ededed;
  font-size: 0.9rem;
  line-height: 1.35;
  word-break: break-word;
}

@media (max-width: 800px) {
  :root {
    --header-clearance: 102px;
    --footer-clearance: 84px;
  }

  .app-header-image {
    width: min(290px, 76vw);
  }

  .page--graph {
    padding-top: calc(var(--header-clearance) + 38px);
  }

  .page--detail {
    padding-top: calc(var(--header-clearance) + 22px);
    padding-bottom: calc(var(--footer-clearance) + 22px);
  }

  .graph-top-actions {
    top: calc(var(--header-clearance) - 14px);
    gap: 6px;
  }

  .graph-action-button {
    min-height: 28px;
    padding: 4px 9px;
    font-size: 0.74rem;
  }

  .start-screen {
    width: min(94vw, 420px);
  }

  .start-actions-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .start-action-button {
    min-height: 40px;
    font-size: 0.9rem;
  }

  .graph-stage {
    --node-w: 120px;
    --node-h: 180px;
  }

  .app-footer {
    bottom: 22px;
    gap: 6px;
  }

  .app-footer-link {
    width: 74px;
    min-height: 26px;
    padding: 4px 8px;
    font-size: 0.75rem;
  }

  .cover-modal-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .cover-modal-text-wrap {
    padding-top: 0;
  }

  .cover-modal-attributes div {
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 10px;
  }

  .cover-modal-content {
    margin-top: 4vh;
    padding: 14px 12px 12px;
  }
}
