@font-face { font-family: 'Fredoka'; src: url('fonts/Fredoka.woff2') format('woff2'); font-weight: 300 700; font-display: block; }
@font-face { font-family: 'Caveat'; src: url('fonts/Caveat.woff2') format('woff2'); font-weight: 400 700; font-display: block; }

:root {
  --cream: #f6ecd9; --paper: #fbf4e6; --cream-2: #efe1c6; --ink: #3b2738; --ink-soft: #6b5468;
  --cranberry: #9e2a3a; --cranberry-dk: #7a1e2c; --sage: #8fa77f; --sage-dk: #5f7a52; --honey: #d9a441; --honey-lt: #f2d48a;
  --plum: #5b3a5e; --night: #2a1f3d; --night-2: #3a2a4e;
  --shadow: 0 6px 18px rgba(30, 12, 34, 0.28); --shadow-sm: 0 2px 6px rgba(30, 12, 34, 0.25);
  --r: 16px; --btn: 56px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); }
body {
  font-family: 'Fredoka', 'Nunito', 'Trebuchet MS', system-ui, sans-serif; color: var(--ink);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; text-wrap: balance; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus { outline: none; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--honey); outline-offset: 2px; }
.ic { width: 24px; height: 24px; display: block; }
.ic.stroke, .ic .stroke { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ic .fill { fill: currentColor; stroke: none; }
.icw { display: inline-flex; }

/* ---------- buttons */
.btn {
  min-height: 48px; padding: 10px 20px; border-radius: 999px; border: 0; font-weight: 600; font-size: 17px;
  background: var(--cream); color: var(--ink); box-shadow: var(--shadow-sm), inset 0 -3px 0 rgba(59, 39, 56, 0.12);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; line-height: 1.15;
  transition: transform 0.08s ease;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: var(--cranberry); color: #fff6ea; box-shadow: var(--shadow-sm), inset 0 -3px 0 rgba(0, 0, 0, 0.22); }
.btn.sage { background: var(--sage-dk); color: #fff6ea; }
.btn.big { min-height: 60px; font-size: 21px; padding: 12px 30px; }
.btn.ghost { background: rgba(251, 244, 230, 0.16); color: var(--cream); box-shadow: inset 0 0 0 2px rgba(246, 236, 217, 0.5); }
.btn.small { min-height: 40px; font-size: 15px; padding: 6px 14px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(251, 244, 230, 0.14); color: var(--cream); flex: none;
}
.icon-btn:active { transform: scale(0.95); }
.badge { position: absolute; top: -6px; right: -6px; background: var(--honey); color: var(--ink); font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 999px; box-shadow: var(--shadow-sm); }

/* ---------- title */
.title-screen { background: #1d1530; }
#title-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
/* until the title's fonts and art are in: only a small yarn ball pulses (no text, so nothing jumps) */
.title-screen > * { transition: opacity 0.5s; }
.title-screen.booting > * { opacity: 0; visibility: hidden; transition: none; }
.title-screen.booting::after { content: ''; position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d65a6c, var(--cranberry) 55%, #5e1220); box-shadow: 0 0 0 6px rgba(158, 42, 58, 0.18); animation: bootpulse 1.2s ease-in-out infinite; }
@keyframes bootpulse { 50% { transform: scale(0.8); opacity: 0.7; } }
.title-ui { position: absolute; left: 0; right: 0; top: calc(6vh + var(--sat)); text-align: center; pointer-events: none; padding: 0 16px; }
.logo { font-size: clamp(54px, 11vw, 112px); font-weight: 700; line-height: 0.95; letter-spacing: 0.01em; }
.logo span { display: inline-block; color: var(--cream); text-shadow: 0 3px 0 var(--cranberry-dk), 0 6px 18px rgba(0, 0, 0, 0.55); }
.logo .logo-a { transform: rotate(-4deg); margin-right: 0.18em; }
.logo .logo-b { color: var(--honey-lt); transform: rotate(3deg); }
.logo-sub { text-wrap: balance; margin-top: 10px; font-family: 'Caveat', cursive; font-size: clamp(22px, 3.6vw, 32px); color: #f3e3c4; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); }
.tap-start {
  position: absolute; left: 50%; bottom: calc(7vh + var(--sab)); transform: translateX(-50%);
  border: 0; border-radius: 999px; padding: 16px 36px; font-size: 24px; font-weight: 600; color: #fff6ea; background: var(--cranberry); white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.25); animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.05); } }

/* ---------- paper screens (book, cast on) */
.paper-screen { background: #e8dcc4 url('assets/tex/tex-paper.webp') repeat; background-size: 384px; overflow-y: auto; touch-action: pan-y; }
.page { max-width: 1100px; margin: 0 auto; padding: calc(12px + var(--sat)) calc(16px + var(--sar)) calc(28px + var(--sab)) calc(16px + var(--sal)); }
/* big screens: the book, cast-on and bag pages scale up to use the room (--pz is set in ui.js) */
.page { zoom: var(--pz, 1); }
.topline { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.topline h2 { flex: 1; font-size: 24px; color: var(--plum); }
.topline .icon-btn { background: var(--plum); color: var(--cream); }

.cover {
  position: relative; border-radius: 18px; padding: 22px 20px 20px; color: var(--cream); overflow: hidden;
  background: linear-gradient(150deg, #6e4672, #4a2c4f 60%, #3a2240); box-shadow: var(--shadow);
}
.cover::before { content: ''; position: absolute; inset: 0; background: url('assets/tex/tex-fibre.png'); background-size: 160px; mix-blend-mode: soft-light; opacity: 0.55; pointer-events: none; }
.cover::after { content: ''; position: absolute; inset: 9px; border: 2.5px dashed rgba(246, 236, 217, 0.55); border-radius: 12px; pointer-events: none; }
.cover > * { position: relative; z-index: 1; }
.cover h1 { font-size: 34px; letter-spacing: 0.01em; }
.cover .sub { font-family: 'Caveat', cursive; font-size: 22px; opacity: 0.9; text-wrap: balance; }
.ribbons { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.ribbon { width: 22px; height: 34px; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); background: rgba(246, 236, 217, 0.18); }
.ribbon.won { background: linear-gradient(#e85a6a, var(--cranberry)); }
.ribbon.won:nth-child(2) { background: linear-gradient(#a8c494, var(--sage-dk)); }
.ribbon.won:nth-child(3) { background: linear-gradient(#f2d48a, #c08a2a); }
.ribbon.won:nth-child(4) { background: linear-gradient(#b38bc0, var(--plum)); }
.ribbon.won:nth-child(5) { background: linear-gradient(#9cc4d8, #46679a); }
.ribbon.won:nth-child(6) { background: linear-gradient(#f3b39a, #b5532b); }
.ribbon.won:nth-child(7) { background: linear-gradient(#cdd59a, #5f7a3a); }
.ribbon.gold { background: linear-gradient(#ffe9a0, #c9982f) !important; }
.front-btns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
.front-btns .btn { position: relative; justify-content: flex-start; padding-left: 16px; }
.front-btns .btn.continue, .front-btns .btn.wide { grid-column: 1 / -1; }
.front-btns .btn .sub { font-weight: 400; font-size: 14px; opacity: 0.85; display: block; }
.front-btns .btn .lbl { text-align: left; }
@media (min-width: 760px) { .front-btns { grid-template-columns: 1.3fr 1fr 1fr 1fr; } .front-btns .btn .lbl { white-space: nowrap; } .front-btns .btn.continue, .front-btns .btn.wide { grid-column: auto; } }

.tabs { display: flex; gap: 6px; margin: 18px 0 12px; overflow-x: auto; touch-action: pan-x; scrollbar-width: none; padding: 2px 2px 6px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; border-radius: 12px 12px 4px 4px; padding: 8px 14px; background: rgba(91, 58, 94, 0.12); color: var(--plum); font-weight: 600; font-size: 15px; min-height: 44px; }
.tab .n { opacity: 0.6; margin-right: 6px; }
/* narrow screens: every tab fits without scrolling sideways. Chapters show their number, the open one
   its name too; the bag's tabs wrap onto two rows */
@media (max-width: 900px) {
  .tabs:not(.bag-tabs) .tab:not(.on) .nm { display: none; }
  .tabs:not(.bag-tabs) .tab:not(.on) .n { margin: 0; opacity: 1; }
  .tabs:not(.bag-tabs) .tab { min-width: 42px; padding: 8px 10px; }
  .tabs { flex-wrap: wrap; overflow: visible; }
  .bag-tabs { flex-wrap: wrap; overflow: visible; }
  .bag-tabs .tab { flex: 1 0 auto; padding: 8px 10px; }
}
/* phones held upright: all seven chapter tabs on one row, numbers only (the chapter's name is the
   heading right under them) */
@media (max-width: 599px) {
  .tabs:not(.bag-tabs) { flex-wrap: nowrap; gap: 4px; }
  .tabs:not(.bag-tabs) .tab { flex: 1 1 0; min-width: 0; padding: 8px 4px; }
  .tabs:not(.bag-tabs) .tab .nm { display: none; }
  .tabs:not(.bag-tabs) .tab .n { margin: 0; opacity: 1; }
}
.src, .empty-note, .caston-info .facts { text-wrap: pretty; }
.tab.on { background: var(--plum); color: var(--cream); box-shadow: var(--shadow-sm); }
.chapter-title { font-size: 22px; color: var(--plum); margin: 4px 2px 10px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.card {
  position: relative; border-radius: 14px; background: var(--paper); box-shadow: var(--shadow-sm); padding: 10px; display: flex; flex-direction: column; gap: 6px;
  border: 0; text-align: left; transition: transform 0.1s; min-width: 0;
}
.card:active { transform: scale(0.985); }
.card .pv { height: 128px; border-radius: 10px; background: radial-gradient(circle at 40% 30%, #8a6585, #5a3c5c); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.card .pv canvas { max-width: 100%; max-height: 100%; }
.card h3 { font-size: 17px; line-height: 1.15; color: var(--ink); }
.card .tech { font-size: 13px; color: var(--ink-soft); line-height: 1.25; }
.card .meta { font-size: 13px; color: var(--plum); font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card .done-tag { background: var(--sage); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.card .prog { height: 6px; border-radius: 3px; background: rgba(91, 58, 94, 0.15); overflow: hidden; }
.card .prog i { display: block; height: 100%; background: var(--cranberry); }
.card .prog { margin-top: auto; }
.card > .card-open + .read, .card.locked .lock-text { margin-top: auto; }
.card .read { align-self: flex-start; background: transparent; border: 0; color: var(--cranberry); font-weight: 600; font-size: 14px; padding: 8px 0 2px; min-height: 36px; text-decoration: underline; text-underline-offset: 3px; }
.card.locked { background: rgba(251, 244, 230, 0.55); }
.card.locked .pv { background: rgba(91, 58, 94, 0.18); }
.card.locked h3 { color: var(--ink-soft); }
.card .lock-text { font-size: 13px; color: var(--plum); font-weight: 600; display: flex; gap: 6px; align-items: center; }
.card .lock-text .ic { width: 16px; height: 16px; }
.card.flip { animation: flip 0.9s ease both; }
@keyframes flip { 0% { transform: perspective(600px) rotateY(90deg); } 60% { transform: perspective(600px) rotateY(-12deg); } 100% { transform: none; } }
.card.flip::after { content: ''; position: absolute; inset: -4px; border-radius: 16px; box-shadow: 0 0 0 3px var(--honey), 0 0 24px 6px rgba(242, 212, 138, 0.8); animation: glowout 2.2s ease forwards; pointer-events: none; }
@keyframes glowout { to { opacity: 0; } }
.card.started { box-shadow: var(--shadow-sm), 0 0 0 2px rgba(158, 42, 58, 0.35); }

/* ---------- cast on */
.caston-wrap { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .caston-wrap { grid-template-columns: 1.1fr 1fr; align-items: start; } }
.caston-pv { border-radius: 16px; background: radial-gradient(circle at 40% 30%, #8a6585, #4a2f4d); min-height: 260px; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow); padding: 12px; }
.caston-pv canvas { max-width: 100%; }
.caston-info { background: var(--paper); border-radius: 16px; padding: 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 12px; }
.caston-info .src { font-family: 'Caveat', cursive; font-size: 22px; color: var(--plum); line-height: 1.1; }
.caston-info .facts { font-size: 15px; color: var(--ink-soft); }
.slot-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px; background: var(--cream); border: 0; width: 100%; text-align: left; min-height: 64px; }
.slot-row .letter { width: 30px; height: 30px; border-radius: 50%; background: var(--plum); color: var(--cream); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.slot-row .nm { flex: 1; font-weight: 600; }
.slot-row .nm small { display: block; font-weight: 400; color: var(--ink-soft); font-size: 13px; }
.slot-row .chg { color: var(--cranberry); font-weight: 600; font-size: 14px; }
.caston-actions { display: flex; gap: 10px; flex-wrap: wrap; }
/* phones: Cast on and Read the pattern stay pinned at the bottom of the screen */
@media (max-width: 759px), (max-height: 500px) {
  .caston-actions { position: sticky; bottom: calc(8px + var(--sab)); z-index: 3; flex-wrap: nowrap; margin: 0 -8px; padding: 10px 8px; border-radius: 14px; background: var(--paper); box-shadow: 0 -4px 18px rgba(34, 22, 46, 0.22); }
  .caston-actions .btn.primary { flex: 1; }
  /* more page under the pinned bar: a soft shadow fades up from it */
  .caston-actions::before { content: ''; position: absolute; left: 0; right: 0; bottom: 100%; height: 28px; pointer-events: none; opacity: 0; transition: opacity 0.2s;
    background: linear-gradient(rgba(34, 22, 46, 0), rgba(34, 22, 46, 0.22)); border-radius: 14px 14px 0 0; }
  .caston-screen.more-below .caston-actions::before { opacity: 1; }
}
@media (max-width: 759px) and (min-height: 500px) { .caston-pv { min-height: 150px; padding: 8px; } }

/* ---------- knitting screen */
.knit-screen { background: #2a1f3d; display: grid; touch-action: none; }
.knit-screen > canvas.work { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.knit-screen > canvas.fx { pointer-events: none; }
.knit-screen > :not(canvas) { position: relative; z-index: 1; min-width: 0; min-height: 0; }
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 8px;
  padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 6px calc(8px + var(--sal));
  background: linear-gradient(rgba(34, 22, 46, 0.92), rgba(34, 22, 46, 0.78)); color: var(--cream); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.progress { flex: 1; min-width: 0; position: relative; height: 44px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.prog-line { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog-line b { font-weight: 600; color: var(--honey-lt); }
.prog-bar { height: 5px; border-radius: 3px; background: rgba(246, 236, 217, 0.18); overflow: hidden; }
.prog-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--honey), #f0c46a); transition: width 0.2s; }
.zoom { display: flex; gap: 4px; }
.rip-btn {
  height: 44px; min-width: 56px; padding: 0 12px; border: 0; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px;
  background: rgba(246, 236, 217, 0.92); color: var(--cranberry-dk); font-weight: 600; font-size: 15px; flex: none;
}
.rip-btn .ic { width: 20px; height: 20px; }
.rip-btn:active { background: #fff; }
.chip-host { position: absolute; inset: 0; pointer-events: none; display: flex; align-items: center; }
.chip {
  pointer-events: auto; display: flex; align-items: center; gap: 8px; width: 100%; height: 40px; padding: 0 6px 0 12px;
  border-radius: 999px; background: var(--cream); color: var(--ink); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-sm);
  animation: chipin 0.22s ease;
}
.chip .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .dot { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2); }
.chip button { border: 0; border-radius: 999px; background: var(--plum); color: var(--cream); font-weight: 600; height: 32px; padding: 0 12px; font-size: 14px; flex: none; }
@keyframes chipin { from { transform: translateY(-8px); opacity: 0; } }

.work-area { grid-area: work; pointer-events: none; }
.hint {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); padding: 12px 22px; border-radius: 999px;
  background: rgba(34, 22, 46, 0.78); color: var(--cream); font-size: 20px; font-weight: 600; white-space: nowrap; display: flex; gap: 8px; align-items: center;
  animation: pulse 1.6s ease-in-out infinite; transition: opacity 0.6s;
}
.hint.fade { opacity: 0; }
@keyframes pulse { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.06); } }
.tip {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: min(92%, 360px); padding: 10px 14px; border-radius: 14px;
  background: rgba(251, 244, 230, 0.95); color: var(--ink); font-size: 15px; line-height: 1.3; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: flex-start; text-wrap: balance;
  transition: opacity 0.4s, transform 0.4s;
}
.tip .ic { color: var(--honey); width: 22px; height: 22px; flex: none; margin-top: 1px; }
.tip.out { opacity: 0; transform: translateX(-50%) translateY(-8px); }
.basket-slot { grid-area: basket; pointer-events: none; }
.basket-slot canvas { width: 100%; height: 100%; display: block; }
.preview-slot { grid-area: preview; display: flex; align-items: center; justify-content: center; }
.preview-card {
  width: 88px; height: 88px; border: 0; padding: 0; border-radius: 12px; background: transparent; position: relative; cursor: zoom-in;
}
.preview-card canvas { width: 100%; height: 100%; display: block; border-radius: 12px; }
.preview-card.glow::after { content: ''; position: absolute; inset: -3px; border-radius: 14px; box-shadow: 0 0 0 2px var(--honey), 0 0 22px 6px rgba(242, 212, 138, 0.85); animation: glowout 1.2s ease forwards; }
.panel { grid-area: panel; display: flex; flex-direction: column; gap: 6px; padding: 6px calc(8px + var(--sar)) calc(6px + var(--sab)) calc(8px + var(--sal)); background: linear-gradient(rgba(34, 22, 46, 0.55), rgba(34, 22, 46, 0.88)); }
.strip {
  display: flex; align-items: center; gap: 6px; min-height: 81px; padding: 4px 4px 4px 12px; border-radius: 14px; background: rgba(251, 244, 230, 0.95);
  box-shadow: var(--shadow-sm);
}
.strip .words { flex: 1; min-width: 0; font-family: 'Caveat', cursive; font-size: 23px; line-height: 1.05; color: var(--ink); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; padding-right: 6px; }
/* the card is always as tall as its longest row can be (3 lines; 2 on a landscape phone), so it never jumps */
.strip .lbl { font-weight: 700; color: var(--plum); margin-right: 4px; }
.strip .tok.rep { background: rgba(217, 164, 65, 0.3); border-radius: 4px; }
.strip .tok.cur { text-decoration: underline; text-decoration-color: var(--cranberry); text-decoration-thickness: 2.5px; text-underline-offset: 3px; color: var(--cranberry-dk); font-weight: 700; }
.strip .cnt { font-family: 'Fredoka', sans-serif; font-size: 12px; color: var(--ink-soft); margin-left: 8px; white-space: nowrap; }
.strip abbr { text-decoration: none; }
.strip .q { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--plum); color: var(--cream); display: flex; align-items: center; justify-content: center; flex: none; }
.yarnbar { display: grid; grid-template-columns: repeat(6, var(--btn)); gap: 6px; justify-content: center; }
.ybtn {
  width: var(--btn); height: var(--btn); border-radius: 16px; border: 0; padding: 0; position: relative; background: rgba(251, 244, 230, 0.12);
  display: flex; align-items: center; justify-content: center; transition: transform 0.15s, background 0.15s;
}
.ybtn canvas { pointer-events: none; }
.ybtn .slot { position: absolute; left: 3px; top: 3px; font-size: 12px; font-weight: 700; color: var(--cream); background: rgba(34, 22, 46, 0.7); border-radius: 6px; padding: 0 5px; line-height: 17px; }
.ybtn.next { transform: translateY(-5px); background: rgba(242, 212, 138, 0.35); box-shadow: 0 0 0 2px var(--honey-lt); }
.ybtn.active-free { box-shadow: 0 0 0 2.5px var(--honey-lt); background: rgba(242, 212, 138, 0.28); }
.ybtn.follow { flex-direction: column; font-size: 11px; font-weight: 600; color: var(--cream); line-height: 1.05; gap: 2px; text-align: center; padding: 2px; }
.ybtn.follow.on { background: var(--sage-dk); box-shadow: 0 0 0 2px #b9d0a8; }
.ybtn.follow .ic { width: 22px; height: 22px; }
.ybtn.basket-btn .bk { position: relative; width: 50px; height: 50px; }
.ybtn.basket-btn .bk img { position: absolute; inset: 0; width: 100%; height: 100%; }
.ybtn.empty { display: none; }
.next-yarn { display: none; }
.big-buttons { --btn: 64px; }

/* layouts */
.knit-screen.lay-port { grid-template-columns: 176px 1fr 96px; grid-template-rows: auto 1fr 96px auto; grid-template-areas: "top top top" "work work work" "basket . preview" "panel panel panel"; }
.knit-screen.lay-port .basket-slot { width: 176px; height: 96px; margin-left: var(--sal); }
.knit-screen.lay-port .yarnbar { grid-template-columns: repeat(6, var(--btn)); }
.knit-screen.lay-port .topbar { flex-wrap: wrap; row-gap: 2px; padding-bottom: 4px; }
.knit-screen.lay-port .topbar > .icon-btn:first-child { margin-right: auto; }
.knit-screen.lay-port .progress { order: 10; flex: 1 0 100%; height: 40px; }
.knit-screen.lay-port .prog-line { text-align: center; }
.knit-screen.lay-land { grid-template-columns: calc(130px + var(--sal)) 1fr calc(280px + var(--sar)); grid-template-rows: auto 96px 1fr 84px; grid-template-areas: "top top top" "preview work panel" ". work panel" "basket work panel"; }
.knit-screen.lay-land .preview-slot { padding-left: var(--sal); }
.knit-screen.lay-land .basket-slot { width: 126px; height: 80px; align-self: end; margin: 0 0 4px calc(2px + var(--sal)); }
.knit-screen.lay-land .panel { justify-content: flex-start; padding-top: 6px; }
.knit-screen.lay-land .strip { min-height: 54px; }
.knit-screen.lay-land .strip .words { font-size: 21px; }
.knit-screen.lay-land .yarnbar { grid-template-columns: repeat(3, 56px); grid-auto-rows: 56px; gap: 6px 14px; }
.knit-screen.lay-land .topbar { padding-top: calc(4px + var(--sat)); padding-bottom: 4px; }
.knit-screen.lay-desk { grid-template-columns: 1fr 400px; grid-template-rows: auto auto minmax(0, 1fr) 190px; grid-template-areas: "top top" "work panel" "work preview" "work basket"; }
.knit-screen.lay-desk .panel { background: rgba(34, 22, 46, 0.62); padding: 14px 14px 8px; gap: 12px; }
.knit-screen.lay-desk .preview-slot { background: rgba(34, 22, 46, 0.62); padding: 4px 0 8px; min-height: 0; }
.knit-screen.lay-desk .preview-card { height: min(300px, 100%); width: auto; aspect-ratio: 1; min-height: 120px; }
.knit-screen.lay-desk .basket-slot { width: 400px; height: 190px; background: linear-gradient(rgba(34, 22, 46, 0.62), rgba(34, 22, 46, 0.35)); }
.knit-screen.lay-desk .yarnbar { grid-template-columns: repeat(6, 56px); --btn: 56px; gap: 8px; justify-content: space-between; }
.knit-screen.lay-desk .strip { min-height: 102px; padding-left: 16px; }
.knit-screen.lay-desk .strip .words { -webkit-line-clamp: 2; font-size: 28px; line-height: 1.1; }
.knit-screen.lay-desk .prog-line { font-size: 16px; }

/* ---------- toasts (over the progress line on the knitting screen; top centre elsewhere) */
#toasts { position: fixed; z-index: 40; left: 50%; top: max(calc(8px + var(--sat)), var(--tb, 8px)); transform: translateX(-50%); width: min(94vw, 440px); pointer-events: none; }
#toasts.over { left: var(--tl); top: var(--tt); width: var(--tw); transform: none; }
/* a sheet or modal is open: the toast waits until it closes */
#toasts.wait { visibility: hidden; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 6px 4px 14px; border-radius: 22px;
  background: linear-gradient(90deg, #fff4d8, var(--cream)); color: var(--ink); box-shadow: 0 0 0 2px var(--honey), var(--shadow); font-weight: 600; font-size: 15px;
  animation: toastin 0.3s cubic-bezier(.2,1.4,.5,1);
}
.toast .t { flex: 1; min-width: 0; line-height: 1.2; padding: 3px 0; text-wrap: balance; overflow-wrap: break-word; }
.toast .ic { color: var(--honey); flex: none; }
.toast button { border: 0; border-radius: 999px; background: var(--cranberry); color: #fff6ea; font-weight: 600; height: 36px; padding: 0 14px; flex: none; }
.toast.out { opacity: 0; transform: translateY(-10px); transition: 0.3s; }
@keyframes toastin { from { transform: translateY(-14px) scale(0.95); opacity: 0; } }

#notice { position: fixed; z-index: 60; left: 50%; bottom: calc(18px + var(--sab)); transform: translateX(-50%); width: max-content; max-width: 92vw; padding: 12px 18px; border-radius: 14px; background: var(--night-2); color: var(--cream); box-shadow: var(--shadow); font-size: 15px; text-align: center; text-wrap: balance; }

/* ---------- sheets */
#sheet-layer { position: fixed; inset: 0; z-index: 50; background: rgba(20, 10, 28, 0.42); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: min(100%, 560px); max-height: min(88vh, 760px); overflow-y: auto; touch-action: pan-y; background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 14px 16px calc(16px + var(--sab)); box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35); transform: translateY(30px); opacity: 0; transition: transform 0.22s ease, opacity 0.18s;
}
.sheet.in { transform: none; opacity: 1; }
@media (min-width: 700px) and (min-height: 520px) { #sheet-layer { align-items: center; } .sheet { border-radius: 22px; padding-bottom: 18px; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; position: sticky; top: -14px; background: var(--paper); padding: 4px 0; z-index: 2; }
.sheet-head h2 { flex: 1; font-size: 22px; color: var(--plum); }
.sheet-x { background: rgba(91, 58, 94, 0.12); color: var(--plum); }
.sheet p { line-height: 1.4; margin: 6px 0; }
.menu-list { display: grid; gap: 8px; }
.menu-list .btn { justify-content: flex-start; width: 100%; background: var(--cream); }
.menu-list .btn.primary { background: var(--cranberry); color: #fff6ea; }
.menu-list .btn .ic { color: var(--plum); }
.menu-list .btn.primary .ic { color: var(--cream); }

/* picker */
.picker .types { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.picker .type { border: 0; border-radius: 999px; padding: 6px 12px; min-height: 40px; background: var(--cream); font-weight: 600; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.picker .type.on { background: var(--plum); color: var(--cream); }
.picker .type canvas { width: 26px; height: 26px; }
.picker .type.locked { opacity: 0.45; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
@media (min-width: 480px) { .swatches { grid-template-columns: repeat(10, 1fr); } }
.sw { aspect-ratio: 1; border-radius: 50%; border: 0; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.25); min-width: 30px; position: relative; }
.sw.on { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5.5px var(--cranberry); }
.picker h3 { font-size: 15px; color: var(--plum); margin: 14px 0 8px; }
.picker .cur { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-weight: 600; }
.picker .cur canvas { flex: none; }
.mix { display: grid; gap: 8px; padding: 10px; background: var(--cream); border-radius: 14px; }
.mix label { display: grid; grid-template-columns: 90px 1fr; align-items: center; font-size: 14px; gap: 8px; }
input[type=range] { width: 100%; accent-color: var(--cranberry); height: 32px; touch-action: pan-x; }
.mix .row { display: flex; gap: 10px; align-items: center; }
.mix .swatch-big { width: 44px; height: 44px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2); flex: none; }

/* written pattern + glossary */
.pattern-text { font-size: 16px; line-height: 1.45; }
.pattern-text .ln { padding: 3px 8px; border-radius: 8px; }
.pattern-text .ln.title { font-size: 20px; font-weight: 700; color: var(--plum); }
.pattern-text .ln.info { color: var(--ink-soft); }
.pattern-text .ln.section, .pattern-text .ln.part { font-weight: 600; color: var(--plum); margin-top: 6px; }
.pattern-text .ln.row .l { font-weight: 600; color: var(--cranberry-dk); }
.pattern-text .ln.cur { background: rgba(217, 164, 65, 0.3); box-shadow: inset 3px 0 0 var(--honey); }
.pattern-text .ln.end { margin-top: 6px; }
.pattern-text b { color: var(--ink); }
.key { margin-top: 14px; padding: 10px 12px; background: var(--cream); border-radius: 12px; font-size: 15px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.key b { color: var(--plum); }
.key span, .pattern-text .ln { text-wrap: pretty; }
.settings-list { display: grid; gap: 12px; }
.set-row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.set-row > span { flex: 1; font-weight: 500; }
.set-row input[type=range] { flex: 1.3; }
.toggle { width: 60px; height: 34px; border-radius: 999px; border: 0; background: rgba(91, 58, 94, 0.25); position: relative; flex: none; }
.toggle::after { content: ''; position: absolute; left: 4px; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: var(--shadow-sm); }
.toggle.on { background: var(--sage-dk); }
.toggle.on::after { transform: translateX(26px); }
.reset-box { display: flex; gap: 8px; flex-wrap: wrap; }
.reset-box input { flex: 1; min-width: 120px; height: 44px; border-radius: 12px; border: 2px solid rgba(91, 58, 94, 0.3); padding: 0 12px; font: inherit; background: #fff; }
.howto-cards { display: grid; gap: 12px; }
.howto-card { display: flex; gap: 14px; align-items: center; background: var(--cream); border-radius: 16px; padding: 12px; }
.howto-card canvas { flex: none; border-radius: 12px; }
.howto-card h3 { font-size: 18px; color: var(--plum); }
.howto-card p { font-size: 15px; margin: 4px 0 0; }
.credits p { font-size: 15px; }
.credits h3 { color: var(--plum); margin-top: 12px; font-size: 17px; }
.keys-list { font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.keys-list kbd { font-family: inherit; background: var(--cream); border-radius: 6px; padding: 1px 6px; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12); color: var(--ink); }

/* ---------- finished */
.finished-screen { background: #2a1f3d; }
.finished-screen canvas.fx { position: absolute; inset: 0; width: 100%; height: 100%; }
.fin-ui { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 16px calc(18px + var(--sab)); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; color: var(--cream); background: linear-gradient(rgba(20, 10, 30, 0), rgba(20, 10, 30, 0.85) 30%); }
.fin-ui h2 { font-size: 30px; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.fin-ui .facts { font-size: 15px; opacity: 0.92; max-width: 560px; }
.fin-ui .btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; opacity: 0; transform: translateY(10px); transition: 0.5s; }
.fin-ui .btns.show { opacity: 1; transform: none; }
.fin-top { position: absolute; top: calc(14px + var(--sat)); left: 0; right: 0; text-align: center; font-family: 'Caveat', cursive; font-size: 34px; color: var(--honey-lt); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7); pointer-events: none; }

/* ---------- gallery */
.gallery-screen { background: linear-gradient(rgba(58, 26, 30, 0.42), rgba(40, 18, 30, 0.5)), url('assets/tex/tex-wood.webp') repeat; background-size: auto, 360px; display: flex; flex-direction: column; }
.gallery-screen.night { filter: brightness(0.55) saturate(0.7) hue-rotate(-10deg); }
.gal-top { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--sat)) calc(10px + var(--sar)) 8px calc(10px + var(--sal)); background: linear-gradient(rgba(34, 22, 46, 0.85), rgba(34, 22, 46, 0.55)); color: var(--cream); }
.gal-top h2 { font-size: 22px; flex: 1; }
.gal-tabs { display: flex; gap: 6px; padding: 8px 12px 0; justify-content: center; }
.gal-tabs .tab { background: rgba(34, 22, 46, 0.55); color: var(--cream); }
.gal-tabs .tab.on { background: var(--cream); color: var(--plum); }
.wall { flex: 1; position: relative; min-height: 0; }
.pegs { position: absolute; inset: 0; display: grid; padding: 16px 52px 8px; gap: 8px; }
.peg { position: relative; display: flex; flex-direction: column; align-items: center; min-height: 0; border: 0; background: none; padding: 0; }
.peg .knob { width: 34px; height: 34px; flex: none; background: url('assets/items/gallery-peg.png') center / contain no-repeat; z-index: 2; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.4)); }
.peg .cord { width: 2px; height: 10px; background: #e8d6b0; margin-top: -8px; flex: none; }
.peg .hang { flex: 1; min-height: 0; width: 100%; display: flex; align-items: flex-start; justify-content: center; }
.peg canvas { max-width: 100%; max-height: 100%; filter: drop-shadow(2px 6px 6px rgba(20, 8, 10, 0.45)); transform-origin: 50% 0; animation: sway 6s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-0.8deg); } 50% { transform: rotate(0.8deg); } }
.peg .tag { font-family: 'Caveat', cursive; font-size: 19px; background: #f3e6cc; color: var(--ink); padding: 0 10px; border-radius: 4px; margin-top: 4px; box-shadow: var(--shadow-sm); max-width: 100%; white-space: normal; overflow-wrap: anywhere; text-align: center; line-height: 1.1; padding-top: 2px; padding-bottom: 2px; text-wrap: balance; flex: none; display: inline-flex; gap: 4px; align-items: center; }
.peg .tag .ic { width: 14px; height: 14px; color: var(--plum); }
.peg.empty .hang { opacity: 0.35; }
.peg.arrive canvas { animation: arrive 0.9s cubic-bezier(.2,1.3,.5,1) both, sway 6s 0.9s ease-in-out infinite; }
@keyframes arrive { from { transform: translate(0, 40vh) scale(1.8); opacity: 0.2; } }
@media (max-height: 500px) and (orientation: landscape) {
  .pegs { padding: 6px 60px 4px; gap: 10px; }
  .peg .knob { width: 26px; height: 26px; }
  .peg .tag { font-size: 17px; max-width: 96%; }
}
.wall-arrow { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; background: rgba(34, 22, 46, 0.7); }
.wall-arrow.l { left: 6px; } .wall-arrow.r { right: 6px; }
.wall-arrow:active { transform: translateY(-50%) scale(0.95); }
.plaque { align-self: center; margin: 6px auto calc(8px + var(--sab)); padding: 6px 18px; border-radius: 8px; background: linear-gradient(#e7c56c, #b88a2c); color: #3a2408; font-weight: 600; font-size: 14px; box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.5); text-align: center; }
.gal-actions { display: flex; gap: 10px; justify-content: center; padding: 8px; flex-wrap: wrap; }
.basket-list { flex: 1; overflow-y: auto; touch-action: pan-y; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; align-content: start; }
.bpiece { background: rgba(251, 244, 230, 0.92); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; border: 0; }
.bpiece .pv { height: 120px; display: flex; align-items: center; justify-content: center; }
.bpiece .pv canvas { max-width: 100%; max-height: 100%; }
.bpiece .nm { font-family: 'Caveat', cursive; font-size: 20px; }
.empty-note { grid-column: 1 / -1; text-align: center; color: var(--cream); background: rgba(34, 22, 46, 0.6); border-radius: 14px; padding: 18px; font-size: 16px; }
.detail .big { display: flex; justify-content: center; padding: 10px; background: radial-gradient(circle at 40% 30%, #8a6585, #4a2f4d); border-radius: 14px; }
.detail .big canvas { max-width: 100%; max-height: 50vh; }
.detail .rename { display: flex; gap: 8px; margin: 10px 0; }
.detail .rename input { flex: 1; height: 44px; border-radius: 12px; border: 2px solid rgba(91, 58, 94, 0.3); padding: 0 12px; font-family: 'Caveat', cursive; font-size: 22px; background: #fff; }
.detail .facts { color: var(--ink-soft); font-size: 14px; }
.detail .acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- placeholders */
.placeholder-screen { background: radial-gradient(circle at 50% 30%, #4a2f55, #241933); display: flex; align-items: center; justify-content: center; padding: 20px; }
.ph-panel { background: var(--paper); border-radius: 20px; padding: 24px; max-width: 420px; text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.ph-panel h2 { color: var(--plum); font-size: 26px; }
.ph-panel p { color: var(--ink-soft); }

/* report form */
gh-feedback { font-family: 'Fredoka', sans-serif; }
.card .tech, .card .lock-text, .card h3, .front-btns .lbl, .set-row small, .set-row span, .facts, p { text-wrap: pretty; }
.pattern-text .ln { text-wrap: pretty; }
.book-complete { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 4px; }
.book-complete h2 { font-size: 30px; color: var(--plum); }
.book-complete p { color: var(--ink-soft); max-width: 420px; }
.gold-ribbon { width: 54px; height: 82px; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); background: linear-gradient(#fff0b8, #e6b83e 45%, #a8781a); filter: drop-shadow(0 3px 4px rgba(0,0,0,.3)); animation: flip 0.9s ease both; }

/* touch screens: the keyboard list in How to play is for keyboards */
@media (pointer: coarse) and (hover: none) { .howto-keys { display: none; } }
.card h3, .card .tech { text-wrap: balance; }

/* title-screen links (gallery lower-left, GitHub lower-right) */
.title-link { position: absolute; bottom: calc(10px + var(--sab, 0px)); font: 500 13px/1 'Fredoka', sans-serif; color: rgba(247,239,224,0.55); text-decoration: none; padding: 8px 10px; z-index: 3; }
.title-link:hover, .title-link:focus-visible { color: rgba(247,239,224,0.9); text-decoration: underline; }
.title-link-gallery { left: calc(6px + var(--sal, 0px)); }
.title-link-gh { right: calc(6px + var(--sar, 0px)); }
@media (pointer: coarse) { .title-link { font-size: 12px; } }
