:root {
  --bg: #1c1b1a;
  --bg-raised: #2a2826;
  --bg-card: #262422;
  --line: #3a3734;
  --text: #ece7e0;
  --text-dim: #a39b91;
  --accent: #d2a874;        /* warm tan: active buttons, progress, ticks, star */
  --accent-ink: #1c1b1a;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

/* Screen area: content scrolls behind the floating nav bar */
.screen {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding: 24px 20px calc(var(--nav-h) + 48px);
}

h1, h2 {
  font-family: var(--serif);
  font-weight: 400;
  margin: 0 0 8px;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.25rem; }

.tag {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.muted { color: var(--text-dim); line-height: 1.5; }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-top: 16px;
}

/* Floating, rounded bottom navigation */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(360px, calc(100% - 32px));
  height: var(--nav-h);
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(42, 40, 38, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 32px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.tab {
  flex: 1;
  height: 100%;
  background: none;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-dim);
  font-size: 0.72rem;
  cursor: pointer;
  border-radius: 32px;
}

.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.tab.active { color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

/* ---------- Shared ---------- */
a { color: inherit; text-decoration: none; }
.link { color: var(--accent); font-size: 0.9rem; }
h3 { font-family: var(--serif); font-weight: 400; margin: 0; }
svg .solid, .solid { fill: currentColor; stroke: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 999px;
  background: var(--bg-raised); border: 1px solid var(--line);
  color: var(--text-dim); font-size: 0.82rem; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: none; border: 0; color: var(--text-dim); cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { color: var(--text); }
.icon-btn.on { color: var(--accent); }
.icon-btn.on[data-act="fav"] svg { fill: var(--accent); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panel { display: block; }
.panel h2 { margin-bottom: 6px; }
.panel-link:hover, .card:hover, .knot-card:hover { border-color: var(--accent); }
.row-link { display: block; padding: 10px 0; border-top: 1px solid var(--line); }
.row-link:first-of-type { border-top: 0; }
.continue { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.continue .go { color: var(--accent-ink); background: var(--accent); padding: 8px 14px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.four-dots { display: flex; gap: 8px; margin-bottom: 10px; }
.four-dots span {
  min-width: 34px; height: 34px; padding: 0 6px; border-radius: 17px; display: grid; place-items: center;
  border: 2px solid var(--c); color: var(--c); font-size: 0.75rem; font-weight: 700;
}

/* ---------- Library ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 4px; }
.group-title { margin: 24px 0 12px; font-size: 1.1rem; color: var(--text-dim); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  display: flex; flex-direction: column;
}
.card-pic { background: radial-gradient(circle at 50% 45%, #3a3632, #262422 70%); aspect-ratio: 180 / 72; }
.card-pic svg { width: 100%; height: 100%; display: block; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card h3 { font-size: 1rem; display: flex; justify-content: space-between; gap: 6px; }
.card p { margin: 0; font-size: 0.78rem; color: var(--text-dim); line-height: 1.35; }
.card p:not(.tag) { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .tag { margin-top: auto; padding-top: 4px; font-size: 0.62rem; }
.card.soon .card-pic { opacity: 0.55; }
.card-star svg { width: 15px; height: 15px; fill: var(--accent); stroke: var(--accent); }
.empty { margin-top: 24px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 32px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 0.85rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); z-index: 5;
}

/* ---------- Learn the four knots ---------- */
.knot-list { display: grid; gap: 12px; margin-top: 16px; }
.knot-card {
  display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: center;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px 10px 10px;
}
.knot-loop { width: 110px; height: 154px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #3b3733, #211f1d 75%); }
.knot-card h2 { font-size: 1.15rem; margin: 2px 0 4px; }
.knot-card .muted { font-size: 0.85rem; margin: 0 0 6px; }

/* ---------- Tutorial ---------- */
body.no-tabs .tabbar { display: none; }
body.no-tabs .screen { padding: 0; }
.tut {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  padding: 6px 14px calc(10px + env(safe-area-inset-bottom));
}
.tut-top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--text-dim); font-size: 0.9rem; padding: 6px 6px 6px 0; }
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.top-actions { display: flex; }
.tut-head { padding: 0 2px; }
.tut-title { font-size: 1.75rem; margin: 0 0 2px; }
.tut-head .tag { margin: 0; }
.legend { list-style: none; display: flex; gap: 14px; padding: 0; margin: 8px 0 0; font-size: 0.85rem; }
.legend li { display: flex; align-items: center; gap: 6px; color: var(--text-dim); }
.legend li.working { color: var(--text); }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px rgba(0,0,0,.4); }
.legend li.working .dot { box-shadow: 0 0 0 2px var(--accent); }
.legend em { font-style: normal; font-size: 0.65rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }

.stage {
  position: relative; flex: 1; min-height: 180px; margin: 8px -14px 0;
  background: radial-gradient(ellipse 60% 55% at 50% 45%, #3d3934 0%, #2a2725 45%, var(--bg) 80%);
}
.scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.method-switch { display: inline-flex; gap: 4px; margin-top: 10px; padding: 3px; border-radius: 999px; background: var(--bg-raised); border: 1px solid var(--line); }
.method-switch .chip { border: 0; padding: 5px 12px; }
.method-switch .chip:not(.on) { background: transparent; }
.variant-pick { margin-top: 10px; display: grid; gap: 6px; }
.variant-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.variant-row .tag { margin: 0 4px 0 0; min-width: 4.2em; }
.variant-row .chip { padding: 4px 10px; }
.head-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.head-chips .chip { padding: 5px 12px; }
.tracker {
  float: right; margin: 0 0 6px 12px; padding: 5px 7px 7px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.tracker[hidden] { display: none; }
.tracker-label { margin: 0 0 4px; font-size: 0.6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.tracker svg { display: block; }
.legend { flex-wrap: wrap; gap: 6px 12px; }
.bare-bar { display: none; }

.step-card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 18px;
  padding: 12px 14px 10px; margin-top: 8px;
}
.step-meta { display: flex; justify-content: space-between; align-items: baseline; }
.step-meta .tag { margin: 0; color: var(--accent); }
.time { font-size: 0.75rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.step-title { font-weight: 700; margin: 6px 0 2px; font-size: 1rem; }
.step-detail { margin: 0; color: var(--text-dim); font-size: 0.85rem; line-height: 1.4; min-height: 2.8em; }
.step-nums { display: flex; gap: 4px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.step-nums button {
  flex: 1 0 28px; height: 28px; border-radius: 14px; border: 1px solid var(--line);
  background: none; color: var(--text-dim); font-size: 0.78rem; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.step-nums button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.4; }
.step-nums button.past { color: var(--text); border-color: #5a524a; }
.step-nums button.current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.scrub { position: relative; height: 24px; margin-top: 6px; }
.scrub-track { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: var(--line); }
.scrub-fill { height: 100%; border-radius: 2px; background: var(--accent); width: 0; }
.ticks span { position: absolute; top: -3px; width: 2px; height: 10px; margin-left: -1px; background: #6a625a; border-radius: 1px; }
.scrub input { position: absolute; inset: 0; width: 100%; margin: 0; opacity: 0; cursor: pointer; }

.playbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; padding: 6px 10px; border-radius: 32px;
  background: var(--bg-raised); border: 1px solid var(--line);
}
.speed {
  min-width: 48px; height: 32px; border-radius: 16px; border: 1px solid var(--line); background: none;
  color: var(--text); font-size: 0.8rem; cursor: pointer; font-variant-numeric: tabular-nums;
}
.play-btn {
  width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.play-btn svg { width: 26px; height: 26px; }
.play-btn.small { width: 44px; height: 44px; }
.play-btn.small svg { width: 20px; height: 20px; }

/* Hide-controls (eye) mode: only the animation and a small bar */
.tut.bare .tut-top, .tut.bare .tut-head, .tut.bare .step-card, .tut.bare .playbar, .tut.bare .zoom-toggle { display: none; }
.tut.bare .stage { margin-top: 0; }
.tut.bare .bare-bar {
  display: flex; align-items: center; gap: 10px;
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  padding: 6px 10px; border-radius: 30px; background: rgba(42,40,38,.9); border: 1px solid var(--line);
}

/* Show mode: like hide-controls, plus big captions for showing someone a step */
.show-caption { display: none; }
.tut.show .show-caption {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  position: absolute; left: 16px; right: 16px; bottom: 80px;
  padding: 12px 16px; border-radius: 16px; background: rgba(28,27,26,.85); border: 1px solid var(--line);
}
.show-step { font-size: 0.8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.show-title { font-family: var(--serif); font-size: 1.7rem; line-height: 1.2; }
.show-name, .show-detail, .show-progress { display: none; }
.fs-btn { display: none; }
.tut.show .fs-btn { display: grid; }

/* Show mode on a wide screen (a TV, a cast PC tab, a phone turned sideways):
   animation on the left, large caption panel on the right. */
body.showing .screen { max-width: none; }
@media (min-aspect-ratio: 5/4) {
  .tut.show { flex-direction: row; padding: 0; }
  .tut.show .stage { margin: 0; flex: 1; display: flex; justify-content: flex-end; }
  .tut.show .scene { width: 62%; }
  .tut.show .bare-bar { left: 31%; }
  .tut.show .show-caption {
    position: static; flex: 0 0 38%; max-width: 38%;
    align-items: flex-start; justify-content: center; text-align: left; gap: 1.2vh;
    padding: 4vh 4vw 4vh 2vw; border: 0; border-radius: 0; background: none;
  }
  .tut.show .show-name { display: block; font-family: var(--serif); font-size: clamp(1rem, 2.2vw, 2.2rem); color: var(--text-dim); }
  .tut.show .show-step { font-size: clamp(0.8rem, 1.5vw, 1.5rem); }
  .tut.show .show-title { font-size: clamp(1.4rem, 3.6vw, 4rem); line-height: 1.15; }
  .tut.show .show-detail { display: block; font-size: clamp(0.85rem, 1.9vw, 2rem); line-height: 1.45; color: var(--text-dim); }
  .tut.show .show-progress { display: block; width: 100%; height: 6px; margin-top: 2vh; border-radius: 3px; background: var(--line); overflow: hidden; }
  .tut.show .show-progress span { display: block; height: 100%; width: 0; background: var(--accent); }
}

/* Info sheet */
.sheet {
  border: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 16px 20px 24px;
  background: var(--bg-raised); color: var(--text);
  width: 100%; max-width: 560px; margin: auto auto 0; max-height: 85vh;
}
.sheet::backdrop { background: rgba(0,0,0,.6); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-pic { display: block; width: 120px; height: 168px; margin: 4px auto 8px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #3b3733, #211f1d 75%); }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 0.9rem; }
.sheet dt { color: var(--text-dim); }
.sheet dd { margin: 0; }
.sheet { overflow-y: auto; overscroll-behavior: contain; padding-top: 0; }
.sheet-head { position: sticky; top: 0; z-index: 1; background: var(--bg-raised); padding-top: 12px; }
.sheet-h { font-size: 1.1rem; margin: 22px 0 6px; color: var(--accent); }
.sheet-body p, .sheet-body li { font-size: 0.9rem; line-height: 1.5; color: var(--text); }
.sheet-body p { margin: 0 0 10px; }
.sheet-body ul { margin: 0; padding-left: 20px; }
.sheet-body li { margin-bottom: 8px; }
.sheet-body li::marker { color: var(--accent); }
.units-toggle { display: flex; margin: 0 auto 14px; width: fit-content; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.units-toggle button { border: 0; background: transparent; color: var(--text-dim); padding: 7px 14px; font-size: 0.82rem; cursor: pointer; }
.units-toggle button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

@media (max-height: 700px) {
  .tut-title { font-size: 1.4rem; }
  .step-detail { min-height: 0; }
  .play-btn { width: 46px; height: 46px; }
}

/* Practice: pattern designer */
.designer-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.stepper { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-dim); }
.stepper button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-raised); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.stepper b { min-width: 1.6em; text-align: center; color: var(--text); font-variant-numeric: tabular-nums; }
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; box-shadow: 0 0 0 1px rgba(0,0,0,.5) inset; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--accent); }
.swatch.any { width: auto; padding: 0 12px; border-radius: 999px; background: var(--bg-raised); border-color: var(--line); font-size: 0.8rem; color: var(--text-dim); }
.swatch.any.on { color: var(--text); border-color: var(--accent); }
.design-wrap { background: radial-gradient(circle at 50% 40%, #34302c, #211f1d 80%); border-radius: 16px; padding: 10px; }
.design { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }
.design .guide { stroke: #3a3734; stroke-width: 1; }
.design text { font: 700 9px var(--sans); text-anchor: middle; fill: #1c1b1a; pointer-events: none; }
.design .strand-dot { cursor: pointer; }
.design .strand-dot circle { stroke: rgba(0,0,0,.5); stroke-width: 1.5; }
.design .strand-dot text { font-size: 11px; }
.design .cell { cursor: pointer; }
.design .cell ellipse { stroke: #5a524a; stroke-width: 1; stroke-dasharray: 3 2; }
.design .cell:not(.set) text { fill: var(--text-dim); }
.design .cell.set ellipse { stroke: rgba(0,0,0,.45); stroke-dasharray: none; }
.design .cell.bad ellipse { stroke: #ff5a5a; stroke-width: 2.5; stroke-dasharray: none; }
.design-status { font-size: 0.88rem; line-height: 1.45; color: #e9a08a; min-height: 3em; }
.design-status.ok { color: var(--text-dim); }
.design-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.go-btn { color: var(--accent-ink); background: var(--accent); padding: 9px 16px; border-radius: 999px; font-size: 0.9rem; font-weight: 600; }
.go-btn { border: 0; cursor: pointer; font-family: inherit; }
.go-btn.disabled { opacity: 0.4; cursor: not-allowed; }
.design-name { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.design-name .tag { margin: 0; }
.design-name input { flex: 1; min-width: 0; background: var(--bg-raised); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 0.95rem; }
.design-name input:focus { outline: none; border-color: var(--accent); }
.chip.danger { color: #e9a08a; }
.chip[hidden] { display: none; }
.design-note { font-size: 0.88rem; color: var(--text-dim); min-height: 1.4em; }
.card.new-design .card-pic { display: grid; place-items: center; font-size: 2rem; color: var(--accent); }

/* Thread colors picker */
.colors-sheet .muted { font-size: 0.85rem; margin: 0 0 12px; }
.color-row { border-top: 1px solid var(--line); }
.color-head { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 2px; background: none; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.color-head .muted { margin: 0 0 0 auto; font-size: 0.8rem; }
.color-name { text-transform: capitalize; }
.color-name small { text-transform: none; color: var(--text-dim); font-size: 0.75rem; margin-left: 4px; }
.dot.big { width: 26px; height: 26px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px rgba(0,0,0,.4); flex: none; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 8px; padding: 0 2px 14px; }
.swatch { aspect-ratio: 1; border-radius: 50%; background: var(--c); border: 2px solid rgba(0,0,0,.35); cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.swatch.custom { position: relative; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); overflow: hidden; }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.colors-foot { display: flex; justify-content: space-between; gap: 10px; margin: 16px 0 4px; }
