:root {
  --paper: #fbfaf7;      /* warm white background */
  --card: #ffffff;
  --border: #e9e4db;     /* soft warm border */
  --border-strong: #ddd6c9;
  --ink: #17191d;        /* headings / wordmark / primary */
  --text: #3b3e45;       /* body text */
  --muted: #9a9284;      /* warm gray */
  --sun: #c98a4b;        /* single warm accent (ochre) */
  --sage: #5f7a63;       /* success */
  --err: #b4553f;        /* muted terracotta-red for errors */
  --radius: 16px;
  --shadow: 0 1px 2px rgba(23, 25, 29, 0.04), 0 8px 24px rgba(23, 25, 29, 0.05);

  --serif: "Bitter", Georgia, "Times New Roman", serif;
  --sans: "Red Hat Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* ---- Masthead ---------------------------------------------------- */
.masthead {
  position: relative;
  text-align: center;
  padding: calc(28px + env(safe-area-inset-top)) 20px 20px;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.mark { width: 46px; height: 46px; margin-bottom: 8px; }
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.32em;
  color: var(--muted);
  text-indent: 0.32em;
}
.wordmark {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 2px 0 0;
  line-height: 1;
}
.tagline {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 15px;
  color: var(--muted);
  margin: 12px 0 0;
}

.status {
  position: absolute;
  top: calc(24px + env(safe-area-inset-top));
  right: 20px;
  display: inline-flex;
  align-items: center;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(154, 146, 132, 0.14);
  transition: background 0.3s, box-shadow 0.3s;
}
.status.ok .status-dot { background: var(--sage); box-shadow: 0 0 0 4px rgba(95, 122, 99, 0.16); }
.status.err .status-dot { background: var(--err); box-shadow: 0 0 0 4px rgba(180, 85, 63, 0.16); }

.rule {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0 0;
}

main { padding: 20px 16px 8px; max-width: 620px; margin: 0 auto; }

/* ---- Empty state ------------------------------------------------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 72px 28px;
}
.empty-mark { width: 64px; height: 64px; color: var(--border-strong); margin-bottom: 18px; }
.empty p {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.8;
  color: var(--muted);
  margin: 0;
}

/* ---- Access key setup -------------------------------------------- */
.setup {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
  margin: 28px 0 16px;
  text-align: center;
}
.setup h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 21px;
  color: var(--ink);
  margin: 0 0 8px;
}
.setup-desc {
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
  margin: 0 0 18px;
}
.setup-desc code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--text);
}
.setup input {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  padding: 13px 14px;
  font-size: 15px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
  margin-bottom: 12px;
}
.setup input:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(201, 138, 75, 0.12);
}
.setup .btn-primary { width: 100%; }
.setup-msg {
  margin-top: 14px;
  font-size: 13.5px;
  color: var(--err);
  line-height: 1.6;
}

.credit-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- Cards ------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  animation: rise 0.28s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: #f1ede6;
}

.card-body { padding: 18px 18px 20px; }

.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}
.field input[type="text"],
.field textarea,
.field select {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  padding: 12px 13px;
  font-size: 15px;
  font-family: var(--sans);
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* The title reads like a gallery caption headline */
.field input.title-input {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 19px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.field textarea { resize: vertical; min-height: 62px; line-height: 1.55; }
.field select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239a9284' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 34px;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(201, 138, 75, 0.12);
}

.analyzing {
  display: flex; align-items: center; gap: 11px;
  color: var(--muted); font-size: 15px;
  font-family: var(--serif); font-style: italic;
  padding: 10px 2px 16px;
}
.spinner {
  width: 17px; height: 17px;
  border: 2px solid var(--border);
  border-top-color: var(--sun);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.btn {
  border: none;
  border-radius: 11px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.btn-primary { background: var(--ink); color: #fff; flex: 1; }
.btn-primary:active { background: #000; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:active { background: var(--paper); }

.result {
  padding: 13px 15px;
  font-size: 14px;
  line-height: 1.6;
  border-top: 1px solid var(--border);
  background: #fcfbf9;
}
.result.ok { color: var(--sage); }
.result.err { color: var(--err); }
.result a { color: var(--ink); font-weight: 600; word-break: break-all; }

/* ---- Footer credit ---------------------------------------------- */
.credit {
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 12px 16px 4px;
}
.credit strong { color: var(--text); font-weight: 600; }

/* ---- Pick bar ---------------------------------------------------- */
/* `display: flex` below would otherwise beat the [hidden] attribute. */
.pickbar[hidden] { display: none; }

.pickbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 14px 18px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 62%, rgba(251, 250, 247, 0));
  display: flex;
  z-index: 20;
}
.pick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  flex: 1;
  max-width: 620px;
  margin: 0 auto;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  padding: 16px;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(23, 25, 29, 0.16);
}
.pick-btn:active { background: #000; }

/* ---- Banner ------------------------------------------------------ */
.banner {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 50;
  max-width: 88%;
  box-shadow: 0 8px 28px rgba(23, 25, 29, 0.28);
}
