/*
 * Space AI Photobooth — staff pages.
 * Mobile-first, dark, one column, Traditional Chinese.
 */

:root {
  --void: #0B0C1A;
  --panel: #151733;
  --panel-2: #1C1E42;
  --line: #2A2D55;
  --ink: #ECEAF5;
  --muted: #8B90B8;
  --gold: #F0B44C;
  --gold-deep: #C98A2E;
  --danger: #E06B6B;
  --radius: 14px;
  --stage-max: 440px;
  /* Reading scale, changed by the floating font control (1 = 100%). */
  --fs: 1;
}

* { box-sizing: border-box; }

/* The hidden attribute must beat the display rules on .gate/.app/.stage-message. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html { overflow: hidden; }

body {
  overflow: hidden;
  line-height: 1.6;
}

h1, h2, h3 { font-family: "Noto Serif TC", "Songti TC", serif; font-weight: 700; margin: 0; }

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ------------------------------- gate ------------------------------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #1a1c3d 0%, var(--void) 68%);
}

.gate-card {
  position: relative;
  width: 100%;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    radial-gradient(140% 90% at 50% -20%, rgba(240, 180, 76, 0.10), transparent 60%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 24px 26px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(240, 180, 76, 0.05) inset;
}
.gate-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22px;
  right: 22px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(240, 180, 76, 0.55), transparent);
}

.gate-brand { text-align: center; }
.gate-brand .logo {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 10px;
  border-radius: 50%;
  font-size: calc(24px * var(--fs));
  color: var(--gold);
  background: radial-gradient(circle at 50% 35%, rgba(240, 180, 76, 0.22), rgba(240, 180, 76, 0.04) 70%);
  border: 1px solid rgba(240, 180, 76, 0.35);
  box-shadow: 0 0 26px rgba(240, 180, 76, 0.18);
}
.gate-brand h1 { font-size: calc(22px * var(--fs)); letter-spacing: 0.01em; }
.gate-sub { color: var(--muted); font-size: calc(11.5px * var(--fs)); margin: 4px 0 0; letter-spacing: 0.32em; }
.gate-msg { color: var(--muted); font-size: calc(13.5px * var(--fs)); margin: 2px 0 0; text-align: center; line-height: 1.7; }
.gate-err { color: var(--danger); font-size: calc(13px * var(--fs)); min-height: 18px; text-align: center; }

/* password field with a lock glyph and a reveal toggle */
.field { position: relative; }

.input {
  width: 100%;
  appearance: none;
  background: #0c0e21;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  font: inherit;
  font-size: calc(16px * var(--fs));           /* keeps iOS from zooming on focus */
  letter-spacing: 0.14em;
  padding: 16px 66px 16px 46px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.input::placeholder { color: #5b6189; letter-spacing: 0.02em; }
.input:hover:not(:disabled) { border-color: #3a3f78; }
.input:focus {
  outline: none;
  background: #10122c;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(240, 180, 76, 0.16), 0 0 22px rgba(240, 180, 76, 0.12);
}
.input:disabled { opacity: 0.5; }

.field-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: calc(15px * var(--fs));
  opacity: 0.72;
  pointer-events: none;
}
.field:focus-within .field-icon { opacity: 1; }

.reveal {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: calc(12.5px * var(--fs));
  padding: 8px 11px;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.reveal:hover { color: var(--ink); background: rgba(255, 255, 255, 0.05); }
.reveal:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ------------------------------- app -------------------------------- */

.app {
  position: relative;
  z-index: 1;
  max-width: var(--stage-max);
  margin: 0 auto;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar { padding: 2px 2px clamp(8px, 1.6vh, 14px); flex: none; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { color: var(--gold); font-size: 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text .name { font-weight: 700; font-size: 15px; letter-spacing: 0.01em; }
.brand-text .cn { color: var(--muted); font-size: 11px; letter-spacing: 0.28em; }

.steps {
  position: relative;
  list-style: none;
  display: flex;
  justify-content: space-between;
  margin: 16px 0 0;
  padding: 0;
}
.steps::before {
  content: "";
  position: absolute;
  top: 11px;
  left: 12px;
  right: 12px;
  height: 1px;
  background: var(--line);
}
.steps li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 25%;
  color: var(--muted);
  font-size: calc(11px * var(--fs));
}
.steps .dot {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: calc(11px * var(--fs));
  color: var(--muted);
}
.steps li.active .dot { background: var(--gold); border-color: var(--gold); color: #201803; font-weight: 700; }
.steps li.active .lbl { color: var(--ink); }
.steps li.done .dot { background: var(--panel-2); border-color: var(--gold-deep); color: var(--gold); }

/* ------------------------------ stage ------------------------------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.6vh, 16px);
  overflow: hidden;
}

.lead { margin: 0; flex: none; }
.lead h2 { font-size: clamp(calc(18px * var(--fs)), calc(3.6vh * var(--fs)), calc(24px * var(--fs))); line-height: 1.35; }
.lead p { color: var(--muted); font-size: clamp(calc(12px * var(--fs)), calc(1.9vh * var(--fs)), calc(14px * var(--fs))); margin: clamp(3px, 0.8vh, 6px) 0 0; }

/* ------------------------------ views ------------------------------- */

.view { display: none; }
.view.active {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.6vh, 16px);
}

.stage-message {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: calc(13.5px * var(--fs));
  color: var(--muted);
}
.stage-message.error { border-color: var(--danger); color: #f2c4c4; }

/* ------------------------------ buttons ----------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  font-size: calc(15px * var(--fs));
  padding: 13px 18px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #201803;
  font-weight: 700;
}
.btn-primary:hover:not(:disabled) { background: #f6c161; }

.btn-ghost { background: transparent; }

.btn-block { width: 100%; }

.actions { display: flex; flex-direction: column; gap: clamp(8px, 1.2vh, 10px); flex: none; }
.actions .row { display: flex; gap: 10px; }
.actions .row .btn { flex: 1; }

/* ------------------------------ camera ------------------------------ */

.cam {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #05060f;
  border: 1px solid var(--line);
}
.cam video,
.cam img.preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* An uploaded photo is shown whole; the live video/still use cover so the
   still matches exactly what the camera showed. */
.cam img.preview.contain { object-fit: contain; }
.cam video.mirror,
.cam img.preview.mirror { transform: scaleX(-1); }

.guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.guide .mask { fill: rgba(5, 6, 18, 0.5); }
.guide .oval { fill: none; stroke: var(--gold); stroke-width: 2.4; stroke-dasharray: 7 7; opacity: 0.95; }
.guide .shoulder { fill: none; stroke: rgba(236, 234, 245, 0.5); stroke-width: 1.6; stroke-dasharray: 4 6; }
.guide .corner { fill: none; stroke: rgba(236, 234, 245, 0.6); stroke-width: 2; }
.guide .hint { fill: rgba(236, 234, 245, 0.85); font-size: 11px; font-family: "Noto Sans TC", sans-serif; }

.cam-badge {
  position: absolute;
  left: 10px;
  top: 10px;
  font-size: calc(11px * var(--fs));
  color: var(--muted);
  background: rgba(5, 6, 18, 0.6);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}

.cam-off {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: calc(13px * var(--fs));
  text-align: center;
  padding: 20px;
}

/* ------------------------------ tiles ------------------------------- */

.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(50px, 1fr);
  gap: clamp(5px, 0.9vh, 10px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.grid::-webkit-scrollbar { width: 6px; }
.grid::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

.tile {
  position: relative;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: clamp(2px, 0.5vh, 6px) 6px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1px, 0.35vh, 3px);
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.tile:active { transform: translateY(1px); }
.tile:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.tile[aria-pressed="true"] {
  border-color: var(--gold);
  background: rgba(240, 180, 76, 0.12);
  box-shadow: 0 0 0 2px var(--gold) inset;
}
.tile > span { flex: none; }
.tile .code {
  color: var(--gold);
  font-weight: 700;
  font-size: clamp(calc(10px * var(--fs)), calc(1.7vh * var(--fs)), calc(13px * var(--fs)));
  letter-spacing: 0.12em;
  line-height: 1.2;
}
.tile .arch {
  max-width: 100%;
  font-size: clamp(calc(11px * var(--fs)), calc(1.7vh * var(--fs)), calc(13px * var(--fs)));
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile .role {
  max-width: 100%;
  font-size: clamp(calc(9.5px * var(--fs)), calc(1.4vh * var(--fs)), calc(11.5px * var(--fs)));
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Short-but-still-two-column screens: trim the text block a little so all
   three lines fit without clipping. */
@media (min-height: 741px) and (max-height: 810px) {
  .tile { padding: 2px 5px; gap: 1px; }
  .tile .arch { font-size: clamp(calc(10px * var(--fs)), calc(1.6vh * var(--fs)), calc(12.5px * var(--fs))); }
  .tile .role { font-size: clamp(calc(9px * var(--fs)), calc(1.3vh * var(--fs)), calc(11px * var(--fs))); }
}

/* Very short screens: four columns keeps all 16 archetypes on screen instead
   of hiding the last row behind a scroll. Names may wrap inside the box. */
@media (max-height: 740px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow-y: hidden;
  }
  .tile { padding: 3px 2px; gap: 1px; }
  .tile .arch,
  .tile .role {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
  .tile .arch { font-size: clamp(calc(9px * var(--fs)), calc(1.5vh * var(--fs)), calc(11px * var(--fs))); }
  .tile .role { font-size: clamp(calc(8px * var(--fs)), calc(1.3vh * var(--fs)), calc(11px * var(--fs))); }
}

/* ---------------------------- generate ------------------------------ */

.summary {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(8px, 1.4vh, 12px);
  flex: none;
}
.summary img {
  width: clamp(56px, 9vh, 84px);
  height: clamp(56px, 9vh, 84px);
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.summary .meta { min-width: 0; }
.summary .meta .code { color: var(--gold); font-weight: 700; letter-spacing: 0.12em; font-size: calc(12px * var(--fs)); }
.summary .meta .arch { font-size: calc(16px * var(--fs)); font-weight: 600; }
.summary .meta .role { color: var(--muted); font-size: calc(13px * var(--fs)); }

.progress {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(10px, 1.6vh, 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: none;
}
.progress .bar {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}
.progress .bar span {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  animation: sweep 1.6s ease-in-out infinite;
}
@keyframes sweep {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
.progress .status { font-size: calc(14px * var(--fs)); }
.progress .elapsed { color: var(--muted); font-size: calc(13px * var(--fs)); font-variant-numeric: tabular-nums; }

.tminus {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: calc(12px * var(--fs));
  letter-spacing: 0.08em;
}

@media (prefers-reduced-motion: reduce) {
  .progress .bar span { animation: none; width: 100%; background: var(--gold-deep); }
  .btn { transition: none; }
}

/* ------------------------------ card -------------------------------- */

.card-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}
.card-frame img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 11px;
  background: var(--void);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.5);
  cursor: zoom-in;
}

/* Tap the card to inspect it full screen; tap again (or press Esc) to close. */
.card-frame.is-full {
  position: fixed;
  inset: 0;
  z-index: 30;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  border-radius: 0;
  background: var(--void);
  box-shadow: none;
  cursor: zoom-out;
}
.card-frame.is-full img {
  border-radius: 4px;
  box-shadow: none;
  cursor: zoom-out;
}

.download-note { color: var(--muted); font-size: calc(13px * var(--fs)); text-align: center; margin: 0; }

.qr-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(5px, 1vh, 10px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(8px, 1.4vh, 16px);
  flex: none;
}
.qr-block .qr {
  width: clamp(84px, 14vh, 168px);
  height: clamp(84px, 14vh, 168px);
  background: #fff;
  border-radius: 10px;
  padding: clamp(6px, 1vh, 10px);
  display: grid;
  place-items: center;
}
.qr-block .qr img, .qr-block .qr canvas { width: 100% !important; height: auto !important; display: block; }
.qr-block p { margin: 0; font-size: clamp(calc(11px * var(--fs)), calc(1.7vh * var(--fs)), calc(13px * var(--fs))); color: var(--muted); text-align: center; }
.qr-block .url { font-size: calc(11px * var(--fs)); word-break: break-all; color: var(--muted); text-align: center; }

.fineprint { color: var(--muted); font-size: clamp(calc(10.5px * var(--fs)), calc(1.6vh * var(--fs)), calc(12px * var(--fs))); text-align: center; margin: 0; flex: none; }

.upload-label {
  display: block;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px;
  color: var(--muted);
  font-size: calc(13.5px * var(--fs));
  cursor: pointer;
}
.upload-label input { display: none; }

/* Short phones: keep the card itself as large as possible by compressing the
   QR block and the secondary copy. Nothing scrolls. */
@media (max-height: 700px) {
  .qr-block { gap: 4px; padding: 6px 8px; }
  .qr-block .qr {
    width: 72px;
    height: 72px;
    padding: 4px;
  }
  .qr-block p { font-size: calc(10px * var(--fs)); }
  .qr-block .url { display: none; }
}

@media (max-height: 620px) {
  .view[data-step="4"] .lead p { display: none; }
  .view[data-step="4"] .lead h2 { font-size: calc(20px * var(--fs)); }
  .actions .btn { padding: 10px 14px; font-size: calc(14px * var(--fs)); }
}

.hidden { display: none !important; }
