:root {
  --wood: #7a5c3e;
  --wood-dark: #5d442c;
  --wood-deep: #463321;
  --linen: #f2e3c9;
  --linen-deep: #e8d3ac;
  --cream: #faf3e3;
  --coral: #d76a5b;
  --coral-deep: #b54f42;
  --moss: #7d8f5f;
  --indigo: #6a7b9c;
  --ink: #3c2f21;
  --shadow-soft: 0 6px 16px rgba(70, 51, 33, 0.25);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html { height: 100%; }

body {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(250, 243, 227, 0.08), transparent 55%),
    linear-gradient(160deg, var(--wood-deep) 0%, var(--wood) 60%, var(--wood-dark) 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hoop-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: calc(96px + var(--safe-bottom));
}

/* ---------- linen screen inside the hoop ---------- */
.tab-page {
  flex: 1;
  background: var(--linen);
  margin: calc(10px + var(--safe-top)) 10px 18px;
  border-radius: 50% 50% 44% 44% / 14% 14% 8% 8%;
  border: 6px solid var(--wood);
  box-shadow: inset 0 0 0 3px var(--cream), var(--shadow-soft);
  padding: 30px 20px 26px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.tab-page::-webkit-scrollbar { width: 0; }

/* ---------- headers ---------- */
.hoop-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }

.hoop-mark {
  width: 58px; height: 58px; flex: none;
  border-radius: 50%;
  border: 6px solid var(--wood);
  box-shadow: inset 0 0 0 3px var(--cream), 0 3px 8px rgba(70,51,33,.3);
  position: relative;
  background: var(--cream);
}
.hoop-mark span {
  position: absolute; left: 2px; right: 2px; top: 50%;
  height: 3px; margin-top: -1.5px; border-radius: 2px;
  background: var(--coral);
  transform: rotate(-24deg);
}
.hoop-mark span::after {
  content: ""; position: absolute; right: -7px; top: -6px;
  width: 14px; height: 3px; border-radius: 2px;
  background: var(--coral-deep);
  transform: rotate(28deg);
}

.app-title {
  font-size: 1.55rem; letter-spacing: .5px; color: var(--wood-dark);
  font-weight: normal;
}
.app-sub, .page-sub {
  font-size: .78rem; color: var(--wood); font-style: italic; margin-top: 2px;
}

.list-head { margin-bottom: 16px; }
.page-title { font-size: 1.4rem; font-weight: normal; color: var(--wood-dark); }

.section-label {
  font-size: .72rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--wood); margin: 22px 0 10px;
  display: flex; align-items: center; gap: 10px;
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--linen-deep); }

/* ---------- spool counters on the shelf ---------- */
.spool-shelf {
  display: flex; justify-content: space-evenly; align-items: flex-end;
  gap: 16px;
  padding: 6px 8px 18px;
  border-bottom: 3px dashed var(--linen-deep);
}

.spool {
  width: 132px;
  text-align: center;
  position: relative;
  padding: 16px 8px 12px;
}
.spool::before, .spool::after {
  content: ""; position: absolute; left: 6px; right: 6px; height: 12px;
  border-radius: 5px; background: linear-gradient(180deg, #8a6a49, var(--wood-dark));
  box-shadow: 0 2px 4px rgba(70,51,33,.35);
}
.spool::before { top: 0; }
.spool::after { bottom: 0; }

.spool-count {
  display: block;
  font-size: 2.4rem; line-height: 1;
  color: var(--cream);
  background: radial-gradient(circle at 35% 30%, #93714d, var(--wood-dark) 78%);
  border-radius: 50%;
  width: 96px; height: 96px; margin: 6px auto 8px;
  border: 4px solid var(--wood-dark);
  box-shadow: inset 0 -6px 10px rgba(0,0,0,.22), inset 0 5px 8px rgba(255,255,255,.12), 0 4px 8px rgba(70,51,33,.3);
  text-shadow: 0 1px 0 rgba(0,0,0,.35), 0 -1px 0 rgba(255,255,255,.08);
  padding-top: 24px;
}
.spool-label {
  display: block; font-size: .72rem; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--wood-dark); line-height: 1.35;
}
.spool-thread {
  position: absolute; top: 46px; left: -8px; right: -8px; height: 5px;
  border-radius: 3px; opacity: .85;
}
.t-coral { background: var(--coral); }
.t-wood { background: var(--moss); }

/* ---------- recent row on hoop ---------- */
.recent-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--cream);
  border: 2px dashed var(--coral);
  border-radius: 14px;
  padding: 14px 14px;
  box-shadow: 0 2px 6px rgba(70,51,33,.12);
}
.recent-row .swatch-strip { margin-bottom: 0; flex: none; }
.recent-main { flex: 1; min-width: 0; }
.recent-title { font-size: 1.02rem; color: var(--wood-dark); }
.recent-focus { font-size: .82rem; font-style: italic; color: var(--wood); }
.stage-chip { margin-left: auto; flex: none; }

/* ---------- swatch strip ---------- */
.swatch-strip {
  display: flex; gap: 4px; margin-bottom: 8px;
}
.swatch-strip i {
  width: 16px; height: 10px; border-radius: 3px;
  display: block; box-shadow: inset 0 0 0 1px rgba(70,51,33,.2);
}

/* ---------- stage chips / border colors ---------- */
.stage-chip {
  font-size: .68rem; letter-spacing: 1px; text-transform: uppercase;
  padding: 4px 10px; border-radius: 20px; background: var(--linen);
  white-space: nowrap;
}
.stage-chip.s-draft     { color: var(--indigo);    border: 1.5px solid var(--indigo); }
.stage-chip.s-stitching { color: var(--coral-deep);border: 1.5px solid var(--coral); }
.stage-chip.s-finish    { color: var(--moss);      border: 1.5px solid var(--moss); }

/* ---------- linen patch cards ---------- */
.patch-list { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }

.patch {
  background: var(--cream);
  border-radius: 4px;
  padding: 14px 14px 12px;
  border: 2.5px dashed var(--wood);
  position: relative;
  box-shadow: 0 3px 8px rgba(70,51,33,.14);
  transition: transform .12s ease;
}
.patch:active { transform: scale(.98); }

.patch.s-draft     { border-color: var(--indigo); border-style: dotted; }
.patch.s-stitching { border-color: var(--coral); }
.patch.s-finish    { border-color: var(--moss); }

.patch-top { display: flex; align-items: flex-start; gap: 10px; }
.patch-title { font-size: 1.08rem; color: var(--wood-dark); flex: 1; min-width: 0; word-break: break-word; }
.patch-focus { font-size: .85rem; font-style: italic; color: var(--wood); margin-top: 3px; }
.patch-palette { font-size: .78rem; color: var(--ink); opacity: .75; margin-top: 6px; }
.patch-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }

.patch-del {
  background: none; border: none; cursor: pointer;
  font-size: .74rem; letter-spacing: 1px; text-transform: uppercase;
  color: var(--coral-deep); padding: 10px 8px; margin: -6px -4px -6px 0;
  min-height: 44px;
}
.patch-del:active { opacity: .6; }

/* ---------- empty states ---------- */
.empty-state {
  text-align: center;
  padding: 34px 18px;
  color: var(--wood);
  font-style: italic;
  line-height: 1.6;
  font-size: .92rem;
}
.empty-state .empty-hoop {
  width: 64px; height: 64px; margin: 0 auto 14px;
  border-radius: 50%;
  border: 5px solid var(--linen-deep);
  box-shadow: inset 0 0 0 3px var(--cream);
  position: relative;
}
.empty-state .empty-hoop::after {
  content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 2px;
  background: var(--linen-deep); transform: rotate(-30deg);
}

/* ---------- search ---------- */
.search-wrap { margin-bottom: 4px; }
.native-input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--linen-deep);
  border-radius: 10px;
  padding: 13px 14px;
  min-height: 48px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.native-input:focus { border-color: var(--coral); }
.native-input::placeholder { color: var(--wood); opacity: .55; font-style: italic; }

/* ---------- form ---------- */
.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: .7rem; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--wood); margin-bottom: 6px;
}

.stage-choice { display: flex; gap: 8px; }
.stage-opt {
  flex: 1;
  min-height: 48px;
  font-family: inherit;
  font-size: .85rem;
  letter-spacing: .5px;
  border-radius: 10px;
  border: 2px solid var(--linen-deep);
  background: var(--cream);
  color: var(--wood);
  cursor: pointer;
}
.stage-opt.s-draft[aria-pressed="true"]     { border-color: var(--indigo); color: var(--indigo); background: #eef1f5; box-shadow: inset 0 0 0 1px var(--indigo); }
.stage-opt.s-stitching[aria-pressed="true"] { border-color: var(--coral); color: var(--coral-deep); background: #f9e8e2; box-shadow: inset 0 0 0 1px var(--coral); }
.stage-opt.s-finish[aria-pressed="true"]    { border-color: var(--moss); color: var(--moss); background: #eef1e4; box-shadow: inset 0 0 0 1px var(--moss); }

.form-error {
  color: var(--coral-deep);
  font-size: .85rem;
  background: #f9e8e2;
  border: 1.5px dashed var(--coral);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.form-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

/* ---------- buttons ---------- */
.btn {
  font-family: inherit;
  font-size: .95rem;
  letter-spacing: .5px;
  min-height: 50px;
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(70,51,33,.2);
}
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; margin-top: 18px; }
.btn-primary { background: var(--wood); color: var(--cream); }
.btn-danger { background: var(--coral); color: var(--cream); }
.btn-ghost {
  background: transparent; color: var(--wood-dark);
  border: 2px dashed var(--wood); box-shadow: none;
}

/* ---------- guide ---------- */
.tip {
  background: var(--cream);
  border-left: 4px solid var(--coral);
  border-radius: 4px 12px 12px 4px;
  padding: 14px 14px;
  margin-bottom: 14px;
  box-shadow: 0 2px 6px rgba(70,51,33,.1);
}
.tip h3 { font-size: .98rem; font-weight: normal; color: var(--wood-dark); margin-bottom: 6px; }
.tip p { font-size: .85rem; line-height: 1.55; color: var(--ink); }

.about-card {
  margin-top: 22px;
  background: var(--wood);
  color: var(--linen);
  border-radius: 14px;
  padding: 18px 16px;
  box-shadow: var(--shadow-soft);
}
.about-card h3 { font-size: 1rem; font-weight: normal; margin-bottom: 8px; color: var(--cream); }
.about-card p { font-size: .84rem; line-height: 1.6; opacity: .92; }
.about-data { margin-top: 10px; font-style: italic; }
.about-card .btn-ghost { color: var(--linen); border-color: var(--linen-deep); margin-top: 14px; }

.guide-empty {
  margin-top: 16px;
  text-align: center;
  font-style: italic;
  color: var(--wood);
  font-size: .9rem;
  line-height: 1.7;
  padding: 14px 8px;
}

/* ---------- bobbin bottom nav ---------- */
.bobbin-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  padding: 10px 12px calc(12px + var(--safe-bottom));
  background: linear-gradient(180deg, var(--wood-dark), var(--wood-deep));
  border-top: 3px solid var(--wood);
  z-index: 10;
}

.bobbin {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 10px 0;
  min-width: 64px;
}

.bobbin-body {
  width: 40px; height: 34px;
  border-radius: 7px;
  background: linear-gradient(180deg, #a07c52, var(--wood));
  border: 1.5px solid var(--wood-deep);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  padding: 5px 0;
  transition: transform .18s ease, box-shadow .18s ease;
}
.bobbin-line {
  display: block;
  width: 26px; height: 3px;
  border-radius: 2px;
  background: var(--linen-deep);
  opacity: .8;
}
.bobbin:nth-child(1) .bobbin-line { background: var(--coral); opacity: .9; }
.bobbin:nth-child(2) .bobbin-line { background: var(--moss); }
.bobbin:nth-child(3) .bobbin-line { background: var(--indigo); }
.bobbin:nth-child(4) .bobbin-line { background: var(--linen); }

.bobbin-tail {
  width: 3px; height: 0;
  background: var(--linen-deep);
  border-radius: 2px;
  transition: height .18s ease;
  position: absolute;
  top: 30px;
  left: 50%;
  margin-left: -1.5px;
}

.bobbin-label {
  font-size: .68rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--linen-deep);
  opacity: .75;
  transition: opacity .18s ease;
}

.bobbin.active .bobbin-body {
  transform: translateY(-7px);
  box-shadow: 0 8px 12px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
  background: linear-gradient(180deg, #b08a5c, #8a6845);
  border-color: var(--wood-deep);
}
.bobbin.active .bobbin-tail { height: 14px; top: 36px; background: var(--coral); }
.bobbin.active .bobbin-label { opacity: 1; color: var(--cream); font-weight: bold; }

/* ---------- narrow tweaks ---------- */
@media (max-width: 360px) {
  .spool { width: 116px; }
  .spool-count { width: 84px; height: 84px; padding-top: 20px; font-size: 2rem; }
  .tab-page { padding: 24px 14px 22px; }
}
