@font-face {
  font-family: "Pinyon Script";
  src: url("/fonts/pinyon-script-latin-400-normal.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Cormorant Garamond";
  src: url("/fonts/cormorant-garamond-latin-400-normal.woff2") format("woff2");
  font-display: swap;
}

:root {
  --forest: #2f4a34;
  --cream: #f6f1e7;
  --ring: clamp(18px, 6vw, 34px);   /* ring-light border width */
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; background: #000; color: #fff; overflow: hidden;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}

/* ---- viewfinder ---------------------------------------------------------- */
.stage {
  position: fixed; inset: 0;
  background: #000;
  /* preview sits between the top bar and the controls, so nothing covers the photo or its filter */
  padding: calc(env(safe-area-inset-top) + 64px) 0 calc(env(safe-area-inset-bottom) + 200px);
  transition: padding .25s ease, background-color .25s ease;
}
.frame {
  position: relative; width: 100%; height: 100%; overflow: hidden; border-radius: 14px;
  transition: border-radius .25s ease;
}
video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  background: #000;
}
/* filter preview: same box as the video, so it matches the saved (cropped) photo */
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
video.mirror { transform: scaleX(-1); }

/* Selfie ring light: the screen itself becomes a white light around the preview */
body.ringlight .stage {
  background: #fff;
  padding: calc(var(--ring) + 54px + env(safe-area-inset-top)) var(--ring)
           calc(var(--ring) + 200px + env(safe-area-inset-bottom));
}
body.ringlight .frame { border-radius: 28px; }
body.ringlight .top .brand { color: #1f3324; background: none; }
body.ringlight .top .icon-btn { background: rgba(0,0,0,.7); }

/* shutter blink / screen flash */
.blink { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }
.blink.go { animation: blink .18s ease-out; }
.blink.white { background: #fff; opacity: 1; transition: none; }
@keyframes blink { 0% { opacity: .85; } 100% { opacity: 0; } }

/* ---- top bar ------------------------------------------------------------- */
.top {
  position: fixed; left: 0; right: 0; top: 0; z-index: 2;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.brand {
  flex: 0 1 auto; margin: 0 auto; text-align: center;
  font-family: "Pinyon Script", cursive; font-size: 28px; line-height: 1.2;
  color: #fff; padding: 4px 16px 6px; border-radius: 22px;
  background: rgba(0,0,0,.6);              /* readable over a bright scene (>= 4.5:1) */
}
.brand span { font-family: "Cormorant Garamond", serif; font-size: 20px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; padding: 10px;
  background: rgba(0,0,0,.6); color: #fff; position: relative; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#flash svg { fill: currentColor; stroke: none; }
#flash[aria-pressed="true"] { color: #ffd54a; }
#flash .slash { position: absolute; width: 26px; height: 2px; background: currentColor; transform: rotate(-45deg); border-radius: 2px; }
#flash[aria-pressed="true"] .slash { display: none; }
#ring[aria-pressed="true"] { color: #ffd54a; }
.top .icon-btn:first-child { margin-right: 0; }

/* ---- bottom controls ----------------------------------------------------- */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 18px 28px calc(env(safe-area-inset-bottom) + 26px);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0));
}
body.ringlight .controls { background: none; }

/* The shutter: white disc inside a white ring, like the stock camera apps */
.shutter {
  width: 78px; height: 78px; border-radius: 50%;
  border: 5px solid #fff; background: transparent; padding: 4px; cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}
.shutter-inner {
  display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff;
  transition: transform .08s ease;
}
.shutter:active .shutter-inner, .shutter.pressed .shutter-inner { transform: scale(.86); }
.shutter:disabled { opacity: .5; }
body.ringlight .shutter { border-color: #222; }
body.ringlight .shutter-inner { background: #222; }

.thumb {
  justify-self: start; width: 52px; height: 52px; border-radius: 10px; padding: 0;
  border: 2px solid rgba(255,255,255,.85); background: rgba(255,255,255,.08);
  overflow: visible; position: relative; cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; }
.badge {
  position: absolute; top: -10px; right: -10px; min-width: 26px; height: 26px; padding: 0 7px;
  border-radius: 13px; background: #ffd54a; color: #000; font-size: 15px; font-weight: 700;
  display: grid; place-items: center;
}
.badge.done { background: #1b5e20; color: #fff; }
.round { justify-self: end; width: 52px; height: 52px; background: rgba(0,0,0,.6); }
body.ringlight .thumb { border-color: #222; }
body.ringlight .round { background: rgba(0,0,0,.7); }

/* ---- filter chips ------------------------------------------------------ */
.filters {
  position: fixed; left: 0; right: 0; z-index: 2;
  bottom: calc(env(safe-area-inset-bottom) + 134px);
  display: flex; gap: 8px; justify-content: safe center; overflow-x: auto;
  padding: 0 16px; scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 22px; min-height: 44px; padding: 8px 18px; cursor: pointer;
  font-family: "Cormorant Garamond", Georgia, serif; font-size: 18px; font-weight: 600; letter-spacing: .02em;
  background: rgba(0,0,0,.7); color: #fff;      /* >= 4.5:1 even over a white scene */
}
.chip[aria-checked="true"] { background: var(--cream); color: var(--forest); }

/* ---- toast + sheet ------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 190px); z-index: 3;
  transform: translateX(-50%); margin: 0; max-width: 86vw;
  padding: 10px 16px; border-radius: 20px; background: rgba(0,0,0,.8); color: #fff;
  font-size: 17px; text-align: center;
}

.sheet {
  position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 24px;
  background: rgba(0,0,0,.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.sheet-card {
  width: min(100%, 360px); background: var(--cream); color: #1f3324; border-radius: 4px;
  padding: 28px 24px; text-align: center; display: grid; gap: 12px;
  font-family: "Cormorant Garamond", Georgia, serif; font-size: 18px;
  outline: 1px solid #d8cfbb; outline-offset: -8px;
}
.sheet-card p { margin: 0; }
.script { font-family: "Pinyon Script", cursive; font-size: 46px; line-height: 1.1; color: #1f3324; font-weight: 400; margin: 0; }
.sheet-card label { font-size: 16px; letter-spacing: .12em; text-transform: uppercase; color: var(--forest); margin-top: 6px; }
.sheet-card input {
  font: inherit; font-size: 18px; padding: 10px 12px; text-align: center;
  border: 1px solid #d8cfbb; border-radius: 2px; background: #fff; color: #1f3324;
}
.primary {
  font: inherit; font-size: 19px; padding: 12px; border: 0; border-radius: 2px;
  background: var(--forest); color: var(--cream); cursor: pointer;
}
.hint { font-size: 17px; font-style: italic; color: #2f4a34; }
.sheet-card input::placeholder { color: #5f6b60; }

body.sheet-open .filters, body.sheet-open .controls, body.sheet-open .top { visibility: hidden; }

/* ---- accessibility ------------------------------------------------------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 3px solid #ffd54a; outline-offset: 3px; }
.sheet-card :focus-visible { outline-color: #1f3324; }
@media (prefers-reduced-motion: reduce) {
  .stage, .frame, .shutter-inner { transition: none; }
  .blink.go { animation: none; }
}

/* ---- tilt: layout stays put, icons and labels turn (like the stock camera) */
:root { --ui-rot: 0deg; }
.icon-btn svg, .badge, .chip, #flash .slash {
  transition: transform .3s ease;
}
.icon-btn svg { transform: rotate(var(--ui-rot)); }
#flash .slash { transform: rotate(calc(-45deg + var(--ui-rot))); }
.badge { transform: rotate(var(--ui-rot)); }
.chip .short { display: none; }
body.sideways .chip .long { display: none; }
body.sideways .chip .short { display: inline; }
body.sideways .chip, body.upside-down .chip { transform: rotate(var(--ui-rot)); }
/* turned labels stand taller than the row, so give the row room (and let swipes pass through it) */
body.sideways .filters {
  gap: 6px; padding-top: 36px; padding-bottom: 36px;
  bottom: calc(env(safe-area-inset-bottom) + 98px); pointer-events: none;
}
body.sideways .chip { pointer-events: auto; }
body.sideways .chip { min-width: 44px; padding: 8px 14px; }
body.sideways .top .brand { visibility: hidden; }
body.sideways .toast, body.upside-down .toast {
  bottom: auto; top: 45%; transform: translate(-50%, -50%) rotate(var(--ui-rot));
}
@media (prefers-reduced-motion: reduce) {
  .icon-btn svg, .badge, .chip, #flash .slash { transition: none; }
}

/* ---- landscape: full-screen viewfinder, controls float over it ------------ */
/* Turning the phone sideways for a group shot: the preview fills the screen,
   the shutter column sits on the right like the stock camera apps, filters on top. */
@media (orientation: landscape) {
  .stage {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .frame { border-radius: 0; }
  body.ringlight .stage {
    padding: var(--ring) calc(var(--ring) + env(safe-area-inset-right))
             var(--ring) calc(var(--ring) + env(safe-area-inset-left));
  }
  body.ringlight .frame { border-radius: 22px; }

  /* top-left: flash / ring-light / install toggles; the name header steps aside */
  .top {
    right: auto; gap: 10px;
    padding: calc(env(safe-area-inset-top) + 12px) 0 0 calc(env(safe-area-inset-left) + 12px);
  }
  body.ringlight .top { padding: calc(var(--ring) + 10px) 0 0 calc(var(--ring) + env(safe-area-inset-left) + 10px); }
  .top .brand { display: none; }

  /* right edge: switch camera, shutter (centred), photo count */
  .controls {
    left: auto; top: 0; bottom: 0;
    right: calc(env(safe-area-inset-right) + 14px);
    padding: 16px 0; background: none;
    display: grid; grid-template-columns: auto; grid-template-rows: 1fr auto 1fr;
    justify-items: center; row-gap: 22px;
  }
  /* shutter dead centre; switch camera above it, photo count below */
  .controls #flip { grid-row: 1; align-self: end; justify-self: center; }
  .controls .shutter { grid-row: 2; }
  .controls .thumb { grid-row: 3; align-self: start; justify-self: center; }
  body.ringlight .controls { right: calc(var(--ring) + env(safe-area-inset-right) + 12px); }

  /* over the live picture the shutter is always white, with a dark edge for bright scenes */
  .shutter, body.ringlight .shutter { border-color: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.5), inset 0 0 0 1px rgba(0,0,0,.3); }
  body.ringlight .shutter-inner { background: #fff; }
  body.ringlight .thumb { border-color: rgba(255,255,255,.9); }
  .thumb { box-shadow: 0 0 0 2px rgba(0,0,0,.5); }

  /* filter chips along the top */
  .filters { top: calc(env(safe-area-inset-top) + 12px); bottom: auto; padding: 0 120px; }
  body.ringlight .filters { top: calc(var(--ring) + 10px); }

  .toast { bottom: calc(env(safe-area-inset-bottom) + 18px); }

  /* the start card scrolls on a short landscape screen */
  .sheet { overflow-y: auto; align-items: start; }
}
