/* Cloud Photo Saver. Night is warm charcoal, like a darkroom, so photos stand out;
   day is warm paper. theme.js sets data-theme on <html>. */

:root, :root[data-theme="dark"] {
  --bg:        #141210;
  --surface:   #1f1c19;
  --surface-2: #2a2622;
  --line:      #3a352f;
  --text:      #f3eee6;
  --muted:     #b0a699;
  --accent:    #e8a33d;
  --accent-hi: #f3b75c;
  --on-accent: #1b1712;
  --danger:    #f0796c;
  --on-danger: #24100d;
  --ok-bg:     #1f2c20;
  --ok-text:   #a8dcaa;
  --err-bg:    #33201c;
  --err-text:  #f6b1a8;
  --shadow:    0 12px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:        #f8f4ed;
  --surface:   #ffffff;
  --surface-2: #efe9df;
  --line:      #dcd4c6;
  --text:      #26211b;
  --muted:     #6a6054;
  --accent:    #9c5a06;
  --accent-hi: #824a03;
  --on-accent: #ffffff;
  --danger:    #b83a2c;
  --on-danger: #ffffff;
  --ok-bg:     #e6f2e5;
  --ok-text:   #245c28;
  --err-bg:    #f9e6e2;
  --err-text:  #8f2a1e;
  --shadow:    0 12px 40px rgba(60,40,10,.16);
  color-scheme: light;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh;
}

h1, h2 { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-weight: 600; line-height: 1.15; margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-hi); }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); border: 0;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.15rem;
  background: var(--accent); color: var(--on-accent);
  border: 1px solid transparent; border-radius: 8px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: var(--accent-hi); color: var(--on-accent); }
.btn-small { min-height: 36px; padding: .3rem .8rem; font-size: .92rem; }
.btn-large { min-height: 52px; padding: .7rem 1.6rem; font-size: 1.08rem; }
.btn-block { width: 100%; }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--line); }
.btn-quiet:hover { background: var(--surface-2); color: var(--text); }
.btn-quiet[aria-pressed="true"] { background: var(--surface-2); border-color: var(--accent); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-danger:hover { background: var(--danger); color: var(--on-danger); filter: brightness(1.08); }
.btn-danger-quiet { color: var(--danger); }
.btn-danger-quiet:hover { color: var(--danger); }
.btn[disabled], .btn-disabled { opacity: .5; cursor: not-allowed; }
input:focus-visible + .btn, .btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  min-width: 40px; min-height: 40px;
  background: none; border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-size: 1.05rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---- forms ---- */
label { display: block; font-weight: 600; font-size: .92rem; margin: 1rem 0 .3rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input:not([type]) {
  display: block; width: 100%; min-height: 44px; padding: .5rem .75rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit;
}
input:disabled { color: var(--muted); }
input::placeholder { color: var(--muted); }
.field-hint { font-size: .85rem; color: var(--muted); margin-top: .3rem; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.label-row a { font-size: .88rem; }
form .btn { margin-top: 1.25rem; }
progress {
  display: block; width: 100%; height: 6px; border: 0; border-radius: 3px;
  background: var(--surface-2); overflow: hidden; appearance: none; accent-color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.notice { padding: .65rem .85rem; border-radius: 8px; margin: 1rem 0; font-size: .95rem; }
.notice-success { background: var(--ok-bg); color: var(--ok-text); }
.notice-error { background: var(--err-bg); color: var(--err-text); }

/* ---- site header ---- */
.wordmark {
  display: inline-flex; align-items: center; gap: .55rem;
  color: var(--text); text-decoration: none;
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-weight: 600; font-size: 1.12rem;
  white-space: nowrap;
}
.wordmark:hover { color: var(--text); }
.wordmark img { border-radius: 6px; }

.site-nav {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem clamp(1rem, 3vw, 2rem);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.site-nav nav { display: flex; align-items: center; gap: clamp(.5rem, 2vw, 1.1rem); }
.site-nav nav > a { white-space: nowrap; }
.site-nav nav > a:not(.btn) { color: var(--muted); text-decoration: none; font-weight: 500; padding: .5rem .15rem; }
.site-nav nav > a:not(.btn):hover, .site-nav nav > a[aria-current] { color: var(--text); }
/* A form, as logging out has to be a POST, but it looks like the links beside it. */
.nav-logout { display: flex; margin: 0; }
.nav-logout button {
  background: none; border: 0; cursor: pointer; white-space: nowrap;
  color: var(--muted); font: inherit; font-weight: 500; padding: .5rem .15rem;
}
.nav-logout button:hover { color: var(--text); }

/* ---- landing page ---- */
.hero {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4rem); align-items: center;
  max-width: 1120px; margin: 0 auto;
  padding: clamp(2.5rem, 8vw, 6rem) clamp(1rem, 3vw, 2rem);
}
.hero h1 { font-size: clamp(2.3rem, 5.5vw, 3.9rem); letter-spacing: -.01em; }
.lede { margin-top: 1.25rem; font-size: clamp(1.05rem, 2vw, 1.25rem); color: var(--muted); max-width: 34em; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; margin-top: 2rem; }
.link-quiet { color: var(--muted); }

.hero-art { position: relative; aspect-ratio: 1 / .92; }
.print {
  position: absolute; padding: 10px 10px 34px; background: #fbf8f2;
  border-radius: 3px; box-shadow: var(--shadow);
}
.print .scene { width: 100%; height: 100%; border-radius: 1px; }
.print-a { width: 58%; height: 66%; left: 0; top: 4%; transform: rotate(-5deg); }
.print-b { width: 52%; height: 60%; right: 0; top: 0; transform: rotate(4deg); }
.print-c { width: 56%; height: 62%; left: 24%; bottom: 0; transform: rotate(-1.5deg); }
.scene-dusk { background:
  radial-gradient(circle at 68% 58%, #ffd98a 0 9%, transparent 10%),
  linear-gradient(180deg, #33305e 0%, #a2547a 48%, #f1995c 74%, #2e2231 75%, #181320 100%); }
.scene-lake { background:
  linear-gradient(to top right, #2f5a4e 49.5%, transparent 50%) 0% 58% / 38% 30% no-repeat,
  linear-gradient(to top left, #2f5a4e 49.5%, transparent 50%) 38% 58% / 38% 30% no-repeat,
  linear-gradient(to top right, #3f7262 49.5%, transparent 50%) 62% 58% / 30% 22% no-repeat,
  linear-gradient(to top left, #3f7262 49.5%, transparent 50%) 100% 58% / 30% 22% no-repeat,
  linear-gradient(180deg, #a9d5e6 0%, #e5eedd 58%, #4d8ea6 58.5%, #27566f 100%); }
.scene-field { background:
  radial-gradient(circle at 26% 26%, #fff3c9 0 8%, transparent 8.5%),
  radial-gradient(ellipse 90% 34% at 72% 76%, #6d8a34 0 99%, transparent 100%),
  radial-gradient(ellipse 90% 40% at 20% 92%, #8fa83f 0 99%, transparent 100%),
  linear-gradient(180deg, #f6c58a 0%, #f7e3b0 62%, #a7ad52 63%, #7d9136 100%); }

.features {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(1.5rem, 4vw, 3rem);
  max-width: 1120px; margin: 0 auto;
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1rem, 3vw, 2rem);
  border-top: 1px solid var(--line);
}
.features h2 { font-size: 1.3rem; margin-bottom: .5rem; }
.features p { color: var(--muted); }
.site-foot { max-width: 1120px; margin: 0 auto; padding: 2rem clamp(1rem, 3vw, 2rem) 3rem; color: var(--muted); font-size: .9rem; }

/* ---- log in, sign up, reset ---- */
.page-auth { display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card {
  width: 100%; max-width: 420px; padding: clamp(1.5rem, 5vw, 2.5rem);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.auth-card h1 { font-size: 1.85rem; margin: 1.5rem 0 .5rem; }
.auth-alt { margin-top: 1.25rem; text-align: center; color: var(--muted); font-size: .95rem; }
.auth-card > .btn { margin-top: 1.25rem; }

/* ---- account ---- */
.account { max-width: 620px; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) 1rem 4rem; }
.account h1 { font-size: 2.1rem; margin-bottom: 1.5rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: clamp(1.1rem, 4vw, 1.75rem); margin-bottom: 1.25rem; }
.panel h2 { font-size: 1.25rem; margin-bottom: .85rem; }
.panel progress + p { margin-top: .6rem; }
.panel input { background: var(--bg); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

/* ---- library ---- */
.library { max-width: 1500px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); padding-bottom: 6rem; }
.confirm-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1.25rem;
  padding: .85rem 1.1rem; margin-bottom: 1.25rem;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 10px;
}
.confirm-banner form .btn { margin-top: 0; }

.library-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.library-head h1 { font-size: clamp(1.7rem, 3.5vw, 2.4rem); overflow-wrap: anywhere; }
.usage { display: flex; align-items: center; gap: .75rem; margin-top: .55rem; font-size: .88rem; }
.usage progress { width: 130px; flex: none; }
.library-actions { display: flex; gap: .6rem; }
.library-actions label { margin: 0; font-size: 1rem; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1.5rem; margin: 1.35rem 0 1rem; }
.filters { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.filters button {
  flex: none; min-height: 38px; padding: .3rem .8rem;
  background: none; border: 0; border-radius: 999px;
  color: var(--muted); font: inherit; font-weight: 500; cursor: pointer;
}
.filters button:hover { color: var(--text); }
.filters button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.filters span { opacity: .7; font-size: .85em; margin-left: .15rem; font-variant-numeric: tabular-nums; }
.toolbar input[type="search"] { width: min(100%, 280px); min-height: 38px; }

.message { padding: 1rem; color: var(--err-text); background: var(--err-bg); border-radius: 8px; margin-bottom: 1rem; }

.empty { text-align: center; padding: clamp(3rem, 10vw, 7rem) 1rem; border: 2px dashed var(--line); border-radius: 16px; }
.empty img { border-radius: 12px; }
.empty h2 { font-size: 1.6rem; margin: 1rem 0 .4rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(105px, 18vw, 210px), 1fr)); gap: 5px; }

.tile {
  position: relative; display: block; width: 100%; aspect-ratio: 1; padding: 0; overflow: hidden;
  background: var(--surface-2); border: 0; border-radius: 4px; color: var(--muted); cursor: pointer;
}
.tile img, .tile video { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tile:hover img, .tile:hover video { opacity: .92; }
.tile-video::before {
  content: "▶"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.7rem; opacity: .55;
}
.tile-video video { position: relative; }
.tile-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem;
  width: 100%; height: 100%; font-size: .78rem; letter-spacing: .05em; text-transform: uppercase;
}
.tile-fallback b { font-size: 1.6rem; font-weight: 400; }
.tile-badge, .tile-star {
  position: absolute; bottom: 6px; padding: 1px 6px; border-radius: 4px;
  background: rgba(0,0,0,.62); color: #fff; font-size: .8rem; line-height: 1.5; pointer-events: none;
}
.tile-badge { left: 6px; }
.tile-star { right: 6px; color: #f6c869; }
.tile-check {
  position: absolute; top: 7px; left: 7px; width: 24px; height: 24px;
  border: 2px solid #fff; border-radius: 50%; background: rgba(0,0,0,.35);
  color: transparent; font-size: .85rem; line-height: 20px; text-align: center; pointer-events: none;
}
.grid:not(.selecting) .tile-check { display: none; }
.tile[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile[aria-pressed="true"] .tile-check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.load-more { height: 1px; }

.selection-bar {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 1.25rem;
  width: min(calc(100vw - 2rem), 460px); padding: .6rem .6rem .6rem 1.1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.selection-bar > div { display: flex; gap: .4rem; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(20,18,16,.82); color: #fff; pointer-events: none;
  font-family: Georgia, "Iowan Old Style", serif; font-size: clamp(1.6rem, 4vw, 2.6rem);
  outline: 3px dashed #e8a33d; outline-offset: -18px;
}

.upload-tray {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 40;
  width: min(calc(100vw - 2rem), 360px); padding: .85rem 1rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.upload-tray-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-height: 32px; }
.upload-tray .icon-btn { min-width: 30px; min-height: 30px; border: 0; }
.progress-track { height: 6px; margin: .55rem 0; border-radius: 3px; overflow: hidden; background: var(--surface-2); }
.progress-fill { width: 0; height: 100%; background: var(--accent); transition: width .2s; }
.upload-note { font-size: .86rem; }
.failed-list { list-style: none; max-height: 130px; overflow-y: auto; margin: .5rem 0 0; padding: 0; color: var(--err-text); font-size: .85rem; overflow-wrap: anywhere; }
.failed-list li { margin-bottom: .25rem; }
#retryFailed { margin-top: .6rem; }

/* ---- viewer ---- */
.viewer {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: #0c0b0a; color: #f3eee6; overflow: hidden;
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer::backdrop { background: #0c0b0a; }
.viewer-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; touch-action: pan-y; }
.viewer-media { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: clamp(0px, 2vw, 1.25rem); }
.viewer-media img, .viewer-media video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.viewer-fallback { text-align: center; padding: 2rem; color: #c9c0b4; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 48px; height: 72px;
  background: rgba(0,0,0,.45); border: 0; border-radius: 8px; color: #fff; font-size: 2rem; line-height: 1; cursor: pointer;
}
.viewer-nav:hover { background: rgba(0,0,0,.7); }
.viewer-nav:disabled { display: none; }
.viewer-prev { left: .6rem; }
.viewer-next { right: .6rem; }
.viewer-panel {
  flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem 1rem; align-items: center;
  padding: .7rem clamp(.75rem, 3vw, 1.5rem) calc(.7rem + env(safe-area-inset-bottom));
  background: #1a1815; border-top: 1px solid #36312b;
  --text: #f3eee6; --muted: #b0a699; --line: #4a443c; --surface-2: #2a2622; --bg: #141210; --danger: #f0796c; --accent: #e8a33d; --accent-hi: #f3b75c; --on-accent: #1b1712;
}
.viewer-panel input { min-height: 40px; border-color: transparent; background: transparent; color: #f3eee6; padding-left: .4rem; }
.viewer-panel input:hover, .viewer-panel input:focus { border-color: var(--line); background: var(--bg); }
.viewer-name { grid-row: 2; font-size: .82rem; padding-left: .4rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: center; gap: .4rem; }
.viewer-actions .icon-btn { color: #f3eee6; }
.viewer-actions .icon-btn[aria-pressed="true"] { color: #f6c869; border-color: #f6c869; }
.logout-form .btn { margin-top: .5rem; }

@media (max-width: 800px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-art { width: min(100%, 440px); margin: 0 auto; }
  .features { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .wordmark { gap: .4rem; }
  .wordmark span { font-size: .92rem; }
  .wordmark img { width: 22px; height: 22px; }
  .site-nav { gap: .5rem; padding-left: .75rem; padding-right: .75rem; }
  .site-nav nav { gap: .5rem; }
  .site-nav .btn-small { padding: .3rem .6rem; }
  .site-nav .icon-btn { min-width: 36px; }
  .toolbar input[type="search"] { width: 100%; }
  .viewer-panel { grid-template-columns: minmax(0, 1fr); }
  .viewer-actions { grid-column: 1; grid-row: auto; flex-wrap: wrap; margin-top: .3rem; }
  .viewer-nav { width: 40px; height: 60px; }
  .field-pair { grid-template-columns: 1fr; }
}

/* The logged-in menu has more in it, so it runs out of room sooner. */
@media (max-width: 460px) {
  .site-nav-user .wordmark span { display: none; }
}

@media (max-width: 360px) {
  .wordmark span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
