:root {
  color-scheme: light;
  --ink: #17202a;
  --ink-muted: #66717e;
  --paper: #f5f7f9;
  --surface: #ffffff;
  --line: #dce2e8;
  --line-strong: #bbc6d1;
  --blue: #0a63d8;
  --blue-dark: #06489f;
  --blue-soft: #eaf3ff;
  --cyan: #18a8c7;
  --danger: #ad2b2b;
  --danger-soft: #fff0f0;
  --success: #18815b;
  --success-ring: rgba(24, 129, 91, 0.12);
  --grid-line: rgba(31, 67, 104, 0.035);
  --topbar-background: rgba(255, 255, 255, 0.88);
  --image-frame: #eef1f4;
  --image-background: #ffffff;
  --card-background: rgba(255, 255, 255, 0.9);
  --empty-cell-background: rgba(255, 255, 255, 0.45);
  --card-hover-shadow: 0 12px 30px rgba(25, 48, 75, 0.1);
  --shadow: 0 18px 48px rgba(25, 48, 75, 0.1);
  font-family: Inter, Aptos, "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f0f5fa;
  --ink-muted: #aebdcd;
  --paper: #111923;
  --surface: #182330;
  --line: #2b3a49;
  --line-strong: #46596c;
  --blue: #69adff;
  --blue-dark: #9ac8ff;
  --blue-soft: #12335b;
  --cyan: #57d2e8;
  --danger: #ff8f8f;
  --danger-soft: #4b2029;
  --success: #53d29a;
  --success-ring: rgba(83, 210, 154, 0.15);
  --grid-line: rgba(138, 182, 228, 0.065);
  --topbar-background: rgba(17, 25, 35, 0.9);
  --image-frame: #e8edf2;
  --image-background: #ffffff;
  --card-background: rgba(24, 35, 48, 0.94);
  --empty-cell-background: rgba(34, 51, 69, 0.7);
  --card-hover-shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
  --shadow: 0 20px 52px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 20;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  color: white;
  background: var(--blue-dark);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.topbar {
  height: 76px;
  padding: 0 clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-background);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; fill: none; stroke: var(--blue); stroke-width: 2; }
.brand div { display: grid; gap: 2px; }
.brand strong { font-size: 16px; letter-spacing: -0.01em; }
.brand span { color: var(--ink-muted); font-size: 12px; }

.system-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 650;
}
.header-actions { display: flex; align-items: center; gap: 18px; }
.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-ring);
}
.theme-toggle {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  color: var(--ink-muted);
  background: var(--surface);
  font-size: 11px;
  font-weight: 750;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}
.theme-toggle:hover { color: var(--blue); border-color: var(--blue); }
.theme-toggle:focus-visible { outline: 3px solid rgba(105, 173, 255, 0.35); outline-offset: 3px; }
.theme-toggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-linejoin: round; stroke-width: 1.8; }

.workspace {
  min-height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: clamp(28px, 5vw, 76px);
  padding: clamp(36px, 5vw, 72px) clamp(20px, 4vw, 64px);
  max-width: 1580px;
  margin: 0 auto;
}

.query-panel { align-self: start; position: sticky; top: 28px; }
.section-heading { margin-bottom: 26px; }
.eyebrow {
  display: block;
  margin-bottom: 10px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
h1, h2 { margin: 0; letter-spacing: -0.035em; }
h1 { max-width: 420px; font-size: clamp(30px, 3.2vw, 46px); line-height: 1.02; }
h2 { font-size: clamp(25px, 2.4vw, 34px); }
.section-heading p {
  margin: 16px 0 0;
  max-width: 430px;
  color: var(--ink-muted);
  font-size: 15px;
  line-height: 1.6;
}

.drop-zone {
  position: relative;
  min-height: 300px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  outline: 0;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.drop-zone::before,
.drop-zone::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  pointer-events: none;
}
.drop-zone::before { top: 10px; left: 10px; border-top: 2px solid var(--blue); border-left: 2px solid var(--blue); }
.drop-zone::after { right: 10px; bottom: 10px; border-right: 2px solid var(--blue); border-bottom: 2px solid var(--blue); }
.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.is-dragging {
  border-color: var(--blue);
  box-shadow: 0 20px 54px rgba(10, 99, 216, 0.16);
}
.drop-zone.is-dragging { transform: translateY(-2px); background: var(--blue-soft); }

.upload-prompt { padding: 30px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.profile-guide { width: min(220px, 75%); margin-bottom: 18px; fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: square; }
.profile-guide .scan-line { stroke: var(--cyan); stroke-width: 1.5; stroke-dasharray: 5 7; }
.upload-prompt strong { font-size: 16px; }
.upload-prompt span { margin-top: 5px; color: var(--blue); font-size: 14px; }
.upload-prompt small { margin-top: 18px; color: var(--ink-muted); font-size: 11px; }

.preview-shell { width: 100%; height: 100%; min-height: 300px; position: relative; background: var(--image-frame); }
.preview-shell img { width: 100%; height: 300px; display: block; object-fit: contain; background: var(--image-background); }
.preview-meta {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding: 11px 13px;
  color: white;
  background: rgba(19, 30, 42, 0.9);
  backdrop-filter: blur(10px);
}
.preview-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.preview-meta span { color: #bac8d6; font-size: 11px; }
.text-button { grid-row: 1 / 3; grid-column: 2; border: 0; color: #9dccff; background: transparent; font-size: 12px; font-weight: 700; }

.primary-button {
  width: 100%;
  min-height: 52px;
  margin-top: 14px;
  display: grid;
  place-items: center;
  border: 0;
  color: white;
  background: var(--blue);
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: background 140ms ease, transform 140ms ease;
}
.primary-button:hover:not(:disabled) { background: var(--blue-dark); transform: translateY(-1px); }
.primary-button:focus-visible { outline: 3px solid rgba(10, 99, 216, 0.3); outline-offset: 3px; }
.primary-button:disabled { cursor: not-allowed; background: #9ca9b6; }
.button-loader { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
.primary-button.is-loading .button-label { display: none; }
.primary-button.is-loading .button-loader { display: block; }

.error-message { padding: 11px 13px; margin: 12px 0 0; color: var(--danger); background: var(--danger-soft); border-left: 3px solid var(--danger); font-size: 13px; }
.score-note { margin-top: 22px; display: flex; gap: 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.score-icon { flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center; color: var(--blue); border: 1px solid var(--blue); font-weight: 800; font-size: 12px; }
.score-note p { margin: 0; color: var(--ink-muted); font-size: 12px; line-height: 1.5; }
.score-note strong { display: block; margin-bottom: 2px; color: var(--ink); }

.results-panel { min-width: 0; }
.results-header { min-height: 78px; display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 25px; padding-bottom: 18px; border-bottom: 1px solid var(--line-strong); }
.result-summary { text-align: right; }
.result-summary strong { display: block; color: var(--blue); font-size: 30px; line-height: .9; }
.result-summary span { color: var(--ink-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }

.empty-state, .loading-state { min-height: 520px; display: grid; place-items: center; align-content: center; text-align: center; }
.empty-state strong, .loading-state strong { margin-top: 24px; font-size: 17px; }
.empty-state p, .loading-state p { max-width: 330px; margin: 7px 0 0; color: var(--ink-muted); font-size: 13px; line-height: 1.5; }
.empty-grid { width: 210px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; opacity: .6; }
.empty-grid span { aspect-ratio: 1; border: 1px dashed var(--line-strong); background: var(--empty-cell-background); }

.scanner { position: relative; width: 220px; height: 150px; overflow: hidden; }
.scanner svg { width: 100%; height: 100%; fill: none; stroke: var(--ink); stroke-width: 5; opacity: .42; }
.scanner span { position: absolute; left: 0; right: 0; height: 2px; top: 0; background: var(--cyan); box-shadow: 0 0 18px var(--cyan); animation: scan 1.6s ease-in-out infinite alternate; }

.results-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.result-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 32px 96px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  gap: 0 12px;
  position: relative;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--card-background);
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}
.result-card:hover { transform: translateY(-2px); border-color: var(--blue); box-shadow: var(--card-hover-shadow); }
.result-card:first-child { border-color: var(--blue); box-shadow: inset 3px 0 var(--blue); }
.rank { grid-row: 1 / 3; color: var(--line-strong); font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-card:first-child .rank { color: var(--blue); }
.result-image { grid-row: 1 / 3; width: 96px; height: 82px; display: grid; place-items: center; background: var(--image-frame); overflow: hidden; }
.result-image img { width: 100%; height: 100%; display: block; object-fit: contain; }
.result-content { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.result-content strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.result-content span { margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-muted); font-size: 11px; }
.score { align-self: end; min-width: 0; padding-top: 8px; }
.score strong { display: block; margin-bottom: 5px; color: var(--blue); font-size: 13px; font-variant-numeric: tabular-nums; }
.score-bar { display: block; height: 3px; background: linear-gradient(90deg, var(--blue) var(--score), var(--line) var(--score)); }
.result-footer { display: flex; justify-content: space-between; gap: 20px; margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--ink-muted); font-size: 11px; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes scan { from { transform: translateY(10px); } to { transform: translateY(136px); } }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(300px, 370px) minmax(0, 1fr); gap: 30px; }
  .results-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .topbar { height: 66px; }
  .system-state span:last-child { display: none; }
  .theme-toggle span { display: none; }
  .theme-toggle { min-width: 34px; justify-content: center; }
  .workspace { min-height: calc(100vh - 66px); grid-template-columns: 1fr; padding-top: 28px; }
  .query-panel { position: static; }
  .results-header { margin-top: 24px; }
  .empty-state, .loading-state { min-height: 330px; }
}

@media (max-width: 430px) {
  .brand span { display: none; }
  .workspace { padding-left: 14px; padding-right: 14px; }
  h1 { font-size: 32px; }
  .result-card { grid-template-columns: 25px 78px minmax(0, 1fr); gap: 0 9px; padding: 9px; }
  .result-image { width: 78px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

