:root {
  --primary: #fafafa;
  --accent: #00acc1;
  --secondary: #ff5722;
  --ink: #2b2b2b;
  --hand: "Marker Felt", "Comic Sans MS", "Segoe Print", cursive;
  --red: #e53935;
  --coral: #ff7043;
  --teal: #26a69a;
  --gold: #f9a825;
  --olive: #9e9d24;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #eceff1;
  font-family: var(--hand);
  color: var(--ink);
}

.app {
  max-width: 520px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--primary);
  position: relative;
  overflow: hidden;
}

/* ---------- Whiteboard surface ---------- */
.stage {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  padding-bottom: 96px;
  position: relative;
  background-color: var(--primary);
  background-image:
    radial-gradient(circle at 18% 12%, rgba(0,0,0,0.04) 0, transparent 60px),
    radial-gradient(circle at 82% 30%, rgba(0,0,0,0.04) 0, transparent 70px),
    radial-gradient(circle at 40% 70%, rgba(0,0,0,0.03) 0, transparent 80px);
}

.grid-empty {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,172,193,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,172,193,0.08) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
}

.empty-msg {
  position: relative;
  text-align: center;
  color: #9aa3aa;
  font-size: 1rem;
  padding: 70px 24px;
  line-height: 1.6;
}

/* ---------- Dashboard counters (marker clips) ---------- */
.counters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.clip {
  background: linear-gradient(180deg, #ffffff, #e8e8ec);
  border-radius: 6px;
  border: 1px solid #d6d6db;
  box-shadow: 0 2px 4px rgba(0,0,0,0.10);
  padding: 10px 12px 12px;
  position: relative;
  transform: rotate(-1.5deg);
}
.clip::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 4px;
  height: 5px;
  border-radius: 2px;
  background: linear-gradient(180deg, #fff, #d0d0d6);
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.12);
}
.clip:nth-child(2) { transform: rotate(1.8deg); }
.clip-value {
  font-size: 2.1rem;
  font-weight: 700;
  margin: 8px 0 0;
  line-height: 1;
  color: #37474f;
}
.clip-label {
  font-size: 0.85rem;
  color: #607d8b;
  margin: 2px 0 0;
}

/* ---------- Search bar ---------- */
.search {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--hand);
  font-size: 1rem;
  border: 1px dashed #cfd8dc;
  border-radius: 12px;
  background: rgba(255,255,255,0.7);
  color: var(--ink);
  margin-bottom: 14px;
  outline: none;
}
.search:focus { border-color: var(--accent); border-style: solid; }

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

.card {
  background: #fff;
  border: 1px solid #e2e2e6;
  border-radius: 10px;
  padding: 14px 14px 12px;
  position: relative;
  transform: rotate(var(--tilt, 0deg));
  background-image:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 21px,
      rgba(13,71,161,0.08) 21px,
      rgba(13,71,161,0.08) 22px
    );
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card:nth-child(odd) { --tilt: -0.6deg; }
.card:nth-child(even) { --tilt: 0.7deg; }

.magnet {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8a65, #d84315 70%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.magnet.star {
  border-radius: 0;
  background: var(--gold);
  -webkit-clip-path: polygon(50% 0, 61% 34%, 98% 35%, 68% 56%, 79% 92%, 50% 72%, 21% 92%, 32% 56%, 2% 35%, 39% 34%);
  clip-path: polygon(50% 0, 61% 34%, 98% 35%, 68% 56%, 79% 92%, 50% 72%, 21% 92%, 32% 56%, 2% 35%, 39% 34%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.card-head { margin-left: 22px; }
.card-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
  color: #263238;
}
.date-stamp {
  display: inline-block;
  font-family: var(--hand);
  font-size: 0.82rem;
  color: var(--red);
  font-weight: 700;
  margin-top: 2px;
}

.rating-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  margin-left: 22px;
}
.rating-icon {
  width: 22px;
  height: 22px;
  overflow: visible;
}
.rating-bg { fill: #e0e0e0; stroke: #bdbdbd; stroke-width: 0.6; }
.rating-fill { fill: var(--accent); stroke: none; clip-path: url(#ratingClip); }
.leaf-vein { stroke: rgba(255,255,255,0.85); stroke-width: 0.8; }
.rating-note {
  font-size: 0.8rem;
  color: #78909c;
}

.card-changes {
  margin: 8px 0 0 22px;
  font-size: 0.9rem;
  color: #546e7a;
  line-height: 1.4;
}
.card-changes:empty { display: none; }

.card-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0 0 22px;
}
.edit-btn, .del-btn {
  font-family: var(--hand);
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #cfd8dc;
  background: #f5f5f5;
  color: #37474f;
  cursor: pointer;
}
.del-btn { color: #c62828; border-color: #ef9a9a; background: #fff5f5; }

/* ---------- Sticky Log Trial marker button ---------- */
.marker-action {
  position: fixed;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: max-content;
  pointer-events: none;
}
.marker-action[hidden] { display: none; }

.marker-btn {
  pointer-events: auto;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.2));
}
.marker-btn-tip {
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, #2b2b2b, #4a4a4a);
  -webkit-clip-path: polygon(100% 0, 0 0, 0 100%);
  clip-path: polygon(100% 0, 0 0, 0 100%);
  border-radius: 2px 0 0 2px;
}
.marker-btn-body {
  font-family: var(--hand);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, #4a4a4a, #303030);
  padding: 12px 18px;
  border-radius: 0 12px 12px 0;
  letter-spacing: 0.5px;
}

/* ---------- Forms ---------- */
.form-card {
  background: #fff;
  border: 1px solid #e2e2e6;
  border-radius: 10px;
  padding: 16px;
  background-image:
    repeating-linear-gradient(to bottom, transparent 0, transparent 23px, rgba(13,71,161,0.08) 23px, rgba(13,71,161,0.08) 24px);
}
.form-card h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
  color: #263238;
}
.form-card p.hint {
  margin: 0 0 14px;
  color: #78909c;
  font-size: 0.85rem;
}

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 0.85rem;
  color: #607d8b;
  margin-bottom: 4px;
}
.field input[type="text"],
.field input[type="date"],
.field input[type="number"],
.field textarea {
  width: 100%;
  font-family: var(--hand);
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid #cfd8dc;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field .error {
  color: #c62828;
  font-size: 0.78rem;
  margin-top: 3px;
  display: block;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.save-btn {
  flex: 1;
  font-family: var(--hand);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, #4a4a4a, #303030);
  border: none;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  box-shadow: 0 2px 3px rgba(0,0,0,0.25);
}
.save-btn:active { transform: translateY(2px); box-shadow: 0 0 0 rgba(0,0,0,0.25); }
.save-btn::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 16px;
  border-radius: 8px 0 0 8px;
  background: linear-gradient(90deg, #2b2b2b, #3a3a3a);
}
.cancel-btn {
  font-family: var(--hand);
  font-size: 1rem;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #cfd8dc;
  background: #f5f5f5;
  color: #37474f;
  cursor: pointer;
}

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 4px 0 0 4px; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: rgba(0,172,193,0.3);
}
.timeline li {
  position: relative;
  padding: 0 0 18px 22px;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px #fff;
}
.timeline-date {
  color: var(--red);
  font-size: 0.82rem;
  font-weight: 700;
}
.timeline-name {
  margin: 2px 0;
  font-size: 1.05rem;
  color: #263238;
}
.timeline-name .mini-icon {
  width: 16px;
  height: 16px;
  vertical-align: -2px;
  margin-left: 6px;
}
.timeline-summary {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: #546e7a;
  line-height: 1.4;
}
.timeline-summary:empty { display: none; }

/* ---------- Bottom cap tab bar ---------- */
.capbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #f0f0f2;
  border-top: 2px solid #e2e2e6;
  padding: 8px 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.06);
}

.cap {
  border: none;
  background: none;
  padding: 4px 2px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: var(--hand);
}
.cap-top {
  width: 30px;
  height: 18px;
  border-radius: 4px 4px 0 0;
  display: block;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

/* Cap colors */
.cap[data-tab="trials"] .cap-top { background: linear-gradient(180deg, #ffab91, var(--coral)); }
.cap[data-tab="new"] .cap-top { background: linear-gradient(180deg, #80deea, var(--teal)); }
.cap[data-tab="keepers"] .cap-top { background: linear-gradient(180deg, #ffd54f, var(--gold)); }
.cap[data-tab="timeline"] .cap-top { background: linear-gradient(180deg, #cddc39, var(--olive)); }

.cap-tag {
  font-size: 0.68rem;
  color: #78909c;
  letter-spacing: 0.2px;
}
.cap.active .cap-tag { color: #37474f; font-weight: 700; }

/* Active cap lifted ~5mm revealing glossy marker body */
.cap.active .cap-top {
  transform: translateY(-14px);
  box-shadow: 0 6px 8px rgba(0,0,0,0.25);
  background: linear-gradient(180deg, #ffffff, #eef0f0 60%, var(--coral));
}
.cap.active[data-tab="new"] .cap-top { background: linear-gradient(180deg, #ffffff, #eef0f0 60%, var(--teal)); }
.cap.active[data-tab="keepers"] .cap-top { background: linear-gradient(180deg, #ffffff, #eef0f0 60%, var(--gold)); }
.cap.active[data-tab="timeline"] .cap-top { background: linear-gradient(180deg, #ffffff, #eef0f0 60%, var(--olive)); }

/* glossy body revealed below lifted cap */
.cap.active::after {
  content: "";
  width: 30px;
  height: 16px;
  margin-top: -16px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(180deg, #ffffff, #d7dbdd 60%, #b9bec2);
  box-shadow: 0 3px 4px rgba(0,0,0,0.18);
  display: block;
}

.cap.inactive .cap-top { filter: saturate(0.7) brightness(0.96); }

/* ---------- misc ---------- */
.hidden { display: none !important; }