/* BoBo Crochet — warm, mobile-first, large touch targets, no framework, no external fonts.
   Contrast: --ink/--muted/--brand-strong all >= 4.5:1 on --bg and white (WCAG AA). */
:root {
  --bg: #fdf8f4; --card: #fff; --ink: #3b2f2a; --muted: #6f5f57; --line: #eadfd6; --soft: #fbefe9;
  --brand: #e07a5f; --brand-strong: #b9533a; --brand-ink: #fff; --focus: #2f6fb3;
  --ok: #2e7d4f; --warn: #8a5800; --err: #b3261e;
  --radius: 16px; --gap: 1rem; --tap: 48px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand-strong); }
h1 { font-size: clamp(1.45rem, 4vw, 1.9rem); line-height: 1.25; margin: .2rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 0 0 .6rem; }
code { background: var(--soft); padding: 0 .3rem; border-radius: 6px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: .5rem; background: var(--card); padding: .6rem 1rem; border-radius: 10px; z-index: 10; }
.skip-link:focus { left: .5rem; }
main:focus { outline: none; }

/* Layout */
.container { max-width: 1440px; margin: 0 auto; padding: var(--gap); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; padding: .5rem var(--gap); background: rgba(255,255,255,.95); border-bottom: 1px solid var(--line); }
.topbar nav { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.brand { display: inline-flex; align-items: center; gap: .45rem; min-height: var(--tap); font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--gap); margin-bottom: var(--gap); box-shadow: 0 1px 2px rgba(59,47,42,.05); }
.narrow { max-width: 420px; margin: 2rem auto; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.row > label { flex: 1 1 140px; }
.row-top { align-items: flex-start; }  /* fields with a hint under them: line up the inputs, not the hints */
.center { text-align: center; }
.inline { display: inline; }
.muted { color: var(--muted); font-weight: 400; }

/* Forms */
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: .6rem; font-weight: 500; min-height: var(--tap); }
.hint, .optional { color: var(--muted); font-weight: 400; font-size: .9rem; }
input, select, textarea { font: inherit; color: inherit; padding: .65rem .8rem; border: 1.5px solid #d9cabe; border-radius: 12px; background: #fff; min-height: var(--tap); width: 100%; }
textarea { resize: vertical; }
input[type=file] { padding: .5rem; background: var(--soft); border-style: dashed; }
label.check input { width: 24px; height: 24px; min-height: 0; accent-color: var(--brand-strong); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: var(--tap); padding: .5rem 1.1rem; border-radius: 12px; border: 1.5px solid #d9cabe; background: #fff; color: var(--ink); font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; transition: background .15s, transform .1s; }
.btn:hover { background: var(--soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .65; cursor: progress; }
.btn-primary { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--brand-ink); box-shadow: 0 2px 0 #8f3c28; }
.btn-primary:hover { background: #a3452e; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-big { font-size: 1.12rem; padding: .85rem 1.5rem; min-height: 54px; }
.btn-block { width: 100%; }
.link { background: none; border: none; color: var(--brand-strong); font: inherit; cursor: pointer; padding: .5rem .25rem; min-height: 44px; text-decoration: underline; }

/* Alerts & badges */
.alert { border-radius: 12px; padding: .8rem 1rem; margin: 0 0 var(--gap); border-left: 5px solid currentColor; }
.alert p { margin: 0; }
.alert ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.alert-action { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; justify-content: space-between; }
.alert-error { background: #fdecea; color: var(--err); }
.alert-warn { background: #fff4e0; color: var(--warn); }
.alert-ok { background: #e8f5ec; color: var(--ok); font-weight: 600; }
.badge { display: inline-block; font-size: .85rem; font-weight: 600; padding: .2rem .7rem; border-radius: 999px; background: #f1e7df; color: var(--ink); white-space: nowrap; }
.badge-tested { background: #e3f0ff; color: #1d4f86; } .badge-published { background: #e8f5ec; color: var(--ok); }

/* List */
.empty { text-align: center; padding: 2rem 1rem; }
.empty-art { width: 96px; height: 96px; }
.empty p { max-width: 32ch; margin: .5rem auto 1.2rem; }
.pattern-list { list-style: none; padding: 0; margin: 0; }
.pattern-link { display: flex; gap: .75rem; align-items: center; min-height: 72px; text-decoration: none; color: var(--ink); transition: border-color .15s; }
.pattern-link:hover { border-color: var(--brand); }
.pattern-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.pattern-main strong { font-size: 1.1rem; overflow-wrap: anywhere; }
.chevron { font-size: 1.8rem; color: var(--muted); line-height: 1; }

/* View */
.title-row, .toolbar, .status-picker, .resize-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: var(--gap); }
.title-row h1 { margin: 0; }
.status-label { font-weight: 600; }
.segmented { display: inline-flex; border: 1.5px solid #d9cabe; border-radius: 12px; overflow: hidden; background: #fff; }
.segmented a, .segmented button { padding: .5rem .95rem; min-height: var(--tap); display: inline-flex; align-items: center; border: 0; background: #fff; color: var(--ink); font: inherit; text-decoration: none; cursor: pointer; }
.segmented > * + * { border-left: 1.5px solid #d9cabe; }
.segmented .active { background: var(--brand-strong); color: #fff; font-weight: 650; }
.pattern-header { background: var(--soft); }
.pattern-header p { margin: .2rem 0; }
.part h2 { color: var(--brand-strong); }
.rounds { margin: 0; padding: 0; list-style: none; font-size: 1.05rem; line-height: 1.6; font-variant-numeric: tabular-nums; }
.rounds li { padding: .5rem .6rem; border-radius: 8px; overflow-wrap: anywhere; }
.rounds .round:nth-child(even) { background: #faf5f1; }
.rounds .note { margin: .35rem 0; background: #fff8e6; border-left: 4px solid #e0b04a; font-style: italic; }
.rounds .note::before { content: "✎ "; font-style: normal; }

/* Job progress */
.job { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 1.6rem 1rem; }
.job p { margin: .3rem 0; }
.spinner { width: 44px; height: 44px; margin-bottom: .4rem; border: 5px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Editor */
.editor { display: grid; gap: var(--gap); }
.editor:has(#edit-form.htmx-request) #preview { opacity: .55; transition: opacity .2s; }
.profile { width: 100%; border-collapse: collapse; }
.profile th { text-align: left; font-size: .9rem; color: var(--muted); padding: 0 .2rem; }
.profile td { padding: .2rem; }
.profile-help summary { cursor: pointer; color: var(--brand-strong); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.profile-help-body { display: flex; gap: .8rem; align-items: center; background: var(--soft); border-radius: 12px; padding: .7rem; font-size: .95rem; }
.profile-help-body p { margin: 0; }
.profile-svg { width: 84px; flex: none; }
.sticky-actions { position: sticky; bottom: 0; z-index: 4; display: flex; flex-wrap: wrap; gap: .6rem; padding: .7rem var(--gap); margin: 0 calc(-1 * var(--gap)); background: rgba(253,248,244,.97); border-top: 1px solid var(--line); }
.sticky-actions .btn-primary { flex: 1 1 160px; }
.versions summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.versions li { padding: .2rem 0; }
.yarn-row { border-top: 1px solid var(--line); padding-top: .9rem; }

@media (min-width: 900px) {
  .editor { grid-template-columns: 1fr 1fr; align-items: start; }
  .editor aside { position: sticky; top: 5rem; max-height: calc(100vh - 6rem); overflow: auto; }
  .jump-preview { display: none; }
}
@media (max-width: 480px) { .topbar .btn-ghost { padding: .5rem .6rem; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .spinner { animation: none; border-top-color: var(--brand); border-right-color: var(--brand); }
}

/* Print: chart only, black on white, no splitting a round across pages. */
@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .topbar, .skip-link, .no-print, .alert, .job { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; margin-bottom: 1rem; }
  .part { break-inside: auto; }
  .part h2 { color: #000; break-after: avoid; border-bottom: 1pt solid #000; }
  .rounds li { break-inside: avoid; padding: .15rem 0 .15rem 1.6rem; position: relative; border-bottom: .5pt dotted #999; }
  .rounds .round::before { content: ""; position: absolute; left: 0; top: .35rem; width: .8rem; height: .8rem; border: 1pt solid #000; }
  .rounds .round:nth-child(even), .rounds .note, .pattern-header { background: none; }
  a { color: #000; text-decoration: none; }
}

/* Phase 4: silhouettes, assembly diagram, cover photo */
.part-title { display: flex; align-items: center; gap: .8rem; margin-bottom: .4rem; }
.part-title h2 { margin: 0; }
.part-svg svg { width: 72px; height: auto; display: block; }
.assembly-svg svg { width: 100%; max-width: 420px; height: auto; display: block; margin: 0 auto; }
.cover-photo { max-width: 100%; max-height: 420px; border-radius: 12px; display: block; margin-bottom: .8rem; }
@media print { .part-svg svg { width: 60px; } .assembly { break-inside: avoid; } }

/* Phase 8: expected shape preview (2D+3D) */
.expected-shape-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.expected-shape-part { margin: 0; border: 1px solid var(--line); border-radius: 12px; padding: .6rem; background: #fffdfb; }
.expected-shape-part figcaption { font-weight: 650; margin: 0 0 .35rem; color: var(--brand-strong); }
.expected-shape-part svg { width: 100%; height: auto; display: block; }
.shape-3d { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .9rem; }
.shape-3d summary { cursor: pointer; font-weight: 650; color: var(--brand-strong); }
.shape-3d [data-shape-reset] { margin-top: .5rem; }
.shape-3d [data-shape-reset][hidden] { display: none; }
.shape-3d-stage { border: 1px solid var(--line); border-radius: 12px; height: 380px; background: linear-gradient(#fff, #f8f2ed); overflow: hidden; }
.shape-3d-stage canvas { display: block; }
/* build playback (shape-3d-build-playback.js); fullscreen = the model only, for screen-recorded clips */
.shape-build { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: .5rem; }
.shape-build[hidden], .shape-build [hidden] { display: none; }
.shape-build input[type=range] { flex: 1 1 10rem; width: auto; padding: 0; border: 0; background: none; accent-color: var(--brand-strong); }
.shape-build select { width: auto; }
.resize-form label { flex: 1 1 22rem; }
.resize-form .alert { flex-basis: 100%; margin: 0; }
.resize-form input { max-width: 8rem; }
.shape-build-hint { flex-basis: 100%; margin: 0; font-size: .85rem; }
.shape-3d-stage:fullscreen { width: 100vw; height: 100vh; border: 0; border-radius: 0; background: #f8f2ed; }

/* Phase 5: learning */
.grow { flex: 1 1 260px; }
.lesson { border-top: 1px solid var(--line, #eadfd6); padding-top: .6rem; }
.star { flex-direction: row; align-items: center; gap: .3rem; padding: .5rem .8rem; font-weight: 600; cursor: pointer; }
.star input { width: auto; min-height: auto; }
.lesson .badge, label > .badge { align-self: flex-start; }

/* Help page */
.help-toc ol, .help-steps { margin: .4rem 0 0; padding-left: 1.4rem; }
.help-toc li, .help-steps li { margin: .3rem 0; }
.help-table { width: 100%; border-collapse: collapse; }
.help-table th, .help-table td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--line, #eadfd6); }
.help-faq dt { font-weight: 700; margin-top: .8rem; }
.help-faq dd { margin: .2rem 0 0; }
section[id] { scroll-margin-top: 80px; }

/* Pattern management */
.manage-filters { display: flex; flex-direction: column; gap: .8rem; }
.manage-filters .segmented { flex-wrap: wrap; }
.pattern-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.pattern-row .pattern-link { flex: 1 1 320px; }
.pattern-facts { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .9rem; margin-top: .2rem; }
.toolbar-manage { justify-content: flex-end; }
.btn-danger { background: #b3261e; border-color: #b3261e; color: #fff; }
.btn-danger-text { color: #b3261e; }
.timeline { list-style: none; padding: 0; }
.tl-item { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line, #eadfd6); }
.tl-time { min-width: 9.5rem; color: var(--muted, #6b5d55); font-variant-numeric: tabular-nums; }
.tl-body { flex: 1 1 260px; display: flex; flex-direction: column; }
.tl-fail strong { color: #b3261e; }
.segmented small { margin-left: .3rem; opacity: .8; }

/* yarn colour tables (/settings/colors) */
.swatch { display: inline-block; width: 1.4em; height: 1.4em; border-radius: 50%; border: 1px solid #0003; background: #e9dccb; vertical-align: middle; flex: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.photo-thumb { margin: 0; }
.photo-thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; }
.photo-thumb figcaption { font-size: .85rem; display: flex; flex-direction: column; gap: .2rem; margin-top: .3rem; }
.measure-table { border-collapse: collapse; width: 100%; }
.measure-table th, .measure-table td { padding: .25rem .4rem; text-align: left; }
.measure-table input { width: 6rem; }
.part-real { margin: .6rem 0; }
.part-real .photo-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.size-real { margin: .2rem 0; font-size: .9rem; }

/* Colour table (Cài đặt › Mã màu len): one compact row per colour, column headings once. */
.table-scroll { overflow-x: auto; }
.color-table { width: 100%; border-collapse: collapse; }
.color-table th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; padding: .3rem .35rem; }
.color-table td { padding: .2rem .35rem; border-top: 1px solid #0000000f; vertical-align: middle; }
.color-table input:not([type=checkbox]) { width: 100%; min-width: 4.5rem; padding: .3rem .45rem; }
.color-table td:nth-child(3) input { min-width: 11rem; }
.color-table .actions { white-space: nowrap; text-align: right; }
.color-table .actions form + form { margin-left: .6rem; }
.btn-small { padding: .25rem .7rem; font-size: .9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.color-table input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand-strong); }
