@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("assets/fonts/space-grotesk-latin-500.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("assets/fonts/space-grotesk-latin-600.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("assets/fonts/space-grotesk-latin-700.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("assets/fonts/ibm-plex-sans-latin-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("assets/fonts/ibm-plex-sans-latin-500.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("assets/fonts/ibm-plex-sans-latin-600.woff2") format("woff2");
}

:root {
  --bg: #121614;
  --bg-panel: #1a1f1c;
  --bg-soft: #232a26;
  --ink: #f2f5f2;
  --muted: rgba(242, 245, 242, 0.58);
  --line: rgba(242, 245, 242, 0.1);
  --accent: #ff5a36;
  --accent-soft: rgba(255, 90, 54, 0.18);
  --field: #0e1210;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.toolbar {
  position: relative;
  z-index: 20;
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  align-items: center;
  padding: 14px 22px;
  padding-top: calc(14px + var(--safe-top));
  padding-left: calc(22px + var(--safe-left));
  padding-right: calc(22px + var(--safe-right));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

.search {
  display: flex;
  gap: 10px;
  flex: 1 1 320px;
  max-width: 520px;
  align-items: stretch;
  position: relative;
}

.search-field {
  position: relative;
  flex: 1;
}

.search-clear {
  display: none;
}

#poster-search {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--ink);
  background: var(--field);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 160ms var(--ease);
}

#poster-search::placeholder {
  color: rgba(242, 245, 242, 0.35);
}

#poster-search::-webkit-search-decoration,
#poster-search::-webkit-search-cancel-button,
#poster-search::-webkit-search-results-button,
#poster-search::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

#poster-search:focus {
  border-color: rgba(242, 245, 242, 0.45);
}

.autofill-traps {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

  .suggestions {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  max-height: min(420px, calc(100dvh - var(--keyboard-inset, 0px) - 120px));
  overflow: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  z-index: 30;
  -webkit-overflow-scrolling: touch;
}

.suggestions li {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.92rem;
  color: var(--ink);
}

.suggestions li[aria-selected="true"],
.suggestions li:hover {
  background: rgba(255, 255, 255, 0.06);
}

.suggestions li.suggestions-empty,
.suggestions li.suggestions-empty:hover,
.suggestions li.suggestions-empty[aria-selected="true"] {
  cursor: default;
  background: transparent;
  padding: 4px 4px 2px;
  color: var(--muted);
  line-height: 1.45;
}

.suggestions.is-empty {
  max-height: min(420px, calc(100dvh - var(--keyboard-inset, 0px) - 100px));
  padding: 12px 14px 14px;
}

.suggestions-empty-title {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
}

.suggestions-empty-lead {
  margin: 0 0 8px;
  font-size: 0.82rem;
}

.suggestions-empty-reasons {
  margin: 0 0 12px;
  padding: 0;
}

.suggestions-empty-reasons p {
  position: relative;
  margin: 0;
  padding: 3px 0 3px 14px;
  font-size: 0.82rem;
  color: var(--ink);
}

.suggestions-empty-reasons p::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.suggestions-empty-help {
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--ink);
}

.suggestions li.suggestions-more,
.suggestions li.suggestions-more:hover {
  cursor: default;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
}

.btn {
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition: background 140ms var(--ease), border-color 140ms var(--ease);
}

.btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(242, 245, 242, 0.22);
}

.btn.primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
  font-weight: 600;
}

.btn.primary:hover {
  background: #fff;
  border-color: #fff;
}

.btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.nav-controls {
  display: none;
  align-items: center;
  gap: 8px;
}

.nav-controls.is-open {
  display: flex;
}

.nav-controls .btn {
  min-width: 42px;
  padding: 0 12px;
}

.match-status {
  min-width: 5ch;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stage {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.split {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  grid-template-areas: "overview detail";
  min-height: 0;
  gap: 1px;
  background: var(--line);
}

.overview-panel {
  grid-area: overview;
}

.detail-panel {
  grid-area: detail;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--bg-panel);
}

.panel-label {
  margin: 0;
  padding: 10px 16px;
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.overview-frame {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  background: linear-gradient(180deg, #1c221e 0%, #151a17 100%);
}

.overview-inner {
  position: relative;
  width: 100%;
  height: 100%;
}

#overview-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  user-select: none;
  -webkit-user-drag: none;
}

.overview-inner .overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.overview-highlight {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
  paint-order: stroke fill;
  opacity: 0;
  transition: opacity 200ms var(--ease);
}

.overview-highlight.is-on {
  opacity: 1;
}

.overview-dim,
.dim {
  fill: rgba(8, 10, 9, 0.55);
  opacity: 0;
  transition: opacity 240ms var(--ease);
}

.overview-dim.is-on,
.dim.is-on {
  opacity: 1;
}

.highlight {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  opacity: 0;
  transition: opacity 200ms var(--ease);
}

.highlight.is-on {
  opacity: 1;
}

.viewport {
  flex: 1;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  position: relative;
  min-height: 0;
  background: #101412;
}

.viewport.dragging {
  cursor: grabbing;
}

.canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  /* will-change toggled from JS during pan/zoom only — permanent promotion
     kept a multi‑megapixel layer on GPU and hurt Surface tablets. */
  opacity: 0.28;
  transition: opacity 280ms var(--ease);
}

body.has-match .canvas {
  opacity: 1;
}

#poster {
  display: block;
  /* Raster size is capped in JS via --detail-poster-width (was a fixed 3200px). */
  width: var(--detail-poster-width, 1600px);
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.detail-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 400;
  pointer-events: none;
  transition: opacity 200ms var(--ease);
}

.detail-placeholder.is-hidden {
  opacity: 0;
}

.status {
  margin: 0;
  flex: 0 0 auto;
  padding: 10px 18px;
  padding-bottom: calc(10px + var(--safe-bottom));
  padding-left: calc(18px + var(--safe-left));
  padding-right: calc(18px + var(--safe-right));
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--bg);
  min-height: 2.4rem;
}

.status.is-updating {
  opacity: 0.4;
}

/* Phones & small tablets — portrait: detail on top (~1/3), full poster below */
@media (max-width: 900px) and (orientation: portrait) {
  .toolbar {
    gap: 10px 12px;
    padding: 10px 14px;
    padding-top: calc(10px + var(--safe-top));
    padding-left: calc(14px + var(--safe-left));
    padding-right: calc(14px + var(--safe-right));
  }

  .brand h1 {
    font-size: 1.2rem;
  }

  .subtitle {
    display: none;
  }

  .search {
    flex: 1 1 100%;
    max-width: none;
  }

  #poster-search {
    height: 48px;
    font-size: 16px;
    padding-right: 44px;
  }

  .search-clear {
    display: grid;
    place-items: center;
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font-size: 1.45rem;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
  }

  .search-clear:not([hidden]):hover,
  .search-clear:not([hidden]):active {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.06);
  }

  .btn {
    height: 48px;
    min-width: 48px;
    font-size: 0.95rem;
  }

  .nav-controls.is-open {
    width: 100%;
    gap: 10px;
  }

  .nav-controls .btn {
    min-width: 48px;
    flex: 0 0 auto;
  }

  .match-status {
    flex: 1;
    font-size: 0.95rem;
  }

  .suggestions {
    max-height: min(45vh, 380px);
  }

  .suggestions.is-empty {
    max-height: min(55vh, 420px);
  }

  .suggestions li {
    padding: 14px 14px;
    font-size: 1rem;
  }

  .suggestions li.suggestions-empty {
    padding: 4px 4px 2px;
  }

  .panel-label {
    padding: 8px 12px;
  }

  .overview-frame {
    padding: 10px;
  }

  .overview-highlight {
    stroke-width: 4;
  }

  .split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(160px, 34%) minmax(0, 1fr);
    grid-template-areas:
      "detail"
      "overview";
  }

  .detail-placeholder {
    font-size: 0.88rem;
    padding: 16px;
  }

  .status {
    font-size: 0.75rem;
    padding: 8px 14px;
    padding-bottom: calc(8px + var(--safe-bottom));
  }
}

/* Narrow landscape: keep side-by-side so detail isn't a thin strip */
@media (max-width: 900px) and (orientation: landscape) {
  .toolbar {
    gap: 8px 14px;
    padding: 8px 12px;
    padding-top: calc(8px + var(--safe-top));
    padding-left: calc(12px + var(--safe-left));
    padding-right: calc(12px + var(--safe-right));
  }

  .brand h1 {
    font-size: 1.1rem;
  }

  .subtitle {
    display: none;
  }

  .search {
    flex: 1 1 220px;
    max-width: none;
  }

  #poster-search {
    height: 44px;
    font-size: 16px;
    padding-right: 40px;
  }

  .search-clear {
    display: grid;
    place-items: center;
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font-size: 1.35rem;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
  }

  .btn {
    height: 44px;
    min-width: 44px;
  }

  .nav-controls.is-open {
    gap: 6px;
  }

  .overview-frame {
    padding: 8px;
  }

  .overview-highlight {
    stroke-width: 3.5;
  }

  .split {
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    grid-template-areas: "overview detail";
  }

  .panel-label {
    padding: 6px 10px;
    font-size: 0.62rem;
  }

  .status {
    padding: 6px 12px;
    padding-bottom: calc(6px + var(--safe-bottom));
    font-size: 0.72rem;
    min-height: 0;
  }
}

/* Very small phones */
@media (max-width: 640px) and (orientation: portrait) {
  .search {
    flex: 1 1 100%;
    max-width: none;
  }

  .nav-controls.is-open {
    width: 100%;
  }

  .brand-logo {
    height: 36px;
    max-width: min(140px, 42vw);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* —— Header brand logo + 5-tap target —— */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
  -webkit-user-select: none;
}

.brand-logo {
  height: 44px;
  width: auto;
  max-width: min(168px, 28vw);
  aspect-ratio: auto;
  object-fit: contain;
  object-position: left center;
  border-radius: 4px;
  background: transparent;
  flex: 0 0 auto;
  display: block;
}

.brand.is-test-setup .subtitle {
  color: #ffd28a;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* —— Admin —— */
.admin-body {
  overflow: auto;
  height: auto;
  min-height: 100dvh;
}

.admin-toolbar {
  position: sticky;
  top: 0;
}

.admin-toolbar-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}

.admin-main {
  max-width: 920px;
  margin: 0 auto;
  padding: 22px;
  padding-bottom: calc(40px + var(--safe-bottom));
}

.admin-banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.9rem;
}

.admin-banner.is-error {
  background: rgba(255, 80, 80, 0.18);
}

.admin-empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 12px;
}

.event-list {
  display: grid;
  gap: 12px;
}

.event-card {
  display: flex;
  gap: 14px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  transition: border-color 160ms var(--ease), background 160ms var(--ease);
}

.event-card:hover,
.event-card:focus-visible {
  border-color: rgba(242, 245, 242, 0.35);
  outline: none;
}

.event-card.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.event-card-logo {
  width: 120px;
  height: 52px;
  border-radius: 6px;
  overflow: hidden;
  background: transparent;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.event-card-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.event-card-placeholder {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--muted);
}

.event-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.event-card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
}

.event-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-soft);
  color: var(--muted);
}

.badge[data-status="ready"] {
  color: #9fe0b8;
  background: rgba(80, 180, 120, 0.18);
}

.badge[data-status="analyzing"],
.badge[data-status="queued"] {
  color: #ffd28a;
  background: rgba(255, 180, 60, 0.16);
}

.badge[data-status="failed"] {
  color: #ff9b9b;
  background: rgba(255, 80, 80, 0.16);
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--accent);
  color: #1a100c;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.field input {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--field);
}

.field input:focus {
  outline: none;
  border-color: rgba(242, 245, 242, 0.45);
}

.drop-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 720px) {
  .drop-row {
    grid-template-columns: 1fr;
  }
}

.dropzone {
  min-height: 160px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--bg-panel);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  transition: border-color 160ms var(--ease), background 160ms var(--ease);
}

.dropzone.is-disabled {
  cursor: default;
  opacity: 0.72;
  pointer-events: none;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-drag {
  border-color: rgba(242, 245, 242, 0.45);
  background: var(--bg-soft);
  outline: none;
}

.drop-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
}

.drop-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.drop-preview {
  max-width: 220px;
  max-height: 96px;
  width: auto;
  height: auto;
  margin-top: 8px;
  object-fit: contain;
  border-radius: 4px;
  background: transparent;
}

.drop-preview-wide {
  max-width: 220px;
  max-height: 120px;
}

.status-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.status-detail {
  font-size: 0.85rem;
  color: var(--muted);
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 240ms var(--ease);
}

.progress-msg,
.error-msg {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.error-msg {
  color: #ff9b9b;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn.linkish {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 4px 0;
  align-self: flex-start;
}

.btn.linkish:hover {
  color: var(--ink);
}

.btn.accent {
  background: var(--accent);
  color: #1a100c;
  border-color: transparent;
}

.btn.accent:disabled {
  opacity: 0.4;
}

.btn.danger {
  background: transparent;
  border-color: rgba(255, 80, 80, 0.45);
  color: #ff9b9b;
  margin-left: auto;
}

.btn.danger:disabled {
  opacity: 0.35;
}
