:root {
  --cork: #b97a4f;
  --cork-dark: #9f6542;
  --cork-light: #ca8a5e;
  --string: rgba(255, 244, 226, 0.16);
  --card: #fffdf6;
  --ink: #3a2f28;
  --ink-soft: #6b5a4c;
  --red: #d94a4a;
  --amber: #e8a33d;
  --green: #5cc99a;
  --blue: #4a7fd9;
  --shadow: 0 4px 10px rgba(40, 20, 8, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "Georgia", "Palatino", "Times New Roman", serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow: hidden;
}

.board {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 12% 18%, rgba(0,0,0,0.05) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 38%, rgba(255,255,255,0.05) 0 1px, transparent 2px),
    radial-gradient(circle at 44% 80%, rgba(0,0,0,0.05) 0 2px, transparent 3px),
    radial-gradient(circle at 88% 66%, rgba(0,0,0,0.04) 0 2px, transparent 3px),
    radial-gradient(circle at 30% 55%, rgba(255,255,255,0.05) 0 1px, transparent 2px),
    linear-gradient(180deg, var(--cork-light), var(--cork) 55%, var(--cork-dark));
  background-size: 140px 140px, 120px 120px, 150px 150px, 130px 130px, 110px 110px, 100% 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--string) 1px, transparent 1px),
    linear-gradient(90deg, var(--string) 1px, transparent 1px),
    linear-gradient(45deg, var(--string) 1px, transparent 1px),
    linear-gradient(-45deg, var(--string) 1px, transparent 1px);
  background-size: 90px 90px;
  pointer-events: none;
}

.app-header {
  padding: calc(env(safe-area-inset-top) + 14px) 18px 10px;
  text-align: center;
  color: #fff8ec;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.app-title {
  font-size: 34px;
  font-weight: bold;
  letter-spacing: 1px;
  font-style: italic;
}

.app-tag {
  font-size: 13px;
  opacity: 0.85;
  font-style: italic;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px calc(92px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

/* ---- Pushpin icons ---- */
.pin-icon {
  display: inline-block;
  width: 22px;
  height: 30px;
  border-radius: 50% 50% 46% 46% / 55% 55% 38% 38%;
  position: relative;
  transform: rotate(8deg);
  box-shadow: inset 0 -4px 6px rgba(0,0,0,0.25), 0 3px 5px rgba(0,0,0,0.3);
}
.pin-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  width: 3px;
  height: 9px;
  background: linear-gradient(90deg, #5a4a3c, #8a7560);
  border-radius: 2px;
}
.pin-icon::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  filter: blur(0.5px);
}
.pin-home { background: radial-gradient(circle at 30% 25%, #e06a6a, var(--red)); }
.pin-amber { background: radial-gradient(circle at 30% 25%, #f0b95f, var(--amber)); }
.pin-blue { background: radial-gradient(circle at 30% 25%, #6a9be0, var(--blue)); }
.pin-green { background: radial-gradient(circle at 30% 25%, #72d8ab, var(--green)); }

/* ---- Tab bar ---- */
.tabbar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  display: flex;
  justify-content: space-around;
  background: rgba(120, 76, 44, 0.92);
  border-radius: 22px;
  padding: 8px 4px;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.15);
  z-index: 20;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: #ffe9cd;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 2px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.tab-label { font-size: 11px; font-weight: bold; letter-spacing: 0.4px; }

.tab.active .pin-icon {
  box-shadow: inset 0 -4px 6px rgba(0,0,0,0.25), 0 0 12px rgba(255,255,255,0.55), 0 0 4px rgba(255,255,255,0.6);
}
.tab.active .pin-icon::before { opacity: 0.9; }
.tab.active .tab-label { color: #fff; text-shadow: 0 0 6px rgba(255,255,255,0.6); }
.tab:not(.active) .pin-icon { filter: saturate(0.85) brightness(0.92); }

/* ---- Index cards ---- */
.card {
  position: relative;
  background: var(--card);
  border-radius: 4px;
  padding: 12px 14px 12px 22px;
  box-shadow: var(--shadow), inset 0 0 2px rgba(0,0,0,0.08);
  color: var(--ink);
  margin-bottom: 18px;
  line-height: 1.4;
}
.card::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%) rotate(12deg);
  width: 18px;
  height: 24px;
  border-radius: 50% 50% 45% 45% / 60% 60% 36% 36%;
  box-shadow: inset 0 -4px 6px rgba(0,0,0,0.22), 0 3px 4px rgba(0,0,0,0.28);
  z-index: 2;
}
.card.pin-red::before { background: radial-gradient(circle at 30% 25%, #e06a6a, var(--red)); }
.card.pin-amber::before { background: radial-gradient(circle at 30% 25%, #f0b95f, var(--amber)); }
.card.pin-green::before { background: radial-gradient(circle at 30% 25%, #72d8ab, var(--green)); }
.card.pin-blue::before { background: radial-gradient(circle at 30% 25%, #6a9be0, var(--blue)); }

.rot-1 { transform: rotate(-1.2deg); }
.rot-2 { transform: rotate(1.6deg); }
.rot-3 { transform: rotate(-0.6deg); }
.rot-4 { transform: rotate(1deg); }

.card-title { font-size: 17px; font-weight: bold; font-style: italic; }
.card-meta { font-size: 13px; color: var(--ink-soft); margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.status-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.st-red { background: var(--red); }
.st-amber { background: var(--amber); }
.st-green { background: var(--green); }

/* ---- Section headings ---- */
.group-label {
  font-size: 15px;
  font-weight: bold;
  color: #fff7e8;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  margin: 16px 0 10px;
  padding-left: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-style: italic;
}
.group-label .pin-icon { width: 14px; height: 20px; transform: rotate(10deg); }

/* ---- Home dashboard ---- */
.counters {
  display: flex;
  gap: 16px;
  margin: 6px 0 22px;
  justify-content: center;
}
.counter {
  flex: 1;
  max-width: 150px;
  text-align: center;
  position: relative;
}
.counter-head {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 130px;
  margin: 0 auto;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 -8px 12px rgba(0,0,0,0.3), 0 6px 10px rgba(0,0,0,0.4);
}
.counter-head.red { background: radial-gradient(circle at 32% 26%, #e06a6a, #c83c3c); }
.counter-head.green { background: radial-gradient(circle at 32% 26%, #72d8ab, #3fae82); }
.counter-head::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  width: 5px;
  height: 12px;
  background: linear-gradient(90deg, #5a4a3c, #8a7560);
  border-radius: 2px;
}
.counter-head .num-cutout {
  width: 62%;
  height: 46%;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: bold;
  color: var(--ink);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.2), 0 2px 4px rgba(0,0,0,0.15);
}
.counter-label { margin-top: 14px; color: #fff8ec; font-weight: bold; font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,0.3); }

.section-title {
  color: #fff8ec;
  font-weight: bold;
  font-size: 16px;
  margin: 20px 0 12px;
  padding-left: 6px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  font-style: italic;
}

.quick-add {
  background: linear-gradient(160deg, #fffdf6, #f6ecd8);
  text-align: center;
  cursor: pointer;
  border: none;
  width: 100%;
  font-family: inherit;
}
.quick-add .qa-btn {
  display: inline-block;
  margin-top: 6px;
  background: var(--green);
  color: #fff;
  font-weight: bold;
  font-family: inherit;
  padding: 6px 18px;
  border-radius: 999px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
}

/* ---- Search ---- */
.search-wrap { margin-bottom: 14px; position: sticky; top: 0; z-index: 5; }
.search-field {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 253, 246, 0.95);
  box-shadow: var(--shadow);
  color: var(--ink);
}

/* ---- Empty state ---- */
.empty {
  text-align: center;
  color: #fff8ec;
  padding: 40px 20px;
  font-style: italic;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.empty .empty-pin { margin: 0 auto 10px; width: 40px; height: 50px; }
.empty p { margin-top: 8px; font-size: 16px; }

/* ---- Form / Add tab ---- */
.form-card .field { margin-bottom: 14px; }
.form-card label { display: block; font-size: 13px; font-weight: bold; color: var(--ink-soft); margin-bottom: 5px; font-style: italic; }
.form-card input[type="text"],
.form-card select,
.form-card textarea {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 2px solid #e6d6bf;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.form-card textarea { min-height: 90px; resize: vertical; }
.form-card input.invalid, .form-card select.invalid, .form-card textarea.invalid { border-color: var(--red); }

.status-picker { display: flex; gap: 8px; }
.status-opt {
  flex: 1;
  border: 3px solid transparent;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  padding: 8px 2px;
  text-align: center;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink-soft);
}
.status-opt .swatch { display: block; width: 22px; height: 22px; border-radius: 50%; margin: 0 auto 5px; }
.status-opt.selected { border-color: #8a6b4c; color: var(--ink); font-weight: bold; }

.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  flex: 1;
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  padding: 12px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 3px 5px rgba(0,0,0,0.25);
}
.btn-save { background: linear-gradient(180deg, #6fdcae, var(--green)); color: #fff; }
.btn-cancel { background: #d9cfbf; color: #5a4a3c; }
.form-error { color: var(--red); font-size: 13px; margin-top: 8px; text-align: center; font-weight: bold; }

/* ---- Progress ---- */
.disc-wrap { text-align: center; margin: 10px 0 24px; }
.disc {
  position: relative;
  width: 190px;
  height: 190px;
  margin: 0 auto;
  background: radial-gradient(circle at 30% 25%, #fdf6e6, #e7d3b4);
  border-radius: 50%;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.25), 0 5px 12px rgba(0,0,0,0.4);
}
.disc::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -9px;
  transform: translateX(-50%) rotate(12deg);
  width: 18px;
  height: 24px;
  border-radius: 50% 50% 45% 45% / 60% 60% 36% 36%;
  background: radial-gradient(circle at 30% 25%, #f0b95f, var(--amber));
  box-shadow: inset 0 -4px 6px rgba(0,0,0,0.22), 0 3px 4px rgba(0,0,0,0.28);
}
.disc svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.disc .track { fill: none; stroke: rgba(0,0,0,0.12); stroke-width: 14; stroke-linecap: round; }
.disc .bar { fill: none; stroke: var(--green); stroke-width: 16; stroke-linecap: round; stroke-dasharray: 0 1000; }
.disc-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.disc-center .big { font-size: 44px; font-weight: bold; }
.disc-center .small { font-size: 15px; font-style: italic; color: var(--ink-soft); }

/* ---- Toast ---- */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%) translateY(20px);
  background: #2c241d;
  color: #ffe9cd;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 30;
  text-align: center;
  max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 620px) {
  .content { max-width: 560px; margin: 0 auto; width: 100%; }
  .tabbar { max-width: 560px; left: 50%; right: auto; transform: translateX(-50%); }
}