:root { --bg:#0b0b0b; --fg:#eaeaea; --accent:#00d0ff; }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: 'Abel', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  letter-spacing: .2px;
}

/* --- Top bar --- */
.topbar{
  position: fixed; 
  top:0; 
  left:0; 
  right:0; 
  height:56px;
  display:flex; 
  align-items:center; 
  justify-content:flex-start;
  padding:0 6px; background:rgba(0,0,0,.35);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  z-index:10;
}
.brand{ font-weight:400; letter-spacing:.3px; }

/* Auth area chips (unified style for name, credits, view result, sign out) */
.auth-area { display:flex; align-items:center; gap: 8px;  margin-left:auto;}

/* Apply the same “chip” look to buttons, the credits trigger, and the clickable name */
.auth-area button,
.auth-area .linklike,
.auth-area .username.clickable {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; color: var(--fg);
  border:1px solid rgba(255,255,255,.35);
  padding:8px 12px; border-radius:12px; cursor:pointer;
  min-height:36px;
  font-family: inherit; letter-spacing:.2px;
  text-decoration: none;  /* ensure linklike has no underline */
}
.auth-area button:hover,
.auth-area .linklike:hover,
.auth-area .username.clickable:hover { border-color: rgba(255,255,255,.55); background: rgba(255,255,255,.04); }
.auth-area button:focus-visible,
.auth-area .linklike:focus-visible,
.auth-area .username.clickable:focus-visible { outline:2px solid #fff; outline-offset:2px; border-radius:12px; }
.auth-area button[disabled],
.auth-area .linklike[disabled] { opacity:.5; cursor:not-allowed; }
.auth-area .username{ opacity:.85; }

/* --- Stage --- */
main{ position:fixed; inset:0; display:grid; place-items:center; }
/* True viewport height on mobile (fallback to 100vh) */
@supports (height: 100dvh) { main { height: 100dvh; } }
@supports not (height: 100dvh) { main { height: 100vh; } }

#camera{
  position:absolute; inset:0; width:100%; height:100%;
  object-fit:cover; background:#000;
}

/* --- Primary CTA --- */
.cta{
  position:absolute; bottom:54px; left:50%; transform:translateX(-50%);
  background:#000; color:#fff; border:1px solid rgba(255,255,255,.25);
  padding:12px 22px; min-width:120px; min-height:40px;
  border-radius:4px;
  font: 400 18px/1 'Abel', inherit;
  cursor:pointer; box-shadow:none;
  transition: transform .08s ease, background .12s ease, border-color .12s ease, opacity .12s ease;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.cta:hover{ background:#0a0a0a; border-color:rgba(255,255,255,.4); }
.cta:active{ transform:translateX(-50%) translateY(1px); }
.cta:disabled{ opacity:.5; cursor:not-allowed; }
.cta:focus-visible{ outline:2px solid #fff; outline-offset:3px; }

/* Small caption under the button */
.cta-caption{
  position:absolute; bottom:36px; left:50%; transform:translateX(-50%);
  font-size:12px; opacity:.75; pointer-events:none;
}

/* --- Consent overlay --- */
.overlay{
  position:fixed; inset:0; background:rgba(0,0,0,.7);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  display:grid; place-items:center; z-index:20;
}
.overlay.hidden{ display:none; }
.overlay-card{
  background:#111; padding:24px; border-radius:16px; width:min(92vw,420px);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.overlay-card h2{ margin:0 0 8px; font-weight:400; }
.overlay-card p{ margin:0 0 12px; opacity:.85; }
.overlay-card button{
  margin-top:12px; padding:10px 16px; border-radius:6px;
  border:1px solid rgba(255,255,255,.35); color:#fff; background:#000; cursor:pointer;
  min-height:40px;
  font-family: inherit;
}
.overlay-card button:hover{ border-color: rgba(255,255,255,.55); background:#0a0a0a; }
.overlay-card button:focus-visible{ outline:2px solid #fff; outline-offset:2px; }

/* --- Utilities --- */
.visually-hidden{ position:absolute !important; height:1px; width:1px; overflow:hidden; clip:rect(1px,1px,1px,1px); white-space:nowrap; }
.hidden { display:none; }

/* --- Loading Overlay (full screen) --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  /* keep your dim/blur */
  background: rgba(0,0,0,0.7);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.loading-overlay.hidden { display: none; }

/* Make the artwork fill the whole viewport and crop as needed */
#loadingArt {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100svh;          /* modern dynamic viewport height */
  object-fit: cover;       /* crop sides on portrait phones */
  max-width: none;         /* remove previous constraints */
  max-height: none;
  display: block;
  opacity: 0.55;
  pointer-events: none;
  will-change: opacity, transform;
}
@supports not (height: 1svh) {
  #loadingArt { height: 100vh; }  /* fallback */
}

/* Keep the text readable above the image */
#loadingOverlay .loading-text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 30%;                    /* ⬆️ move text up by 30% of viewport height */
  font-size: 14px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #fff;
  opacity: 0.9;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

/* --- Bottom Sheet backdrop --- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  z-index: 900;
  transition: opacity .2s ease;
}
.sheet-backdrop.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* ---- Bottom Sheet ---- */
.sheet{
  position: fixed; left: 0; right: 0; bottom: 0;
  background: #0f0f0f; color: #efefef;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -20px 50px rgba(0,0,0,.45);
  will-change: transform;
  backface-visibility: hidden;

  /* keep GPU-friendly containment without breaking size */
  contain: paint;

  /* explicit size so it doesn’t collapse */
  height: 95svh;
  max-height: 95svh;

  /* stack header + body; body scrolls */
  display: flex;
  flex-direction: column;

  transition: transform .28s cubic-bezier(.2,.9,.25,1);
  z-index: 1001;
  transform: translateY(100%);
  overscroll-behavior: contain;
}
@supports not (height: 1svh) {
  .sheet { height: 95vh; max-height: 95vh; }
}

.sheet.hidden { opacity: 0; pointer-events: none; }

.sheet.show  { transform: translateY(70%); }  /* "peek" */
.sheet.half  { transform: translateY(22%); }
.sheet.full  { transform: translateY(0%); }
.sheet.dragging { transition: none; }

/* header + grabber */
.sheet-grabber { width: 42px; height: 5px; border-radius: 999px; background:#2a2a2a; margin:10px auto 6px; }
.sheet-header  { display:flex; align-items:center; justify-content:space-between; padding:10px 14px 4px; }

/* body fills remaining height and scrolls */
.sheet-body {
  flex: 1 1 auto;
  padding: 12px 14px 20px;
  overflow: auto;
  max-height: calc(95svh - 64px);
}
@supports not (height: 1svh) {
  .sheet-body { max-height: calc(95vh - 64px); }
}

.dist-title-row{
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:8px;
}
.dist-title{
  font-size:12px; color:#9a9a9a; letter-spacing:.06em; text-transform:uppercase;
}
.dist-legend{ display:flex; gap:12px; font-size:12px; color:#cfcfcf; opacity:.9; }
.legend-item{ display:inline-flex; align-items:center; gap:6px; text-transform:lowercase; }
.legend-item .dot{ width:8px; height:8px; border-radius:50%; display:inline-block; }
.legend-item.you .dot{ background:#00d0ff; }
.legend-item.pop .dot{ background:rgba(255,255,255,.6); }

/* Result card layout variants */
.sheet.full .result-card { grid-template-columns: 240px 1fr; }
.sheet.full .result-thumb { width:240px; height:240px; }

/* Chart container in full mode */
.dist-wrap { margin-top:12px; background:#141414; border:1px solid #242424; border-radius:14px; padding:12px; }
.dist-title { font-size:12px; color:#9a9a9a; letter-spacing:.06em; text-transform:uppercase; margin-bottom:6px; }
canvas#distCanvas { width:100%; height:180px; display:block; }

/* result sheet padding bottom for safe area */
.sheet-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

.sheet-close {
  background: transparent; border: 1px solid #2a2a2a; color: #bbb;
  border-radius: 10px; padding: 4px 8px; cursor: pointer; min-height:36px;
}

/* Result card inside sheet */
.result-card {
  display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center;
  background: #141414; border: 1px solid #242424; border-radius: 14px; padding: 12px;
}
.result-thumb {
  width: 96px; height: 96px; border-radius: 10px; object-fit: cover; background: #0a0a0a;
}
.result-meta { display: grid; gap: 6px; }
.kv { display: flex; gap: 8px; align-items: baseline; }
.kv label { color: #9a9a9a; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }
.kv strong { font-size: 20px; letter-spacing: .02em; }
.subtle { color: #9a9a9a; font-size: 12px; }

/* Pager inside sheet */
.pager { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:12px; }
.pager .btn {
  background:transparent; color:#fff; border:1px solid #444; padding:10px 14px; border-radius:12px;
  min-height:40px; cursor:pointer;
}
.pager .btn[disabled] { opacity:.5; cursor:not-allowed; }
.pager-indicator { opacity:.8; }

.mirror { transform: scaleX(-1); transform-origin: center; }

#sheetDelete { color:#ff7b7b; border-color:#3a2a2a; }
#sheetDelete:hover { background:rgba(255,0,0,.06); border-color:#5a2a2a; }

/* --- Prefs Modal (race/gender) --- */
.backdrop {
  position:fixed; inset:0; background:rgba(0,0,0,.55);
  z-index:1100;
}
.modal {
  position:fixed; left:50%; top:50%; transform:translate(-50%,-50%);
  width:min(520px, 92vw); background:#111; color:#fff; border-radius:16px;
  box-shadow:0 10px 40px rgba(0,0,0,.5);
  z-index:1101;
}
.modal-card { padding:16px 18px 14px; }
.modal-header { display:flex; align-items:center; justify-content:space-between; }
.modal-body .field { display:flex; flex-direction:column; gap:6px; margin-top:12px; }
.modal-body select {
  background:#191919; border:1px solid #2a2a2a; color:#fff; padding:10px 12px; border-radius:10px;
  min-height:40px;
}
.modal-footer { display:flex; justify-content:flex-end; gap:8px; margin-top:16px; }
.btn.primary { background:#fff; color:#000; border:none; padding:10px 14px; border-radius:12px; min-height:40px; }
.btn.subtle  { background:transparent; color:#fff; border:1px solid #444; padding:10px 14px; border-radius:12px; min-height:40px; }
.icon-btn { background:transparent; border:none; color:#aaa; font-size:18px; cursor:pointer; }

.linklike.disabled { opacity:.5; cursor:not-allowed; text-decoration:none; }

/* prevent native scroll during drag on header/grabber */
.sheet, .sheet-grabber, .sheet-header {
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

/* Keep linklike base rules for popover trigger (now visually a chip via the group above) */
.linklike {
  background: transparent;
  border: none;
  color: var(--fg);
  cursor: pointer;
  padding: 0 4px;
  font: inherit;
}

/* Popover */
.popover {
  position: absolute;
  background: #101010;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  z-index: 10000;
  display: none;
}
.popover.open { display: block; }
.popover-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.popover-item:hover { background: #181818; border-color: #2a2a2a; }
.popover-item:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.popover-item[disabled] { opacity: .5; cursor: not-allowed; }

/* === Topbar chip normalization (square borders, consistent color) === */
.auth-area { gap: 6px; }

.auth-area .username.clickable,
.auth-area #creditsLink,
.auth-area .btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: var(--fg);
  border: 1px solid rgba(255,255,255,.35);   /* unified light border */
  border-radius: 4px;                         /* square-ish corners */
  padding: 8px;
  min-height: 34px;
  font: inherit;
  letter-spacing: .2px;
  text-decoration: none;
  box-shadow: none;
  cursor: pointer;
  text-transform: lowercase;
  font-size: 12px;
}

/* Override the darker global .btn.subtle border just for the header */
.auth-area .btn.subtle {
  border-color: rgba(255,255,255,.35);
}

/* Hover/focus states match across all four */
.auth-area .username.clickable:hover,
.auth-area #creditsLink:hover,
.auth-area .btn:hover {
  border-color: rgba(255,255,255,.55);
  background: rgba(255,255,255,.05);
}

.auth-area .username.clickable:focus-visible,
.auth-area #creditsLink:focus-visible,
.auth-area .btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  border-radius: 4px;
}

/* Disabled look (used when no results or no price IDs) */
.auth-area .btn[disabled],
.auth-area #creditsLink.disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* Keep name slightly dimmer like before */
.auth-area .username { opacity: .85; }

.topbar .auth-area {
  font-family: 'Abel', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 12px;
  line-height: 1.1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar .auth-area :is(button, input, select, textarea) {
  font: inherit;
  letter-spacing: inherit;
}

/* Tiny note under the anon login button */
.auth-anon .tos-note {
  margin-top: 6px;
  font-size: 12px;
  opacity: .8;
}
.auth-anon .tos-note a { color: #9ee6ff; text-decoration: none; }
.auth-anon .tos-note a:hover { text-decoration: underline; }

/* Reuse your modal styling for the ToS gate */
.tos-modal .modal-card p { margin: 8px 0 0; opacity: .9; }
.tos-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:14px; }

.legal-note{
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 8px;
  text-align: center;
  margin: 0;
  width: 100%;
  font-size: 10px;
  color: #aaa;
}

/* Delete confirmation */
.btn.danger {
  background: transparent;
  color: #ff7b7b;
  border: 1px solid #5a2a2a;
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 40px;
}
.btn.danger:hover { background: rgba(255,0,0,.06); border-color: #7a2a2a; }
.btn.danger:disabled { opacity:.6; cursor:not-allowed; }

/* --- Accessibility / motion --- */
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop, .cta { transition: none !important; }
  .loading-overlay { animation: none !important; }
}

@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
  .topbar .auth-area { font-size: 14px; }
}

/* small-height tweaks */
@supports (height: 100dvh) {
  .sheet-body { max-height: calc(95dvh - 64px); }
}
@media (max-height: 700px) {
  .sheet.show { transform: translateY(68%); }
  .sheet.half { transform: translateY(45%); }
}

#camera { will-change: transform; }
