:root {
  --ink: #111216; --muted: #5b5d68; --faint: #9a9ca6; --line: #ececf1;
  --white: #ffffff; --soft: #f6f6f9; --soft-2: #e9e9ef;
  --rust: #e8454e; --healthy: #2fa66f; --mid: #e0a032;
  --font: "Lexend", system-ui, sans-serif;
  --gutter: clamp(1rem, 4vw, 3rem);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; overflow-x: hidden;
  background: var(--white); color: var(--ink); font: 300 1rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
img { max-width: 100%; }

/* Everything is sized in rem and laid out with container queries on .stage, so browser zoom
   (which shrinks the CSS viewport) steps the layout down exactly like a smaller screen does. */
main { flex: 1; display: grid; place-items: center;
       padding: clamp(2rem, 7vh, 5.5rem) var(--gutter) 1rem; }
.stage { width: min(100%, 54rem); display: flex; flex-direction: column; align-items: center; text-align: center;
         container-type: inline-size; container-name: stage; }

/* ---------- intro ---------- */
.intro h1 { margin: 0; font-weight: 700; font-size: clamp(1.9rem, 1.2rem + 3cqi, 3.2rem); line-height: 1.05; letter-spacing: -.025em; }
.intro p { margin: .85rem auto 0; max-width: 31rem; color: var(--muted); font-size: clamp(.94rem, .85rem + .4cqi, 1.05rem); line-height: 1.6; text-wrap: pretty; }

/* ---------- model choice: plain text, the active one carries the 3D black ball ---------- */
.models { display: flex; flex-wrap: wrap; justify-content: center; gap: .2rem 1.5rem; margin-top: 2rem; min-height: 2.5rem; }
.model {
  position: relative; display: inline-flex; align-items: center; min-height: 2.5rem;
  background: none; border: 0; cursor: pointer; padding: 0 0 0 1.3rem;
  color: var(--muted); font-size: .92rem; white-space: nowrap; transition: color .2s;
}
.model::before {
  content: ""; position: absolute; left: 0; top: 50%; width: .72rem; height: .72rem; margin-top: -.36rem;
  border-radius: 50%; border: 1px solid #c9cad3; transition: border-color .2s;
}
.model[aria-checked="true"] { color: var(--ink); font-weight: 400; }
.model[aria-checked="true"]::before {
  border-color: transparent;
  background: radial-gradient(circle at 34% 30%, #8a8a8f 0%, #2a2a2e 32%, #050506 70%);
  box-shadow: 0 3px 5px rgba(0, 0, 0, .3), inset -1px -2px 3px rgba(0, 0, 0, .6);
  animation: pop .35s ease;
}
.model:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 6px; }
.model:disabled { cursor: progress; }
@keyframes pop { from { transform: scale(0); } }
.model-detail { margin: .2rem 0 0; min-height: 1.4em; color: var(--faint); font-size: .8rem; }

/* ---------- upload pill ---------- */
.upload-view { position: relative; width: min(100%, 40rem); margin-top: clamp(1.6rem, 4vh, 2.8rem); display: grid; place-items: center; }
.glow {
  position: absolute; inset: -45% -6%; pointer-events: none; filter: blur(26px); opacity: .45;
  background:
    radial-gradient(30% 24% at 50% 32%, rgba(255, 196, 160, .8), transparent 70%),
    radial-gradient(32% 20% at 50% 68%, rgba(255, 170, 110, .7), transparent 70%);
}
.detect-btn {
  position: relative; width: 100%; min-height: clamp(5rem, 3rem + 7cqi, 8.5rem);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 clamp(1.5rem, .5rem + 5cqi, 3.8rem); border-radius: 999px; cursor: pointer;
  background: linear-gradient(180deg, #ffffff 0%, #f7f7fa 55%, #efeff4 100%);
  box-shadow:
    inset 0 2px 1px #fff, inset 0 -4px 8px rgba(80, 80, 100, .07),
    0 0 0 1px var(--line),
    -2rem 2.8rem 3rem -1.4rem rgba(70, 72, 92, .26),
    -.8rem 1.2rem 1.8rem -.4rem rgba(70, 72, 92, .1);
  transition: transform .2s, box-shadow .2s;
}
@media (hover: hover) { .detect-btn:hover { transform: translateY(-3px); } }
.detect-btn.over { transform: translateY(-3px); }
.detect-btn:active { transform: translateY(1px); }
.detect-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 6px; }
.detect-btn.busy { pointer-events: none; animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.985); filter: brightness(.97); } }
.btn-copy { display: flex; flex-direction: column; align-items: flex-start; gap: .45rem; min-width: 0; text-align: left; }
.btn-note { display: block; max-width: 24rem; color: var(--muted); font: 300 clamp(.78rem, .7rem + .3cqi, .9rem) / 1.45 var(--font); }
.soon {
  display: inline-block; margin-right: .5rem; padding: .1rem .55rem; border-radius: 999px; vertical-align: .05em;
  background: var(--ink); color: #fff; font: 400 .7rem/1.5 var(--font); font-style: normal; letter-spacing: .02em;
}
/* uploads switched off (UPLOAD_ENABLED = false in app.js): the pill is display-only */
.detect-btn.locked { cursor: default; padding-top: 1.1rem; padding-bottom: 1.1rem; }
.detect-btn.locked:hover, .detect-btn.locked.over, .detect-btn.locked:active { transform: none; }
.detect-btn.locked #btnText, .detect-btn.locked .btn-icon { opacity: .55; }
#btnText { text-align: left; font: 400 clamp(1.35rem, .8rem + 3cqi, 2.6rem) / 1.1 "Helvetica Neue", Arial, sans-serif; letter-spacing: -.01em; }
.btn-icon { flex: none; width: clamp(2.6rem, 1.6rem + 4cqi, 4.4rem); height: auto; fill: none; stroke: var(--ink);
            stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.status { position: relative; min-height: 1.5em; margin: 2rem 0 0; color: var(--muted); font-size: .92rem; }
.status.err { color: var(--rust); font-weight: 400; }
.samples { position: relative; margin: .35rem 0 0; color: var(--faint); font-size: .85rem; line-height: 1.9; }
.link, .again {
  background: none; border: 0; padding: 0; cursor: pointer; color: var(--muted);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
}
@media (hover: hover) { .link:hover, .again:hover { color: var(--ink); } }
.link:focus-visible, .again:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 4px; }

/* ---------- result card: two columns when there is room ---------- */
.result-card {
  width: 100%; margin-top: 2rem; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 1.1rem; padding: 1.1rem; text-align: left;
  background: var(--white); border-radius: 2rem;
  box-shadow: 0 0 0 1px var(--line), 0 30px 60px -30px rgba(40, 44, 70, .3);
  animation: rise .45s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.result-card .frame, .result-card .report { transition: opacity .25s; }
.result-card.busy .frame, .result-card.busy .report { opacity: .45; }
.result-card.busy { pointer-events: none; }

/* two columns: the photo panel stretches to the report's height, the blurred copy fills any spare room */
.frame { position: relative; width: 100%; min-height: 20rem; align-self: stretch; border-radius: 1.4rem; overflow: hidden; background: var(--soft); }
.frame-bg { position: absolute; inset: -10%; background: center / cover no-repeat; filter: blur(22px) brightness(.95); }
.frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.view-toggle {
  position: absolute; left: 50%; bottom: .8rem; transform: translateX(-50%); display: flex; padding: 3px;
  border-radius: 999px; background: rgba(255, 255, 255, .85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.view-toggle button { border: 0; background: none; cursor: pointer; min-height: 2.1rem; padding: 0 1rem; border-radius: 999px;
                      font-size: .82rem; color: var(--muted); transition: background .2s, color .2s; }
.view-toggle button.on { background: var(--ink); color: #fff; }
.view-toggle button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.report {
  --vc: var(--muted); display: flex; flex-direction: column; justify-content: center; min-width: 0;
  padding: clamp(1.2rem, .6rem + 2.4cqi, 2.4rem); border-radius: 1.4rem; background: var(--soft);
}
.report[data-verdict="rust"] { --vc: var(--rust); }
.report[data-verdict="healthy"] { --vc: var(--healthy); }
.report[data-verdict="uncertain"], .report[data-verdict="other"] { --vc: var(--mid); }
.report small { font-weight: 600; font-size: .85rem; }
.report h2 { margin: .1rem 0 .7rem; font-weight: 700; font-size: clamp(1.55rem, 1rem + 2.2cqi, 2.3rem); line-height: 1.1; letter-spacing: -.015em; overflow-wrap: anywhere; }
.pct { font-weight: 300; font-size: clamp(1.45rem, .9rem + 2.2cqi, 2.2rem); color: var(--vc); margin-bottom: .55rem; }
.bar { height: 1.45rem; border-radius: .35rem; background: var(--white); padding: 3px;
       box-shadow: inset 0 1px 3px rgba(0, 0, 0, .1), 0 0 0 1px rgba(255, 255, 255, .7); }
.bar i { display: block; height: 100%; width: 0; border-radius: .25rem; transition: width 1s cubic-bezier(.2, .8, .2, 1);
         background: repeating-linear-gradient(90deg, var(--vc) 0 5px, color-mix(in srgb, var(--vc) 55%, #fff) 5px 7px); }
.detail { margin: .9rem 0 0; color: var(--muted); font-size: .95rem; line-height: 1.6; text-wrap: pretty; }
.scores { list-style: none; margin: 1rem 0 0; padding: .7rem 0 0; border-top: 1px solid var(--soft-2); }
.scores li { display: flex; justify-content: space-between; gap: 1rem; padding: .15rem 0; color: var(--muted); font-size: .88rem; }
.scores li span:last-child { font-variant-numeric: tabular-nums; }
.hint { margin: .8rem 0 0; color: var(--faint); font-size: .78rem; line-height: 1.5; }
.again { align-self: flex-start; margin-top: 1.1rem; min-height: 2.75rem; font-size: .92rem; }

/* ---------- footer ---------- */
.foot { text-align: center; padding: 1.2rem 1rem calc(1.6rem + env(safe-area-inset-bottom)); color: var(--faint); font-size: .8rem; }
.foot nav { display: flex; justify-content: center; align-items: center; gap: .55rem; color: var(--faint); }
.foot nav button { background: none; border: 0; cursor: pointer; min-height: 2.5rem; padding: 0 .3rem; color: var(--muted); font-size: .92rem; }
@media (hover: hover) { .foot nav button:hover { color: var(--ink); } }
.foot nav button:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 6px; }
a.credit, a.credit:visited, a.credit:hover, a.credit:active { color: var(--ink); }
.credit { display: inline-block; margin-top: .3rem; text-decoration: none;
          font-weight: 300; font-size: clamp(1rem, .9rem + .4vw, 1.2rem); }
.credit b { font-weight: 700; }
.credit:hover b { text-decoration: underline; text-underline-offset: 3px; }
.credit:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 6px; }

/* ---------- Method / Limits popups ---------- */
.pop {
  width: min(calc(100vw - 2rem), 34rem); max-height: min(85vh, 85dvh); overflow-y: auto; overscroll-behavior: contain;
  border: 0; border-radius: 1.4rem; padding: 2rem 2rem 1.6rem;
  background: #0d0d10; color: #eceef3; font: 300 .98rem/1.6 var(--font);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.pop::backdrop { background: rgba(20, 22, 30, .35); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.pop[open] { animation: rise .3s ease; }
.pop p, .pop li { text-align: justify; hyphens: auto; }
.pop h3 { margin: 0 2rem .8rem 0; font-weight: 600; font-size: 1.5rem; }
.pop b { font-weight: 600; color: #fff; }
.pop ul { padding-left: 1.1rem; margin: 0; }
.pop li { margin-bottom: .55rem; }
.x { position: absolute; top: .6rem; right: .7rem; width: 2.75rem; height: 2.75rem; background: none; border: 0; color: #aaa;
     font-size: 1.8rem; line-height: 1; cursor: pointer; border-radius: 50%; }
.x:hover, .x:focus-visible { color: #fff; }
.x:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }

/* ---------- medium: result card stacks, photo stays a sensible size ---------- */
@container stage (max-width: 44rem) {
  .result-card { grid-template-columns: 1fr; border-radius: 1.75rem; padding: .85rem; gap: .85rem; }
  .frame { width: min(100%, 26rem); min-height: 0; aspect-ratio: 1; align-self: start; justify-self: center; }
  .report { text-align: center; align-items: center; }
  .bar, .scores { align-self: stretch; }
  .again { align-self: center; }
}

/* ---------- small (phones, or desktop zoomed in): compact, thumb-friendly ---------- */
@container stage (max-width: 32rem) {
  .models { display: grid; grid-template-columns: repeat(2, auto); justify-content: center; column-gap: 1.8rem; row-gap: 0; margin-top: 1.6rem; }
  .model { min-height: 2.75rem; }
  .upload-view { margin-top: 1.4rem; }
  .detect-btn { border-radius: 2.5rem; min-height: 5.25rem; padding: 0 1.4rem 0 1.6rem; }
  .status { margin-top: 1.6rem; }
  .result-card { margin-top: 1.5rem; border-radius: 1.5rem; padding: .65rem; gap: .65rem; }
  .frame { width: 100%; border-radius: 1.1rem; }
  .report { border-radius: 1.1rem; padding: 1.3rem 1.1rem 1rem; }
  .bar { width: 100%; }
}

/* narrow screens: start near the top instead of centring in a tall empty page */
@media (max-width: 40rem) {
  main { place-items: start center; padding-top: clamp(2rem, 6vh, 3.5rem); }
}
/* very short screens (landscape phones, heavy zoom): keep the photo from filling the screen */
@media (max-height: 34rem) {
  main { padding-top: 1.5rem; }
  .frame { max-width: 70vh; justify-self: center; }
}
@media (max-width: 30rem) {
  .pop { padding: 1.6rem 1.3rem 1.3rem; border-radius: 1.2rem; font-size: .95rem; }
  .pop p, .pop li { text-align: left; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
