/* Ink on e-ink paper: the page borrows the frame's own palette, so the only
   imagery — dithered photos — reads as it will on the wall. */
:root {
  --paper: #E4E5E1;
  --ink: #000;
  --graphite: #55565A;
  --rule: #C3C4BF;
  --wash: rgba(228, 229, 225, 0.78);
  --danger: #8E1B12;
  --gutter: 16px;
  --bar-h: 54px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--paper); min-height: 100dvh; }
[hidden] { display: none !important; }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) var(--gutter)
           calc(env(safe-area-inset-bottom) + var(--bar-h) + 40px);
}

h1 {
  font-size: 34px;
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.lede {
  margin-top: 10px;
  font-size: 16px;
  line-height: 1.45;
  color: var(--graphite);
  max-width: 34em;
}

.sub {
  font-size: 15px;
  font-weight: 600;
  margin: 22px 0 10px;
}

.empty {
  margin-top: 40px;
  font-size: 17px;
  line-height: 1.45;
  max-width: 24em;
}

/* Library grid — thumbnails at the frame's own shape and corner radius. */
.grid {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 12px;
  margin-top: 28px;
}

.grid li { position: relative; }

.grid button {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 7px;
}

.grid canvas,
.preview {
  display: block;
  width: 100%;
  aspect-ratio: 783 / 380;
  border-radius: 4.1% / 8.4%;   /* the frame's 32px corner on a 783×380 slot */
  background: var(--rule);
}

/* An upload in flight: progress as an ink rule under the thumbnail. */
.grid .progress {
  height: 3px;
  margin-top: 6px;
  background: var(--rule);
  border-radius: 2px;
  overflow: hidden;
}

.grid .progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ink);
  transition: width 0.2s linear;
}

.grid .failed {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.3;
  color: var(--danger);
}

/* Bottom action bar, thumb-reachable and clear of the home indicator. */
.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 10px;
  /* Content width on a wide screen, the gutter on a phone. */
  padding: 12px max(var(--gutter), calc(50% - 264px)) calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to top, var(--paper) 70%, rgba(228, 229, 225, 0));
}

.bar > * { flex: 1; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--bar-h);
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.btn.primary { background: var(--ink); color: var(--paper); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger.armed { background: var(--danger); color: var(--paper); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn:focus-visible,
.link:focus-visible,
.grid button:focus-visible,
.stage:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* Editor */
.ed-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  color: var(--graphite);
  margin-bottom: 14px;
  min-height: 24px;
}

.link {
  border: 0;
  background: none;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 0;
}

.stage {
  position: relative;
  margin: 0 calc(-1 * var(--gutter));
  height: min(80vw, 440px);
  touch-action: none;
  cursor: grab;
  overflow: hidden;
}

.stage:active { cursor: grabbing; }
.stage canvas { display: block; width: 100%; height: 100%; }

.hint {
  margin-top: 10px;
  font-size: 14px;
  color: var(--graphite);
  text-align: center;
}

.error {
  margin-top: 14px;
  font-size: 15px;
  line-height: 1.4;
  color: var(--danger);
}

/* Sheet: one photo, larger. */
.sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--paper);
  border-radius: 22px 22px 0 0;
  padding: 8px var(--gutter) calc(env(safe-area-inset-bottom) + var(--bar-h) + 36px);
  animation: rise 0.22s ease-out;
}

.sheet .bar { position: absolute; background: none; }

.meta {
  margin-top: 12px;
  font-size: 14px;
  color: var(--graphite);
}

@keyframes rise { from { transform: translateY(40%); opacity: 0; } }

.locked p {
  margin-top: 14px;
  font-size: 17px;
  line-height: 1.45;
  max-width: 24em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + var(--bar-h) + 30px);
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .toast, .grid .progress span { transition: none; }
}
