/* ————— Grain Ledger — design tokens ————— */
:root {
  color-scheme: light;
  --paper: #f3efe6;
  --paper-deep: #eae4d6;
  --ink: #22201b;
  --ink-soft: #57534a;
  --ink-faint: #8a857a;
  --line: #d9d2c2;
  --amber: #b3541e;
  --amber-deep: #8f3f12;
  --dark: #191712;
  --dark-2: #211e18;
  --cream-on-dark: #efe8d8;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 14px;
  --shadow: 0 18px 40px -18px rgba(25, 20, 10, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(179, 84, 30, 0.07), transparent 60%),
    var(--paper);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* ————— Masthead ————— */
.masthead { border-bottom: 1px solid var(--line); background: rgba(243, 239, 230, 0.9); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px); }
.masthead__inner {
  max-width: 72rem; margin: 0 auto; padding: 0.9rem 1.5rem;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--ink); text-decoration: none; }
.brand__mark { width: 1.7rem; height: 1.7rem; color: var(--amber); align-self: center; }
.brand__word { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; letter-spacing: -0.01em; }
.brand__word em { font-style: italic; font-weight: 400; color: var(--amber); }
.masthead__tag { margin: 0; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }

main { max-width: 72rem; margin: 0 auto; padding: 0 1.5rem 5rem; }

/* ————— Hero ————— */
.hero {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 2.5rem;
  align-items: end; padding: 3.5rem 0 2.5rem;
}
.hero__eyebrow { margin: 0 0 0.75rem; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--amber); }
.hero h1 {
  margin: 0 0 0.9rem; font-family: var(--serif); font-weight: 500;
  font-size: clamp(2.1rem, 4.5vw, 3.4rem); line-height: 1.08; letter-spacing: -0.015em;
}
.hero__lede { margin: 0; max-width: 34rem; color: var(--ink-soft); font-size: 1.05rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 0; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stat { background: var(--paper-deep); padding: 1.1rem 1.2rem; }
.stat dt { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); }
.stat dd { margin: 0.25rem 0 0; font-family: var(--serif); font-size: 2rem; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }

/* ————— Uploader ————— */
.dropzone {
  border: 2px dashed #c4bba6; border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
  padding: 2.6rem 1.5rem; text-align: center; cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  outline-offset: 4px;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--amber); background: rgba(255, 255, 255, 0.7); }
.dropzone.is-dragover { border-color: var(--amber); background: #fff8ed; transform: scale(1.005); }
.dropzone__icon { width: 3rem; height: 3rem; color: var(--amber); margin-bottom: 0.4rem; }
.dropzone__title { margin: 0; font-family: var(--serif); font-size: 1.4rem; font-weight: 500; }
.dropzone__hint { margin: 0.3rem 0 0; color: var(--ink-soft); font-size: 0.92rem; }
.dropzone__browse { color: var(--amber-deep); text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }
.uploader__status { min-height: 1.4rem; margin: 0.6rem 0 0; font-family: var(--mono); font-size: 0.78rem; color: var(--ink-faint); }

/* ————— Toolbar ————— */
.collection { margin-top: 2.5rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: center; justify-content: space-between; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.toolbar__title { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 1.6rem; }
.toolbar__controls { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.field { position: relative; }
.field input, .field select {
  font: 500 0.88rem var(--sans); color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 0.5rem 1rem; appearance: none; -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field select { padding-right: 2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2357534a' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.8rem center; cursor: pointer; }
.field input:focus-visible, .field select:focus-visible, .form-field input:focus-visible, .form-field textarea:focus-visible { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(179, 84, 30, 0.18); }
.field--search input { padding-left: 2.2rem; min-width: 15rem; }
.field__icon { position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%); width: 0.95rem; height: 0.95rem; color: var(--ink-faint); pointer-events: none; }

.collection__count { margin: 0.9rem 0 0; font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); }

/* ————— Gallery ————— */
.gallery {
  list-style: none; margin: 1.25rem 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr)); gap: 1.4rem;
}
.frame-card {
  background: var(--dark); border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex; flex-direction: column;
}
.frame-card:hover { transform: translateY(-4px); box-shadow: 0 26px 50px -20px rgba(25, 20, 10, 0.5); }
.frame-card__button { all: unset; cursor: pointer; display: flex; flex-direction: column; width: 100%; }
.frame-card__button:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; border-radius: 10px; }
.frame-card__sprockets {
  display: flex; justify-content: space-between; padding: 0.35rem 0.6rem;
}
.frame-card__sprockets i { width: 0.45rem; height: 0.3rem; border-radius: 2px; background: #3a352b; }
.frame-card__media { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: var(--dark-2); }
.frame-card__media img { width: 100%; height: 100%; object-fit: cover; display: block; filter: saturate(0.96); transition: transform 0.35s ease; }
.frame-card:hover .frame-card__media img { transform: scale(1.03); }
.frame-card__no {
  position: absolute; top: 0.5rem; right: 0.6rem;
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em;
  color: var(--amber); background: rgba(15, 13, 9, 0.72); padding: 0.15rem 0.45rem; border-radius: 4px;
}
.frame-card__caption { padding: 0.7rem 0.85rem 0.85rem; color: var(--cream-on-dark); }
.frame-card__camera { margin: 0; font-family: var(--serif); font-size: 1.02rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frame-card__film { margin: 0.2rem 0 0; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: #a49c8a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ————— Empty states ————— */
.empty { text-align: center; padding: 4rem 1rem 3rem; color: var(--ink-soft); }
.empty__strip { width: 7.5rem; color: #c2b9a2; margin-bottom: 0.8rem; }
.empty__title { margin: 0 0 0.35rem; font-family: var(--serif); font-weight: 500; font-size: 1.5rem; color: var(--ink); }
.empty__text { margin: 0; }
.link-button { border: none; background: none; padding: 0; font: inherit; color: var(--amber-deep); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ————— Buttons ————— */
.button {
  font: 600 0.9rem var(--sans); border-radius: 999px; padding: 0.6rem 1.3rem;
  border: 1px solid transparent; cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.button--primary { background: var(--ink); color: var(--paper); }
.button--primary:hover { background: var(--amber-deep); }
.button--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.button--ghost:hover { border-color: var(--ink-faint); }
.button--danger { background: transparent; color: #a1341f; border-color: rgba(161, 52, 31, 0.4); }
.button--danger:hover { background: #a1341f; color: #fff; border-color: #a1341f; }
.button:focus-visible { outline: 3px solid rgba(179, 84, 30, 0.4); outline-offset: 2px; }

/* ————— Develop dialog ————— */
.dialog { border: none; border-radius: var(--radius); padding: 0; max-width: 40rem; width: calc(100vw - 2.5rem); background: var(--paper); color: var(--ink); box-shadow: 0 40px 80px -30px rgba(0,0,0,0.5); }
.dialog::backdrop, .lightbox::backdrop { background: rgba(20, 17, 11, 0.72); backdrop-filter: blur(3px); }
.dialog__body { padding: 1.8rem 1.8rem 1.5rem; }
.dialog__head h2 { margin: 0 0 0.3rem; font-family: var(--serif); font-weight: 500; font-size: 1.6rem; }
.dialog__sub { margin: 0 0 1.1rem; color: var(--ink-soft); font-size: 0.92rem; }
.develop-thumbs { list-style: none; display: flex; gap: 0.5rem; padding: 0; margin: 0 0 1.2rem; overflow-x: auto; }
.develop-thumbs img { width: 4.2rem; height: 4.2rem; object-fit: cover; border-radius: 8px; border: 2px solid var(--dark); display: block; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.form-field { display: flex; flex-direction: column; gap: 0.3rem; }
.form-field--small { }
.form-field--wide { grid-column: 1 / -1; }
.form-field label { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.form-field input, .form-field textarea {
  font: 400 0.95rem var(--sans); color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s; resize: vertical;
}
.dialog__actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.4rem; }

/* ————— Lightbox ————— */
.lightbox { border: none; background: transparent; padding: 0; max-width: none; max-height: none; width: 100vw; height: 100dvh; margin: 0; display: none; }
.lightbox[open] { display: grid; place-items: center; }
.lightbox__figure {
  margin: 0; display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(17rem, 1fr);
  max-width: 66rem; width: calc(100vw - 6.5rem); max-height: calc(100dvh - 4rem);
  background: var(--dark); border-radius: var(--radius); overflow: hidden; box-shadow: 0 40px 90px -30px rgba(0,0,0,0.8);
}
.lightbox__figure img { width: 100%; height: 100%; max-height: calc(100dvh - 4rem); object-fit: contain; background: #0e0c09; display: block; }
.lightbox__panel { padding: 1.6rem 1.5rem; color: var(--cream-on-dark); overflow-y: auto; }
.lightbox__frame-no { margin: 0 0 0.4rem; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.14em; color: var(--amber); }
.lightbox__camera { margin: 0 0 1rem; font-family: var(--serif); font-weight: 500; font-size: 1.5rem; line-height: 1.15; }
.lightbox__meta { margin: 0 0 1rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; border-top: 1px solid #35permit302a; }
.lightbox__meta div { border-top: 1px solid #353026; padding-top: 0.55rem; }
.lightbox__meta dt { font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.12em; text-transform: uppercase; color: #9a927e; }
.lightbox__meta dd { margin: 0.15rem 0 0; font-size: 0.92rem; }
.lightbox__notes { margin: 0 0 1.2rem; font-size: 0.92rem; color: #cfc7b4; font-style: italic; }
.lightbox__actions { display: flex; gap: 0.55rem; flex-wrap: wrap; }
.lightbox__actions .button--ghost { color: var(--cream-on-dark); border-color: #4a4436; }
.lightbox__actions .button--ghost:hover { border-color: #8a8270; }
.lightbox__edit { display: flex; flex-direction: column; gap: 0.8rem; }
.lightbox__edit .form-field input, .lightbox__edit .form-field textarea { background: #2a261e; border-color: #4a4436; color: var(--cream-on-dark); }
.lightbox__edit .form-field label { color: #9a927e; }

.lightbox__close, .lightbox__nav {
  position: fixed; z-index: 5; border: none; cursor: pointer;
  background: rgba(243, 239, 230, 0.12); color: #f3efe6;
  width: 2.6rem; height: 2.6rem; border-radius: 50%; font-size: 1.1rem;
  display: grid; place-items: center; transition: background 0.15s;
}
.lightbox__close:hover, .lightbox__nav:hover { background: rgba(243, 239, 230, 0.28); }
.lightbox__close { top: 1rem; right: 1.1rem; }
.lightbox__nav--prev { left: 0.8rem; top: 50%; transform: translateY(-50%); }
.lightbox__nav--next { right: 0.8rem; top: 50%; transform: translateY(-50%); }

/* ————— Toast ————— */
.toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); font-size: 0.88rem; font-weight: 500;
  padding: 0.65rem 1.2rem; border-radius: 999px; box-shadow: var(--shadow); z-index: 50;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 0.6rem); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ————— Footer ————— */
.footer { border-top: 1px solid var(--line); padding: 1.6rem 1.5rem 2.2rem; text-align: center; }
.footer p { margin: 0; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.06em; color: var(--ink-faint); }

/* ————— Responsive ————— */
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 1.6rem; padding-top: 2.4rem; }
  .lightbox__figure { grid-template-columns: 1fr; width: calc(100vw - 2rem); overflow-y: auto; }
  .lightbox__figure img { max-height: 48dvh; }
  .lightbox__nav { display: none; }
}
@media (max-width: 600px) {
  .masthead__tag { display: none; }
  .toolbar__controls { width: 100%; }
  .field--search { flex: 1 1 100%; }
  .field--search input { width: 100%; min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat { padding: 0.8rem 0.7rem; }
  .stat dd { font-size: 1.5rem; }
}

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