:root {
  color-scheme: dark;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-synthesis: none;
  --ink: #f7f9fc;
  --muted: #9dadc1;
  --surface: #101d2d;
  --surface-strong: #17273a;
  --line: #2b3d52;
  --accent: #70d6ff;
  --saved: #7ce2b8;
  --danger: #ff9b9b;
  background: #07111f;
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 10% -10%, rgba(37, 137, 182, 0.24), transparent 38rem),
    #07111f;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.85rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.85rem
    max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(134, 165, 196, 0.2);
  background: rgba(7, 17, 31, 0.88);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 1.75rem);
  line-height: 1.2;
}

.summary {
  display: grid;
  min-width: 4.5rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  background: var(--surface);
  text-align: center;
}

.summary strong {
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
}

.summary span {
  margin-top: 0.22rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.gallery {
  display: grid;
  gap: clamp(1rem, 4vw, 1.6rem);
  width: min(100%, 72rem);
  margin-inline: auto;
  padding: 1rem max(0.75rem, env(safe-area-inset-right)) max(3rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
}

.image-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: linear-gradient(145deg, rgba(23, 39, 58, 0.98), rgba(13, 27, 43, 0.98));
  box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.22);
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 4rem;
  padding: 0.8rem 0.9rem;
}

.card-heading > div {
  min-width: 0;
}

.sequence {
  display: block;
  margin-bottom: 0.16rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.filename {
  overflow: hidden;
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-status {
  flex: 0 0 auto;
  padding: 0.32rem 0.55rem;
  border-radius: 99rem;
  background: rgba(124, 226, 184, 0.11);
  color: var(--saved);
  font-size: 0.78rem;
  font-weight: 700;
}

.save-status[data-state="dirty"],
.save-status[data-state="saving"] {
  background: rgba(112, 214, 255, 0.1);
  color: var(--accent);
}

.save-status[data-state="error"] {
  background: rgba(255, 155, 155, 0.1);
  color: var(--danger);
}

.image-frame {
  display: grid;
  place-items: center;
  min-height: 8rem;
  border-block: 1px solid var(--line);
  background: #03070d;
}

.image-frame img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 82vh;
  object-fit: contain;
}

.note-label {
  display: grid;
  gap: 0.55rem;
  padding: 0.9rem;
}

.note-label > span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 8rem;
  max-height: 60vh;
  resize: vertical;
  padding: 0.85rem;
  border: 1px solid #3b526c;
  border-radius: 0.8rem;
  outline: none;
  background: rgba(4, 13, 23, 0.72);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.65;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

textarea::placeholder {
  color: #718198;
}

textarea:focus {
  border-color: var(--accent);
  background: #071523;
  box-shadow: 0 0 0 3px rgba(112, 214, 255, 0.14);
}

.loading,
.empty,
.fatal-error {
  display: grid;
  place-items: center;
  min-height: 45vh;
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (min-width: 760px) {
  .topbar {
    padding-inline: max(2rem, calc((100vw - 72rem) / 2));
  }

  .gallery {
    padding: 1.5rem 1.5rem 4rem;
  }

  .card-heading,
  .note-label {
    padding-inline: 1.2rem;
  }
}

/* Keep the image and its note together when there is room beside it.  The
   landscape clause also covers phones turned sideways. */
@media (min-width: 760px), ((orientation: landscape) and (min-width: 560px)) {
  .image-card {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(15rem, 1fr);
    align-items: stretch;
  }

  .card-heading {
    grid-column: 1 / -1;
  }

  .image-frame {
    border-block: 1px solid var(--line);
    border-inline-end: 1px solid var(--line);
  }

  .image-frame img {
    max-height: min(72vh, 44rem);
  }

  .note-label {
    align-content: start;
    padding: 1.2rem;
  }

  textarea {
    min-height: 14rem;
    max-height: none;
    height: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .spinner {
    animation-duration: 1.8s;
  }
}
