:root {
  --oatmeal: #f4ebdd;
  --oatmeal-2: #eadbc4;
  --card: #fffdf8;
  --ink: #243b53;
  --ink-soft: #5a7189;
  --accent: #d97757;
  --accent-dark: #b95e3f;
  --line: #d9c9ab;
  --draft: #5b7fa6;
  --gathering: #d69a2e;
  --ready: #2f7d68;
  --danger: #b3452f;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--oatmeal);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; }

main { padding: 0 16px calc(112px + env(safe-area-inset-bottom)); }

.page { display: none; padding-top: 12px; }
.page.active { display: block; animation: pagefade .18s ease; }
@keyframes pagefade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- stitched passport-cover headers ---------- */
.cover-head {
  background: var(--ink);
  border-radius: 18px 18px 12px 12px;
  padding: 10px;
  margin-top: 10px;
  box-shadow: 0 6px 14px rgba(36, 59, 83, .18);
}
.cover-head.slim { border-radius: 14px; }
.stitch {
  border: 1.5px dashed rgba(244, 235, 221, .4);
  border-radius: 12px;
  padding: 18px 16px 16px;
}
.stitch.slim { padding: 14px 16px; }

.cover-kicker {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(244, 235, 221, .55);
}
.cover-title {
  margin: 0 0 16px;
  font-size: 22px;
  letter-spacing: .02em;
  color: var(--oatmeal);
  display: flex;
  align-items: center;
  gap: 9px;
}
.dot-stamp { width: 13px; height: 13px; border-radius: 50%; background: var(--accent); flex: none; }
.slim-title {
  margin: 0;
  font-size: 18px;
  color: var(--oatmeal);
  display: flex;
  align-items: center;
  gap: 8px;
}
.slim-sub { margin: 4px 0 0; font-size: 12px; color: rgba(244, 235, 221, .62); }

/* ---------- round ink-stamp counters ---------- */
.counters { display: flex; gap: 22px; margin: 4px 0 18px; }
.stamp-counter {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 2px solid rgba(244, 235, 221, .75);
  background: rgba(244, 235, 221, .06);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--oatmeal);
  transform: rotate(-5deg);
}
.stamp-counter:nth-child(2) { transform: rotate(4deg); }
.stamp-counter::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 1.5px dashed rgba(244, 235, 221, .35);
}
.counter-num { font-size: 27px; font-weight: 800; line-height: 1; }
.counter-label {
  margin-top: 5px;
  font-size: 9px;
  letter-spacing: .12em;
  text-transform: uppercase;
  text-align: center;
  color: rgba(244, 235, 221, .7);
  line-height: 1.3;
}
.stamp-counter.hot .counter-num { color: #f2b39c; }

/* ---------- flat Add Folio quick action ---------- */
.add-folio {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff8ef;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--accent-dark);
}
.add-folio:active { transform: translateY(1px); box-shadow: none; }

/* ---------- stage strip ---------- */
.stage-strip { margin: 20px 4px 6px; }
.strip-caption {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.stage-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.stage-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.stage-chip b { font-weight: 800; }
.strip-note { margin: 12px 2px 0; font-size: 11.5px; color: var(--ink-soft); }

/* ---------- readiness dots + spines ---------- */
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.dot.draft { background: var(--draft); }
.dot.gathering { background: var(--gathering); }
.dot.ready { background: var(--ready); }

.spine { width: 12px; flex: none; }
.spine.draft { background: var(--draft); }
.spine.gathering { background: var(--gathering); }
.spine.ready { background: var(--ready); }

/* ---------- folio cards ---------- */
.folio-card {
  width: 100%;
  display: flex;
  align-items: stretch;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0;
  margin: 0 0 12px;
  overflow: hidden;
  cursor: pointer;
  font: inherit;
  color: inherit;
  box-shadow: 0 1px 2px rgba(36, 59, 83, .08);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.folio-card:active { background: #fbf3e4; }
.folio-body { flex: 1; padding: 12px 14px 13px; display: block; min-width: 0; }
.folio-top { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
.folio-stage {
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}
.folio-title {
  display: block;
  font-size: 16.5px;
  font-weight: 750;
  margin: 0 0 7px;
  word-break: break-word;
}
.folio-meta { display: block; font-size: 13px; color: var(--ink-soft); margin-top: 3px; word-break: break-word; }

/* ---------- grouped stack ---------- */
.stage-group { margin: 20px 0 0; }
.group-head {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  padding-left: 10px;
  border-left: 3px solid transparent;
  font-weight: 800;
}
.stage-group.draft .group-head { border-left-color: var(--draft); }
.stage-group.gathering .group-head { border-left-color: var(--gathering); }
.stage-group.ready .group-head { border-left-color: var(--ready); }
.group-head .count {
  background: var(--oatmeal-2);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
}
.group-empty { margin: 0 0 12px 13px; font-size: 12px; color: var(--ink-soft); font-style: italic; }

/* ---------- search + find rows ---------- */
.search-wrap { position: relative; margin: 14px 0 10px; }
#search-input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 12px 14px 12px 42px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
#search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
#search-input:focus { outline: none; border-color: var(--ink); }
.search-wrap::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 50%;
  width: 13px;
  height: 13px;
  margin-top: -8px;
  border: 2px solid var(--ink-soft);
  border-radius: 50%;
}
.search-wrap::after {
  content: "";
  position: absolute;
  left: 26px;
  top: 50%;
  width: 7px;
  height: 2px;
  margin-top: 5px;
  background: var(--ink-soft);
  transform: rotate(45deg);
  transform-origin: left center;
  border-radius: 2px;
}
.result-count { margin: 0 4px 10px; font-size: 12px; color: var(--ink-soft); }

.find-row {
  width: 100%;
  display: flex;
  align-items: stretch;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0;
  margin: 0 0 10px;
  overflow: hidden;
  cursor: pointer;
  font: inherit;
  color: inherit;
  box-shadow: 0 1px 2px rgba(36, 59, 83, .08);
}
.find-row:active { background: #fbf3e4; }
.row-body { flex: 1; padding: 10px 12px; display: block; min-width: 0; }
.row-title { display: block; font-weight: 750; font-size: 15px; word-break: break-word; }
.row-sub { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; word-break: break-word; }

/* ---------- empty states ---------- */
.empty-state {
  margin: 26px 0 10px;
  text-align: center;
  padding: 28px 18px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 248, .6);
}
.empty-state h2 { margin: 14px 0 6px; font-size: 16px; }
.empty-state p { margin: 0; font-size: 13px; color: var(--ink-soft); line-height: 1.5; }
.empty-stamp {
  display: inline-block;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px dashed var(--ink-soft);
  position: relative;
  opacity: .55;
}
.empty-stamp::before {
  content: "";
  position: absolute;
  inset: 15px;
  border-radius: 50%;
  background: var(--ink-soft);
  opacity: .35;
}

/* ---------- form ---------- */
#folio-form { margin-top: 18px; }
.field { margin: 0 0 16px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
.field input::placeholder { color: #a99f8a; }
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(36, 59, 83, .12);
}
.field .error { display: none; margin: 5px 2px 0; font-size: 12px; color: var(--danger); font-weight: 600; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.field.invalid .error { display: block; }

.btn {
  font: inherit;
  cursor: pointer;
  border: none;
}
.btn.primary {
  width: 100%;
  background: var(--ink);
  color: var(--oatmeal);
  border-radius: var(--radius);
  padding: 15px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .03em;
  box-shadow: 0 2px 0 #16273a;
}
.btn.primary:active { transform: translateY(1px); box-shadow: none; }
.btn.ghost {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
}

/* ---------- about / settings ---------- */
.about {
  margin: 28px 0 6px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.about h2 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.about h2:not(:first-child) { margin-top: 18px; }
.about p { margin: 0 0 12px; font-size: 13.5px; line-height: 1.55; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-label { font-size: 13px; color: var(--ink-soft); }
#btn-reset {
  background: none;
  border: 1.5px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
}
#btn-reset:active { background: var(--danger); color: #fff6f0; }

/* ---------- hint ---------- */
.hint {
  margin: 16px 4px 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  text-align: center;
  letter-spacing: .02em;
}

/* ---------- bottom tab bar (passport stamps) ---------- */
#tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 40;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  background: var(--ink);
  padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(20, 32, 48, .18);
  border-top: 1px solid rgba(244, 235, 221, .08);
}
.stamp-tab {
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: rgba(244, 235, 221, .55);
  font: inherit;
}
.stamp-tab .stamp-box {
  width: 46px;
  height: 34px;
  border-radius: 9px;
  border: 1.5px dashed currentColor;
  display: grid;
  place-items: center;
  transition: transform .12s ease, box-shadow .12s ease;
}
.tab-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.stamp-tab.active { color: var(--oatmeal); }
.stamp-tab.active .stamp-box {
  background: var(--accent);
  border: 1.5px solid var(--accent);
  transform: translateY(2px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .25);
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: var(--oatmeal);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 70;
  max-width: 85%;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- modal ---------- */
#modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 30, 45, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
#modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(12px);
  transition: transform .15s ease;
}
#modal-overlay.open .modal { transform: none; }
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal p { margin: 0 0 18px; font-size: 13.5px; line-height: 1.5; color: var(--ink-soft); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; padding: 13px; border-radius: 10px; font-size: 15px; font-weight: 800; }
.btn.cancel { background: var(--oatmeal-2); color: var(--ink); }
.btn.confirm-delete { background: var(--danger); color: #fff6f0; }

button:focus-visible { outline: 3px solid rgba(217, 119, 87, .55); outline-offset: 2px; }
