:root {
  --primary: #b08a6c;
  --secondary: #fdf1e7;
  --accent: #d64045;
  --ink: #4a3a2e;
  --cork: #b08a6c;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--cork);
  overscroll-behavior: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  position: relative;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(76px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

/* Corkboard texture */
.board {
  min-height: 100%;
  background-color: var(--cork);
  background-image:
    radial-gradient(circle at 20% 20%, rgba(90,60,40,0.12) 1px, transparent 1.5px),
    radial-gradient(circle at 60% 40%, rgba(90,60,40,0.10) 1px, transparent 1.5px),
    radial-gradient(circle at 40% 70%, rgba(90,60,40,0.12) 1px, transparent 1.5px),
    radial-gradient(circle at 80% 15%, rgba(90,60,40,0.08) 1px, transparent 1.5px),
    repeating-linear-gradient(45deg, rgba(70,45,30,0.03) 0 3px, rgba(255,255,255,0.02) 3px 6px);
  background-size: 28px 28px, 34px 34px, 42px 42px, 26px 26px, 12px 12px;
  padding: 18px 12px 30px;
}

.view { display: none; }
.view.active { display: block; }

/* Search bar */
.searchbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 8px 12px;
  background: linear-gradient(var(--cork), rgba(176,138,108,0.9));
}
.searchbar input {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 20px;
  background: var(--secondary);
  color: var(--ink);
  font-size: 14px;
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(120,90,60,0.25);
}
.searchbar input::placeholder { color: rgba(74,58,46,0.5); }

/* Clothesline */
.line {
  height: 6px;
  margin: 4px 0 14px;
  border-radius: 3px;
  background: repeating-linear-gradient(90deg, #8a6a4e 0 14px, #9c7a5c 14px 28px);
  box-shadow: 0 2px 3px rgba(60,40,25,0.35);
}

/* Hanging wooden tags */
.tags {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin: 18px 0;
}
.tag {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d8b88f, #b48a62 70%, #a37b55);
  border: 2px solid #8a6a4e;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 3px 4px rgba(60,40,25,0.3);
}
.tag::before {
  content: "";
  position: absolute;
  top: -9px;
  width: 12px;
  height: 8px;
  border-radius: 3px;
  background: #7a5c40;
}
.tag-num {
  font-family: "Georgia", serif;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}
.tag-lbl {
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #5a442e;
  margin-top: 3px;
}
.tag-issue .tag-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  margin-bottom: 4px;
  box-shadow: 0 1px 2px rgba(180,40,40,0.5);
}

/* Shutter capture button */
.shutter {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 128px;
  height: 128px;
  margin: 10px auto 18px;
  border-radius: 50%;
  border: 6px solid rgba(90,60,40,0.35);
  background: radial-gradient(circle at 35% 30%, #fdf1e7, #d9c4ae 75%);
  cursor: pointer;
  box-shadow: 0 6px 10px rgba(60,40,25,0.4);
}
.shutter:active { transform: scale(0.96); }
.shutter .shutter-ring {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 32%, #fff, #cdb8a2 70%, #b8a088);
  border: 3px solid rgba(90,60,40,0.3);
  margin-bottom: 8px;
}
.shutter-lbl {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--ink);
  margin-top: 2px;
}
.shutter.save { width: 100%; height: 54px; border-radius: 26px; flex-direction: row; gap: 10px; border-width: 2px; margin: 14px 0 6px; }
.shutter.save .shutter-ring { width: 26px; height: 26px; margin: 0; }

.mini-head {
  font-family: "Georgia", serif;
  font-size: 14px;
  letter-spacing: 1px;
  text-align: center;
  color: rgba(255,250,240,0.85);
  text-shadow: 0 1px 2px rgba(60,40,25,0.5);
  margin: 6px 0 10px;
}

/* Recent row (dashboard) */
.recent {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 4px 12px;
  scroll-snap-type: x mandatory;
}

/* Polaroid cards */
.polaroid {
  width: 150px;
  background: #fff;
  padding: 8px 8px 10px;
  border-radius: 4px;
  position: relative;
  flex-shrink: 0;
  scroll-snap-align: center;
  box-shadow: 0 3px 5px rgba(50,35,20,0.3);
}
.polaroid.mini { width: 130px; }
.polaroid .clip {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  height: 14px;
  background: linear-gradient(#d9bd95, #a97f55);
  border-radius: 3px;
  box-shadow: 0 3px 4px rgba(40,25,15,0.5);
  z-index: 2;
}
.polaroid.flagged .clip {
  background: linear-gradient(#f06b6b, #b93035);
}
.polaroid .thread {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  z-index: 3;
}
.polaroid .photo-wrap {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  position: relative;
  border-radius: 2px;
}
.polaroid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: sepia(0.4) contrast(0.95) brightness(1.02);
  display: block;
}
.polaroid .unit {
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-style: italic;
  transform: rotate(-2deg);
  font-size: 16px;
  font-weight: 700;
  color: #333;
  padding: 6px 4px 2px;
  text-align: center;
}
.polaroid .date {
  font-size: 10px;
  color: #999;
  text-align: center;
}
.polaroid .curl {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(0,0,0,0.12);
  border-top: 2px solid rgba(0,0,0,0.12);
  transform: rotate(15deg);
  border-radius: 0 3px 0 0;
}

/* Pinboard grid (gallery/flagged) */
.pinboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 24px 12px;
  padding: 16px 4px 12px;
  justify-items: center;
}
.pinboard .polaroid { margin-top: 12px; }

.empty {
  text-align: center;
  color: rgba(255,250,240,0.8);
  font-family: "Georgia", serif;
  font-style: italic;
  padding: 30px 10px;
}

/* Capture preview */
.preview {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 6px;
  background: #d8c4ae;
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  margin-bottom: 10px;
}
.preview img { width: 100%; height: 100%; object-fit: cover; display: none; filter: sepia(0.4); }
.preview.has img { display: block; }
.preview-empty {
  font-family: "Georgia", serif;
  font-style: italic;
  color: #7a5c40;
}
.pick-btn {
  display: block;
  text-align: center;
  padding: 12px;
  border-radius: 22px;
  background: rgba(255,255,255,0.9);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 16px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(60,40,25,0.3);
}

.capture-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,250,240,0.9);
}
.field input, .field textarea {
  border: none;
  border-radius: 8px;
  background: var(--secondary);
  padding: 12px;
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(120,90,60,0.3);
}
.field textarea { resize: vertical; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
}
.toggle input { display: none; }
.toggle-track {
  width: 52px;
  height: 30px;
  border-radius: 16px;
  background: #c9b8a6;
  position: relative;
  transition: background 0.2s;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(22px); }
.toggle-lbl { font-size: 15px; color: var(--secondary); font-weight: 600; }

.form-err {
  color: #ffe0e0;
  font-size: 13px;
  min-height: 16px;
  margin-top: 6px;
  text-align: center;
}

/* Edit panel */
.edit-panel {
  position: fixed;
  inset: 0;
  background: rgba(40,25,15,0.55);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.edit-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 90vh;
  overflow-y: auto;
}
.edit-x {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  z-index: 3;
}
.edit-photo {
  border-radius: 4px;
  overflow: hidden;
  border: 4px solid #f3e9df;
  margin-bottom: 4px;
}
.edit-photo img { width: 100%; display: block; filter: sepia(0.4); }
.edit-card .field input, .edit-card .field textarea { color: var(--ink); background: #fdf1e7; }
.edit-close {
  border: none;
  background: #e5d9cc;
  color: var(--ink);
  padding: 10px;
  border-radius: 20px;
  font-weight: 600;
}

/* Bottom tab bar - clothespins */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  padding: 0 8px env(safe-area-inset-bottom);
  background: linear-gradient(transparent, rgba(60,40,25,0.35));
  pointer-events: none;
}
.tab {
  pointer-events: auto;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 4px;
  cursor: pointer;
}
.pin {
  width: 34px;
  height: 34px;
  background: linear-gradient(#e2c7a2, #b38a5c);
  border-radius: 4px;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
}
.pin::before, .pin::after {
  content: "";
  position: absolute;
  top: 2px;
  width: 6px;
  height: 30px;
  background: linear-gradient(#e7cfa9, #a87f53);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(60,40,25,0.3);
}
.pin::before { left: 6px; }
.pin::after { right: 6px; }
.pin.teal { background: linear-gradient(#8fd0c8, #4f9c92); }
.pin.teal::before, .pin.teal::after { background: linear-gradient(#a5dcd5, #3f8a80); }
.pin.coral { background: linear-gradient(#f0a48a, #d0634a); }
.pin.coral::before, .pin.coral::after { background: linear-gradient(#f5b59e, #c0533a); }
.pin.mustard { background: linear-gradient(#edcf7a, #c8a23c); }
.pin.mustard::before, .pin.mustard::after { background: linear-gradient(#f2db92, #b08d2e); }
.pin-lbl {
  font-size: 10px;
  color: var(--secondary);
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(60,40,25,0.5);
}
.tab.active .pin {
  transform: translateY(-6px);
  box-shadow: 0 5px 8px rgba(40,25,15,0.5);
}
.tab.active .pin::before { transform: rotate(-14deg); transform-origin: top; }
.tab.active .pin::after { transform: rotate(14deg); transform-origin: top; }
.tab:not(.active) .pin { opacity: 0.85; }