:root {
  --wood: #8b6e4e;
  --wood-dark: #6f563b;
  --wood-light: #a58766;
  --cream: #f3ecd8;
  --ink: #2c2520;
  --charcoal: #4a423a;
  --red: #c44d4d;
  --yellow: #e6b800;
  --green: #4caf50;
  --paper: #fffdf6;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 24px 28px, rgba(0,0,0,0.16) 0 4px, transparent 5px),
    radial-gradient(circle at 74px 78px, rgba(0,0,0,0.16) 0 4px, transparent 5px),
    radial-gradient(circle at 124px 48px, rgba(0,0,0,0.12) 0 3px, transparent 4px),
    radial-gradient(circle at 44px 122px, rgba(0,0,0,0.12) 0 3px, transparent 4px),
    linear-gradient(160deg, #9c7d5a 0%, var(--wood) 40%, var(--wood-dark) 100%);
  background-size: 150px 150px, 150px 150px, 150px 150px, 150px 150px, 100% 100%;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  min-height: 100%;
}

/* ---------- Tabs ---------- */
.tab-view { display: none; }
.tab-view.active { display: block; }

main.tab-view {
  padding-top: calc(env(safe-area-inset-top) + 12px);
  padding-left: 12px;
  padding-right: 12px;
}

/* ---------- Board top ---------- */
.board-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin: 6px 4px 10px;
}

.counters { display: flex; gap: 18px; }

.peg-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.peg-counter .peg {
  width: 12px;
  height: 40px;
  background: linear-gradient(90deg, #7a5f40, var(--wood-light) 50%, #7a5f40);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2), 1px 2px 3px rgba(0,0,0,0.35);
  position: relative;
}

.peg-counter .peg::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 5px;
  background: #5d4527;
  border-radius: 50%;
}

.counter-tag {
  background: var(--cream);
  border-radius: 3px;
  box-shadow: 1px 2px 4px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 9px;
  position: relative;
}

.counter-tag::before {
  content: "";
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 6px;
  background: #6b563c;
}

.counter-tag strong {
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
}

.counter-tag em {
  font-style: normal;
  font-size: 8px;
  letter-spacing: 0.04em;
  color: var(--charcoal);
  text-transform: uppercase;
  margin-top: 2px;
}

/* ---------- Quick add ---------- */
.quick-add {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.35));
}

.quick-add .ring {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  color: var(--ink);
  font-weight: 500;
}

.quick-add .ring::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  border: 4px solid var(--red);
  border-radius: 50%;
}

.quick-add .ring::after {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 8px;
  background: #6b563c;
}

.quick-add .ring > span {
  position: relative;
  z-index: 1;
  font-size: 26px;
}

/* ---------- Board columns ---------- */
.board-wrap {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.column-zone {
  background: rgba(0,0,0,0.12);
  border-radius: 12px;
  padding: 10px 8px 16px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
}

.col-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--cream);
  margin: 0 0 8px;
  text-transform: uppercase;
}

.ring-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}
.ring-dot.red { background: var(--red); }
.ring-dot.yellow { background: var(--yellow); }
.ring-dot.green { background: var(--green); }

.pegs {
  display: flex;
  justify-content: space-around;
  margin-bottom: 6px;
}

.metal-peg {
  width: 4px;
  height: 30px;
  background: linear-gradient(90deg, #b9c0c6, #f4f7fa 50%, #b9c0c6);
  border-radius: 2px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.35);
  position: relative;
}

.metal-peg::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 7px;
  height: 5px;
  background: radial-gradient(circle at 30% 30%, #ffffff, #a8b0b7);
  border-radius: 50%;
}

/* ---------- Tags ---------- */
.tags {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 2px;
}

.tag {
  background: var(--cream);
  border-radius: 4px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.35);
  padding: 14px 12px 10px;
  position: relative;
  cursor: pointer;
  transition: transform 0.1s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.tag:active { transform: scale(0.97); }

.tag .hole {
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: transparent;
  z-index: 1;
}

.tag .hole::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid var(--red);
}

.tag[data-status="in_progress"] .hole::before { border-color: var(--yellow); }
.tag[data-status="done"] .hole::before { border-color: var(--green); }

.tag h3 {
  margin: 8px 0 3px;
  font-size: 15px;
  line-height: 1.2;
  color: var(--ink);
  word-break: break-word;
}

.tag .meta {
  font-size: 11px;
  color: var(--charcoal);
  line-height: 1.3;
  margin: 0;
}

.tag .meta .sub { font-weight: 600; }

/* Overdue tags get a light red shadow (only non-done due today/overdue) */
.tag.overdue { box-shadow: 0 3px 8px rgba(196, 77, 77, 0.55); }

/* ---------- Zone heads ---------- */
.zone-head { margin: 8px 4px 12px; }

.zone-head h1 {
  margin: 0;
  font-size: 22px;
  color: var(--cream);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.zone-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: rgba(255,246,232,0.85);
}

/* ---------- Flat list ---------- */
.flat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flat-list .tag { margin: 0; }

.empty-peg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 26px 10px;
  background: rgba(0,0,0,0.10);
  border-radius: 10px;
}

.empty-peg .peg {
  width: 12px;
  height: 46px;
  background: linear-gradient(90deg, #7a5f40, var(--wood-light) 50%, #7a5f40);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2), 1px 2px 3px rgba(0,0,0,0.35);
  position: relative;
  flex-shrink: 0;
}

.empty-peg .peg::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 5px;
  background: #5d4527;
  border-radius: 50%;
}

.empty-peg .tag {
  border: 1px dashed rgba(44,37,32,0.4);
  color: var(--charcoal);
  font-size: 13px;
  cursor: default;
  box-shadow: none;
}

/* ---------- Search bar ---------- */
.search-bar { margin: 4px 0 14px; }

.search-bar input {
  width: 100%;
  padding: 14px 14px;
  font-size: 16px;
  border-radius: 10px;
  border: none;
  background: var(--paper);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), 0 2px 5px rgba(0,0,0,0.25);
  appearance: none;
  -webkit-appearance: none;
}

.search-bar input::placeholder { color: #9a8f80; }

/* ---------- Forms ---------- */
.entry-form {
  background: rgba(0,0,0,0.14);
  border-radius: 14px;
  padding: 18px 16px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.entry-form label { display: flex; flex-direction: column; gap: 6px; }

.entry-form label > span,
.entry-form legend {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--cream);
  text-transform: uppercase;
}

.entry-form input[type="text"],
.entry-form input[type="date"] {
  padding: 13px 12px;
  font-size: 16px;
  border-radius: 8px;
  border: none;
  background: var(--paper);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  appearance: none;
  -webkit-appearance: none;
}

.status-pick { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.status-option {
  display: flex;
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  padding: 12px 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}

.status-option input { accent-color: var(--red); margin: 0; }
.status-option.yellow input { accent-color: var(--yellow); }
.status-option.green input { accent-color: var(--green); }

.status-option span {
  font-size: 14px;
  color: var(--paper);
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
}

.status-option:has(input:checked) {
  border-color: var(--red);
  background: rgba(196,77,77,0.14);
}
.status-option.yellow:has(input:checked) { border-color: var(--yellow); background: rgba(230,184,0,0.14); }
.status-option.green:has(input:checked) { border-color: var(--green); background: rgba(76,175,80,0.14); }

.form-error {
  margin: 0;
  font-size: 13px;
  color: #ffd9d9;
  min-height: 18px;
}

.pin-btn {
  border: none;
  appearance: none;
  cursor: pointer;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 999px;
  color: var(--ink);
  background:
    radial-gradient(circle at 30% 25%, #c39a6f, var(--wood-light) 45%, var(--wood) 70%, var(--wood-dark));
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.4), 0 3px 6px rgba(0,0,0,0.35);
}

.ghost-btn {
  border: none;
  appearance: none;
  cursor: pointer;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
  color: var(--cream);
  background: rgba(0,0,0,0.15);
}

.danger-btn {
  border: none;
  appearance: none;
  cursor: pointer;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 8px;
  color: #fff;
  background: var(--red);
}

/* ---------- Overlay / sheet ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,14,8,0.55);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 10px calc(12px + env(safe-area-inset-bottom));
}

.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: linear-gradient(160deg, #9c7d5a, var(--wood) 45%, var(--wood-dark));
  border-radius: 16px 16px 0 0;
  padding: 14px 14px 20px;
  box-shadow: 0 -6px 24px rgba(0,0,0,0.45);
}

.sheet.narrow { max-width: 380px; }

/* ---------- Bottom tab bar ---------- */
.tab-bar {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  height: 60px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 30px 28px, rgba(0,0,0,0.14) 0 3px, transparent 4px),
    radial-gradient(circle at 110px 18px, rgba(0,0,0,0.12) 0 3px, transparent 4px),
    linear-gradient(180deg, #9c7d5a, var(--wood) 55%, var(--wood-dark));
  background-size: 150px 150px, 150px 150px, 100% 100%;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.3), 0 -3px 12px rgba(0,0,0,0.4);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 10;
  padding: 0 6px;
}

.tab-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  width: 25%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
}

.tab-btn .peg {
  width: 12px;
  height: 34px;
  background: linear-gradient(90deg, #7a5f40, var(--wood-light) 50%, #7a5f40);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
}

.tab-btn .band {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 7px;
  border-radius: 4px;
  background: transparent;
  box-shadow: 0 1px 1px rgba(0,0,0,0.3);
  opacity: 0;
}

.tab-btn.active .band.green { background: var(--green); opacity: 1; }
.tab-btn.active .band.orange { background: var(--orange, #f28b2c); opacity: 1; }
.tab-btn.active .band.blue { background: var(--blue, #3a7bd5); opacity: 1; }
.tab-btn.active .band.purple { background: var(--purple, #8e5bb5); opacity: 1; }

.tab-btn .label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: rgba(255,246,232,0.85);
}

.tab-btn.active .peg {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2), 0 0 8px rgba(0,0,0,0.45);
}
.tab-btn.active .label { color: var(--paper); }

:root {
  --orange: #f28b2c;
  --blue: #3a7bd5;
  --purple: #8e5bb5;
}