@font-face { font-family: "Archivo"; src: url("../fonts/archivo-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Archivo"; src: url("../fonts/archivo-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }

:root {
  --bg: #ecebe6;
  --bg-2: #dcdad3;
  --ink: #16161a;
  --ink-2: #55544f;
  --line: rgba(22, 22, 26, .12);
  --card: rgba(255, 255, 255, .78);
  --accent: #16161a;
  --focus: #2f5bff;
  --r: 14px;
  --gut: clamp(12px, 3vw, 24px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
p { margin: 0; }
button, input, label { font: inherit; color: inherit; }
svg { display: block; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
#upload { font-size: 16px; }   /* iOS zooms into inputs under 16px */

/* ---------- layout: header / stage / dock ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);   /* never let a wide label stretch the page */
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "stage" "dock";
  background: radial-gradient(120% 90% at 50% 38%, #f7f6f2 0%, var(--bg) 55%, var(--bg-2) 100%);
}
.bar {
  grid-area: bar;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) calc(var(--gut) + env(safe-area-inset-right)) 10px calc(var(--gut) + env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; overflow: hidden; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-mark circle { fill: var(--ink); }
.brand-mark ellipse { fill: none; stroke: var(--bg); stroke-width: 2; }
.brand-text { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand-name { margin: 0; font-weight: 600; font-size: 17px; line-height: 1.2; letter-spacing: -.01em; white-space: nowrap; }
.brand-tag {
  font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 8px;
}

.stage { grid-area: stage; position: relative; min-height: 0; }
.gl {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; outline: none;
  touch-action: none;                 /* page must not scroll or zoom while rotating */
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
.gl:active { cursor: grabbing; }
.gl:focus-visible { box-shadow: inset 0 0 0 3px var(--focus); border-radius: var(--r); }

.dock {
  grid-area: dock;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  grid-template-areas: "switch tools info";
  align-items: center; gap: 10px 16px;
  padding: 10px calc(var(--gut) + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(var(--gut) + env(safe-area-inset-left));
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 99px;
  border: 1px solid transparent; background: none; cursor: pointer;
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-ghost { border-color: var(--line); background: var(--card); }
.btn-solid { background: var(--ink); color: #fff; }
.upload { flex: none; }
.upload:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

.switcher {
  grid-area: switch;
  display: inline-flex; padding: 4px; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 99px;
  min-width: 0;
}
.seg {
  min-height: 44px; min-width: 44px; padding: 0 18px; border: 0; border-radius: 99px;
  background: none; cursor: pointer; font-size: 15px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap; transition: background-color .2s, color .2s;
}
.seg[aria-pressed="true"] { background: var(--ink); color: #fff; }

.tools { grid-area: tools; display: flex; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line); background: var(--card); cursor: pointer;
  transition: background-color .2s, color .2s;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

button:focus-visible, .icon-btn:focus-visible, .seg:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  .seg:not([aria-pressed="true"]):hover { color: var(--ink); background: rgba(22,22,26,.06); }
  .icon-btn:not([aria-pressed="true"]):hover, .btn-ghost:hover { background: #fff; }
}

.info { grid-area: info; min-width: 0; text-align: right; }
.info-title { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.info-meta, .info-credit { font-size: 13px; color: var(--ink-2); line-height: 1.4; overflow-wrap: anywhere; }
.info-credit a { color: inherit; }

/* ---------- overlays ---------- */
.loader, .notice {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  pointer-events: none;
}
.notice { pointer-events: auto; }
.loader-card, .notice-card {
  width: min(320px, 100%);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px 20px; text-align: center;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(22, 22, 26, .08);
}
.loader-title, .notice-title { font-weight: 600; font-size: 16px; }
.loader-meta { margin-top: 10px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.progress { margin-top: 14px; height: 6px; border-radius: 99px; background: rgba(22, 22, 26, .1); overflow: hidden; }
.progress-fill { height: 100%; width: 100%; background: var(--ink); border-radius: inherit; transform-origin: left; transform: scaleX(0); transition: transform .15s linear; }
.notice-text { margin-top: 8px; font-size: 14px; color: var(--ink-2); line-height: 1.45; }
.notice-card .btn { margin-top: 14px; }

.hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 8px 14px; border-radius: 99px; background: rgba(22, 22, 26, .78); color: #fff;
  font-size: 13px; text-align: center; pointer-events: none; white-space: nowrap;
  transition: opacity .4s;
}
.hint.is-off { opacity: 0; }
.hint-touch { display: none; }
.hint-key { display: none; }
@media (pointer: coarse) { .hint-touch { display: inline; } .hint-mouse { display: none; } }
/* keyboard users see the keys while the 3D view has focus */
.gl:focus-visible ~ .hint { opacity: 1; }
.gl:focus-visible ~ .hint .hint-touch, .gl:focus-visible ~ .hint .hint-mouse { display: none; }
.gl:focus-visible ~ .hint .hint-key { display: inline; }

/* ---------- narrow phones ---------- */
@media (max-width: 719px) {
  .dock {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "info tools" "switch switch";
  }
  .info { text-align: left; }
  .switcher { display: flex; }
  .seg { flex: 1 1 0; padding: 0 10px; }
  .cr-name { display: none; }
  .hint { font-size: 12px; }
}
@media (max-width: 389px) { .brand-tag { display: none; } }
@media (max-width: 359px) {
  .upload { padding: 0 12px; }
  .info-credit { font-size: 12px; }
}
@media (max-width: 299px) {
  .upload span { display: none; }          /* icon only, label kept for screen readers via aria */
  .upload { width: 44px; padding: 0; }
  .tools { gap: 4px; }
  .dock { gap: 8px 8px; }
}

/* ---------- short landscape phones: controls go to a side column ---------- */
@media (orientation: landscape) and (max-height: 540px) and (min-width: 480px) {
  .app {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 32%);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "stage bar" "stage dock";
  }
  .bar { padding-left: 12px; padding-top: calc(10px + env(safe-area-inset-top)); flex-wrap: wrap; }
  .dock {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "switch switch" "tools tools" "info info";
    align-content: start; overflow-y: auto; padding-left: 12px;
  }
  .switcher { display: flex; }
  .seg { flex: 1 1 0; padding: 0 8px; }
  .info { text-align: left; }
  .cr-name { display: none; }
  .stage { margin-left: env(safe-area-inset-left); }
  .hint { bottom: 10px; }
}

/* very short and narrow windows (e.g. page zoom 400%): let the page scroll so the 3D view keeps a usable size */
@media (max-height: 420px) and (max-width: 479px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; grid-template-rows: auto 80vh auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
