:root {
  --ink: #f4f2ea;
  --muted: #96998f;
  --paper: #0d0f0e;
  --panel: #141715;
  --line: #292d29;
  --acid: #c9ff38;
  --cyan: #50e6ff;
  --magenta: #ff4dc4;
  --danger: #ff7369;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(255,255,255,.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.022) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
  font-family: "Arial", system-ui, sans-serif;
  overflow-x: hidden;
}

button, input { font: inherit; }
button, .dropzone { cursor: pointer; }
button:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--acid); outline-offset: 3px; }
.noise { position: fixed; inset: 0; pointer-events: none; opacity: .025; z-index: 20; background: 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='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E"); }

.topbar {
  height: 74px;
  padding: 0 clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(13,15,14,.8);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; gap: 12px; align-items: center; color: var(--ink); text-decoration: none; font-size: 18px; font-weight: 600; letter-spacing: -.03em; }
.brand b { color: var(--acid); }
.brand-mark { width: 29px; height: 29px; display: grid; grid-template-columns: repeat(2,1fr); gap: 3px; transform: rotate(2deg); }
.brand-mark i { border: 1px solid var(--acid); display: block; }
.brand-mark i:nth-child(2) { background: var(--acid); }
.brand-mark i:nth-child(3) { opacity: .4; }
.api-status { font: 500 11px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.api-status span { width: 7px; height: 7px; border-radius: 50%; background: var(--acid); box-shadow: 0 0 14px var(--acid); }

main { width: min(1480px, calc(100% - 40px)); margin: 0 auto; }
.hero { max-width: 920px; margin: 0 auto; padding: clamp(72px, 11vw, 150px) 0 90px; text-align: center; }
.eyebrow { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font: 500 11px ui-monospace, "SFMono-Regular", monospace; letter-spacing: .09em; text-transform: uppercase; }
.eyebrow span { color: var(--acid); border: 1px solid #44541d; padding: 4px 6px; }
h1 { font-size: clamp(48px, 7vw, 96px); letter-spacing: -.065em; line-height: .98; margin: 25px 0 28px; font-weight: 700; }
h1 em { color: transparent; -webkit-text-stroke: 1.5px var(--muted); font-style: normal; }
.hero-copy { max-width: 690px; margin: 0 auto; color: #b2b5ab; font-size: clamp(15px, 1.6vw, 18px); line-height: 1.7; }

.upload-card { margin-top: 52px; border: 1px solid #343934; background: rgba(20,23,21,.94); box-shadow: 0 30px 80px rgba(0,0,0,.3); text-align: left; }
.dropzone { margin: 10px; min-height: 190px; border: 1px dashed #50564d; background: #101210; display: flex; flex-direction: column; gap: 18px; align-items: center; justify-content: center; text-align: center; padding: 36px; transition: .2s ease; position: relative; overflow: hidden; }
.dropzone::after { content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%; background: var(--acid); filter: blur(90px); opacity: 0; transition: .2s ease; }
.dropzone:hover, .dropzone.is-dragging, .dropzone.has-file { border-color: var(--acid); background: #14180e; }
.dropzone:hover::after, .dropzone.is-dragging::after { opacity: .08; }
.dropzone > * { position: relative; z-index: 1; }
.drop-icon { width: 47px; height: 47px; display: grid; place-items: center; border: 1px solid var(--acid); color: var(--acid); }
.drop-icon span { font-size: 23px; transform: rotate(-45deg); }
.dropzone strong { display: block; font-size: 17px; margin-bottom: 8px; }
.dropzone p { margin: 0; color: var(--muted); font: 400 12px ui-monospace, "SFMono-Regular", monospace; }
.sample-option { margin: 0 10px 10px; min-height: 76px; padding: 10px; display: grid; grid-template-columns: 98px minmax(0,1fr) auto; gap: 14px; align-items: center; border: 1px solid var(--line); background: #101210; transition: .18s ease; }
.sample-option.is-selected { border-color: var(--acid); background: #15190f; box-shadow: inset 3px 0 0 var(--acid); }
.sample-thumbnail { width: 98px; height: 55px; position: relative; overflow: hidden; border: 1px solid #3b413a; background: #080908; }
.sample-thumbnail img { width: 100%; height: 100%; display: block; object-fit: cover; }
.sample-thumbnail span { position: absolute; left: 4px; bottom: 4px; padding: 2px 4px; color: #11140b; background: var(--acid); font: 700 7px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; letter-spacing: .05em; }
.sample-copy { min-width: 0; }
.sample-copy strong { display: block; font-size: 12px; margin-bottom: 5px; }
.sample-copy p { margin: 0; color: var(--muted); font-size: 11px; }
.sample-button { display: inline-flex; gap: 18px; align-items: center; padding: 10px 12px; border: 1px solid #3a3e39; color: var(--ink); background: #171a17; font-size: 10px; font-weight: 700; white-space: nowrap; transition: .18s ease; }
.sample-button:hover { color: #11140b; border-color: var(--acid); background: var(--acid); }
.sample-option.is-selected .sample-button { color: #11140b; border-color: var(--acid); background: var(--acid); }
.upload-footer { border-top: 1px solid var(--line); padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.analysis-profile { color: var(--muted); font: 500 10px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 8px; }
.analysis-profile span { width: 7px; height: 7px; border-radius: 50%; background: var(--acid); box-shadow: 0 0 9px rgba(201,255,56,.55); }
.primary-button, .ghost-button { border: 0; padding: 13px 18px; font-weight: 700; transition: .18s ease; }
.primary-button { display: inline-flex; align-items: center; gap: 30px; background: var(--acid); color: #11140b; }
.primary-button:hover:not(:disabled) { background: #dcff7a; transform: translateY(-1px); }
.primary-button:disabled { opacity: .32; cursor: not-allowed; }
.primary-button b { font-size: 18px; }
.primary-button.compact { padding: 10px 13px; font-size: 12px; gap: 16px; }
.ghost-button { color: var(--ink); border: 1px solid #3a3e39; background: transparent; font-size: 12px; }
.ghost-button:hover { border-color: var(--ink); }
.local-note { margin: 18px 0 0; color: #73776e; font: 400 10px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; letter-spacing: .08em; }
.local-note span { color: var(--acid); margin-right: 5px; }

.workspace { padding: 64px 0 100px; animation: enter .45s ease; }
.is-hidden { display: none !important; }
@keyframes enter { from { opacity: 0; transform: translateY(12px); } }
.workspace-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 32px; }
.workspace-heading h2 { margin: 13px 0 0; font-size: clamp(31px, 4vw, 54px); letter-spacing: -.05em; }
.heading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.stats { display: grid; grid-template-columns: repeat(4,1fr); border: 1px solid var(--line); margin-bottom: 18px; }
.stats article { min-height: 105px; padding: 17px 19px; background: rgba(20,23,21,.87); position: relative; border-right: 1px solid var(--line); }
.stats article:last-child { border: 0; }
.stats span, .stats small { color: var(--muted); font: 500 10px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; letter-spacing: .08em; display: block; }
.stats strong { display: block; margin-top: 7px; font-size: 31px; letter-spacing: -.04em; }
.stats small { position: absolute; right: 17px; bottom: 17px; opacity: .65; }
.stats .stat-ui strong { color: var(--cyan); }
.stats .stat-text strong { color: var(--magenta); }

.inspector-grid { display: grid; grid-template-columns: minmax(0, 1fr) 370px; min-height: 690px; border: 1px solid var(--line); background: var(--panel); }
.canvas-panel { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.panel-toolbar, .canvas-footer { min-height: 55px; padding: 0 17px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.filename { max-width: 45%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font: 500 11px ui-monospace, "SFMono-Regular", monospace; }
.legend { display: flex; gap: 17px; }
.toggle { color: var(--muted); font: 500 10px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; display: flex; gap: 7px; align-items: center; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { width: 8px; height: 8px; background: currentColor; box-shadow: 0 0 8px currentColor; }
.ui-toggle { color: var(--cyan); }
.text-toggle { color: var(--magenta); }
.toggle:has(input:not(:checked)) { color: #4f534d; text-decoration: line-through; }
.canvas-scroll { min-height: 580px; flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px; overflow: auto; background: #090a09; background-image: radial-gradient(#2d312d 1px, transparent 1px); background-size: 14px 14px; }
.canvas-scroll.is-zoomed { align-items: flex-start; justify-content: flex-start; }
.image-stage { position: relative; max-width: 100%; max-height: 750px; line-height: 0; box-shadow: 0 15px 60px rgba(0,0,0,.65); }
.image-stage img { display: block; max-width: 100%; max-height: 750px; width: auto; height: auto; }
.image-stage.is-zoomed { flex: 0 0 auto; max-width: none; max-height: none; }
.image-stage.is-zoomed img { width: 100%; max-width: none; max-height: none; }
.overlay { position: absolute; inset: 0; pointer-events: none; }
.region-box { position: absolute; padding: 0; background: transparent; pointer-events: auto; transition: background .12s, box-shadow .12s; }
.region-box.interface { border: 1.5px solid var(--cyan); box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.region-box.text { border: 1.5px solid var(--magenta); }
.region-box:hover, .region-box.active { z-index: 4; background: rgba(201,255,56,.13); border-color: var(--acid); box-shadow: 0 0 0 1px var(--acid), 0 0 18px rgba(201,255,56,.3); }
.region-box.canvas-region { pointer-events: none; opacity: .45; }
.region-tag { position: absolute; left: -1px; top: -18px; height: 17px; padding: 2px 5px; background: currentColor; color: #090a09; font: 600 8px ui-monospace, "SFMono-Regular", monospace; line-height: 13px; white-space: nowrap; opacity: 0; }
.region-box:hover .region-tag, .region-box.active .region-tag { opacity: 1; background: var(--acid); }
.canvas-footer { min-height: 39px; border-top: 1px solid var(--line); border-bottom: 0; color: #686c65; font: 400 9px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; }
.zoom-controls { display: flex; align-items: center; border: 1px solid var(--line); background: #0c0e0d; }
.zoom-controls button { width: 32px; height: 28px; padding: 0; border: 0; color: var(--ink); background: transparent; font-size: 16px; line-height: 1; }
.zoom-controls button:disabled { color: #3d413c; cursor: not-allowed; }
.zoom-controls button:not(:disabled):hover { color: #11140b; background: var(--acid); }
.zoom-controls span { min-width: 52px; padding: 0 6px; color: var(--muted); text-align: center; }

.regions-panel { min-width: 0; display: flex; flex-direction: column; max-height: 690px; }
.regions-heading { padding: 14px 14px 13px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.regions-heading > div:first-child { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; }
.regions-heading strong { color: var(--acid); font: 500 10px ui-monospace, "SFMono-Regular", monospace; border: 1px solid #3e4b1b; padding: 3px 6px; }
.filter-buttons { display: flex; background: #0e100f; border: 1px solid var(--line); padding: 2px; }
.filter-buttons button { border: 0; background: transparent; color: #777b73; padding: 5px 7px; font: 500 8px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; }
.filter-buttons button.active { color: var(--ink); background: #2a2e29; }
.regions-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; scrollbar-color: #373c36 #131513; scrollbar-width: thin; }
.region-card { width: 100%; display: grid; grid-template-columns: 62px minmax(0,1fr) auto; gap: 11px; align-items: center; padding: 9px; border: 1px solid transparent; border-bottom-color: var(--line); background: transparent; color: var(--ink); text-align: left; }
.region-card:hover, .region-card.active { border-color: #555c51; background: #1b1e1b; }
.region-card.active { border-left-color: var(--acid); }
.thumb { width: 62px; height: 44px; background: #080908; border: 1px solid #30342f; object-fit: contain; }
.region-info { min-width: 0; }
.region-info strong { display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
.region-info span { display: block; color: #747970; font: 400 8px ui-monospace, "SFMono-Regular", monospace; text-transform: uppercase; }
.kind-dot { width: 7px; height: 7px; border-radius: 50%; align-self: start; margin-top: 4px; }
.kind-dot.interface { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.kind-dot.text { background: var(--magenta); box-shadow: 0 0 8px var(--magenta); }
.empty-list { color: var(--muted); text-align: center; padding: 60px 20px; font-size: 12px; }

.api-strip { margin-top: 18px; border: 1px solid var(--line); background: #121412; padding: 18px 20px; display: grid; grid-template-columns: auto 1fr auto; gap: 28px; align-items: center; }
.api-strip > div { display: flex; align-items: center; gap: 12px; }
.api-strip span { padding: 4px 6px; color: #11140b; background: var(--acid); font: 700 9px ui-monospace, "SFMono-Regular", monospace; }
.api-strip code { font: 500 11px ui-monospace, "SFMono-Regular", monospace; color: var(--ink); }
.api-strip p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.api-strip a { color: var(--acid); font: 500 10px ui-monospace, "SFMono-Regular", monospace; text-decoration: none; white-space: nowrap; }

.loading { position: fixed; inset: 0; z-index: 30; background: rgba(9,10,9,.88); backdrop-filter: blur(12px); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.loading strong { font-size: 20px; margin: 26px 0 7px; }
.loading p { margin: 0; color: var(--muted); font: 400 11px ui-monospace, "SFMono-Regular", monospace; }
.scanner { width: 100px; height: 100px; border: 1px solid #465044; position: relative; background: linear-gradient(90deg, transparent 49%, #282e26 50%, transparent 51%), linear-gradient(transparent 49%, #282e26 50%, transparent 51%); overflow: hidden; }
.scanner::before, .scanner::after { content: ""; position: absolute; width: 20px; height: 20px; border-color: var(--acid); border-style: solid; }
.scanner::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.scanner::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }
.scanner span { position: absolute; left: 0; right: 0; height: 1px; background: var(--acid); box-shadow: 0 0 15px 5px rgba(201,255,56,.25); animation: scan 1.5s ease-in-out infinite; }
@keyframes scan { 0%,100% { top: 8px; } 50% { top: 92px; } }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 40; max-width: 420px; padding: 14px 18px; color: #24100d; background: var(--danger); font-weight: 700; font-size: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }

@media (max-width: 1000px) {
  .inspector-grid { grid-template-columns: 1fr; }
  .canvas-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .regions-panel { max-height: 500px; }
  .api-strip { grid-template-columns: 1fr; gap: 12px; }
}
@media (max-width: 680px) {
  body { padding-bottom: env(safe-area-inset-bottom); -webkit-tap-highlight-color: transparent; }
  main { width: min(100% - 16px, 1480px); }
  .topbar { height: calc(58px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0; }
  .brand { gap: 9px; font-size: 16px; }
  .brand-mark { width: 25px; height: 25px; }
  .api-status { max-width: 118px; font-size: 8px; letter-spacing: .04em; text-align: right; }
  .hero { padding: 46px 0 48px; }
  .eyebrow { font-size: 9px; }
  h1 { margin: 20px 0; font-size: clamp(38px, 12vw, 48px); line-height: 1.02; overflow-wrap: anywhere; }
  .hero-copy { font-size: 14px; line-height: 1.55; }
  .upload-card { margin-top: 32px; }
  .dropzone { min-height: 154px; margin: 7px; padding: 23px 14px; gap: 14px; }
  .drop-icon { width: 42px; height: 42px; }
  .dropzone strong { font-size: 15px; }
  .dropzone p { font-size: 10px; line-height: 1.5; }
  .upload-footer, .workspace-heading { align-items: stretch; flex-direction: column; }
  .sample-option { margin: 0 7px 7px; grid-template-columns: 80px 1fr; gap: 10px; padding: 9px; }
  .sample-thumbnail { width: 80px; height: 48px; }
  .sample-copy strong { font-size: 11px; }
  .sample-copy p { font-size: 10px; line-height: 1.35; }
  .sample-button { grid-column: 1 / -1; justify-content: space-between; }
  .upload-footer { padding: 13px; gap: 13px; }
  .analysis-profile { justify-content: center; min-height: 28px; }
  .primary-button, .ghost-button, .sample-button { min-height: 48px; justify-content: space-between; }
  .local-note { padding: 0 10px; line-height: 1.5; }
  .workspace { padding: 38px 0 64px; }
  .workspace-heading { gap: 18px; margin-bottom: 22px; }
  .workspace-heading h2 { font-size: 35px; line-height: 1; }
  .heading-actions { width: 100%; }
  .heading-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .heading-actions button { width: 100%; min-width: 0; }
  .stats { grid-template-columns: repeat(2,1fr); }
  .stats article { min-height: 90px; padding: 14px; }
  .stats strong { font-size: 27px; }
  .stats small { right: 13px; bottom: 13px; font-size: 8px; }
  .stats article:nth-child(2) { border-right: 0; }
  .stats article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .inspector-grid { min-height: 0; }
  .panel-toolbar { min-height: 0; padding: 11px; align-items: stretch; flex-direction: column; }
  .filename { max-width: 100%; padding-bottom: 2px; }
  .legend { width: 100%; gap: 7px; }
  .toggle { min-height: 42px; flex: 1; justify-content: center; border: 1px solid var(--line); background: #0e100f; }
  .toggle span { width: 9px; height: 9px; }
  .canvas-scroll { min-height: 280px; max-height: 68svh; padding: 8px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .region-box { touch-action: manipulation; }
  .canvas-footer { min-height: 48px; padding: 6px 9px; }
  .canvas-hint { display: none; }
  .zoom-controls { margin-left: auto; }
  .zoom-controls button { width: 44px; height: 36px; }
  .zoom-controls span { min-width: 57px; }
  .regions-panel { max-height: 70svh; }
  .regions-heading { align-items: stretch; flex-direction: column; padding: 11px; }
  .regions-heading > div:first-child { justify-content: space-between; }
  .filter-buttons { width: 100%; }
  .filter-buttons button { min-height: 42px; flex: 1; font-size: 9px; }
  .regions-list { padding: 5px; -webkit-overflow-scrolling: touch; }
  .region-card { min-height: 66px; grid-template-columns: 72px minmax(0,1fr) auto; padding: 8px; }
  .thumb { width: 72px; height: 50px; }
  .region-info strong { font-size: 12px; }
  .region-info span { font-size: 8px; line-height: 1.45; }
  .api-strip { padding: 15px; gap: 14px; }
  .api-strip code { overflow-wrap: anywhere; }
  .api-strip a { display: flex; min-height: 44px; align-items: center; }
  .loading { padding: 24px; text-align: center; }
  .toast { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); max-width: none; }
}

@media (max-width: 380px) {
  .api-status { max-width: 94px; }
  h1 { font-size: 36px; }
  .heading-actions { grid-template-columns: 1fr; }
  .stats small { display: none; }
  .sample-copy p { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
