:root {
  --primary: #8b5a2b;
  --secondary: #d2b48c;
  --accent: #e07a5f;
  --ink: #2a1a0c;
  --wood-dark: #6b4423;
  --wood-light: #a06b36;
  --kraft: #e8d5a3;
  --paper: #f5ecd7;
  --thread-grey: #9a9a9a;
  --thread-yellow: #f2c94c;
  --thread-red: #e26d5a;
  --thread-green: #6aa84f;
}

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

html, body {
  height: 100%;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: #5c3a1e;
  -webkit-font-smoothing: antialiased;
}

/* ---- Pegboard wall ---- */
.pegboard {
  min-height: 100%;
  min-height: 100dvh;
  background-color: var(--wood-dark);
  background-image:
    radial-gradient(circle, rgba(30, 16, 8, 0.85) 2px, transparent 2.5px),
    radial-gradient(circle, rgba(255, 220, 170, 0.06) 3px, transparent 3.5px);
  background-size: 44px 44px, 44px 44px;
  background-position: 0 0, 22px 22px;
  padding: 0 0 calc(88px + env(safe-area-inset-bottom, 0px));
  position: relative;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0px) 14px 0;
}

/* ---- Views ---- */
.view {
  display: none;
  padding-bottom: 24px;
}
.view.active {
  display: block;
  animation: rise 0.25s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-head {
  text-align: center;
  margin: 14px 0 6px;
}
.page-head h1 {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--secondary);
  font-size: 1.35rem;
  letter-spacing: 0.5px;
  text-shadow: 1px 2px 2px rgba(0,0,0,0.5);
}
.page-head .sub {
  color: rgba(245, 236, 215, 0.55);
  font-size: 0.78rem;
  margin-top: 2px;
}

/* ---- Board ---- */
.board-counts {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin: 22px 0 4px;
}
.spool {
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(2px 4px 4px rgba(0,0,0,0.4));
}
.spool .lid {
  width: 46px;
  height: 10px;
  background: var(--wood-light);
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.25);
}
.spool .body {
  position: relative;
  width: 58px;
  height: 84px;
  background: var(--wood-light);
  background: linear-gradient(90deg, #8a5a2e, #b9844f 45%, #8a5a2e);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 6px #7c5028, inset 0 0 0 7px rgba(0,0,0,0.15);
  overflow: hidden;
}
.spool.big .body { height: 96px; width: 64px; }
.spool.small .body { height: 78px; width: 54px; }
.spool .thread {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.18) 0 3px, transparent 3px 6px);
  z-index: 2;
}
.spool.grey .thread { background-color: var(--thread-grey); }
.spool.yellow .thread { background-color: var(--thread-yellow); }
.spool .num {
  position: relative;
  z-index: 3;
  font-family: Georgia, serif;
  font-weight: bold;
  font-size: 2rem;
  color: #5d3a18;
  text-shadow: 0 1px 0 rgba(255,255,255,0.25), inset 0 0 4px rgba(0,0,0,0.5);
  background: rgba(240, 225, 195, 0.5);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spool .label {
  margin-top: 7px;
  color: var(--secondary);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* Recent cards row */
.board-recents h2 {
  text-align: center;
  color: var(--secondary);
  font-family: Georgia, serif;
  font-size: 0.95rem;
  margin: 18px 0 2px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
.hook-rail {
  position: relative;
  height: 14px;
  margin: 6px 0 2px;
}
.hook-rail .rail {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(180deg, #c9c9c9, #8f8f8f);
  box-shadow: 0 2px 3px rgba(0,0,0,0.4);
}
.recent-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 6px 2px 10px;
  scrollbar-width: thin;
}
.hook {
  position: relative;
  flex: 0 0 auto;
  margin-top: 4px;
}
.hook .pin {
  width: 4px;
  height: 16px;
  background: linear-gradient(90deg, #b7b7b7, #7d7d7d);
  margin: 0 auto;
  border-radius: 2px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.4);
}

/* ---- Tool-shaped kraft cards ---- */
.card {
  position: relative;
  background: var(--kraft);
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.toolcut {
  display: inline-block;
}
.toolcut svg {
  display: block;
  width: 100%;
  height: auto;
}
.card.tiny {
  width: 84px;
  padding: 8px 8px 20px;
  border-radius: 10px 6px 12px 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(0,0,0,0.15);
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.03) 0 2px, transparent 2px 5px),
    var(--kraft);
  position: relative;
  margin-top: 6px;
}
.card.tiny .toolcut { width: 44px; margin: 0 auto; display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3)); }
.card.tiny .cname {
  text-align: center;
  font-family: Georgia, serif;
  font-weight: bold;
  font-size: 0.66rem;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card.tiny .minispool {
  width: 10px;
  height: 14px;
  border-radius: 3px;
  margin: 6px auto 0;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.2);
}
.card.tiny .scrap {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 3px;
  transform: rotate(-8deg);
  border: 1px dashed rgba(0,0,0,0.3);
}
.card.tiny .scrap::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: rgba(255,255,255,0.5);
  transform: translateY(-50%);
}

/* ---- Projects list ---- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(245, 236, 215, 0.92);
  border: 2px solid var(--wood-light);
  border-radius: 22px;
  padding: 8px 14px;
  margin: 12px 0 14px;
}
.searchbar input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: var(--ink);
  outline: none;
  font-family: inherit;
}
.searchbar input::placeholder { color: rgba(42,26,12,0.45); }
.searchbar .lens {
  color: var(--primary);
  font-size: 1.1rem;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.list-item {
  background: var(--paper);
  border: 1px solid rgba(0,0,0,0.18);
  border-left: 6px solid var(--secondary);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 3px 5px rgba(0,0,0,0.35);
  position: relative;
  overflow: hidden;
}
.list-item .row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.list-item .toolcut { width: 34px; flex: 0 0 auto; }
.list-item .toolcut svg { filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3)); }
.list-item .info { flex: 1; min-width: 0; }
.list-item .cname {
  font-family: Georgia, serif;
  font-weight: bold;
  font-size: 1.05rem;
}
.list-item .ctype {
  font-size: 0.78rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 1px;
}
.list-item .notes-preview {
  font-size: 0.8rem;
  color: rgba(42,26,12,0.6);
  margin-top: 4px;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.threadspool {
  flex: 0 0 auto;
  width: 22px;
  height: 30px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 3px rgba(0,0,0,0.12);
  border: 1px solid rgba(0,0,0,0.2);
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.18) 0 2px, transparent 2px 4px),
    #999;
}
.threadspool.red { background-color: var(--thread-red); }
.threadspool.yellow { background-color: var(--thread-yellow); }
.threadspool.green { background-color: var(--thread-green); }

.delete-zone {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 74px;
  background: var(--thread-red);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: bold;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.list-item.armed .delete-zone { transform: translateX(0); }
.list-item.armed .row { transform: translateX(-74px); transition: transform 0.25s ease; }

.confirm-strip {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  background: #2a1a0c;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 40;
  font-size: 0.85rem;
  width: 92%;
  max-width: 420px;
}
.confirm-strip button {
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
}
.confirm-strip .yes { background: var(--thread-red); color: #fff; }
.confirm-strip .no { background: var(--secondary); color: var(--ink); }

.empty {
  text-align: center;
  color: rgba(245,236,215,0.7);
  padding: 40px 16px;
  font-family: Georgia, serif;
  font-size: 1rem;
  font-style: italic;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* ---- New / edit form ---- */
.form-sheet {
  background: var(--paper);
  border-radius: 16px;
  padding: 20px 18px 26px;
  margin-top: 8px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.45);
  border: 2px solid var(--wood-light);
}
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-family: Georgia, serif;
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--primary);
  margin-bottom: 6px;
}
.field label .req { color: var(--thread-red); }
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--secondary);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: #fffdf6;
  color: var(--ink);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
}
.field textarea { min-height: 96px; resize: vertical; }

.status-picker {
  display: flex;
  gap: 8px;
}
.status-picker button {
  flex: 1;
  border: 2px solid var(--secondary);
  background: #fffdf6;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
}
.status-picker button .dot {
  display: block;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  margin: 0 auto 6px;
}
.status-picker button .dot.red { background: var(--thread-red); }
.status-picker button .dot.yellow { background: var(--thread-yellow); }
.status-picker button .dot.green { background: var(--thread-green); }
.status-picker button.selected {
  border-color: var(--primary);
  background: var(--secondary);
  font-weight: bold;
  box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}

.errmsg {
  color: var(--thread-red);
  font-size: 0.8rem;
  margin: -8px 0 12px;
  font-weight: bold;
  min-height: 14px;
}

.btn-thread {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-size: 1.05rem;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(180deg, var(--accent), #c95f47);
  cursor: pointer;
  box-shadow: 0 4px 0 #a34a35, 0 6px 10px rgba(0,0,0,0.3);
  font-family: Georgia, serif;
}
.btn-thread:active { transform: translateY(2px); box-shadow: 0 2px 0 #a34a35; }
.btn-cancel {
  width: 100%;
  border: 2px solid var(--secondary);
  background: transparent;
  color: var(--secondary);
  border-radius: 12px;
  padding: 11px;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
  margin-bottom: 10px;
}

/* ---- Settings ---- */
.about-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 22px;
  margin-top: 12px;
  text-align: center;
  border: 2px solid var(--wood-light);
}
.about-card .logo {
  font-family: Georgia, serif;
  font-size: 1.6rem;
  color: var(--primary);
  font-weight: bold;
}
.about-card .ver {
  color: var(--primary);
  margin: 4px 0 14px;
  font-size: 0.85rem;
}
.about-card p {
  font-size: 0.85rem;
  color: rgba(42,26,12,0.7);
  margin-bottom: 18px;
}
.btn-danger {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 1rem;
  font-weight: bold;
  background: var(--thread-red);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #b2503f;
  font-family: inherit;
}
.btn-danger:active { transform: translateY(2px); }

/* ---- Bottom tab bar (wooden dowels + spools) ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: linear-gradient(180deg, rgba(30,16,8,0.4), rgba(20,10,4,0.9));
}
.tabbar-inner {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  padding: 6px 6px 8px;
  background: linear-gradient(180deg, #7c5028, #5c3a1e);
  border-top: 3px solid #3a2412;
}
.dowel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 0 2px;
  position: relative;
}
.dowel .stick {
  width: 26px;
  height: 10px;
  background: linear-gradient(180deg, var(--wood-light), #7a4d28);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.dowel .spoolmini {
  width: 34px;
  height: 38px;
  border-radius: 7px;
  position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.2) 0 3px, transparent 3px 6px),
    var(--c, #999);
  transition: transform 0.25s ease;
}
.dowel .spoolmini::before,
.dowel .spoolmini::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 40px;
  height: 8px;
  background: linear-gradient(180deg, #c8955c, #8a5a2e);
  transform: translateX(-50%);
  border-radius: 3px;
}
.dowel .spoolmini::before { top: -4px; }
.dowel .spoolmini::after { bottom: -4px; }
.dowel .tail {
  position: absolute;
  top: -2px;
  right: -12px;
  width: 12px;
  height: 26px;
  background: var(--c, #999);
  border-radius: 0 0 8px 8px;
  opacity: 0;
  transform: rotate(40deg);
  transform-origin: top left;
  transition: opacity 0.2s ease;
  clip-path: polygon(0 0, 55% 0, 100% 38%, 68% 100%, 30% 62%, 8% 55%);
}
.dowel.active .spoolmini {
  transform: rotate(-10deg);
}
.dowel.active .tail {
  opacity: 1;
  animation: curl 1.4s ease-in-out infinite alternate;
}
@keyframes curl {
  from { transform: rotate(38deg) scaleY(1); }
  to { transform: rotate(46deg) scaleY(1.15); }
}
.dowel .tlabel {
  margin-top: 3px;
  color: var(--secondary);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
}

/* ---- Modal ---- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(20,10,4,0.6);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--paper);
  width: 100%;
  max-width: 560px;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  text-align: center;
  font-family: Georgia, serif;
  box-shadow: 0 -6px 18px rgba(0,0,0,0.5);
}
.modal h3 { color: var(--primary); margin-bottom: 8px; }
.modal p { color: rgba(42,26,12,0.75); font-size: 0.9rem; margin-bottom: 18px; }
.modal .actions { display: flex; gap: 10px; }
.modal .actions button {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
}
.modal .danger { background: var(--thread-red); color: #fff; }
.modal .cancel { background: var(--secondary); color: var(--ink); }

.hidden { display: none !important; }

@media (min-width: 600px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 16px; }
}