/* Gate (recipient) page — minimal layout on the shared design system.
 * CSP: inline styles are allowed (unsafe-inline), inline scripts are not,
 * so all state transitions live in gate.js and this file is static. */

:root { color-scheme: light dark; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ds-bg); color: var(--ds-text);
  font: var(--ds-font);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; min-height: 100vh;
}
main {
  width: 100%; max-width: 520px;
  text-align: center;
}

.hidden { display: none !important; }

/* Shared stacked layout. Reserves a stable vertical space so loading →
 * challenge / image / message doesn't jump the page around. */
.card {
  background: var(--ds-card); border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md); padding: 28px 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,.02);
}
h1 { margin: 0 0 6px; font-size: 1.4rem; font-weight: 600; line-height: 1.3; }
p.sub { margin: 0; color: var(--ds-muted); font-size: 0.95rem; }

/* Loading skeleton while the initial /api/open request is in flight. */
.skeleton { display: grid; gap: 14px; justify-items: center; }
.skeleton .bar {
  background: linear-gradient(90deg, var(--ds-border), color-mix(in srgb, var(--ds-border) 40%, transparent), var(--ds-border));
  background-size: 200% 100%;
  border-radius: 6px;
  animation: skel 1.2s ease-in-out infinite;
}
.skeleton .bar-1 { width: 70%; height: 20px; }
.skeleton .bar-2 { width: 50%; height: 14px; }
.skeleton .bar-img { width: 100%; max-width: 420px; aspect-ratio: 16 / 10; border-radius: var(--ds-radius-md); }
@keyframes skel { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton .bar { animation: none; } }

/* Fail image presentation: framed, centered, bounded. */
.image-frame {
  margin: 0 auto;
  border-radius: var(--ds-radius-md);
  overflow: hidden;
  background: var(--ds-card);
  border: 1px solid var(--ds-border);
  max-width: 520px;
}
.image-frame img {
  display: block;
  width: 100%; height: auto;
  max-height: 70vh; object-fit: contain;
  background: color-mix(in srgb, var(--ds-text) 4%, var(--ds-card));
}

/* Challenge card: confirm / passcode / Turnstile. */
.challenge-card { text-align: center; }
.challenge-card h1 { margin-bottom: 10px; }
.email-row {
  margin: 14px auto 4px;
  padding: 10px 14px;
  background: var(--ds-bg);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-sm);
  font-size: 1rem; font-weight: 600;
  word-break: break-all;
  max-width: 420px;
}
.pc-wrap {
  margin: 18px auto 6px;
  max-width: 320px; text-align: left;
}
.pc-wrap label {
  display: block; font-size: 0.85rem; color: var(--ds-muted);
  margin-bottom: 6px;
}
.pc-wrap input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-sm);
  background: var(--ds-bg); color: var(--ds-text);
  font-size: 1rem; letter-spacing: 0.08em;
  text-align: center;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.pc-wrap input:focus-visible {
  outline: 2px solid var(--ds-accent); outline-offset: 1px;
  border-color: var(--ds-accent);
}

.ts-wrap {
  display: flex; justify-content: center;
  min-height: 70px; margin: 16px 0 10px;
}
.ts-loading {
  color: var(--ds-muted); font-size: 0.85rem;
  display: inline-flex; align-items: center; gap: 8px;
}
.ts-loading::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--ds-border); border-top-color: var(--ds-accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ts-loading::before { animation: none; } }

.continue-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 160px;
  background: var(--ds-text); color: var(--ds-bg);
  border: 0; border-radius: var(--ds-radius-sm);
  padding: 12px 22px; font-size: 1rem; font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.continue-btn:hover { filter: brightness(1.08); }
.continue-btn:focus-visible { outline: 2px solid var(--ds-accent); outline-offset: 3px; }
.continue-btn[aria-busy="true"] { cursor: progress; opacity: 0.8; }
.continue-btn[aria-busy="true"]::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .continue-btn[aria-busy="true"]::after { animation: none; } }

.err {
  margin-top: 12px; min-height: 1.2em;
  color: var(--ds-err); font-size: 0.9rem; line-height: 1.4; word-break: break-word;
}

/* RTL polish — most things flip from the root dir attribute, but tabular
 * passcode input text alignment is explicit, and so is the email row. */
html[dir="rtl"] .pc-wrap input { text-align: center; }
html[dir="rtl"] .pc-wrap { text-align: right; }

/* Mobile */
@media (max-width: 480px) {
  .card { padding: 22px 18px; }
  h1 { font-size: 1.2rem; }
  .continue-btn { width: 100%; }
}
