/* Atelier — a darkroom on a phone. Graphite room, photo-paper white for text and the one
   main button, grease-pencil red only for marks (picked, starred, delete). The gallery is
   a contact sheet: numbered frames, picks circled in red. */

@font-face {
  font-family: 'Instrument Sans';
  src: url('fonts/instrument-sans-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-display: swap;
}

:root {
  --graphite: #1d1c1b;
  --sheet: #262422;
  --raise: #2f2d2a;
  --line: #3b3834;
  --paper: #efe9df;
  --dim: #a39d93;
  --faint: #756f67;
  --pencil: #e5483a;
  --tabbar: 58px;
  --gap: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--graphite); }
body {
  margin: 0; background: var(--graphite); color: var(--paper);
  font: 400 16px/1.45 'Instrument Sans', system-ui, sans-serif;
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
body.veil #app, body.veil #viewer, body.veil #sheet { filter: blur(30px); }

h2 { font-size: 19px; font-weight: 600; margin: 34px 0 6px; letter-spacing: -0.01em; }
h2:first-child { margin-top: 12px; }
p { margin: 0; }
.note { color: var(--dim); font-size: 13.5px; line-height: 1.45; margin-top: 6px; }
.dim { color: var(--faint); font-weight: 400; }
.msg { color: var(--dim); font-size: 13.5px; min-height: 0; white-space: pre-wrap; }
.msg:empty { display: none; }
.msg.err { color: var(--pencil); }
.help p { color: var(--dim); font-size: 13.5px; margin-top: 8px; overflow-wrap: anywhere; }
.help a { color: var(--paper); }

.wordmark { font-stretch: 75%; font-weight: 650; font-size: 44px; letter-spacing: 0.01em; line-height: 1; margin: 0 0 18px; }
.wordmark.small { font-size: 19px; margin: 0; }

/* ---- controls ------------------------------------------------------------------- */

button, .button, select, input, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; background: var(--sheet); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; outline: none;
}
textarea { resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--faint); }
select { appearance: none; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--dim); }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, opacity .12s;
}
button:active, .button:active { background: var(--raise); }
button:disabled { opacity: .45; }
:focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }
.primary { background: var(--paper); color: var(--graphite); border-color: var(--paper); font-weight: 600; }
.primary:active { background: #d9d2c6; }
.quiet { border-color: transparent; color: var(--dim); }
.danger { color: var(--pencil); }
.small { padding: 6px 11px; font-size: 13.5px; }
input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--paper); height: 28px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--paper); margin: 0; }

label { display: block; color: var(--dim); font-size: 13.5px; margin-bottom: 7px; }
label.check { display: inline-flex; gap: 9px; align-items: center; margin: 0; color: var(--paper); font-size: 15px; }
label.button { color: var(--paper); margin: 0; font-size: 15px; }
.value { color: var(--paper); font-variant-numeric: tabular-nums; margin-left: 4px; }

.field { margin-top: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.grid2, .grid3 { display: grid; gap: 0 12px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1.25fr 1fr 0.8fr; }
.grid3 > div > label { margin-bottom: 7px; }

/* ---- login ---------------------------------------------------------------------- */

#login { max-width: 340px; margin: 0 auto; padding: 26vh 20px 0; display: grid; gap: 14px; }

/* ---- app frame: header, sections, tab bar --------------------------------------- */

.top {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) var(--gap) 8px; background: var(--graphite);
}
.top .wordmark { grid-column: 1; }
.top .status { grid-column: 2; }
.top #lock { grid-column: 3; justify-self: end; padding: 8px 4px; }

.status {
  border: 0; border-radius: 999px; padding: 7px 14px; font-size: 13.5px; background: var(--sheet); color: var(--paper);
  font-variant-numeric: tabular-nums;
}
.status.working::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--paper); margin-right: 2px;
  animation: pulse 1.2s ease-in-out infinite;
}
.status.fresh { background: var(--paper); color: var(--graphite); font-weight: 600; }
.status.failed { color: var(--pencil); }
@keyframes pulse { 50% { opacity: .25; } }

main section { max-width: 720px; margin: 0 auto; padding: 4px var(--gap) calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px); }
#tab-create { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 96px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--graphite); border-top: 1px solid var(--line);
}
.tabbar button { border: 0; border-radius: 0; color: var(--faint); font-size: 15px; font-weight: 500; position: relative; }
.tabbar button.on { color: var(--paper); }
.tabbar button.on::after { content: ''; position: absolute; top: -1px; left: 30%; right: 30%; height: 2px; background: var(--paper); }
.count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; font-stretch: 75%; }

/* ---- create --------------------------------------------------------------------- */

.modes { display: grid; grid-template-columns: 1fr 1fr; background: var(--sheet); border-radius: 12px; padding: 4px; margin-top: 8px; }
.modes button { border: 0; border-radius: 9px; padding: 11px 6px; color: var(--dim); font-weight: 600; }
.modes button.on { background: var(--raise); color: var(--paper); }

/* Label row with the small info button; the explanation opens right below it. */
.lab { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; color: var(--dim); font-size: 13.5px; }
.lab label { margin: 0; }
.info {
  width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 1px solid var(--line); flex: none;
  font-size: 11.5px; font-weight: 700; font-style: italic; color: var(--dim); line-height: 1;
}
.info.on { background: var(--paper); border-color: var(--paper); color: var(--graphite); }
.explain {
  font-size: 14px; line-height: 1.5; color: var(--paper); background: var(--sheet); border-radius: 10px;
  padding: 11px 13px; margin: 0 0 10px; white-space: pre-line;
}

.presets { display: flex; flex-wrap: wrap; gap: 7px; }
.preset { border-radius: 999px; padding: 8px 14px; font-size: 14.5px; color: var(--paper); background: var(--sheet); border-color: var(--sheet); }
.preset.on { border-color: var(--paper); }
.preset.add { background: transparent; border: 1px dashed var(--line); color: var(--dim); }
.preset-actions { display: flex; gap: 4px; margin-top: 6px; }
.preset-actions .quiet { padding: 6px 4px; margin-right: 10px; }
.group { margin-top: 26px; padding-top: 6px; border-top: 1px solid var(--line); }

.strip { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.strip:empty { display: none; }
.strip .ref { position: relative; flex: none; }
.strip img { width: 74px; height: 74px; object-fit: cover; border-radius: 3px; display: block; background: var(--sheet); }
.strip .ref button {
  position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(20, 19, 18, .8); font-size: 13px;
}

#loras > div { margin-bottom: 10px; }
.lora-row { display: grid; grid-template-columns: 1fr 76px 40px; gap: 6px; align-items: center; }
.lora-row input { text-align: center; padding: 11px 4px; font-variant-numeric: tabular-nums; }
.lora-row button { padding: 10px 0; border-color: transparent; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.chip { padding: 4px 10px; font-size: 13px; border-radius: 999px; color: var(--dim); }

.fold { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 14px; }
.fold summary { list-style: none; cursor: pointer; font-size: 15px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::before {
  content: ''; width: 7px; height: 7px; border-right: 1.5px solid var(--dim); border-bottom: 1.5px solid var(--dim);
  transform: rotate(-45deg); transition: transform .15s;
}
.fold[open] summary::before { transform: rotate(45deg); }
.fold + .fold { margin-top: 14px; }
.seed input { max-width: 200px; }

.runbar {
  position: fixed; left: 0; right: 0; z-index: 25; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding: 22px var(--gap) 12px; background: linear-gradient(to bottom, rgba(29, 28, 27, 0), var(--graphite) 38%);
}
.runbar > * { max-width: 688px; margin-left: auto; margin-right: auto; }
.runbar .msg { background: var(--sheet); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
#run { width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; display: flex; }
body:not([data-tab=create]) .runbar { display: none; }

/* ---- gallery: the contact sheet ------------------------------------------------- */

.gal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0 14px; }
.filters { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.filters button { border: 0; padding: 8px 10px; color: var(--faint); font-weight: 500; }
.filters button.on { color: var(--paper); }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--sheet);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; color: var(--dim); font-size: 14px; }

.sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 8px; }
.empty { color: var(--dim); padding: 40px 0; text-align: center; grid-column: 1 / -1; }
.frame { margin: 0; position: relative; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.frame .pic { aspect-ratio: 1; border-radius: 3px; overflow: hidden; background: var(--sheet); }
.frame img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .18s; }
.frame img.in { opacity: 1; }
.frame figcaption { display: flex; align-items: center; justify-content: space-between; height: 18px; margin-top: 5px;
  font-stretch: 75%; font-size: 13px; color: var(--faint); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.frame.fresh figcaption .no { color: var(--paper); }
.tick { width: 16px; height: 14px; }
.tick path, .mark path { fill: none; stroke: var(--pencil); stroke-linecap: round; stroke-linejoin: round; }
.tick path { stroke-width: 2.4; }
.upl { font-size: 12px; }
.mark { position: absolute; left: -7px; right: -7px; top: -7px; aspect-ratio: 1; width: calc(100% + 14px); pointer-events: none; overflow: visible; }
.mark path { stroke-width: 2.6; stroke-dasharray: 1; stroke-dashoffset: 1; opacity: 0; transition: stroke-dashoffset .3s ease-out, opacity 0s .3s; }
.frame.sel .mark path { stroke-dashoffset: 0; opacity: 1; transition: stroke-dashoffset .3s ease-out, opacity 0s; }
body.selecting .frame:not(.sel) .pic { opacity: .72; }

.actionbar {
  position: fixed; left: 0; right: 0; z-index: 35; bottom: 0;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding: 0 8px env(safe-area-inset-bottom);
  display: flex; align-items: center; gap: 2px; background: var(--sheet); border-top: 1px solid var(--line);
}
.actionbar button { border: 0; padding: 10px 9px; font-size: 15px; }
#sel-count { flex: 1; padding-left: 8px; color: var(--dim); font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---- viewer --------------------------------------------------------------------- */

#viewer { position: fixed; inset: 0; z-index: 50; background: #000; touch-action: pan-y pinch-zoom; }
.v-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#v-img { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .22s ease-out; will-change: transform; }
#v-img.drag { transition: none; }
.v-top, .v-bar {
  position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 4px; padding: 10px 10px;
  transition: opacity .18s;
}
.v-top { top: 0; justify-content: space-between; padding-top: calc(env(safe-area-inset-top) + 8px);
  background: linear-gradient(rgba(0,0,0,.6), rgba(0,0,0,0)); }
.v-bar { bottom: 0; justify-content: space-around; padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.7)); }
.v-bar button, .v-bar .button, .v-top button { border: 0; font-size: 15px; padding: 10px 8px; color: var(--paper); }
.v-bar .danger { color: var(--pencil); }
.v-bar #v-star.on { color: var(--pencil); }
.frame-no { font-stretch: 75%; color: var(--dim); font-variant-numeric: tabular-nums; font-size: 15px; }
#viewer.bare .v-top, #viewer.bare .v-bar, #viewer.bare #v-meta { opacity: 0; pointer-events: none; }
#v-meta {
  position: absolute; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 70px); max-height: 46vh; overflow: auto;
  margin: 0; padding: 14px; background: rgba(29, 28, 27, .94); border-radius: 12px;
  font: 13.5px/1.5 'Instrument Sans', system-ui, sans-serif; color: var(--paper); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ---- bottom sheet (job errors) -------------------------------------------------- */

.sheetpanel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-height: 70vh; overflow: auto;
  background: var(--sheet); border-radius: 16px 16px 0 0; border-top: 1px solid var(--line);
  padding: 18px var(--gap) calc(env(safe-area-inset-bottom) + 16px); box-shadow: 0 -12px 40px rgba(0,0,0,.45);
}
.sheet-title { font-weight: 600; font-size: 17px; }
#sheet-body { font: 14px/1.5 'Instrument Sans', system-ui, sans-serif; color: var(--dim); white-space: pre-wrap; overflow-wrap: anywhere; margin: 10px 0 16px; }
.sheetpanel .primary { width: 100%; }

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

.lora-form { display: grid; grid-template-columns: 1fr 88px; gap: 8px; margin-top: 14px; }
.lora-form #lf-url, .lora-form #lf-name, .lora-form #lf-trigger, .lora-form #lf-note, .lora-form button { grid-column: 1 / -1; }
.lora-form #lf-scale { text-align: center; }
.list { margin-top: 12px; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 14px 0; border-top: 1px solid var(--line); }
.item > div:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item .name { font-weight: 600; font-size: 15px; }
.item .meta { color: var(--dim); font-size: 13.5px; margin-top: 3px; }
.item .air { color: var(--faint); font-size: 12.5px; margin-top: 3px; }
.item .state { font-size: 13.5px; margin-top: 5px; }
.item .state.ok { color: var(--dim); }
.item .state.bad { color: var(--pencil); }
.item .actions { display: flex; flex-direction: column; gap: 6px; flex: none; }
.search input { flex: 1; min-width: 140px; }
.search select { width: auto; }

@media (min-width: 640px) {
  .sheet { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

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

/* The info button looks small but takes a finger-sized tap. */
.info { position: relative; }
.info::before { content: ''; position: absolute; inset: -12px; }
