:root {
  --paper: #f4efe4;
  --paper-raised: #faf6ec;
  --paper-sunk: #ece5d6;
  --ink: #26221c;
  --ink-soft: #5c554a;
  --ink-faint: #8c8272;
  --line: #d6cbb6;
  --line-strong: #bfb298;
  --accent: #a52a2a;
  --accent-soft: #f0ded9;
  --primary: #4f46e5;
  --secondary: #d1c4a8;
  --danger: #8f2424;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 3px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 18% 12%, rgba(255,255,255,.55), transparent 42%),
    radial-gradient(circle at 82% 78%, rgba(209,196,168,.32), transparent 55%);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='0.22'/></svg>");
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: .01em;
  margin: 0;
}

button, input, textarea, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- masthead ---------- */
.masthead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 239, 228, .92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}

.masthead-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  color: var(--accent);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--paper-raised);
  flex: none;
}

.brand-text h1 {
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: .04em;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--ink-faint);
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  flex: none;
}
.icon-btn:active { background: var(--paper-sunk); }

/* ---------- layout ---------- */
.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 18px calc(var(--tabbar-h) + var(--safe-b) + 28px);
  outline: none;
}

.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 8px;
}

.section-head h2 { font-size: 26px; }

.count-pill {
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 2px 9px;
  white-space: nowrap;
}

.lede {
  margin: 10px 0 18px;
  color: var(--ink-soft);
  font-size: 13.5px;
  max-width: 46ch;
}

.sub-head {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-weight: 600;
  margin-bottom: 8px;
}

/* ---------- dashboard ---------- */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  margin-bottom: 18px;
  border-radius: var(--radius);
}

.stat {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat + .stat { border-left: 1px solid var(--line); }

.stat-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .11em;
  color: var(--ink-faint);
}

.stat-value {
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1.1;
  color: var(--accent);
}

/* ---------- recent ---------- */
.recent-block { margin-bottom: 20px; }

.recent-list { list-style: none; margin: 0; padding: 0; }

.recent-list li {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 7px 2px;
  border-bottom: 1px dotted var(--line-strong);
}
.recent-list li:first-child { border-top: 1px dotted var(--line-strong); }

.recent-idx {
  font-family: var(--serif);
  font-size: 12px;
  color: var(--ink-faint);
}

.recent-title {
  font-family: var(--serif);
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-loc {
  display: block;
  font-family: var(--sans);
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-vibe {
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--accent);
  white-space: nowrap;
}

/* ---------- search ---------- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  padding: 0 10px;
  margin-bottom: 10px;
}
.search-icon { color: var(--ink-faint); flex: none; }
.search-bar input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 11px 0;
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search-bar input::-webkit-search-cancel-button { display: none; }
.search-bar:focus-within { border-color: var(--accent); }

.clear-btn {
  border: 0;
  background: var(--paper-sunk);
  color: var(--ink-soft);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  line-height: 1;
  font-size: 15px;
  display: grid;
  place-items: center;
  flex: none;
}

.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 12px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }

.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 12px;
  white-space: nowrap;
  flex: none;
}
.chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper-raised);
}

/* ---------- log cards ---------- */
.log-list { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius) 10px var(--radius) 7px;
  padding: 13px 15px 12px;
  position: relative;
  transform: rotate(var(--tilt, 0deg));
}
.card:nth-child(3n+1) { --tilt: -0.25deg; }
.card:nth-child(3n+2) { --tilt: 0.2deg; }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.card h3 {
  font-size: 17px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.card-loc {
  margin: 3px 0 0;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.card-date {
  font-size: 11px;
  color: var(--ink-faint);
  white-space: nowrap;
  padding-top: 3px;
  flex: none;
}

.vibe {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--ink-soft);
}
.vibe-dots { display: inline-flex; gap: 3px; }
.vibe-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  display: block;
}
.vibe-dots i.on { background: var(--accent); }

.card-obs {
  margin: 9px 0 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.55;
  border-left: 2px solid var(--line);
  padding-left: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  gap: 6px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px dotted var(--line-strong);
}

.link-btn {
  border: 0;
  background: transparent;
  padding: 4px 8px;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--ink-soft);
  border-radius: 3px;
  min-height: 32px;
}
.link-btn:active { background: var(--paper-sunk); }
.link-btn.is-danger { color: var(--danger); margin-left: auto; }

/* ---------- gallery index ---------- */
.index-list { display: flex; flex-direction: column; }

.index-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 13px 2px;
}
.index-row:first-child { border-top: 1px solid var(--line); }
.index-row:active { background: rgba(0,0,0,.035); }

.index-letter {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--accent);
  width: 26px;
  flex: none;
  text-align: center;
  line-height: 1;
}

.index-name {
  flex: 1;
  min-width: 0;
  font-family: var(--serif);
  font-size: 15.5px;
  overflow-wrap: anywhere;
}
.index-meta {
  display: block;
  font-family: var(--sans);
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-top: 2px;
}

.index-count {
  font-size: 11px;
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 1px 8px;
  flex: none;
}

/* ---------- mood index ---------- */
.mood-average {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mood-avg-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink-faint);
}
.mood-avg-value {
  font-family: var(--serif);
  font-size: 26px;
  color: var(--accent);
  line-height: 1.1;
}
.mood-avg-value small { font-size: 13px; color: var(--ink-faint); font-family: var(--sans); }

.mood-bars { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }

.mood-list { display: flex; flex-direction: column; gap: 10px; }

.mood-row {
  display: grid;
  grid-template-columns: 78px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.mood-row:active { border-color: var(--line-strong); }

.mood-title {
  font-family: var(--serif);
  font-size: 14px;
}

.mood-track {
  height: 6px;
  background: var(--paper-sunk);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.mood-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  min-width: 3px;
}
.mood-fill[data-r="1"] { opacity: .28; }
.mood-fill[data-r="2"] { opacity: .45; }
.mood-fill[data-r="3"] { opacity: .62; }
.mood-fill[data-r="4"] { opacity: .8; }
.mood-fill[data-r="5"] { opacity: 1; }

.mood-count {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  min-width: 26px;
  text-align: right;
}

.mood-note {
  font-size: 11.5px;
  color: var(--ink-faint);
  margin: 16px 0 0;
  font-style: italic;
}

/* ---------- form ---------- */
.entry-form {
  border-top: 1px solid var(--line-strong);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field { border: 0; margin: 0; padding: 0; min-width: 0; }

.field > label, .field > legend, .label-row label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 600;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.label-row label { margin-bottom: 6px; }

.req { color: var(--accent); }

.field input[type="text"],
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  padding: 11px 12px;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s;
}

.field textarea {
  resize: vertical;
  min-height: 104px;
  line-height: 1.55;
}

.field input[type="text"]::placeholder,
.field textarea::placeholder { color: var(--ink-faint); opacity: .85; }

.field input[type="text"]:focus,
.field textarea:focus { border-color: var(--accent); }

.field.has-error input,
.field.has-error textarea { border-color: var(--danger); }

.field-error {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--danger);
}

.counter { font-size: 11px; color: var(--ink-faint); font-family: var(--sans); }

/* rating */
.rating-input {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.rate-btn {
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  border-radius: var(--radius);
  padding: 9px 0 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--ink-faint);
  font-size: 15px;
  min-height: 52px;
  transition: background .12s, color .12s, border-color .12s;
}
.rate-btn .rate-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid currentColor;
}
.rate-btn.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.rate-btn.is-on .rate-dot { background: currentColor; }

.rating-caption {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
  min-height: 18px;
  font-style: italic;
}

/* actions */
.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

.btn {
  border-radius: var(--radius);
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .03em;
  border: 1px solid transparent;
  min-height: 46px;
  flex: 1;
}

.btn-primary {
  background: var(--ink);
  color: var(--paper-raised);
  border-color: var(--ink);
}
.btn-primary:active { background: #000; }

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink-soft);
  flex: none;
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
  width: 100%;
  margin-top: -6px;
  font-weight: 500;
  font-size: 13px;
}

.local-note {
  text-align: center;
  font-size: 11px;
  color: var(--ink-faint);
  margin: 18px 0 0;
  font-style: italic;
}

/* ---------- empty states ---------- */
.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(250, 246, 236, .55);
  padding: 26px 20px;
  text-align: center;
  color: var(--ink-soft);
}
.empty-mark {
  font-family: var(--serif);
  font-size: 30px;
  color: var(--line-strong);
  line-height: 1;
  margin-bottom: 8px;
}
.empty h3 { font-size: 17px; margin-bottom: 5px; }
.empty p { margin: 0 auto 14px; font-size: 12.5px; max-width: 34ch; color: var(--ink-faint); }
.empty .btn { flex: none; display: inline-block; width: auto; min-height: 40px; padding: 10px 18px; font-size: 13px; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(250, 246, 236, .97);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--line-strong);
  padding-bottom: var(--safe-b);
}

.tab {
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 2px 7px;
  font-size: 9.5px;
  letter-spacing: .02em;
  height: var(--tabbar-h);
  position: relative;
}
.tab svg { opacity: .8; }
.tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.tab.is-active { color: var(--accent); }
.tab.is-active svg { opacity: 1; }
.tab.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22%;
  right: 22%;
  height: 2px;
  background: var(--accent);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink);
  color: var(--paper-raised);
  font-size: 12.5px;
  padding: 9px 16px;
  border-radius: 3px;
  max-width: calc(100vw - 40px);
  text-align: center;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- detail sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(38, 34, 28, .38);
  z-index: 70;
  animation: fade .18s ease;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  background: var(--paper-raised);
  border-top: 1px solid var(--line-strong);
  border-radius: 12px 12px 0 0;
  max-height: 82vh;
  max-height: 82dvh;
  overflow-y: auto;
  padding: 8px 20px calc(20px + var(--safe-b));
  box-shadow: 0 -1px 0 var(--line);
  animation: sheetUp .24s cubic-bezier(.2,.8,.3,1);
  width: 100%;
}
.sheet[hidden], .sheet-backdrop[hidden] { display: none; }

@keyframes sheetUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-grip {
  width: 38px;
  height: 3px;
  border-radius: 2px;
  background: var(--line-strong);
  margin: 4px auto 14px;
}

.sheet-kicker {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--ink-faint);
  margin: 0 0 4px;
}
.sheet h3 { font-size: 21px; line-height: 1.3; overflow-wrap: anywhere; }
.sheet-location {
  margin: 5px 0 0;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent);
  overflow-wrap: anywhere;
}
.sheet-rating { margin-top: 12px; }
.sheet-observation {
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.sheet-date {
  font-size: 11px;
  color: var(--ink-faint);
  margin: 12px 0 0;
}
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }

@media (min-width: 640px) {
  :root { --tabbar-h: 68px; }
  .app { padding-left: 28px; padding-right: 28px; }
  .masthead-inner { padding-left: 28px; padding-right: 28px; }
  .section-head h2 { font-size: 29px; }
  .sheet {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    max-width: 520px;
    border: 1px solid var(--line-strong);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
    animation: none;
  }
  .tab { font-size: 10.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .card { transform: none; }
}
