:root {
  --burgundy: #61080d;
  --ivory: #f6f1e7;
  --ivory-deep: #ebe4d6;
  --ink: #24180f;
  --gold: #f0b64d;
  --gold-deep: #d7a03a;
  --muted: #6f6258;
  --line: rgba(240, 182, 77, 0.85);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--ivory);
}

img { max-width: 100%; }

button, input { font: inherit; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 28px;
  border: 0;
  background: var(--gold);
  color: var(--burgundy);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
}

.button:hover { background: var(--gold-deep); }

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button-secondary {
  background: transparent;
  color: var(--burgundy);
  box-shadow: inset 0 0 0 1.5px var(--burgundy);
}

.button-secondary:hover {
  background: var(--burgundy);
  color: var(--ivory);
}

.page-start {
  background: var(--burgundy);
  color: var(--ivory);
}

.page-start::before {
  content: "";
  position: fixed;
  inset: 16px;
  border: 1px solid var(--line);
  pointer-events: none;
}

.start {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px 64px;
}

.logo {
  width: min(92vw, 560px);
  height: auto;
}

.eyebrow {
  margin: 8px 0 0;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
}

.start h1 {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-size: clamp(56px, 8vw, 92px);
  font-weight: 500;
  line-height: 0.9;
  letter-spacing: -0.03em;
}

.lede {
  max-width: 420px;
  margin: 18px 0 32px;
  font-size: 20px;
  line-height: 1.45;
}

.notice {
  max-width: 420px;
  margin: 28px 0 0;
  color: var(--gold);
  font-size: 14px;
}

.bar {
  display: flex;
  justify-content: center;
  background: var(--burgundy);
  padding: 18px 24px 14px;
}

.bar a {
  display: flex;
  justify-content: center;
}

.bar img {
  display: block;
  height: 112px;
  width: auto;
}

.sheet {
  width: min(720px, calc(100% - 32px));
  margin: 32px auto 64px;
}

#portrait-form {
  display: flex;
  flex-direction: column;
}

#continue-name {
  align-self: center;
}

.step {
  margin: 0 0 6px;
  color: var(--gold-deep);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.sheet h1,
.sheet h2 {
  margin: 0 0 18px;
  font-family: var(--serif);
  font-size: clamp(40px, 6vw, 58px);
  font-weight: 500;
  line-height: 0.95;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.field span {
  font-size: 15px;
  font-weight: 600;
}

.field input {
  width: 100%;
  height: 58px;
  padding: 0 16px;
  border: 1px solid #d9d0c2;
  background: white;
  color: var(--ink);
  font-size: 22px;
}

.field input:focus {
  outline: 2px solid var(--gold);
  border-color: transparent;
}

#name-section[hidden] { display: none; }

#photo-section { margin-top: 36px; }

.hint {
  margin: -6px 0 18px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.45;
}

.viewport {
  width: min(100%, 420px);
  aspect-ratio: 4 / 5;
  background: #1a120f;
  overflow: hidden;
}

.viewport video,
.viewport img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.viewport video { transform: scaleX(-1); }

#still {
  position: fixed;
  left: -12000px;
  top: 0;
  width: 2px;
  height: 2px;
}

.viewport img[hidden],
.viewport video[hidden],
#photo-section[hidden],
.button[hidden] { display: none; }

.status {
  min-height: 1.4em;
  margin: 12px 0;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.error {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: #8d1d1d;
  font-weight: 600;
}

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(97, 8, 13, 0.94);
  color: var(--ivory);
  text-align: center;
  z-index: 5;
}

.loading[hidden] { display: none; }

.thought { width: min(92vw, 640px); }

.digit-ring {
  position: relative;
  width: 168px;
  height: 168px;
  margin: 0 auto 26px;
  animation: spin 9s linear infinite;
}

.digit-ring span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  margin: -14px 0 0 -12px;
  font-family: var(--serif);
  font-size: 26px;
  color: var(--gold);
  transform: rotate(var(--a)) translateY(-72px);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-title {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: clamp(36px, 5vw, 52px);
  line-height: 1;
  transition: opacity 0.28s ease;
}

.loading-title.is-fading { opacity: 0; }

.loading p:last-child {
  margin: 0;
  font-size: 18px;
}

.page-result {
  background: var(--burgundy);
  min-height: 100vh;
}

.result {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px 16px;
}

.result-art {
  width: auto;
  height: auto;
  max-width: min(72vw, 640px);
  max-height: calc(100vh - 160px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.page-result .button-ghost {
  background: transparent;
  color: var(--gold);
  box-shadow: inset 0 0 0 1.5px var(--gold);
}

.page-result .button-ghost:hover {
  background: var(--gold);
  color: var(--burgundy);
}

.qr-popup {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(22, 0, 2, 0.72);
}

.qr-popup[hidden] { display: none; }

.qr-card {
  position: relative;
  width: min(92vw, 380px);
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 36px 28px 24px;
  background: var(--ivory);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.4);
}

.qr-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--burgundy);
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
}

.qr-card p {
  margin: 0;
  max-width: 260px;
  font-family: var(--serif);
  font-size: 32px;
  line-height: 1.05;
}

.qr-card img {
  width: min(68vw, 240px);
  height: auto;
  display: block;
}

.qr-card .button { min-width: 160px; }

.page-admin { background: var(--ivory); }

.admin {
  width: min(1100px, calc(100% - 40px));
  margin: 28px auto 64px;
}

.admin h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(42px, 5vw, 64px);
  font-weight: 500;
  line-height: 0.95;
}

.admin-count {
  margin: 8px 0 28px;
  font-family: var(--sans);
  font-size: 64px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--burgundy);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 22px;
}

.admin-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  background: white;
  box-shadow: 0 8px 24px rgba(52, 0, 4, 0.08);
}

.admin-card img {
  width: 100%;
  aspect-ratio: 210 / 297;
  object-fit: contain;
  display: block;
  background: var(--ivory-deep);
}

.admin-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.admin-actions {
  display: grid;
  gap: 8px;
}

.admin-actions .button { width: 100%; }

body.is-photo {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.is-photo .bar {
  flex: none;
  padding: 8px 20px 6px;
}

body.is-photo .bar img { height: 72px; }

body.is-photo .sheet {
  flex: 1;
  width: auto;
  max-width: none;
  margin: 0;
  padding: 12px 28px 18px;
  min-height: 0;
}

body.is-photo #portrait-form {
  height: 100%;
}

body.is-photo #photo-section {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  align-items: center;
  gap: 32px;
  height: 100%;
  margin: 0;
}

body.is-photo #photo-section[hidden] { display: none; }

body.is-photo .photo-stage {
  display: flex;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

body.is-photo .viewport {
  width: auto;
  height: 100%;
  max-height: calc(100vh - 108px);
  aspect-ratio: 4 / 5;
  max-width: 100%;
}

body.is-photo .photo-actions {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  gap: 12px;
}

body.is-photo .photo-actions h2 { margin-bottom: 0; }

body.is-photo .photo-actions .hint { margin: 0; }

body.is-photo .photo-actions .button {
  width: 250px;
  margin: 0;
}

@media (max-width: 640px) {
  .actions, .button { width: 100%; }
  #continue-name { width: auto; }
  .start h1 { font-size: 52px; }
  .bar { padding: 14px 16px 10px; }
  .bar img { height: 88px; }
}
