/* Mofu Mofu Loom — the app shell, the workbench and the choosers.
   Phone first (stage on top, the cream panel below); html[data-layout="wide"] puts the stage on the
   left and the panel on the right as one centred group. */

:root {
  --cream: #fffaf1;
  --cream-edge: #f1e6d3;
  --wood: #f5e6cc;
  --wood-2: #efdcbc;
  --wood-edge: #e3cca5;
  --wall: #fbf7ff;
  --ring: #b3a5f2;
  --ring-soft: #ebe5ff;
  --gutter: 10px;
  --panel-h: clamp(300px, 56%, 480px);   /* Threads and Weave: a fixed height, so the loom does not jump between tabs or steps */
}

html, body { height: 100%; }
html { overflow: hidden; }
body {
  position: fixed; inset: 0;          /* the page itself never scrolls; only .opts may */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  background-attachment: scroll;
}
textarea { -webkit-user-select: text; user-select: text; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.screen { position: absolute; inset: 0; }

/* ---------------------------------------------------------------- Start */
.start { display: grid; place-items: center; padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 20px); }
.start-group { display: grid; justify-items: center; gap: 12px; text-align: center; width: min(100%, 460px); }
.start-charm { height: min(46svh, 380px); aspect-ratio: 80 / 112; margin-bottom: 4px; }
.start-charm .sway, .start-charm svg { width: 100%; height: 100%; }
.start h1 { margin: 0; font-size: clamp(30px, 8.6vw, 44px); font-weight: 700; color: var(--logo); letter-spacing: .01em; line-height: 1.05; }
.start-line { margin: 0; color: var(--ink-soft); font-size: clamp(16px, 4.4vw, 19px); }
.btn.big { min-height: 60px; padding: 0 36px; font-size: 20px; margin-top: 10px; }
@media (max-height: 600px) { .start-charm { height: 38svh; } .btn.big { min-height: 54px; } }

.sway { transform-origin: 50% 4.5%; animation: sway 3.2s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }

/* ---------------------------------------------------------------- maker: phone */
.maker {
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + var(--gutter)) var(--gutter) 0;
}
.stage {
  position: relative; flex: 1 1 auto; min-height: 0;
  border-radius: 28px; overflow: hidden;
  background: linear-gradient(180deg, #fdfaff 0%, #fbf4fb 55%, #fdf3ee 100%);
  box-shadow: inset 0 0 0 2px #f1e9fb;
}
/* the pale wood desk: the lower part of the stage, with a soft front edge and two long grain lines */
.desk {
  position: absolute; left: 0; right: 0; bottom: 0; height: 46%;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-2) 100%);
  border-top: 3px solid #fbf1df;
  box-shadow: inset 0 3px 0 #ead7b5;
}
.desk::before, .desk::after {
  content: ''; position: absolute; height: 2px; border-radius: 2px; background: #e8d2ad; opacity: .8;
}
.desk::before { left: 9%; width: 36%; top: 30%; }
.desk::after { right: 12%; width: 28%; top: 58%; }
.prop { position: absolute; bottom: 30px; width: 58px; opacity: .95; }
.prop svg { width: 100%; height: auto; }
.prop-spool { left: 12px; }
.prop-scissors { right: 12px; transform: rotate(-12deg); }
/* on a phone the loom is as wide as the desk: the props step aside */
html[data-layout="phone"] .maker:is([data-step="wish"], [data-step="threads"], [data-step="weave"]) .prop { opacity: 0; }
.prop { transition: opacity .3s; }

.dots {
  position: absolute; z-index: 3; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; margin: 0; padding: 7px 12px; list-style: none;
  background: rgba(255, 255, 255, .78); border-radius: 999px; box-shadow: 0 2px 0 #efe6fb;
}
.dot { width: 12px; height: 12px; border-radius: 999px; background: #fff; border: 2px solid #ddd3fb; transition: width .3s cubic-bezier(.3,1.4,.5,1), background .3s; }
.dot.done { background: var(--lilac); border-color: var(--lilac-deep); }
.dot.now { width: 30px; background: var(--lilac-deep); border-color: var(--lilac-deep); }

.view { position: absolute; inset: 52px 12px 34px; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
.view-in { position: relative; z-index: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; min-height: 0; min-width: 0; height: 100%; container-type: size; }

.panel {
  position: relative; z-index: 2;
  flex: 0 0 auto; max-height: 62%;
  display: flex; flex-direction: column;
  margin: -24px calc(-1 * var(--gutter)) 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--cream);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -4px 0 var(--cream-edge), 0 -14px 30px -18px rgba(110, 90, 140, .35);
}
.panel-head { padding: 0 4px; }
html[data-layout="phone"] .maker[data-step="threads"] .panel, html[data-layout="phone"] .maker[data-step="weave"] .panel { height: var(--panel-h); max-height: none; }
#stepTitle:focus { outline: none; }
.panel-head h2 { margin: 0; font-size: 22px; font-weight: 700; color: var(--logo); line-height: 1.15; outline-offset: 2px; }
.panel-head p { margin: 2px 0 0; min-height: 1.3em; color: var(--ink-soft); font-size: 15px; line-height: 1.3; }
.opts { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 12px 10px 8px; margin: 0 -10px; scrollbar-width: thin; }
.opts-in { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 2px 0; }
.nav .btn { min-width: 100px; }
.nav-extra { display: flex; justify-content: center; flex: 1 1 auto; min-width: 0; }
.nav-extra:empty { display: none; }
#nextBtn { margin-left: auto; }
#nextBtn { min-width: 132px; }
#nextBtn.off { opacity: .45; cursor: default; box-shadow: 0 4px 0 var(--lilac-deep); transform: none; }

/* ---------------------------------------------------------------- choices */
.choices { display: grid; gap: 8px; }
.choice {
  position: relative; appearance: none; margin: 0; padding: 6px 4px;
  display: grid; justify-items: center; align-content: center; gap: 3px;
  min-width: 0; min-height: 48px;
  background: #fff; border: 2px solid #f0e8dc; border-radius: 18px;
  box-shadow: 0 3px 0 #efe5d4;
  cursor: pointer; color: var(--ink);
  transition: transform .22s cubic-bezier(.3,1.6,.5,1), box-shadow .2s, border-color .2s, background .2s;
}
.choice:active { transform: translateY(2px); }
.choice[aria-checked="true"] {
  border-color: var(--ring); background: #fdfcff;
  box-shadow: 0 0 0 3px var(--ring-soft), 0 10px 16px -8px rgba(116, 102, 194, .55);
  transform: translateY(-5px);
}
/* a small tick badge on the chosen one (not colour alone) */
.choice[aria-checked="true"]::after {
  content: ''; position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 999px;
  background: var(--lilac-deep) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5.5 10.4L8.6 13.4L14.6 7' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 100% no-repeat;
  box-shadow: 0 0 0 2px #fff;
}
.choice:focus-visible { outline: 3px solid var(--lilac-deep); outline-offset: 3px; border-radius: 18px; }
.ch-art { display: grid; place-items: center; }
.ch-art svg { width: 100%; height: auto; }
.ch-name { font-size: 13px; font-weight: 600; line-height: 1.12; text-align: center; color: var(--ink); }
.sublabel { margin: 2px 4px 0; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.caption { margin: 0 4px 2px; font-size: 14px; color: var(--ink-soft); line-height: 1.3; min-height: 1.3em; }
.caption b { color: var(--ink); font-weight: 600; }
.caption .ja { font-size: 16px; color: var(--ink); }

/* wishes: 4 + 3, centred */
.wishes { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 8px; padding-top: 6px; }
.wishes .choice { flex: 0 0 calc(25% - 6px); min-height: 70px; padding: 8px 2px 6px; }
.wish-ja { font-family: var(--kanji); font-weight: 600; font-size: 24px; line-height: 1.05; color: var(--ink); }
.wish-ja.four { font-size: 15.5px; letter-spacing: -.02em; padding: 4px 0; }

/* spools: 5 across, two rows */
.spools { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px 8px; padding: 6px 2px 2px; }
.spools .choice { padding: 5px 0 4px; }
.spools .ch-art { width: min(34px, 80%); }
.metals { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 6px 2px 2px; }
.metals .choice { min-height: 44px; grid-auto-flow: column; justify-content: center; align-items: center; gap: 6px; padding: 4px 6px; }
.metals .ch-art { width: 26px; }

/* pattern tiles: 4 across */
.tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 8px; padding: 6px 2px 2px; }
.tiles .choice { padding: 5px 5px 6px; gap: 4px; align-content: start; }
.tiles .ch-art { width: 100%; border-radius: 10px; overflow: hidden; box-shadow: inset 0 0 0 1px #eee4d6; }
.tiles .ch-art svg { border-radius: 10px; aspect-ratio: 3 / 2; height: auto; }
.tiles .ch-name { font-size: 12px; min-height: 2.24em; display: grid; align-items: center; }

/* shapes: 5 across */
.shapes { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; padding-top: 8px; }
.shapes .choice { padding: 8px 2px 6px; }
.shapes .ch-art { width: min(46px, 86%); }

/* cords and add-ons */
.cords { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px 6px; padding: 6px 2px 2px; }
.cords .choice { padding: 6px 0 5px; }
.cords .ch-art { width: min(40px, 88%); }
.cords .ch-name { font-size: 12px; }
.addons { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 6px 2px 2px; }
.addons .choice { grid-auto-flow: column; justify-content: center; align-items: center; gap: 6px; min-height: 52px; }
.addons .ch-art { width: 32px; }
.addons .ch-name { font-size: 15px; }

/* the threads tabs */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; background: #f6eee1; border-radius: 999px; }
.tab {
  appearance: none; border: 0; margin: 0; padding: 0 14px; min-height: 38px; border-radius: 999px;
  background: transparent; font-size: 15px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
  transition: background .2s, color .2s, transform .2s cubic-bezier(.3,1.6,.5,1);
}
.tab[aria-selected="true"] { background: #fff; color: var(--lilac-ink); box-shadow: 0 2px 0 #e8dcc8, 0 0 0 2px var(--ring-soft); transform: translateY(-1px); }
.tab:focus-visible { outline-offset: 1px; border-radius: 999px; }
.surprise { min-height: 44px; padding: 0 14px; font-size: 15px; white-space: nowrap; }
.tabpanel { display: grid; gap: 4px; padding-top: 8px; }
.accent { display: grid; gap: 2px; }

/* ---------------------------------------------------------------- the stage views */
.charm-box { position: relative; height: min(100cqh, 140cqw); aspect-ratio: 80 / 112; }
.charm-box svg { width: 100%; height: 100%; }
.charm-box .om-cord-front, .charm-box .om-cord-back, .charm-box .om-addon { transform-box: fill-box; transform-origin: 50% 0; }
.charm-box .om-cord-front { transform-origin: 50% 30%; }
.charm-box.sway svg { transform-origin: 50% 4.5%; animation: sway 3.2s ease-in-out infinite; }

.loom-box { position: relative; height: min(100cqh, 90cqw); aspect-ratio: 280 / 252; }   /* the loom's view box: js/loom-art.js VIEW */
.loom-box svg { width: 100%; height: 100%; overflow: visible; }
.lm-cloth { transform-box: fill-box; transform-origin: 50% 100%; }

/* Wish: the big plate, the paper slip below it */
.wish-stage { height: 100%; width: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto; justify-items: center; align-items: center; gap: 10px; }
.plate { width: 100%; height: 100%; min-height: 0; }
.plate svg { width: 100%; height: 100%; }
.slip {
  position: relative; width: min(100%, 320px);
  padding: 10px 14px 10px;
  background: #fffef9; border-radius: 6px 6px 14px 14px;
  border: 1.5px solid #efe2c9;
  box-shadow: 0 4px 0 #efe2c9, 0 10px 18px -12px rgba(110, 90, 140, .4);
  transform: rotate(-1.2deg);
}
.slip-label { display: block; margin: 0; padding-right: 48px; font-size: 14px; font-weight: 600; color: var(--ink); }
.slip-text {
  display: block; width: 100%; margin: 2px 0 4px; padding: 4px 6px;
  font: 500 16px/1.35 var(--font); color: var(--ink);
  background: transparent; border: 0; border-bottom: 2px dashed #e7d7bb; border-radius: 0;
  resize: none; outline: none;
}
.slip-text:focus-visible { border-bottom-color: var(--lilac-deep); outline: 0; background: #fbf9ff; }
.slip-note { margin: 0; font-size: 12.5px; color: var(--ink-soft); line-height: 1.3; }
.slip-count { position: absolute; right: 14px; top: 12px; font-size: 11.5px; color: #b4abc9; }
.slip.sealed { text-align: center; padding: 14px; }
.slip.sealed .slip-note { padding: 0; margin-top: 2px; }

/* the slip flying into the pouch while sewing */
.slip-fly {
  position: absolute; left: 50%; top: 30%; width: 34%; aspect-ratio: 3 / 4;
  background: #fffef9; border: 1.5px solid #e7d7bb; border-radius: 4px;
  box-shadow: 0 6px 10px -6px rgba(110, 90, 140, .4);
  background-image: linear-gradient(#efe2c9, #efe2c9), linear-gradient(#efe2c9, #efe2c9);
  background-size: 60% 2px, 44% 2px; background-position: 50% 38%, 50% 56%; background-repeat: no-repeat;
  opacity: 0; pointer-events: none;
}

/* Done */
.sparks { position: absolute; inset: 0; pointer-events: none; }
.spark { position: absolute; left: 50%; top: 46%; width: clamp(52px, 17cqmin, 88px); opacity: 0; }
.glow { position: absolute; z-index: -1; pointer-events: none; left: 50%; top: 48%; width: 92cqmin; aspect-ratio: 1; border-radius: 50%; opacity: 0;
  background: radial-gradient(circle, rgba(255, 244, 200, .95) 0%, rgba(255, 233, 163, .55) 38%, rgba(230, 220, 251, .35) 62%, rgba(255, 255, 255, 0) 72%); }
/* the ground shadow stays on the ground while the charm sways (the SVG's own one would swing with it) */
.charm-box.sway svg > ellipse:first-of-type, .start-charm svg > ellipse:first-of-type { opacity: 0; }
.charm-box.sway::after, .start-charm::after { content: ''; position: absolute; left: 22%; right: 22%; bottom: 4%; height: 4%; border-radius: 50%; background: rgba(110, 90, 140, .12); z-index: -1; }
.start-charm { position: relative; z-index: 0; }
.start-charm .sway { position: relative; cursor: pointer; }
.charm-box.sway { z-index: 0; }
/* Weave: the loom takes the swipes, the page never scrolls or goes back on one (the options box is a
   scroll container, which cuts touch-action off from the panel's, so it says so itself: a downward swipe
   there is a pull, not a scroll) */
.maker[data-step="weave"] .stage, .maker[data-step="weave"] .panel, .maker[data-step="weave"] .opts, .maker[data-step="weave"] .opts * { touch-action: none; }
.weave-box .lm-shuttle-body { transform-box: fill-box; transform-origin: 50% 50%; }
.weave-box .lm-shuttle { cursor: grab; }
.weave-box .lm-shuttle.held { cursor: grabbing; }
.weave-box .lm-shuttle.held .lm-shuttle-body { filter: drop-shadow(0 2px 1.5px rgba(110, 90, 140, .35)); }
.lm-hint { opacity: 0; transition: opacity .35s; pointer-events: none; }
.lm-hint.on { opacity: 1; }
.lm-hint .lm-hand { animation: hand-swipe 1.6s cubic-bezier(.45,.05,.35,1) infinite; }
.lm-hint.to-left .lm-hint-head { transform: translateX(220px) scaleX(-1); }
.lm-hint.to-left .lm-hand { animation-name: hand-swipe-left; }
@keyframes hand-swipe {
  0% { transform: translate(52px, 239px); opacity: 0; } 15% { opacity: 1; }
  70% { transform: translate(164px, 239px); opacity: 1; } 85%, 100% { transform: translate(164px, 239px); opacity: 0; }
}
@keyframes hand-swipe-left {
  0% { transform: translate(168px, 239px); opacity: 0; } 15% { opacity: 1; }
  70% { transform: translate(56px, 239px); opacity: 1; } 85%, 100% { transform: translate(56px, 239px); opacity: 0; }
}
.weave-spark { width: clamp(40px, 13cqmin, 72px); }
/* the beater bar: it glows and bobs gently when a pull is due; the little hand on its end shows the way */
.lm-reed-glow { opacity: 0; transition: opacity .3s; }
.weave-box .lm-reed.due .lm-reed-glow { opacity: .9; }
.weave-box .lm-reed.due .lm-reed-body { animation: bar-bob 1.3s ease-in-out infinite; }
.weave-box .lm-reed.grab { cursor: grab; }
.weave-box .lm-reed.held { cursor: grabbing; }
.weave-box .lm-reed.held .lm-reed-body { animation: none; filter: drop-shadow(0 2px 1.5px rgba(110, 90, 140, .35)); }
@keyframes bar-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }
.lm-pull-hint { opacity: 0; transition: opacity .3s; pointer-events: none; }
.lm-pull-hint.on { opacity: 1; }
.lm-pull-hint .lm-pull-hand { transform: translate(179px, 8px); }
.lm-pull-hint.on .lm-pull-hand { animation: hand-pull 1.3s cubic-bezier(.45,.05,.35,1) infinite; }
@keyframes hand-pull {
  0% { transform: translate(179px, 4px); opacity: 0; } 15% { opacity: 1; }
  65% { transform: translate(179px, 20px); opacity: 1; } 85%, 100% { transform: translate(179px, 20px); opacity: 0; }
}
.weave-arrows { display: flex; justify-content: center; align-items: center; gap: clamp(12px, 5vw, 26px); padding: 8px 0 2px; }
.weave-arrow {
  appearance: none; margin: 0; padding: 0; width: clamp(72px, 24vw, 100px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: #fff; color: #c9bfe9; border: 2.5px solid #ece6fb; box-shadow: 0 4px 0 #ece6fb;
  transition: color .2s, background .2s, border-color .2s, box-shadow .2s, opacity .2s;
}
.weave-arrow svg { width: 52%; height: auto; }
.weave-arrow:active { transform: translateY(3px); box-shadow: 0 1px 0 #ece6fb; }
.weave-arrow.go { background: var(--lilac); color: var(--lilac-ink); border-color: var(--lilac-deep); box-shadow: 0 5px 0 var(--lilac-deep); animation: arrow-pulse 1.5s ease-in-out infinite; }
.weave-arrow.go:active { box-shadow: 0 1px 0 var(--lilac-deep); animation: none; transform: translateY(3px); }
.weave-arrows.done .weave-arrow { opacity: .4; cursor: default; animation: none; }
/* ▼ pull: a pink rounded square between the arrows (pale until there is something to pack) */
.weave-pull { border-radius: 30%; color: #efc3d0; border-color: #fbe3ea; box-shadow: 0 4px 0 #fbe3ea; }
.weave-pull.can { color: #d98ba3; border-color: #f6cbd7; box-shadow: 0 4px 0 #f6cbd7; }
.weave-pull.go { background: #ffd9e3; color: #a24d6a; border-color: #eb9fb3; box-shadow: 0 5px 0 #eb9fb3; animation: pull-pulse 1.3s ease-in-out infinite; }
.weave-pull.go:active { box-shadow: 0 1px 0 #eb9fb3; animation: none; transform: translateY(3px); }
@keyframes pull-pulse { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(2px) scale(1.07); } }
@keyframes arrow-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.weave-keys { margin: 0; text-align: center; font-size: 14px; color: var(--ink-soft); }
.weave-keys kbd { display: inline-block; min-width: 26px; padding: 1px 6px; border-radius: 7px; background: #fff; border: 1.5px solid #e6dfff; box-shadow: 0 2px 0 #e6dfff; font: 600 14px/1.3 var(--font); color: var(--ink); }
html[data-layout="phone"] .weave-keys { display: none; }
html[data-layout="wide"] .weave-arrows { padding: 22px 0 6px; }
html[data-layout="wide"] .weave-arrow { width: 100px; }

/* the music and sound-effect switches: the top corners (on a phone, the stage's corners beside the dots) */
.sound-btn {
  position: fixed; z-index: 10; top: calc(env(safe-area-inset-top) + 16px);
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(255, 255, 255, .9); color: var(--logo); border: 2px solid #e6dfff; box-shadow: 0 3px 0 #e6dfff;
  transition: background .2s, color .2s, transform .08s, box-shadow .08s;
}
.sound-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #e6dfff; }
#musicBtn { left: calc(env(safe-area-inset-left) + 18px); }
#soundBtn { right: calc(env(safe-area-inset-right) + 18px); }
.sound-btn svg { width: 22px; height: 22px; }
.sound-btn .sb-slash, .sound-btn .sb-off { display: none; }
.sound-btn[aria-pressed="false"] { background: #f3f0f8; color: #b9b2cf; border-color: #ebe7f3; box-shadow: 0 3px 0 #ebe7f3; }
.sound-btn[aria-pressed="false"] .sb-slash, .sound-btn[aria-pressed="false"] .sb-off { display: inline; }
.sound-btn[aria-pressed="false"] .sb-on { display: none; }
html[data-layout="wide"] .sound-btn { top: 20px; width: 44px; height: 44px; }
html[data-layout="wide"] #musicBtn { left: 20px; }
html[data-layout="wide"] #soundBtn { right: 20px; }
@media (max-width: 359px) { .sound-btn { width: 36px; height: 36px; top: calc(env(safe-area-inset-top) + 13px); } #musicBtn { left: 14px; } #soundBtn { right: 14px; } .sound-btn svg { width: 20px; height: 20px; } }

/* Weave: the row meter */
.weave-meter { display: grid; gap: 10px; padding: 10px 4px; }
.weave-rows { margin: 0; font-size: 20px; font-weight: 600; color: var(--ink); }
.weave-rows b { font-size: 30px; color: var(--logo); font-variant-numeric: tabular-nums; }
.weave-bar { display: flex; gap: 8px; }
/* three segments of four rows: laid rows fill a segment softly, packing makes it solid */
.weave-bar .seg { position: relative; flex: 1; height: 16px; border-radius: 999px; background: #f3eadb; box-shadow: inset 0 2px 0 #e9dcc5; overflow: hidden; }
.weave-bar i { position: absolute; inset: 0; border-radius: 999px; transform-origin: 0 50%; transform: scaleX(0); transition: transform .2s ease-out; }
.weave-bar .laid { background: #ddd3fb; box-shadow: inset 0 0 0 2px #c9bcf6; }
.weave-bar .packed { background: linear-gradient(90deg, var(--lilac), #ffd9e3); }
.weave-bar .seg.full { box-shadow: 0 0 0 2px #f3c9d6; }
.spark svg { width: 100%; height: auto; }
.done-actions { display: grid; gap: 12px; justify-items: center; padding: 0 0 4px; }
.recipe { margin: 0 0 4px; text-align: center; font-size: 14px; color: var(--ink-soft); line-height: 1.35; max-width: 340px; }
html[data-layout="wide"] .opts-done { min-height: 100%; align-content: center; }
html[data-layout="wide"] .recipe { font-size: 16px; margin-bottom: 10px; }
.done-actions .btn.primary { min-width: 220px; min-height: 54px; font-size: 18px; }

/* ---------------------------------------------------------------- small phones (320 × 568) */
@media (max-width: 359px) {
  :root { --gutter: 8px; }
  .panel { padding: 12px 12px calc(env(safe-area-inset-bottom) + 10px); }
  .panel-head h2 { font-size: 20px; }
  .panel-head p { font-size: 14px; }
  .tab { padding: 0 6px; font-size: 14px; min-height: 34px; }
  .nav .btn { min-width: 76px; padding: 0 14px; }
  #nextBtn { min-width: 96px; }
  .surprise { padding: 0 10px; font-size: 14px; }
  .ch-name { font-size: 12px; }
  .tiles .ch-name { font-size: 11px; }
  .cords .ch-name { font-size: 11px; }
  .addons .ch-name { font-size: 14px; }
  .prop { width: 44px; }
}
@media (max-height: 640px) {
  :root { --panel-h: 60%; }
  .maker[data-step="threads"] #stepHint { display: none; }   /* the tabs say it; room for the options */
  .tiles .ch-art svg { aspect-ratio: 2 / 1; }
  .tiles .choice { padding: 4px 4px 5px; gap: 2px; }
  .tiles { gap: 8px 6px; }
  .tiles .ch-name { line-height: 1.02; min-height: 2.04em; }
  .tabs { padding: 3px; }
  .caption { font-size: 13px; }
  .spools .ch-art { width: 28px; }
  .spools { gap: 8px 6px; }
  .tabpanel { padding-top: 4px; }
  .view { inset: 46px 10px 30px; }
  .dots { top: 10px; padding: 6px 10px; }
  .opts { padding-top: 8px; padding-bottom: 4px; }
  .wishes .choice { min-height: 60px; }
  .slip { padding: 8px 12px; }
  .slip-text { margin: 4px 0 2px; padding: 4px 6px; }
}

/* ---------------------------------------------------------------- wide: one centred group */
html[data-layout="wide"] .maker {
  display: grid;
  grid-template-columns: minmax(0, 680px) minmax(380px, 440px);
  grid-template-rows: min(820px, calc(100% - 72px));
  place-content: center;
  gap: 28px;
  padding: 36px 40px;
}
html[data-layout="wide"] .stage { border-radius: 36px; box-shadow: inset 0 0 0 2px #f1e9fb, 0 18px 40px -26px rgba(110, 90, 140, .45); }
html[data-layout="wide"] .desk { height: 42%; }
html[data-layout="wide"] .prop { width: 92px; bottom: 34px; }
html[data-layout="wide"] .prop-spool { left: 28px; }
html[data-layout="wide"] .prop-scissors { right: 28px; }
html[data-layout="wide"] .dots { top: 20px; }
html[data-layout="wide"] .view { inset: 72px 40px 40px; }
html[data-layout="wide"] .panel {
  margin: 0; height: auto; max-height: none; border-radius: 32px; padding: 28px 26px 24px;
  box-shadow: 0 5px 0 var(--cream-edge), 0 18px 40px -26px rgba(110, 90, 140, .45);
}
html[data-layout="wide"] .panel-head h2 { font-size: 28px; }
html[data-layout="wide"] .panel-head p { font-size: 16px; }
html[data-layout="wide"] .opts { padding-top: 18px; }
html[data-layout="wide"] .nav { margin-top: auto; padding-top: 14px; }
html[data-layout="wide"] .slip { width: min(100%, 360px); }
html[data-layout="wide"] .start-charm { height: min(52vh, 460px); }
html[data-layout="wide"] .start h1 { font-size: 52px; }
html[data-layout="wide"] .start-line { font-size: 20px; }
/* wide: the panel has room, so the choices grow */
html[data-layout="wide"] .ch-name { font-size: 14px; }
html[data-layout="wide"] .sublabel, html[data-layout="wide"] .caption { font-size: 15px; }
html[data-layout="wide"] .caption .ja { font-size: 18px; }
html[data-layout="wide"] .wishes { gap: 14px 8px; }
html[data-layout="wide"] .wishes .choice { flex-basis: calc(25% - 6px); }
html[data-layout="wide"] .wishes .choice { min-height: 96px; }
html[data-layout="wide"] .wish-ja { font-size: 32px; }
html[data-layout="wide"] .wish-ja.four { font-size: 20px; }
html[data-layout="wide"] .spools { gap: 14px 10px; }
html[data-layout="wide"] .spools .ch-art { width: 46px; }
html[data-layout="wide"] .metals .ch-art { width: 32px; }
html[data-layout="wide"] .metals .choice { min-height: 56px; }
html[data-layout="wide"] .tiles { gap: 14px 10px; }
html[data-layout="wide"] .tiles .ch-name { font-size: 13px; }
html[data-layout="wide"] .shapes { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px 10px; }
html[data-layout="wide"] .shapes .choice { flex: 0 0 calc(33.333% - 7px); }
html[data-layout="wide"] .shapes .choice { min-height: 112px; }
html[data-layout="wide"] .shapes .ch-art { width: 62px; }
html[data-layout="wide"] .cords { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 10px; }
html[data-layout="wide"] .cords .choice { grid-auto-flow: column; justify-content: center; align-items: center; gap: 8px; min-height: 62px; }
html[data-layout="wide"] .cords .ch-art { width: 44px; }
html[data-layout="wide"] .cords .ch-name { font-size: 15px; }
html[data-layout="wide"] .addons .choice { min-height: 68px; }
html[data-layout="wide"] .addons .ch-art { width: 40px; }
html[data-layout="wide"] .slip-label { font-size: 16px; }
html[data-layout="wide"] .slip-text { font-size: 18px; }
html[data-layout="wide"] .slip-note { font-size: 14px; }
html[data-layout="wide"] .weave-meter { padding-top: 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .sway, .charm-box.sway svg { animation: none !important; }
}

/* while a step's sewing / tying runs, its options rest */
.opts[inert] { opacity: .5; transition: opacity .25s; }
.opts-weave { min-height: 100%; align-content: center; }
@media (prefers-reduced-motion: reduce) {
  .lm-hint .lm-hand { animation: none !important; transform: translate(150px, 239px); }
  .weave-arrow.go { animation: none !important; }
  .lm-reed.due .lm-reed-body { animation: none !important; }
  .lm-pull-hint .lm-pull-hand, .lm-pull-hint.on .lm-pull-hand { animation: none !important; transform: translate(179px, 14px); }
}

/* ---------------------------------------------------------------- Sew and Tie (the gestures after Next on Shape / Cord)
   js/acts/sew.js and tie.js set .maker[data-act] while they run: the stage and the panel take the taps
   and drags, never a scroll (the options box is its own scroll container, so it says so itself) */
.maker[data-act] .stage, .maker[data-act] .panel, .maker[data-act] .opts, .maker[data-act] .opts * { touch-action: none; }
.maker[data-act="sew"] .stage { cursor: pointer; }
.opts-in.opts-act { align-content: center; }
.act-row { display: flex; align-items: center; gap: 16px; padding: 2px 4px; }
.act-row .act-meter { flex: 1 1 auto; min-width: 0; padding: 0; gap: 8px; }
.act-meter .weave-rows { font-size: 18px; }
.act-meter .weave-rows b { font-size: 26px; }
.weave-bar.eight { gap: 5px; }
.tie-bar .seg { height: 18px; }
.tie-bar .packed { transition: none; }
.act-btn {
  appearance: none; flex: 0 0 auto; margin: 0; padding: 0;
  width: clamp(80px, 23vw, 96px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; align-content: center; gap: 0; cursor: pointer;
  background: var(--lilac); color: var(--lilac-ink); border: 2.5px solid var(--lilac-deep); box-shadow: 0 5px 0 var(--lilac-deep);
  font-size: 15px; font-weight: 700; line-height: 1;
  animation: arrow-pulse 1.5s ease-in-out infinite;
}
.act-btn svg { width: 46%; height: auto; margin-bottom: 1px; }
.act-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--lilac-deep); animation: none; }
.act-btn.done { opacity: .45; cursor: default; animation: none; }
/* the Sew button held down (pointer or key), and buzzing while the sewing machine runs; a long press is a
   hold, so no text selection or callout on the button or the stage */
.sew-btn, .maker[data-act="sew"] .stage { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.sew-btn.held { transform: translateY(3px); box-shadow: 0 1px 0 var(--lilac-deep); background: #c4b8fb; animation: none; }
.sew-btn.machine, .sew-btn.machine:active { animation: sew-buzz .13s linear infinite; }
@keyframes sew-buzz { 0%, 100% { transform: translateY(3px) rotate(0deg); } 30% { transform: translateY(4.5px) rotate(-3deg); } 65% { transform: translateY(2px) rotate(2.5deg); } }
.tie-btn { background: #ffd9e3; color: #a24d6a; border-color: #eb9fb3; box-shadow: 0 5px 0 #eb9fb3; animation-name: pull-pulse; }
.tie-btn:active { box-shadow: 0 1px 0 #eb9fb3; }
.act-keys { margin-top: 2px; }
html[data-layout="wide"] .act-row { flex-direction: column; align-items: stretch; gap: 28px; padding-top: 18px; }
html[data-layout="wide"] .act-btn { order: 2; align-self: center; width: 124px; font-size: 18px; }
@media (max-width: 359px), (max-height: 640px) { .act-btn { width: 74px; font-size: 14px; } .act-meter .weave-rows { font-size: 16px; } .act-meter .weave-rows b { font-size: 22px; } }
/* the needle, the slip, the hint hands (SVG parts; transforms in user units) */
.sew-hint, .tie-hint { pointer-events: none; transition: opacity .3s; }
.sew-hint-ring, .sew-hint-hand { transform-box: fill-box; transform-origin: 50% 50%; }
.sew-needle, .sew-slip, .tie-handle, .tie-target, .tie-guide { pointer-events: none; }
.tie-handle .tie-halo { transform-box: fill-box; transform-origin: 50% 50%; }
.maker[data-act="tie"] .stage { cursor: grab; }
.maker[data-act="tie"] .stage:has(.tie-handle.held) { cursor: grabbing; }
@media (prefers-reduced-motion: reduce) { .act-btn { animation: none !important; } }
