:root {
  --night: #0E0F0D;
  --night-2: #1A1C19;
  --paper: #F2EDE4;
  --paper-mute: rgba(242, 237, 228, 0.66);
  --hair: rgba(242, 237, 228, 0.18);
  --signal: #E4572E;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --brand: "Syne", system-ui, sans-serif;
  --bar: 168px; /* preview controls height */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--paper);
  font: 14px/1.5 var(--mono);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 0 22px;
  font: 500 14px var(--mono); letter-spacing: .04em;
  border-radius: 999px; border: 1px solid var(--paper); cursor: pointer;
}
.btn.primary { background: var(--paper); color: var(--night); }
.btn.ghost { background: transparent; color: var(--paper); border-color: var(--hair); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .icon-btn:focus-visible, .shutter:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--signal); outline-offset: 3px;
}

.icon-btn {
  display: grid; place-items: center;
  width: 48px; height: 48px; padding: 0;
  border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(14, 15, 13, 0.45); color: var(--paper);
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spacer { background: none; }

/* ── Brand text ── */
.wordmark { margin: 0 0 8px; font: 800 clamp(56px, 18vw, 84px)/1 var(--brand); letter-spacing: .06em; }
.pitch { margin: 0; font-size: 16px; line-height: 1.55; color: var(--paper-mute); max-width: 32ch; }
.notice {
  margin: 0; padding: 12px 14px;
  border: 1px solid rgba(228, 87, 46, .55); border-radius: 12px;
  background: rgba(228, 87, 46, .12); font-size: 13px;
}
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.actions.row { flex-direction: row; }
.actions.row { align-items: center; }
.actions.row .btn { flex: 1; }
.icon-btn.outline { flex: none; width: 52px; height: 52px; background: transparent; border: 1px solid var(--hair); }
.fine { margin: 0; font-size: 12px; color: var(--paper-mute); letter-spacing: .04em; }

/* ── Home ── */
.home { justify-content: space-between; }
.home-inner {
  flex: 1; width: 100%; max-width: 420px; margin: 0 auto; padding: 32px 24px;
  display: flex; flex-direction: column; justify-content: center; gap: 18px;
}
.camera-bar {
  display: flex; align-items: center; justify-content: space-around;
  height: 112px; flex: none;
}
.home-note { text-align: center; padding: 0 16px 16px; text-shadow: 0 1px 8px rgba(0, 0, 0, .6); }
.home-note .credits { font-size: 10px; opacity: .8; }

/* Trip clips behind the home screen: full-bleed, crossfading, darkened top and bottom
   so the wordmark and the controls stay readable on any frame. */
.home { isolation: isolate; }
.home-bg { position: absolute; inset: 0; z-index: -1; overflow: hidden; background: var(--night); }
.home-media {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; transition: opacity 1s ease;
  pointer-events: none;
}
.home-media.on { opacity: 1; }
.home-bg::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(to bottom, rgba(14, 15, 13, .62) 0%, rgba(14, 15, 13, .18) 38%, rgba(14, 15, 13, .18) 52%, rgba(14, 15, 13, .82) 100%);
}
.home .wordmark, .home .pitch { text-shadow: 0 2px 18px rgba(0, 0, 0, .45); }
.home .pitch { color: rgba(242, 237, 228, .86); }
/* Who made it (like a signature) + the About page */
.byline {
  margin: -18px 0 4px; width: fit-content; font-size: 13px; color: rgba(242, 237, 228, .72);
  text-decoration: none; text-shadow: 0 1px 10px rgba(0, 0, 0, .5);
}
.about-link {
  position: absolute; z-index: 2; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px;
  font-size: 14px; color: var(--paper); text-decoration: none; text-shadow: 0 1px 10px rgba(0, 0, 0, .5);
}
.byline:active, .about-link:active { opacity: .6; }
.home .btn.recent { background: rgba(14, 15, 13, .38); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.shutter {
  width: 76px; height: 76px; padding: 6px;
  border-radius: 50%; border: 3px solid var(--paper); background: transparent; cursor: pointer;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--paper); transition: transform .12s ease; }
.shutter:active span { transform: scale(.9); }

/* ── Preview ── */
.preview { align-items: center; }
.frame {
  flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 12px 16px 0;
}
.frame .stack {
  position: relative;
  height: 100%; max-height: 100%; max-width: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.frame .stack canvas, .frame .stack img { display: block; width: 100%; height: 100%; max-width: none; }
.frame .stack img { position: absolute; inset: 0; border-radius: 0; box-shadow: none; -webkit-touch-callout: default; }
.preview-bar { width: 100%; max-width: 480px; padding: 14px 16px 16px; display: grid; gap: 12px; flex: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 14px;
  font: 400 13px var(--mono); color: var(--paper);
  background: transparent; border: 1px solid var(--hair); border-radius: 999px; cursor: pointer;
}
.chip.on { background: var(--paper); color: var(--night); border-color: var(--paper); }

/* ── Place line + sheet ── */
.place {
  justify-self: start; max-width: 100%;
  min-height: 32px; padding: 0 2px;
  font: 400 12px var(--mono); letter-spacing: .03em; color: var(--paper-mute);
  background: none; border: 0; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.place::before { content: "◎ "; }
.place.ask { color: var(--paper); text-decoration: underline; text-underline-offset: 3px; }
.place:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  width: 100%; max-width: 480px; max-height: 80dvh;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--night-2); border-radius: 18px 18px 0 0;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font: 500 14px var(--mono); letter-spacing: .04em; }
.sheet-note { margin: -6px 0 0; font: 400 12px var(--mono); color: var(--paper-mute); }
.search {
  width: 100%; min-height: 48px; padding: 0 14px;
  font: 400 16px var(--mono); color: var(--paper);
  background: var(--night); border: 1px solid var(--hair); border-radius: 12px;
}
.search:focus { outline: 2px solid var(--signal); outline-offset: 1px; }
.results { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.result {
  width: 100%; min-height: 52px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  font: 400 14px var(--mono); color: var(--paper); text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--hair); cursor: pointer;
}
.result small { color: var(--paper-mute); font-size: 12px; }
.result.here span::before { content: "◎ "; }
.result:focus-visible { outline: 2px solid var(--signal); outline-offset: -2px; }

/* ── Gallery button on the camera bar ── */
.gallery-btn {
  position: relative; width: 48px; height: 48px; padding: 0;
  display: grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--hair); background: rgba(14, 15, 13, .45);
  color: var(--paper); cursor: pointer; overflow: hidden;
}
.gallery-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.gallery-btn img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.gallery-btn img:not([hidden]) + svg { display: none; }
.gallery-btn:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }

/* ── Gallery ── */
.gallery { overflow: hidden; }
.gallery-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; flex: none;
}
.gallery-head h1 { margin: 0; font: 500 14px var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.grid {
  list-style: none; margin: 0; padding: 4px 12px 16px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  overflow-y: auto; flex: 1; align-content: start;
}
.grid button {
  display: block; width: 100%; aspect-ratio: 9 / 16; padding: 0;
  border: 0; border-radius: 6px; overflow: hidden; background: var(--night-2); cursor: pointer;
}
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid button:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; color: var(--paper-mute); }
.empty p { margin: 0; }
.gallery-note { text-align: center; padding: 8px 16px 12px; flex: none; }

/* ── Viewer ── */
.viewer { align-items: center; }
.frame img {
  display: block; height: 100%; max-height: 100%; width: auto; max-width: 100%;
  aspect-ratio: 9 / 16; object-fit: contain; border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}

/* ── Toast ── */
.toast {
  position: fixed; left: 0; right: 0; top: calc(16px + env(safe-area-inset-top)); z-index: 20;
  width: fit-content; max-width: min(420px, calc(100% - 32px)); margin: 0 auto; padding: 12px 16px;
  font: 400 13px/1.4 var(--mono); color: var(--night); text-align: center;
  background: var(--paper); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}

/* Opened inside Instagram & co. (Android): one tap to the phone's real browser */
.in-app {
  margin-top: 18px; padding: 14px; border-radius: 14px;
  background: rgba(14, 15, 13, .55); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  animation: aera-rise 260ms var(--ease-out) both;
}
.in-app p { margin: 0 0 10px; font-size: 13px; color: rgba(242, 237, 228, .9); }
.in-app .btn { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.in-app .in-app-title { font: 500 16px var(--mono); color: var(--paper); margin-bottom: 6px; }
/* In there, the camera would lead to a photo you can't save: the browser button replaces it */
.in-app-mode .camera-bar, .in-app-mode .home-alt { display: none; }

/* Back from a picked photo: one tap to choose another (a back gesture can't open the picker) */
.pick-again {
  position: fixed; left: 0; right: 0; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 15;
  width: fit-content; margin: 0 auto; min-height: 48px; padding: 0 22px;
  font: 500 14px var(--mono); color: var(--night);
  background: var(--paper); border: 0; border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  cursor: pointer;
}
.pick-again::before { content: "↺ "; }

/* ── Drag to frame ── */
/* Centre guides while the strip snaps (never part of the photo) */
.guide { position: absolute; z-index: 3; pointer-events: none; background: #38BDF8; box-shadow: 0 0 0 .5px rgba(0, 0, 0, .25); }
.guide-v { top: 0; bottom: 0; left: 50%; width: 1.5px; transform: translateX(-50%); }
.guide-h { left: 0; right: 0; top: 50%; height: 1.5px; transform: translateY(-50%); }
.frame .stack.draggable { touch-action: none; cursor: grab; }
.frame .stack.dragging { cursor: grabbing; }
.drag-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2; white-space: nowrap;
  padding: 6px 12px; border-radius: 999px; pointer-events: none;
  font: 400 12px var(--mono); letter-spacing: .04em; color: var(--paper);
  background: rgba(14, 15, 13, .6); transition: opacity .4s ease;
}
.drag-hint.fade { opacity: 0; }

/* ── Best-quality option on home ── */
.home-alt { width: 100%; max-width: 420px; margin: 0 auto; padding: 0 24px 8px; }
.btn.recent { width: 100%; min-height: 60px; flex-direction: column; gap: 2px; padding: 8px 18px; border-color: var(--paper-mute); }
.btn.recent small { font: 400 11px var(--mono); letter-spacing: .04em; color: var(--paper-mute); }

/* ── Info row: reading source + automatic sticker ── */
.info-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.info-row .place { flex: 1; min-width: 0; }
.scene-toggle {
  flex: none; min-height: 32px; padding: 0 2px;
  font: 400 12px var(--mono); letter-spacing: .03em; color: var(--paper-mute);
  background: none; border: 0; cursor: pointer;
}
.scene-toggle::after { content: " · change"; text-decoration: underline; text-underline-offset: 3px; }
.scene-toggle[aria-expanded="true"]::after { content: " · done"; }
.scene-toggle:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* ── White / black text toggle: a half-white, half-black disc; it turns to put the
   current text colour on the left, with a ring when black is on ── */
.ink-btn span {
  display: block; width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(90deg, var(--paper) 50%, #121310 50%);
  box-shadow: 0 0 0 1.5px var(--paper-mute);
  transition: transform .25s ease;
}
.ink-btn.dark span { transform: rotate(180deg); }
.ink-btn.dark { border-color: var(--paper); }
@media (prefers-reduced-motion: reduce) { .ink-btn span { transition: none; } }

/* ── Gallery multi-select ── */
.head-actions { display: flex; align-items: center; gap: 4px; }
.text-btn {
  min-height: 44px; padding: 0 10px;
  font: 500 13px var(--mono); letter-spacing: .04em; color: var(--paper);
  background: none; border: 0; cursor: pointer;
}
.text-btn:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.gallery.selecting #galleryImport { display: none; }
.grid button { position: relative; -webkit-touch-callout: none; user-select: none; }
.gallery.selecting .grid button::after {
  content: ""; position: absolute; top: 6px; right: 6px; width: 22px; height: 22px;
  border-radius: 50%; border: 2px solid var(--paper); background: rgba(14, 15, 13, .35);
}
.gallery.selecting .grid button.picked img { opacity: .55; }
.gallery.selecting .grid button.picked::after {
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='%230E0F0D' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.select-bar {
  display: flex; gap: 10px; flex: none;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hair); background: var(--night);
}
.select-bar .btn { flex: 1; }
.gallery.selecting .gallery-note { display: none; }

/* ── "Tap to begin" bubble above the shutter (until the first photo) ── */
.shutter-wrap { position: relative; display: grid; place-items: center; }
.tap-hint {
  position: absolute; bottom: calc(100% + 14px); left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px; white-space: nowrap; pointer-events: none;
  font: 500 11px/1 var(--mono); letter-spacing: .18em; text-transform: uppercase;
  color: var(--night); background: var(--paper);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
  animation: hint-in .5s ease-out both, hint-float 2.6s ease-in-out .5s infinite;
}
.tap-hint::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--paper);
}
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes hint-float { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -5px); } }
@media (prefers-reduced-motion: reduce) { .tap-hint { animation: none; } }

/* ── Motion: soft, quick, and out of the way ──────────────────────────── */
/* ease-out "lands" like something set down gently; 150–300 ms for responses */
:root { --ease-out: cubic-bezier(.2, .8, .2, 1); }

/* Screens crossfade (View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 180ms; animation-timing-function: ease-out; }

/* Pressed controls give a little under the finger */
.btn, .icon-btn, .result, .gallery-btn, .pick-again, .chip, .grid button, .place {
  transition: transform 120ms var(--ease-out), background-color 200ms ease, opacity 200ms ease;
  touch-action: manipulation;
}
.btn:active, .icon-btn:active, .result:active, .gallery-btn:active, .pick-again:active, .chip:active, .grid button:active, .place:active { transform: scale(.97); }
.btn:disabled:active { transform: none; }

/* The place sheet rises; its backdrop fades */
.sheet:not([hidden]) { animation: aera-fade 200ms ease-out; }
.sheet:not([hidden]) .sheet-card { animation: aera-rise 280ms var(--ease-out); }
/* Toast and "choose another" arrive instead of popping */
.toast:not([hidden]) { animation: aera-drop 220ms var(--ease-out); }
.pick-again:not([hidden]) { animation: aera-rise 260ms var(--ease-out); }
/* Gallery thumbnails fade in once decoded */
.grid img { opacity: 0; transition: opacity 240ms ease-out; }
.grid img.in { opacity: 1; }
/* "Reading the air…" breathes while it waits */
.place.loading { animation: aera-breathe 1.4s ease-in-out infinite; }

@keyframes aera-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes aera-rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes aera-drop { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes aera-breathe { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  .sheet:not([hidden]), .sheet:not([hidden]) .sheet-card, .toast:not([hidden]), .pick-again:not([hidden]), .place.loading, .in-app { animation: none; }
  .grid img { transition: none; opacity: 1; }
}

