:root {
  color-scheme: dark;
  --ink: #f5f4ee;
  --muted: #999b93;
  --line: #30322e;
  --panel: #191a18;
  --panel-raised: #20211e;
  --acid: #d9ff63;
  --danger: #ff8e7d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: #10110f;
  color: var(--ink);
  font: 16px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button, select, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 96px;
}

header { margin-bottom: 32px; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.eyebrow {
  margin: 0;
  color: var(--acid);
  font: 800 12px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .16em;
}
.index-count {
  color: var(--muted);
  border-left: 1px solid var(--line);
  padding-left: 12px;
  font: 600 12px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-transform: uppercase;
}
h1 {
  max-width: 820px;
  margin: 15px 0 0;
  font-size: clamp(44px, 7vw, 80px);
  line-height: .96;
  letter-spacing: -.055em;
}

form {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgb(0 0 0 / 20%);
}

.input-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 6px;
  border-bottom: 1px solid var(--line);
  background: #141513;
}
.tab {
  min-height: 46px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
  cursor: pointer;
}
.tab span { margin-right: 7px; color: currentColor; }
.tab.active { background: var(--panel-raised); color: var(--ink); }
.tab:focus-visible, button:focus-visible, select:focus-visible, #drop-zone:focus-within {
  outline: 2px solid var(--acid);
  outline-offset: 2px;
}

#image-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#drop-zone {
  position: relative;
  min-height: 330px;
  margin: 18px;
  border: 1px dashed #51544c;
  border-radius: 13px;
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  background: #121311;
  transition: border-color .18s ease, background .18s ease;
}
#drop-zone:hover, #drop-zone.dragging { border-color: var(--acid); background: #181b14; }
#drop-copy { display: grid; justify-items: center; gap: 7px; text-align: center; }
.upload-icon {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
  border-radius: 50%;
  place-items: center;
  background: var(--acid);
  color: #111;
  font-size: 23px;
  font-weight: 900;
}
#drop-copy strong { font-size: 20px; }
#drop-copy small { color: var(--muted); }
#preview { display: block; width: 100%; height: 420px; object-fit: contain; background: #090a09; }
#preview[hidden] { display: none; }
#change-photo {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgb(12 13 11 / 82%);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(8px);
}

#camera-panel { margin: 18px; }
.camera-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid #292b27;
  border-radius: 13px;
  background: #090a09;
}
#camera-video, #camera-photo {
  display: block;
  width: 100%;
  max-height: 580px;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #090a09;
}
#camera-video { transform: scaleX(-1); }
#camera-countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 34%);
  color: #fff;
  font-size: clamp(84px, 18vw, 180px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 4px 30px rgb(0 0 0 / 50%);
}
#retry-camera {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 8px;
  background: rgb(9 10 9 / 76%);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
#capture-camera {
  width: 100%;
  min-height: 50px;
  margin-top: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--acid);
  color: #111;
  font-weight: 850;
  cursor: pointer;
}
select { border: 1px solid #41433e; border-radius: 8px; background: #11120f; color: var(--ink); padding: 9px 32px 9px 10px; }

#face-picker { margin: 0 18px; padding: 16px 0 0; border-top: 1px solid var(--line); }
#face-picker-title { margin: 0 0 11px; color: var(--muted); font-size: 13px; }
#face-choices { display: flex; gap: 9px; overflow-x: auto; padding: 1px 1px 6px; scrollbar-width: thin; }
.face-choice {
  flex: 0 0 auto;
  width: 88px;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #10110f;
  color: var(--ink);
  cursor: pointer;
}
.face-choice img { display: block; width: 76px; height: 76px; border-radius: 6px; object-fit: cover; }
.face-choice span { display: block; margin: 5px 0 2px; font: 10px ui-monospace, monospace; }
.face-choice.selected { border-color: var(--acid); background: #292d20; }

.actions {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
}
.actions label { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.actions select { min-width: 72px; }
.actions button {
  min-width: 190px;
  min-height: 48px;
  padding: 12px 17px;
  border: 0;
  border-radius: 10px;
  background: var(--acid);
  color: #111;
  font-weight: 850;
  cursor: pointer;
}
.actions button:disabled, #capture-camera:disabled { opacity: .5; cursor: wait; }
.actions button span { float: right; margin-left: 36px; }

#status { min-height: 54px; padding: 17px 2px; color: var(--muted); font-size: 14px; }
#status:empty { min-height: 26px; padding: 13px 0; }
#status.error { color: var(--danger); }
#results { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 14px; }
.card { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #090a09; }
.card-body { padding: 14px; }
.rank { color: var(--acid); font: 700 10px ui-monospace, monospace; letter-spacing: .1em; }
.card h2 { margin: 8px 0 3px; font-size: 17px; line-height: 1.2; }
.meta { margin: 0 0 11px; color: var(--muted); font-size: 12px; }
.score { font: 700 20px ui-monospace, monospace; }
.score small { color: var(--muted); font: 11px ui-sans-serif, system-ui; }
.links { margin-top: 11px; font-size: 13px; }
.links a { color: var(--ink); text-underline-offset: 3px; }

@media (max-width: 640px) {
  main { width: min(100% - 20px, 520px); padding: 26px 0 64px; }
  header { margin: 0 3px 24px; }
  h1 { margin-top: 13px; font-size: clamp(43px, 14vw, 62px); }
  form { border-radius: 15px; }
  #drop-zone, #camera-panel { margin: 12px; }
  #drop-zone { min-height: 270px; }
  #preview { height: 330px; }
  #camera-video, #camera-photo { aspect-ratio: 3 / 4; }
  #face-picker { margin-inline: 12px; }
  .actions { align-items: center; margin-top: 14px; padding: 14px 12px; }
  .actions button { min-width: 0; flex: 1; }
  .actions button span { margin-left: 16px; }
  #status { padding-inline: 3px; }
  #results { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
  .index-count { display: none; }
  .actions { align-items: stretch; flex-direction: column; }
  .actions label { justify-content: space-between; }
  .actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
