/* pixsz — mobile-first photo upload
   Layout is built around thumb reach: destructive/primary actions live at the
   bottom of the screen, chrome at the top. */

:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-sunken: #eceef2;
  --fg: #12151c;
  --fg-dim: #5b6272;
  --line: #dfe3ea;
  --accent: #3b6ef6;
  --accent-fg: #ffffff;
  --danger: #d63a3a;
  --ok: #1f9d55;
  --warn: #b8770b;
  --radius: 14px;
  --tap: 44px;
  --topbar-h: 56px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 8px 24px rgba(16, 20, 30, .08);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f14;
    --bg-elev: #171a21;
    --bg-sunken: #05070a;
    --fg: #eef1f6;
    --fg-dim: #949cad;
    --line: #262b35;
    --accent: #6d95ff;
    --accent-fg: #07101f;
    --danger: #ff6b6b;
    --ok: #4ad07f;
    --warn: #e2a53a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

/* Several components set an explicit `display`, which would otherwise beat the
   UA's `[hidden] { display: none }` rule and leave invisible panels swallowing
   taps across the whole screen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  min-height: 100svh;
  /* Chrome shouldn't rubber-band away from the sticky bars. */
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll { overflow: hidden; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.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;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: var(--safe-t);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
}

.brand { display: flex; align-items: center; gap: 9px; margin-right: auto; min-width: 0; }
.brand h1 { font-size: 19px; }

.brand-mark {
  width: 22px; height: 22px;
  border-radius: 7px;
  background: linear-gradient(140deg, #6d95ff, #b06dff 55%, #ff7a9c);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
  flex: none;
}

.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  min-width: var(--tap);
  height: var(--tap);
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn:active { background: var(--bg-sunken); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.icon-btn.light { color: #fff; }
.icon-btn.danger { color: var(--danger); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--fg-dim);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--fg-dim);
  flex: none;
}

.pill[data-state="ok"] .dot { background: var(--ok); }
.pill[data-state="busy"] .dot { background: var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.pill[data-state="err"] .dot { background: var(--danger); }

@keyframes pulse { 50% { opacity: .25; } }

/* selection bar replaces the action bar contextually */
.selbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
  border-top: 1px solid var(--line);
}

.selcount { margin-right: auto; font-weight: 600; font-size: 14px; }

.ghost {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  padding: 10px 8px;
  min-height: var(--tap);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.ghost.small { min-height: 34px; padding: 4px 8px; font-size: 13px; }
.ghost.danger { color: var(--danger); }
.ghost:disabled { opacity: .4; }

/* ---------- main ---------- */

main {
  padding: 10px calc(10px + var(--safe-r)) calc(96px + var(--safe-b)) calc(10px + var(--safe-l));
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}

@media (min-width: 520px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 6px; } }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(5, 1fr); gap: 8px; } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(7, 1fr); } }

.cell {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-sunken);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .22s ease;
  -webkit-user-drag: none;
  pointer-events: none;
}

.cell img.ready { opacity: 1; }

/* The badge is a sync indicator, so it stays out of the way entirely when
   there's no sync to report — i.e. local-only photos, which is every photo
   until GitHub is configured. */
.cell .badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: none;
  place-items: center;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .12);
}

.cell .badge svg { width: 11px; height: 11px; stroke-width: 2.6; display: none; }

.cell[data-status="synced"] .badge,
.cell[data-status="queued"] .badge,
.cell[data-status="uploading"] .badge,
.cell[data-status="error"] .badge { display: grid; }

.cell[data-status="synced"] .g-check,
.cell[data-status="queued"] .g-up,
.cell[data-status="uploading"] .g-up,
.cell[data-status="error"] .g-warn { display: block; }

.cell[data-status="queued"] .badge { background: rgba(0, 0, 0, .38); }
.cell[data-status="uploading"] .badge { background: var(--warn); color: #1b1300; animation: pulse 1.1s ease-in-out infinite; }
.cell[data-status="error"] .badge { background: var(--danger); color: #fff; }

.cell .check {
  position: absolute;
  inset: 0;
  background: rgba(59, 110, 246, .32);
  display: none;
  place-items: start end;
  padding: 5px;
}

.cell .check span {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .8);
}

.cell .check span svg { width: 13px; height: 13px; stroke-width: 3; }

body.selecting .cell .check { display: grid; background: transparent; }
body.selecting .cell .check span { background: transparent; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .9); color: transparent; }
body.selecting .cell[aria-selected="true"] .check { background: rgba(59, 110, 246, .32); }
body.selecting .cell[aria-selected="true"] .check span { background: var(--accent); color: var(--accent-fg); box-shadow: 0 0 0 2px rgba(255, 255, 255, .8); }
body.selecting .cell[aria-selected="true"] img { transform: scale(.9); transition: transform .12s ease; }

/* ---------- queue ---------- */

.queue {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.queue-head { display: flex; align-items: center; gap: 8px; }
.queue-head strong { margin-right: auto; font-size: 14px; }

.progress {
  height: 5px;
  border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
  margin-top: 9px;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width .25s ease;
}

.queue-errors {
  list-style: none;
  margin: 9px 0 0;
  padding: 0;
  font-size: 12.5px;
  color: var(--danger);
  display: grid;
  gap: 4px;
}

.queue-errors:empty { display: none; }
.queue-errors li { overflow-wrap: anywhere; }

/* ---------- empty state ---------- */

.empty { text-align: center; padding: 56px 22px; color: var(--fg-dim); }
.empty h2 { font-size: 17px; color: var(--fg); margin-bottom: 6px; }
.empty p { margin: 0; font-size: 14px; max-width: 34ch; margin-inline: auto; }
.empty-art svg { width: 68px; height: 68px; stroke-width: 1.4; opacity: .38; margin-bottom: 12px; }

.grid-end { text-align: center; color: var(--fg-dim); font-size: 12.5px; padding: 18px 0 4px; }

/* ---------- bottom action bar ---------- */

.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  display: flex;
  gap: 10px;
  padding: 10px calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

body.selecting .actionbar { display: none; }

/* On a phone the bar spans the screen so the primary action is a thumb-wide
   target. On a desktop that reads as a banner, so cap and centre it. */
@media (min-width: 720px) {
  .actionbar {
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: 18px;
    background: none;
  }
  .actionbar .btn { box-shadow: 0 4px 24px rgba(16, 20, 30, .18); }
}

.btn {
  flex: none;
  min-height: 50px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow);
  -webkit-user-select: none;
  user-select: none;
}

.btn:active { transform: translateY(1px); }
.btn.primary { flex: 1; background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- dropzone ---------- */

.dropzone {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(3px);
}

.dropzone div {
  border: 2px dashed var(--accent);
  border-radius: 20px;
  padding: 40px 54px;
  font-weight: 650;
  color: var(--accent);
}

/* ---------- lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

.lb-track {
  display: flex;
  height: 100%;
  will-change: transform;
}

.lb-slide {
  flex: 0 0 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: calc(58px + var(--safe-t)) 0 calc(58px + var(--safe-b));
}

.lb-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Without this the browser starts a native image drag, which cancels the
     pointer stream mid-swipe and strands the track. */
  -webkit-user-drag: none;
  pointer-events: none;
}

.lb-slide .spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
}

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

.lb-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(var(--safe-t) + 4px) calc(6px + var(--safe-r)) 4px calc(6px + var(--safe-l));
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .62), transparent);
  color: #fff;
}

.lb-top-right { margin-left: auto; display: flex; gap: 2px; }
.lb-index { font-size: 13px; font-weight: 600; opacity: .85; margin-left: 4px; }

.lb-foot {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l));
  background: linear-gradient(to top, rgba(0, 0, 0, .78), transparent);
}

.lb-meta {
  color: rgba(255, 255, 255, .8);
  font-size: 12.5px;
  text-align: center;
  pointer-events: none;
}

/* Captions are edited here rather than in a separate screen: the moment you're
   looking at a photo is the only moment you know what to call it. */
.lb-edit { display: grid; gap: 6px; margin-bottom: 10px; }

.lb-edit input,
.lb-edit textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 11px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font: 16px/1.35 inherit;
  resize: none;
}

.lb-edit textarea { font-size: 15px; }
.lb-edit input::placeholder, .lb-edit textarea::placeholder { color: rgba(255, 255, 255, .45); }
.lb-edit input:focus, .lb-edit textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: rgba(0, 0, 0, .5); }
.lb-edit[hidden] { display: none; }

.brand-out {
  display: inline-grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 9px;
  color: var(--fg-dim);
  text-decoration: none;
}

.brand-out svg { width: 17px; height: 17px; }
.brand-out:active { background: var(--bg-sunken); }

/* ---------- settings sheet ---------- */

.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, .45);
}

.sheet {
  position: fixed;
  z-index: 81;
  left: 0; right: 0; bottom: 0;
  max-height: 88svh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .35);
  animation: sheet-in .24s cubic-bezier(.22, 1, .36, 1);
}

@keyframes sheet-in { from { transform: translateY(100%); } }

@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: 560px;
    transform: translate(-50%, -50%);
    border-radius: 18px;
    max-height: 84svh;
    animation: none;
  }
}

.sheet-grip {
  width: 38px; height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 8px auto 0;
}

@media (min-width: 720px) { .sheet-grip { display: none; } }

.sheet-head {
  display: flex;
  align-items: center;
  padding: 10px 10px 6px 18px;
}

.sheet-head h2 { font-size: 18px; margin-right: auto; }

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 18px calc(24px + var(--safe-b));
}

.field-group {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.field-group:first-child { border-top: 0; padding-top: 4px; }
.field-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-dim); margin-bottom: 10px; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--fg-dim);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}

.tag[data-on="1"] { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); }

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 0;
  min-height: var(--tap);
}

.row > span { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.row small, .help { color: var(--fg-dim); font-size: 12.5px; }
.help { margin: 0 0 10px; line-height: 1.5; }
.help.warn { color: var(--warn); }

.stack { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.stack > span { font-size: 12.5px; font-weight: 600; color: var(--fg-dim); }
.two-up { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input[type="text"], input[type="password"] {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  color: var(--fg);
  /* 16px keeps iOS Safari from zooming the viewport on focus. */
  font: 16px/1.3 inherit;
}

input[type="text"]:focus, input[type="password"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

input[type="range"] { flex: 0 0 140px; accent-color: var(--accent); height: var(--tap); }
.switch { width: 46px; height: 28px; accent-color: var(--accent); flex: none; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1 1 auto; min-height: var(--tap); font-size: 14px; }

.status { min-height: 18px; margin: 10px 0 0; font-size: 12.5px; color: var(--fg-dim); overflow-wrap: anywhere; }
.status[data-kind="ok"] { color: var(--ok); }
.status[data-kind="err"] { color: var(--danger); }

.footnote { color: var(--fg-dim); font-size: 12px; text-align: center; margin: 18px 0 0; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 11px 16px;
  border-radius: 12px;
  background: #12151c;
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
  animation: toast-in .2s ease;
}

@media (prefers-color-scheme: dark) { .toast { background: #2a303c; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
