/* photosync — shared styles. No build step, no external assets. */

:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #ece9e3;
  --text: #1b1a17;
  --muted: #6c685f;
  --line: rgba(27, 26, 23, 0.12);
  --accent: #e2573b;
  --live: #23a55a;
  --warn: #c98a12;
  --off: #9a968d;
  --tile: #e4e0d8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 30px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --gap: 6px;
  --row: 240px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0e;
    --surface: #181816;
    --surface-2: #22211f;
    --text: #eeece7;
    --muted: #9c988f;
    --line: rgba(238, 236, 231, 0.12);
    --accent: #f06a4d;
    --live: #3cc774;
    --warn: #e3a93a;
    --off: #77736b;
    --tile: #1d1c1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 40px rgba(0, 0, 0, 0.35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

a { color: inherit; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.topbar.scrolled { border-bottom-color: var(--line); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  font-size: 15px;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: inline-grid;
  place-items: center;
}

.brand-mark::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- Live indicator ---------- */

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.live-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--off);
}

.live[data-state="live"] { color: var(--text); }
.live[data-state="live"] .live-dot { background: var(--live); }
.live[data-state="live"] .live-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 2s ease-out infinite;
}
.live[data-state="reconnecting"] .live-dot,
.live[data-state="connecting"] .live-dot {
  background: var(--warn);
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(3); opacity: 0; }
}

@keyframes blink { 50% { opacity: 0.3; } }

/* ---------- Typography ---------- */

.display {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.08;
  margin: 0;
  font-size: clamp(30px, 5.2vw, 54px);
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.lede {
  color: var(--muted);
  font-size: 17px;
  max-width: 34em;
  margin: 16px 0 0;
}

.mono { font-family: var(--mono); font-size: 13.5px; }

/* ---------- Buttons & fields ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: 600 15px/1 var(--font);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.button:active { transform: scale(0.98); }
.button:focus-visible, .input:focus-visible, .lb-btn:focus-visible, .tile:focus-visible, .new-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button.primary { background: var(--text); color: var(--bg); }
.button.primary:hover { opacity: 0.88; }
.button.primary[disabled] { opacity: 0.5; cursor: progress; }
.button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.button.ghost:hover { background: var(--surface-2); }
.button.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; flex: none; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.field-hint {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.field-hint.warn { color: var(--warn); }

.input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: 17px var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 4px color-mix(in srgb, var(--text) 10%, transparent); }
.input::placeholder { color: var(--off); }

.form-error {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--accent);
}

/* ---------- Home ---------- */

.home, .notfound {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: clamp(32px, 9vh, 96px) 20px 64px;
}

.home-intro { margin-bottom: 36px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card + .card { margin-top: 20px; }

#create-form .button { margin-top: 20px; width: 100%; }

.result { animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1); }
.result-head { margin-bottom: 22px; }
.result-title { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 26px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.result-row { padding: 18px 0; border-top: 1px solid var(--line); }

.copy-line {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  min-width: 0;
}

.copy-line > :first-child { min-width: 0; overflow-wrap: anywhere; word-break: break-all; }
.link { text-decoration: none; border-bottom: 1px solid var(--line); }
.link:hover { border-bottom-color: currentColor; }

.command {
  position: relative;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.command pre {
  margin: 0;
  flex: 1;
  min-width: 0;
  font: 13px/1.6 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.notfound .button { margin-top: 28px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Gallery ---------- */

.gallery { padding: 0 max(14px, env(safe-area-inset-right)) 64px max(14px, env(safe-area-inset-left)); }

.gallery-head {
  max-width: 1600px;
  margin: 0 auto;
  padding: clamp(20px, 5vh, 48px) 6px clamp(18px, 3.5vh, 32px);
}

.meta {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.empty {
  max-width: 420px;
  margin: 8vh auto 0;
  text-align: center;
  color: var(--muted);
}

.aperture {
  display: inline-block;
  color: var(--off);
  animation: spin 14s linear infinite;
  margin-bottom: 18px;
}

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

.empty-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 24px;
  color: var(--text);
}

.empty-text { margin: 8px 0 0; font-size: 15px; }

/* Justified rows: each tile grows in proportion to its aspect ratio,
   so photos keep their shape and read left-to-right, newest first. */
.grid {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.grid::after {
  content: "";
  flex-grow: 1000000;
}

.tile {
  --r: 1.5;
  position: relative;
  flex-grow: calc(var(--r) * 100);
  flex-basis: calc(var(--r) * var(--row));
  max-width: calc(var(--r) * var(--row) * 1.9);
  display: block;
  padding: 0;
  border: 0;
  margin: 0;
  overflow: hidden;
  border-radius: 3px;
  background: var(--tile);
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.tile::before {
  content: "";
  display: block;
  padding-bottom: calc(100% / var(--r));
}

.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tile img.loaded { opacity: 1; }

@media (hover: hover) {
  .tile:hover img { transform: scale(1.025); }
}

.tile.is-new { animation: arrive 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.tile.is-new::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px var(--accent);
  animation: fade-ring 2.4s ease-out forwards;
  pointer-events: none;
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-ring {
  0%, 40% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 700px) {
  :root { --row: 120px; --gap: 4px; }
  .gallery { padding-left: 8px; padding-right: 8px; }
  .card { padding: 20px; }
  .live { padding: 5px 10px 5px 9px; font-size: 12px; }
}

.new-pill {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font: 600 14px/1 var(--font);
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: rise 0.3s ease both;
}

/* ---------- Lightbox (always dark: the photo is the subject) ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 8, 7, 0.97);
  color: #eeece7;
  animation: fade-in 0.2s ease;
  touch-action: pan-y;
}

@keyframes fade-in { from { opacity: 0; } }

.lb-stage {
  position: absolute;
  inset: 64px 72px 64px;
}

/* Fills the stage; object-fit keeps the ratio, so the (cached) thumbnail
   is shown at full size until the original finishes loading. */
.lb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.lb-btn {
  position: absolute;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.lb-btn:hover { background: rgba(255, 255, 255, 0.14); }
.lb-btn[disabled] { opacity: 0.25; cursor: default; }
.lb-close { top: max(10px, env(safe-area-inset-top)); right: 10px; }
.lb-prev { left: 10px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 10px; top: 50%; transform: translateY(-50%); }

.lb-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 16px 20px max(18px, env(safe-area-inset-bottom));
  font-size: 13px;
  color: rgba(238, 236, 231, 0.7);
  font-variant-numeric: tabular-nums;
}

.lb-sep { opacity: 0.5; }
.lb-pos { margin-left: 8px; padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, 0.15); }
.lb-download { margin-left: 8px; color: #eeece7; text-decoration: none; border-bottom: 1px solid rgba(255, 255, 255, 0.3); }

@media (max-width: 700px) {
  .lb-stage { inset: 56px 0 76px; }
  .lb-prev, .lb-next { top: auto; bottom: max(8px, env(safe-area-inset-bottom)); transform: none; width: 44px; height: 44px; }
  .lb-caption { padding-left: 64px; padding-right: 64px; }
  .lb-pos { margin-left: 0; padding-left: 0; border-left: 0; }
}

body.lb-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
