:root {
  --primary: #2e4a2e;
  --primary-dark: #1f331f;
  --secondary: #d9c8a9;
  --accent: #e76f2e;
  --paper: #efe6cf;
  --paper-light: #f6efdc;
  --ink: #4a463a;
  --pencil-grey: #9a9484;
  --red-stamp: #b03a2e;
  --ruling: rgba(46, 74, 46, 0.10);
  --shadow: rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--primary);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hand { font-family: "Segoe Print", "Comic Sans MS", "Brush Script MT", cursive; }

.notebook {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  overflow: hidden;
}

/* Ruled paper texture */
.notebook::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 25px,
      rgba(31, 51, 31, 0.05) 25px,
      rgba(31, 51, 31, 0.05) 26px
    );
  pointer-events: none;
}

/* Dark green cover edges */
.cover-top,
.cover-bottom {
  position: absolute;
  left: 0;
  right: 0;
  height: 22px;
  background: linear-gradient(180deg, #1f331f, #2e4a2e);
  z-index: 5;
}
.cover-top { top: 0; }
.cover-bottom {
  bottom: 0;
  background: linear-gradient(0deg, #1f331f, #2e4a2e);
}

/* Black wire spiral binding along the left edge */
.binding {
  position: absolute;
  left: 6px;
  top: 30px;
  bottom: 80px;
  width: 26px;
  z-index: 4;
  pointer-events: none;
}
.binding::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: repeating-linear-gradient(
    to bottom,
    #000 0, #000 9px,
    var(--paper) 9px, var(--paper) 14px
  );
  border-radius: 2px;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.4);
}
.binding::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 0;
  bottom: 0;
  width: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, #000, #3a3a3a, #000);
  box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
}

/* Page area */
.page {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: calc(30px + env(safe-area-inset-top)) 18px 90px 46px;
  -webkit-overflow-scrolling: touch;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-head {
  margin: 6px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(46, 74, 46, 0.25);
}
.title {
  margin: 0;
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.02em;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--pencil-grey);
}

/* ---- Trail Log list ---- */
.hike-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.hike-item {
  position: relative;
  padding: 14px 8px 14px 10px;
  border-bottom: 1px solid rgba(46, 74, 46, 0.12);
  border-radius: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
  transition: background 0.2s, opacity 0.25s, transform 0.25s;
}
.hike-item:nth-child(odd) {
  background: rgba(46, 74, 46, 0.045);
}
.hike-item.tapping { background: rgba(231, 111, 46, 0.12); }
.hike-item.deleting {
  opacity: 0;
  transform: translateX(-60px);
}

.hike-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.hike-trail {
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}
.hike-date {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--red-stamp);
  text-transform: uppercase;
  padding: 1px 6px;
  border: 1.5px solid rgba(176, 58, 46, 0.55);
  border-radius: 3px;
  transform: rotate(-1deg);
}
.hike-meta {
  margin-top: 6px;
  font-size: 0.9rem;
}
.hike-dist {
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  font-weight: 600;
  color: var(--primary);
}
.hike-notes {
  margin-top: 5px;
  font-size: 0.84rem;
  color: var(--pencil-grey);
  font-style: italic;
  line-height: 1.35;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  color: var(--pencil-grey);
  margin-top: 40px;
  font-size: 0.95rem;
  font-family: "Segoe Print", cursive;
}
.empty-state strong { color: var(--primary); }

/* ---- Form ---- */
.field {
  display: block;
  margin-bottom: 16px;
}
.field > span {
  display: block;
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
}
.field > span em { font-size: 0.75rem; color: var(--pencil-grey); font-weight: 400; }
.field input,
.field textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper-light);
  border: 1.5px solid rgba(46, 74, 46, 0.3);
  border-radius: 6px;
  padding: 12px 12px;
  -webkit-appearance: none;
  appearance: none;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(231, 111, 46, 0.2);
}
.field input.invalid { border-color: var(--red-stamp); }
.err {
  display: block;
  margin-top: 5px;
  font-size: 0.8rem;
  color: var(--red-stamp);
  min-height: 0.9em;
}

.btn-primary {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #3a5c3a, var(--primary));
  border: none;
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--primary-dark), 0 5px 8px rgba(0,0,0,0.2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--primary-dark); }

.btn-cancel {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  font-size: 0.9rem;
  color: var(--pencil-grey);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: "Segoe Print", cursive;
}

/* ---- Peak Stats ---- */
.stats-stamps {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 14px 0 18px;
}
.stamp {
  position: relative;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  filter: url(#rough) drop-shadow(2px 3px 3px rgba(0,0,0,0.25));
  transform: rotate(-3deg);
}
.stamp.compass { transform: rotate(4deg); }
.stamp-num {
  font-family: "Segoe Print", cursive;
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
}
.stamp-label {
  margin-top: 4px;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  font-weight: 700;
}
/* Hiking boot print stamp */
.stamp.boot {
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.15), transparent 40%),
    #b8a88c;
  color: #3a3327;
  border: 3px dashed rgba(58, 51, 39, 0.5);
  box-shadow: inset 0 0 0 2px rgba(58,51,39,0.2), 0 2px 6px rgba(0,0,0,0.3);
}
/* Compass rose stamp */
.stamp.compass {
  background:
    repeating-conic-gradient(from 0deg, #c9b695 0 15deg, #d8c8a9 15deg 30deg);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  border: 2px solid #a89270;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.25), 0 2px 6px rgba(0,0,0,0.3);
}
/* imperfect ink edges */
.stamp.boot::before, .stamp.compass::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  opacity: 0.5;
  pointer-events: none;
}
.stamp.boot::before {
  border: 2px dashed rgba(58,51,39,0.4);
  transform: rotate(6deg);
}
.stamp.compass::before {
  border: 2px dashed rgba(255,255,255,0.35);
  transform: rotate(-5deg);
}

.recent-block .block-title {
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  font-size: 1rem;
  color: var(--primary);
  margin: 6px 0 4px;
}
.hike-list.compact .hike-item { padding: 10px 8px; }
.hike-list.compact .hike-notes { -webkit-line-clamp: 1; }

/* ---- Search ---- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-light);
  border: 1.5px solid rgba(46, 74, 46, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.12);
}
.search-bar .compass-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
  flex-shrink: 0;
}
.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  outline: none;
}
.search-bar input::placeholder { color: var(--pencil-grey); }

/* ---- Bottom tab bar: binder clips ---- */
.tab-bar {
  position: relative;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  z-index: 6;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #24402a, #1f331f);
  border-top: 2px solid #14250f;
}
.tab-btn {
  position: relative;
  flex: 1;
  border: none;
  background: none;
  cursor: pointer;
  color: #cfd8c8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.tab-btn .clip {
  width: 38px;
  height: 26px;
  background: linear-gradient(180deg, #d8dde0, #9aa3a8, #c2c9cd);
  border-radius: 4px;
  position: relative;
  box-shadow: 0 3px 3px rgba(0,0,0,0.4);
  transition: transform 0.15s;
}
.tab-btn .clip::before {
  content: "";
  position: absolute;
  left: 5px;
  right: 5px;
  top: -3px;
  height: 6px;
  background: #8a9399;
  border-radius: 3px;
}
.tab-btn .clip::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  top: 3px;
  height: 2px;
  background: rgba(255,255,255,0.4);
}
/* active clip: orange ribbon flag fluttering upward */
.tab-btn.active .clip { transform: translateY(-3px); }
.tab-btn.active .clip::marker { content: ""; }
.tab-btn .ribbon {
  position: absolute;
  top: -14px;
  left: 50%;
  width: 0;
  height: 0;
  opacity: 0;
  transform: translateX(-50%) scale(0);
  transition: opacity 0.2s, transform 0.2s;
}
.tab-btn.active .ribbon {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
.tab-btn .ribbon .flag {
  display: block;
  width: 26px;
  height: 16px;
  background: linear-gradient(180deg, #f08a4f, var(--accent));
  clip-path: polygon(0 0, 100% 0, 100% 60%, 0 100%);
  box-shadow: 0 2px 2px rgba(0,0,0,0.3);
  animation: flutter 1.4s ease-in-out infinite;
}
@keyframes flutter {
  0%, 100% { transform: skewY(0deg); }
  50% { transform: skewY(-4deg) rotate(2deg); }
}
.tab-btn .ribbon .pole {
  position: absolute;
  top: 16px;
  left: 12px;
  width: 2px;
  height: 8px;
  background: var(--accent);
}
.tab-btn .label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-top: 2px;
}
.tab-btn.active { color: #fff; }
.tab-btn.active .label { color: var(--accent); }
.tab-btn.active .clip {
  background: linear-gradient(180deg, #e6eaec, #b6bec3, #cfd5d8);
}

/* keep tap targets large */
.tab-btn { min-height: 56px; }

@media (max-width: 360px) {
  .page { padding-left: 40px; }
  .stamp { width: 115px; height: 115px; }
  .stamp-num { font-size: 1.6rem; }
}