:root {
  --bg: #fdf8f3;
  --surface: #ffffff;
  --ink: #2a1d12;
  --muted: #8a7763;
  --accent: #c97a3b;     /* warm crust */
  --accent-2: #6b8e5a;   /* herb green */
  --line: #ecdfd0;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(80, 50, 20, 0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand .logo { font-size: 32px; }
.brand h1 { margin: 0; font-size: 20px; }
.brand .sub { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: 0.5px; text-transform: uppercase; }
nav { display: flex; gap: 4px; }
.tab {
  background: transparent; border: 0; padding: 8px 14px; border-radius: 999px;
  cursor: pointer; color: var(--muted); font-size: 14px;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--accent); color: white; }

main { padding: 24px 32px 60px; max-width: 1200px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.grid { display: grid; gap: 20px; grid-template-columns: 1fr 1fr; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid .wide { grid-column: 1 / -1; }
.grid .full { grid-column: 1 / -1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 16px; color: var(--ink); }

label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin: 10px 0 0; }
label input, label textarea, label select {
  display: block; width: 100%; margin-top: 4px;
  padding: 10px 12px; font-size: 14px; color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit;
}
label input:focus, label textarea:focus, label select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 122, 59, 0.18);
}
.row { display: flex; gap: 12px; align-items: end; }
.row > * { flex: 1; }

button.primary {
  background: var(--accent); color: white; border: 0;
  padding: 12px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  cursor: pointer; margin-top: 14px;
}
button.primary:hover:not(:disabled) { background: #b6682c; }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent; color: var(--accent); border: 1px solid var(--accent);
  padding: 12px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  cursor: pointer; margin-top: 14px;
}
button.ghost:hover { background: rgba(201, 122, 59, 0.08); }
button.link { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 18px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  min-height: 240px;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 8px;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); background: #fff7ec; }
.dropzone.dragover { border-color: var(--accent); background: #fff3e8; }
.dz-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.dz-icon { font-size: 42px; margin: 0; line-height: 1; }
.dz-text { color: var(--ink); margin: 0; font-size: 15px; }
.dz-hint { color: var(--muted); font-size: 12px; margin: 0; }
#preview { max-width: 100%; max-height: 320px; border-radius: 10px; }
.dz-replace { margin-top: 8px; }
.dropzone #browse { pointer-events: auto; }

.preview-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.photo-wrap {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 320px; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.photo-wrap img { max-width: 100%; max-height: 480px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.history { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.history-item {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  background: var(--surface);
}
.history-item img { width: 100%; border-radius: 6px; max-height: 180px; object-fit: cover; }
.history-item .meta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.history-item .status { font-weight: 600; }
.history-item .status.posted { color: var(--accent-2); }
.history-item .status.failed { color: #c0392b; }

@media (max-width: 760px) {
  .grid, .preview-row, .grid.two { grid-template-columns: 1fr; }
  .topbar { padding: 14px 18px; }
  main { padding: 18px; }
}

details.advanced { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
details.advanced summary { color: var(--muted); cursor: pointer; font-size: 13px; user-select: none; }
details.advanced summary:hover { color: var(--accent); }
details.advanced[open] summary { margin-bottom: 8px; }

/* Style preset chips */
.preset-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 14px; }
.chip {
  background: var(--surface); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px;
  font-size: 13px; color: var(--ink); cursor: pointer;
  font-family: inherit;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Enhance step layout */
.enhance-row { display: grid; grid-template-columns: 240px 1fr; gap: 20px; margin-top: 12px; }
.enhance-controls { display: flex; flex-direction: column; }
.enhance-controls label:first-child { margin-top: 0; }
.photo-wrap.small { min-height: 200px; max-height: 260px; }

/* Variations grid */
.variations {
  display: grid; gap: 12px; margin-top: 16px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.variation {
  position: relative; border: 2px solid var(--line); border-radius: 10px;
  cursor: pointer; overflow: hidden; background: var(--bg);
  aspect-ratio: 1;
  transition: border-color 0.15s, transform 0.15s;
}
.variation:hover { border-color: var(--accent); transform: translateY(-2px); }
.variation.picked { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201, 122, 59, 0.25); }
.variation img { width: 100%; height: 100%; object-fit: cover; display: block; }
.variation .pick-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--accent); color: white; font-size: 11px;
  padding: 3px 8px; border-radius: 999px; font-weight: 600;
  display: none;
}
.variation.picked .pick-badge { display: block; }
.variation .dl-btn {
  position: absolute; top: 6px; left: 6px;
  background: rgba(0,0,0,0.6); color: white; text-decoration: none;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer;
}
.variation .dl-btn:hover { background: var(--accent); }

@media (max-width: 760px) {
  .enhance-row { grid-template-columns: 1fr; }
}

/* Style references grid */
.ref-upload { display: flex; gap: 8px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.ref-upload input[type="text"] {
  flex: 1; min-width: 200px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14px; background: var(--bg); color: var(--ink);
}
.refs-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.ref-item {
  position: relative; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: var(--bg); aspect-ratio: 1;
}
.ref-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref-item .ref-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55); color: white; font-size: 11px;
  padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ref-item .ref-del {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,0.6); color: white; border: 0;
  width: 26px; height: 26px; border-radius: 50%;
  cursor: pointer; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.ref-item .ref-del:hover { background: #c0392b; }

/* Hash-based tab switching (no JS required — clicking a tab link changes the URL
   hash, the browser scrolls to and shows the matching panel via :target). */
.panel { display: none; }
.panel:target { display: block; }
/* Default: show Create tab when no hash is present */
.panel#tab-create { display: block; }

/* Active tab visual: highlight the tab whose href matches the current hash.
   Falls back to highlighting Create when no hash. */
.tab { color: var(--muted); }
a.tab[href="#tab-create"]:target ~ * a.tab[href="#tab-create"],
.tab.active { color: white; background: var(--accent); }
/* Simpler approach: JS will set .active on the matching tab on load + on hashchange.
   We just need a sensible default for when JS hasn't run yet. */
.tab.active { color: white; background: var(--accent); }
.preview-banner {
  background: #fff3e8;
  border-bottom: 1px solid #e8c89e;
  color: #6b4a2b;
  padding: 12px 32px;
  font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start;
  flex-wrap: wrap;
}
.preview-banner code {
  background: rgba(0,0,0,0.08); padding: 1px 5px; border-radius: 4px;
  font-size: 12px;
}
.preview-banner .link {
  background: none; border: 0; color: #c97a3b; text-decoration: underline;
  cursor: pointer; padding: 0; font-weight: 600; flex-shrink: 0;
}

button:disabled { cursor: not-allowed; }

/* Cover the entire dropzone with the file input — any click on the dropzone
   natively opens the file picker. No JS event handling needed for clicks. */
.dropzone { position: relative; }
.vh-file {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
  z-index: 2;
  /* Hide the default file input UI but keep it interactive */
  font-size: 0;
}
.vh-file::-webkit-file-upload-button { display: none; }
.dz-empty, .dz-replace { position: relative; z-index: 1; pointer-events: none; }
.dz-empty button, .dz-replace { pointer-events: auto; }
.dropzone:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
