/* SILK v4 — hệ giao diện "Hộp kim chỉ": đồ nghề may thêu làm giao diện.
   Vải lanh (thẻ, bảng), đường khâu (viền), cúc áo (nút tròn), mác vải dệt (nút chữ), thước dây (tơ còn lại),
   suốt chỉ (công cụ), ghim đầu tròn, sao thêu sa-tanh. Màu chỉ trùng màu tơ trong game: chỉ ngà = tơ Khung, chỉ nghệ = tơ Dính.
   Icon: assets/ui/*.svg, sinh bởi tools/ui-icons.mjs (nét mực khắc + đồ thêu). */
:root {
  --linen: #E4D6B8; --linen-2: #D6C6A3; --ivory: #F5ECD8; --ink: #2E231A; --ink-soft: #6A5843;
  --indigo: #283B56; --indigo-2: #1C2B40; --saffron: #D29A2E; --madder: #A3402E; --moss: #55703F; --deep: #15120E;
  --serif: 'Alegreya', 'Iowan Old Style', Georgia, serif;
  --sans: 'Alegreya Sans', 'Avenir Next', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-b: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  /* cạnh trái/phải: iPhone Duo đặt camera và thanh trạng thái dọc ở cạnh bên. Nền vẫn tràn kín màn hình;
     chỉ chữ và nút (menu, HUD, khay, thẻ, trang giấy) lùi vào bằng các biến này. */
  --safe-l: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --safe-r: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  /* vân vải lanh: sợi ngang + sợi dọc + vài sợi to (slub) */
  --weave: repeating-linear-gradient(0deg, rgba(96, 72, 40, .075) 0 1px, transparent 1px 3px),
           repeating-linear-gradient(90deg, rgba(96, 72, 40, .06) 0 1px, transparent 1px 3px),
           repeating-linear-gradient(0deg, transparent 0 23px, rgba(255, 250, 235, .22) 23px 24px, transparent 24px 61px, rgba(96, 72, 40, .07) 61px 62px),
           repeating-linear-gradient(90deg, transparent 0 41px, rgba(96, 72, 40, .06) 41px 42px, transparent 42px 77px, rgba(255, 250, 235, .2) 77px 78px);
  /* vân dệt của mác nhãn: sợi ngang dày */
  --rib: repeating-linear-gradient(0deg, rgba(255, 255, 255, .07) 0 1px, transparent 1px 2px, rgba(0, 0, 0, .06) 2px 3px);
  /* đường khâu 9 mảnh: mũi chỉ đều, đầu tròn, có bóng */
  --stitch-ink: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30'%3E%3Cg fill='none' stroke-linecap='round' stroke-width='1.8'%3E%3Cg stroke='rgba(255,250,235,.55)' transform='translate(0 .8)'%3E%3Cpath d='M12 5h6M12 25h6M5 12v6M25 12v6M5 7.5Q5 5 7.5 5M22.5 5Q25 5 25 7.5M25 22.5Q25 25 22.5 25M7.5 25Q5 25 5 22.5'/%3E%3C/g%3E%3Cg stroke='%237A5F42'%3E%3Cpath d='M12 5h6M12 25h6M5 12v6M25 12v6M5 7.5Q5 5 7.5 5M22.5 5Q25 5 25 7.5M25 22.5Q25 25 22.5 25M7.5 25Q5 25 5 22.5'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  --stitch-ivory: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30'%3E%3Cg fill='none' stroke-linecap='round' stroke-width='2'%3E%3Cg stroke='rgba(0,0,0,.35)' transform='translate(0 .8)'%3E%3Cpath d='M12 5h6M12 25h6M5 12v6M25 12v6M5 7.5Q5 5 7.5 5M22.5 5Q25 5 25 7.5M25 22.5Q25 25 22.5 25M7.5 25Q5 25 5 22.5'/%3E%3C/g%3E%3Cg stroke='%23F5ECD8'%3E%3Cpath d='M12 5h6M12 25h6M5 12v6M25 12v6M5 7.5Q5 5 7.5 5M22.5 5Q25 5 25 7.5M25 22.5Q25 25 22.5 25M7.5 25Q5 25 5 22.5'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  /* icon mực → màu chỉ ngà khi nằm trên mác chàm/son */
  --to-ivory: brightness(0) invert(.93) sepia(.35);
  /* icon mực khắc trên cúc/vải: một vệt sáng bên dưới nét */
  --engrave: drop-shadow(0 1px 0 rgba(255, 250, 235, .55));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0E0C09; overscroll-behavior: none; }
body { font-family: var(--sans); color: var(--ink); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font-family: inherit; }
.ic { display: block; flex: none; pointer-events: none; -webkit-user-drag: none; }

#app { position: fixed; inset: 0; margin: 0 auto; max-width: max(520px, 56.25dvh); overflow: hidden; background: var(--deep); }
/* app iOS chỉ chạy trên iPhone: chỉ màn trong của iPhone Duo (gần vuông) rộng hơn 520px → cho khung giãn tới tỉ lệ ~0,72 thay vì để dải tối hai bên */
html.p-ios #app { max-width: max(520px, 72dvh); }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }
.boot { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ivory); font: 500 italic 19px var(--serif); background: radial-gradient(circle at 50% 40%, #2E2519, #0E0C09); }

/* ---------- vật liệu dùng chung ---------- */
.linen { background-color: var(--linen); background-image: var(--weave); }

/* ---------- mác vải dệt (nút chữ) ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 52px; padding: 0 24px; border: none; border-radius: 3px; cursor: pointer;
  font: 800 18px/1 var(--sans); letter-spacing: .01em; color: var(--ink);
  background-color: #E8DABD; background-image: var(--rib);
  box-shadow: inset 0 1px 0 rgba(255, 252, 240, .6), inset 0 -2px 0 rgba(90, 64, 36, .18), 0 3px 0 #A58A63, 0 6px 10px rgba(12, 8, 3, .4);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn::after { content: ""; position: absolute; inset: 4px; border: 9px solid transparent; border-image: var(--stitch-ink) 10 round; pointer-events: none; }
.btn .ic { width: 24px; height: 24px; filter: var(--engrave); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 1px 0 rgba(255, 252, 240, .6), inset 0 -2px 0 rgba(90, 64, 36, .18), 0 0 0 #A58A63, 0 2px 4px rgba(12, 8, 3, .4); }
.btn:disabled { opacity: .45; pointer-events: none; filter: saturate(.4); }
.btn.primary { color: var(--ivory); background-color: var(--indigo);
  box-shadow: inset 0 1px 0 rgba(160, 185, 220, .25), inset 0 -2px 0 rgba(0, 0, 0, .3), 0 3px 0 #111C2C, 0 7px 12px rgba(0, 0, 0, .45); }
.btn.danger { color: var(--ivory); background-color: var(--madder);
  box-shadow: inset 0 1px 0 rgba(255, 200, 180, .25), inset 0 -2px 0 rgba(0, 0, 0, .25), 0 3px 0 #5E2218, 0 7px 12px rgba(0, 0, 0, .42); }
.btn.primary::after, .btn.danger::after { border-image-source: var(--stitch-ivory); }
.btn.primary .ic, .btn.danger .ic { filter: var(--to-ivory); }
.btn.primary:active { box-shadow: inset 0 1px 0 rgba(160, 185, 220, .25), 0 0 0 #111C2C, 0 2px 4px rgba(0, 0, 0, .45); }
.btn.danger:active { box-shadow: inset 0 1px 0 rgba(255, 200, 180, .25), 0 0 0 #5E2218, 0 2px 4px rgba(0, 0, 0, .42); }
.btn.big { min-height: 66px; font-size: 25px; padding: 0 34px; }
.btn.big .ic { width: 26px; height: 26px; }
.btn.small { min-height: 42px; font-size: 15px; padding: 0 15px; gap: 6px; }
.btn.small::after { inset: 3px; border-width: 8px; }
.btn.small .ic { width: 20px; height: 20px; }
/* nút đang bật (Lực, lưới mẫu): mác chuyển sang chàm */
.btn.on:not(.icon) { color: var(--ivory); background-color: var(--indigo); box-shadow: inset 0 1px 0 rgba(160, 185, 220, .25), 0 3px 0 #111C2C, 0 6px 10px rgba(0, 0, 0, .45); }
.btn.on:not(.icon)::after { border-image-source: var(--stitch-ivory); }
.btn.on:not(.icon) .ic { filter: var(--to-ivory); }

/* ---------- cúc áo sừng (nút tròn có icon khắc) ---------- */
.btn.icon.round { width: 54px; min-width: 54px; height: 54px; min-height: 54px; padding: 0; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #F6EBD3 0 18%, #E2CFAC 46%, #BFA37A 78%, #8E7352 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 248, 230, .35), inset 0 -3px 5px rgba(80, 55, 30, .35), 0 3px 0 #6E5639, 0 6px 10px rgba(10, 6, 2, .45); }
.btn.icon.round::after { inset: 6px; border: none; border-image: none; border-radius: 50%; box-shadow: inset 0 2px 3px rgba(90, 64, 36, .35), 0 1px 0 rgba(255, 250, 235, .5); }
.btn.icon.round .ic { width: 27px; height: 27px; margin: 0; }
.btn.icon.round:active { box-shadow: inset 0 0 0 2px rgba(255, 248, 230, .35), inset 0 -3px 5px rgba(80, 55, 30, .35), 0 0 0 #6E5639, 0 2px 4px rgba(10, 6, 2, .45); }
.btn.icon.round.small { width: 46px; min-width: 46px; height: 46px; min-height: 46px; }
.btn.icon.round.small::after { inset: 5px; }
.btn.icon.round.small .ic { width: 23px; height: 23px; }
.btn.icon.round.on { box-shadow: inset 0 0 0 2px rgba(255, 248, 230, .35), inset 0 -3px 5px rgba(80, 55, 30, .35), 0 0 0 3px var(--saffron), 0 3px 0 3px #6E5639, 0 6px 10px rgba(10, 6, 2, .45); }

/* ---------- menu ---------- */
#menu-canvas, #game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.menu-ui { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: calc(30px + var(--safe-t)) calc(26px + var(--safe-r)) calc(20px + var(--safe-b)) calc(26px + var(--safe-l)); pointer-events: none; }
.menu-top { position: absolute; left: calc(16px + var(--safe-l)); top: calc(14px + var(--safe-t)); }
.pill-stars { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 13px 0 7px; border-radius: 18px; background: rgba(16, 20, 14, .5); color: var(--ivory); font: 800 16px/1 var(--sans); }
.pill-stars .ic { width: 25px; height: 25px; }
.menu-title { text-align: center; margin-top: 6vh; color: var(--ivory); }
.wordmark { margin: 0; font: 800 clamp(76px, 25vw, 100px)/.88 var(--serif); letter-spacing: -.01em; text-shadow: 0 4px 18px rgba(0, 0, 0, .55); }
.subtitle { margin-top: 6px; font: 500 italic 22px/1.2 var(--serif); color: #F0E3C5; text-shadow: 0 2px 8px rgba(0, 0, 0, .65); }
.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: min(100%, 330px); pointer-events: auto; }
.menu-buttons .row { display: flex; gap: 12px; }
.menu-buttons .row .btn { flex: 1; font-size: 17px; padding: 0 10px; }
.menu-buttons .menu-store .btn { min-height: 44px; font-size: 16px; white-space: normal; }
#btn-play .lbl { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
#btn-play small { font: 500 italic 14px/1 var(--serif); opacity: .85; letter-spacing: 0; }
.menu-buttons .row.icons { justify-content: center; gap: 30px; margin-top: 4px; }
.cuc-cap { display: flex; flex-direction: column; align-items: center; gap: 6px; font: 700 13.5px/1 var(--sans); color: rgba(245, 236, 216, .9); text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
.menu-buttons .row.icons .btn.icon.round { width: 58px; min-width: 58px; height: 58px; min-height: 58px; }
.menu-foot { color: var(--ivory); opacity: .65; font: 500 italic 14px var(--serif); text-align: center; text-shadow: 0 1px 4px rgba(0, 0, 0, .7); }

/* ---------- trang trong hộp kim chỉ (bản đồ, sổ tay, bộ sưu tập, cài đặt): lòng hộp gỗ óc chó ---------- */
.paper { color: var(--ivory); background-color: #211A13;
  background-image: radial-gradient(130% 60% at 50% 0%, rgba(125, 90, 52, .38), transparent 62%),
    repeating-linear-gradient(90deg, rgba(255, 230, 190, .025) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .09) 0 1px, transparent 1px 23px); }
.topbar { display: grid; grid-template-columns: 50px 1fr 76px; align-items: center; gap: 8px; padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) 10px calc(14px + var(--safe-l)); }
.topbar h1 { margin: 0; font: 800 24px/1.1 var(--serif); text-align: center; color: var(--ivory); text-shadow: 0 2px 6px rgba(0, 0, 0, .4); }
.star-total { display: flex; align-items: center; justify-content: flex-end; gap: 4px; font: 800 16px var(--sans); color: #F2D79B; white-space: nowrap; }
.star-total .ic { width: 22px; height: 22px; }
.scroll { position: absolute; top: calc(76px + var(--safe-t)); bottom: 0; left: 0; right: 0; overflow-y: auto; padding: 6px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); -webkit-overflow-scrolling: touch; }
.hint { color: var(--ivory); opacity: .78; font: 500 italic 15px/1.4 var(--serif); margin: 0 22px; text-align: center; }
.hint.small { font-size: 13.5px; margin-top: 18px; }

/* ---------- HUD ---------- */
.hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l)); pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 12, 8, .55), rgba(10, 12, 8, 0)); }
.hud-row { display: flex; align-items: center; gap: 8px; }
.hud-row .btn { pointer-events: auto; }
.hud-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ivory); text-shadow: 0 2px 6px rgba(0, 0, 0, .6); }
.hud-title b { max-width: 100%; font: 800 21px/1.08 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* mác cỡ: số màn khâu như mác áo */
.tag, .hud-title span { display: inline-block; font: 900 12.5px/1 var(--sans); letter-spacing: .04em; color: var(--ivory); text-shadow: none; white-space: nowrap;
  background-color: var(--indigo); background-image: var(--rib); padding: 4px 8px; border-radius: 2px; box-shadow: inset 0 0 0 1.5px rgba(245, 236, 216, .32), 0 2px 4px rgba(0, 0, 0, .4); }
.hud-row.stats { margin-top: 8px; justify-content: space-between; gap: 6px; }
/* thước dây: hộp da tròn ghi số tơ còn lại, dải thước ngắn dần khi dùng tơ, nút chỉ đỏ là mốc 2 sao */
.silk-meter { display: flex; align-items: center; min-width: 92px; flex: 0 1 auto; pointer-events: none; }
.silk-meter .case { position: relative; z-index: 2; flex: none; width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #A6714A, #7C4E2F 60%, #5A3520); box-shadow: inset 0 -3px 5px rgba(0, 0, 0, .35), 0 3px 0 #3A2214, 0 5px 8px rgba(0, 0, 0, .4); }
.silk-meter .case::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; border: 1.8px dashed rgba(226, 170, 70, .9); }
#silk-left { position: relative; font: 800 15px/1 var(--sans); color: var(--ivory); letter-spacing: -.01em; font-variant-numeric: tabular-nums; text-shadow: 0 1px 0 rgba(0, 0, 0, .4); }
.silk-meter .bar { position: relative; margin-left: -8px; height: 22px; flex: 0 1 112px; width: 112px; min-width: 50px; border-radius: 0 3px 3px 0;
  background: rgba(16, 12, 8, .38); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .5); }
.silk-meter .bar i#silk-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 2px 2px 0; transition: width .2s;
  background-color: #E2B648; background-image: repeating-linear-gradient(90deg, rgba(46, 35, 26, .7) 0 1px, transparent 1px 7.5px), linear-gradient(180deg, #F0CB60, #D6A63A);
  background-size: 100% 6px, 100% 100%; background-repeat: repeat-x, no-repeat; box-shadow: 0 2px 0 #9C7422, 0 4px 6px rgba(0, 0, 0, .3); }
.silk-meter .bar i#silk-fill::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 11px; background: repeating-linear-gradient(90deg, transparent 0 28.5px, rgba(46, 35, 26, .9) 28.5px 30px); }
.silk-meter .bar i#silk-fill::after { content: ""; position: absolute; right: -2px; top: -3px; bottom: -3px; width: 6px; border-radius: 2px; background: linear-gradient(90deg, #C3C7CC, #7D838B); box-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.silk-meter .bar i#silk-par { position: absolute; z-index: 1; top: -6px; bottom: -6px; width: 4px; margin-left: -2px; border-radius: 2px; background: var(--madder); box-shadow: 0 0 0 1.5px var(--ivory), 0 1px 3px rgba(0, 0, 0, .55); }
.silk-meter .bar i#silk-par::before { content: ""; position: absolute; left: -4px; top: -4px; width: 12px; height: 8px; border-radius: 50%; background: var(--madder); box-shadow: 0 0 0 1.5px var(--ivory); }
/* ---------- màn rộng (máy gập mở ra): "mở hộp kim chỉ", trang sổ tay bên cạnh vùng chơi ---------- */
/* lớp tối của HUD và khay vẫn trải hết bề ngang (nền liền một mảnh); chỉ nút và chữ dồn vào cột trái */
#scr-play.wide .hud, #scr-play.wide .tray { padding-right: calc(var(--side-w) + 10px); }
#scr-play.wide .bubble { display: none; }
#scr-play.wide .toast { left: calc((100% - var(--side-w)) / 2); }
.side-notes { position: absolute; top: 0; right: 0; bottom: 0; width: var(--side-w, 0px); z-index: 3; pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  padding: calc(18px + var(--safe-t)) calc(12px + var(--safe-r)) calc(16px + var(--safe-b)) 6px;
  background: none; animation: lid-open .45s ease-out both; } /* nền vườn chạy liền một mảnh dưới trang sổ tay */
@keyframes lid-open { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
body.rm .side-notes { animation: none; }
.side-notes .sheet { position: relative; padding: 17px 17px 15px; border-radius: 3px; color: var(--ink); background-color: var(--linen); background-image: var(--weave);
  box-shadow: 0 2px 0 rgba(120, 95, 60, .55), 0 7px 8px -3px rgba(0, 0, 0, .4); transform: rotate(var(--r, 0deg)); }
.side-notes .sheet::after { content: ""; position: absolute; inset: 5px; border: 9px solid transparent; border-image: var(--stitch-ink) 10 round; pointer-events: none; }
.side-notes .sheet:nth-child(odd) { --r: -.5deg; }
.side-notes .sheet:nth-child(even) { --r: .45deg; }
.side-notes .sheet > .pin { position: absolute; top: -7px; width: 18px; height: 18px; }
.side-notes .sheet > .pin.tl { left: 8px; }
.side-notes .sheet > .pin.tr { right: 8px; }
.side-notes h4 { margin: 0 0 7px; font: 800 12px/1 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-soft); }
.side-notes .lvl-name { display: block; margin-top: 6px; font: 800 17px/1.15 var(--serif); }
.side-notes .goals-copy { display: flex; flex-wrap: wrap; gap: 6px; }
.side-notes .goals-copy .chip { height: 40px; font-size: 15px; }
.side-notes .goals-copy .chip img { width: 30px; height: 30px; }
.side-notes .goals-copy .chip .ic { width: 17px; height: 17px; }
.side-notes .stars { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.side-notes .stars li, .side-notes .tips li { display: flex; align-items: center; gap: 6px; font: 600 13px/1.25 var(--sans); }
.side-notes .stars .ic { width: 16px; height: 16px; flex: none; }
.side-notes .tips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.side-notes .tips li { align-items: flex-start; }
.side-notes .tips li .ic { width: 20px; height: 20px; flex: none; filter: var(--engrave); }
.side-notes .tips li.warn { color: #7A2D20; }
.side-notes .say { margin: 0; font: 500 italic 14px/1.35 var(--serif); }
.side-notes .tape { display: flex; align-items: center; }
.side-notes .tape .case { position: relative; z-index: 2; flex: none; width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; color: var(--ivory); font: 800 15px var(--sans);
  background: radial-gradient(circle at 35% 30%, #A6714A, #7C4E2F 60%, #5A3520); box-shadow: inset 0 -3px 5px rgba(0, 0, 0, .35), 0 3px 0 #3A2214; }
.side-notes .tape .case::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; border: 1.8px dashed rgba(226, 170, 70, .9); }
.side-notes .tape .bar { position: relative; margin-left: -8px; height: 24px; flex: 1; border-radius: 0 3px 3px 0; background: rgba(46, 35, 26, .22); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .35); }
.side-notes .tape .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 2px 2px 0; transition: width .2s;
  background-color: #E2B648; background-image: repeating-linear-gradient(90deg, rgba(46, 35, 26, .7) 0 1px, transparent 1px 7.5px), linear-gradient(180deg, #F0CB60, #D6A63A); background-size: 100% 6px, 100% 100%; background-repeat: repeat-x, no-repeat; }
.side-notes .tape .par { position: absolute; top: -6px; bottom: -6px; width: 4px; margin-left: -2px; border-radius: 2px; background: var(--madder); box-shadow: 0 0 0 1.5px var(--ivory); }
.side-notes .tape-note { margin-top: 5px; font: 700 11.5px/1.2 var(--sans); color: var(--ink-soft); }

/* miếng vá thêu: mục tiêu */
.goals { display: flex; gap: 6px; border: none; background: none; padding: 0; margin: 0; cursor: pointer; pointer-events: auto; min-width: 0; }
.chip { position: relative; display: inline-flex; flex-shrink: 0; align-items: center; gap: 2px; height: 44px; padding: 0 11px 0 5px; border-radius: 22px; white-space: nowrap;
  font: 800 16px/1 var(--sans); color: var(--ink); background-color: #E6D8BA; background-image: var(--weave); box-shadow: 0 2px 0 #9E8460, 0 5px 8px rgba(0, 0, 0, .38); }
.chip::after { content: ""; position: absolute; inset: 3px; border-radius: 19px; border: 1.6px dashed rgba(122, 95, 66, .8); pointer-events: none; }
.chip img { width: 34px; height: 34px; }
.chip .ic { width: 19px; height: 19px; }
.chip.friend { background-color: #EBC9BE; }
.chip.friend::after { border-color: rgba(163, 64, 46, .75); }
.goals.done .chip.prey { background-color: #CFD9B0; }
.goals.done .chip.prey::after { border-color: rgba(85, 112, 63, .85); }
.goals.tight { display: grid; grid-template-columns: repeat(2, max-content); justify-content: end; gap: 4px; }
.goals.tight .chip { gap: 1px; padding: 0 7px 0 3px; }
.goals.tight .chip img { width: 28px; height: 28px; }
.goals.tight .chip .ic { width: 17px; height: 17px; }

/* ---------- khay: suốt chỉ, cúc sửa, cúc chàm chạy ---------- */
.tray { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); background: linear-gradient(0deg, rgba(10, 12, 8, .82) 35%, rgba(10, 12, 8, 0)); }
.tray-build { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; position: relative; }
.tools { display: flex; gap: 6px; align-items: flex-end; }
.tool { position: relative; width: 64px; height: 64px; border: none; padding: 0; background: none; display: grid; place-items: center; cursor: pointer; margin-bottom: 24px; }
.tool .ic { width: 64px; height: 64px; filter: drop-shadow(0 5px 5px rgba(0, 0, 0, .45)); transition: transform .15s ease; }
.tool span { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); padding: 4px 7px 3px; border-radius: 2px; white-space: nowrap;
  font: 800 14px/1 var(--sans); color: rgba(245, 236, 216, .78); text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.tool.on .ic { transform: translateY(-8px); }
.tool.on span { color: var(--ivory); text-shadow: none; background-color: var(--indigo); background-image: var(--rib); box-shadow: inset 0 0 0 1.5px rgba(245, 236, 216, .3), 0 2px 4px rgba(0, 0, 0, .4); }
.tool:disabled { opacity: .4; }
.tools .mini { display: flex; flex-direction: column; gap: 10px; margin: 0 0 6px 4px; }
.tools .mini .btn.icon.round.small { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
.tools .mini .btn.icon.round.small .ic { width: 22px; height: 22px; }
/* cúc áo khoác gỗ nhuộm chàm, mặt thêu tam giác sa-tanh (assets/ui/run.svg) */
.go { position: relative; flex: none; width: 86px; height: 86px; margin-bottom: 6px; border: none; padding: 0; cursor: pointer; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 28%, #4C6688 0 12%, #34507A 35%, #22385A 70%, #15243B 100%);
  box-shadow: inset 0 0 0 3px rgba(190, 210, 240, .18), inset 0 -5px 9px rgba(0, 0, 0, .45), 0 4px 0 #0E1828, 0 9px 14px rgba(0, 0, 0, .5); transition: transform .08s; }
.go::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; box-shadow: inset 0 3px 5px rgba(0, 0, 0, .45), 0 1px 0 rgba(170, 195, 230, .25); }
.go .ic { position: relative; width: 100%; height: 100%; }
.go:active { transform: translateY(4px); box-shadow: inset 0 0 0 3px rgba(190, 210, 240, .18), inset 0 -5px 9px rgba(0, 0, 0, .45), 0 0 0 #0E1828, 0 3px 6px rgba(0, 0, 0, .5); }
#btn-old { position: absolute; left: 50%; top: -54px; transform: translateX(-50%); white-space: nowrap; }
#btn-old:active { transform: translateX(-50%) translateY(3px); }
.tray-run { display: flex; gap: 10px; justify-content: center; padding-bottom: 8px; }
.tray-run .btn { flex: 1; max-width: 150px; min-height: 48px; font-size: 17px; padding: 0 10px; }
.tray-run .btn .ic { width: 22px; height: 22px; }
#btn-stop { color: var(--ivory); background-color: var(--madder); box-shadow: inset 0 1px 0 rgba(255, 200, 180, .25), 0 3px 0 #5E2218, 0 6px 10px rgba(0, 0, 0, .42); }
#btn-stop::after { border-image-source: var(--stitch-ivory); }
#btn-stop .ic { filter: var(--to-ivory); }

/* ---------- lời nhắc: mảnh vải lanh ghim lên cảnh ---------- */
.bubble { position: absolute; left: calc(14px + var(--safe-l)); right: calc(14px + var(--safe-r)); top: calc(var(--hud-bottom, calc(116px + var(--safe-t))) + 8px); padding: 12px 16px 12px 60px; border-radius: 3px; transform: rotate(-.5deg);
  font: 500 italic 17.5px/1.3 var(--serif); color: var(--ink); background-color: var(--linen); background-image: var(--weave);
  box-shadow: 0 2px 0 rgba(120, 95, 60, .55), 0 10px 18px rgba(0, 0, 0, .35); pointer-events: auto; cursor: pointer; animation: pop .25s ease; }
.bubble::before { content: ""; position: absolute; left: 12px; top: 50%; width: 38px; height: 38px; transform: translateY(-50%); background: url(../assets/spider.svg) center / contain no-repeat; }
.bubble.worm::before { background-image: url(../assets/silkworm.svg); }
.bubble::after { content: ""; position: absolute; left: -7px; top: -9px; width: 26px; height: 26px; background: url(../assets/ui/pin.svg) center / contain no-repeat; }
.toast { position: absolute; left: 50%; bottom: calc(156px + var(--safe-b)); transform: translateX(-50%); padding: 11px 18px; border-radius: 3px; white-space: nowrap; pointer-events: none;
  font: 800 16px/1 var(--sans); color: var(--ivory); background-color: var(--madder); background-image: var(--rib); box-shadow: inset 0 0 0 1.5px rgba(245, 236, 216, .3), 0 3px 0 #5E2218, 0 8px 14px rgba(0, 0, 0, .4); animation: pop .2s ease; }
.toast.info { color: var(--ink); background-color: var(--linen); background-image: var(--weave); box-shadow: 0 2px 0 rgba(120, 95, 60, .55), 0 8px 14px rgba(0, 0, 0, .4);
  white-space: normal; width: max-content; max-width: 86%; text-align: center; font: 500 italic 16px/1.3 var(--serif); }
@keyframes pop { from { transform: translateX(var(--tx, 0)) scale(.92); opacity: 0; } to { opacity: 1; } }
.toast { --tx: -50%; }
.bubble { --tx: 0; }

/* ---------- thẻ: mảnh vải lanh có đường khâu, ghim hai góc ---------- */
.modal { position: absolute; inset: 0; background: rgba(12, 8, 4, .6); display: flex; align-items: flex-start; justify-content: center; z-index: 10;
  padding: calc(18px + var(--safe-t)) calc(18px + var(--safe-r)) calc(14px + var(--safe-b)) calc(18px + var(--safe-l)); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
/* margin auto: vừa màn thì nằm giữa; thẻ cao hơn màn hình thì bám mép trên và cuộn được */
.modal > .card { margin: auto 0; flex: none; }
.card { position: relative; isolation: isolate; width: min(100%, 352px); padding: 32px 22px 22px; text-align: center; color: var(--ink);
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, .5)); animation: rise .3s cubic-bezier(.2, 1.4, .4, 1); }
.card::before { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: 4px; background-color: var(--linen); background-image: var(--weave); box-shadow: 0 3px 0 #A68D67; }
.card::after { content: ""; position: absolute; inset: 6px; z-index: -1; border: 10px solid transparent; border-image: var(--stitch-ink) 10 round; pointer-events: none; }
.card .pin { position: absolute; top: -9px; width: 28px; height: 28px; pointer-events: none; }
.card .pin.tl { left: -6px; }
.card .pin.tr { right: -6px; transform: scaleX(-1); }
@keyframes rise { from { transform: translateY(24px) scale(.95); opacity: 0; } }
.card h2 { margin: 2px auto 4px; font: 800 28px/1.08 var(--serif); color: var(--ink); }
.card p { margin: 6px 0; color: var(--ink-soft); font: 500 16px/1.4 var(--sans); }
.chap-tag { margin: 0 0 14px; font: 500 italic 16px/1.3 var(--serif); color: var(--ink-soft); }
.size-tag { position: absolute; left: 50%; top: -13px; transform: translateX(-50%); font-size: 15px; padding: 7px 12px 6px; }
.card p.mod { text-align: left; background: rgba(210, 154, 46, .16); border-left: 3px solid var(--saffron); border-radius: 2px; padding: 8px 10px; color: var(--ink); font-size: 15px; }
.card .actions { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.card .actions .row { display: flex; gap: 10px; }
.card .actions .row .btn { flex: 1; font-size: 17px; white-space: nowrap; padding: 0 10px; }
.card .saved { display: flex; align-items: center; justify-content: center; gap: 5px; font: 500 italic 15px var(--serif); color: #3E5130; margin-top: 12px; }
.card .saved .ic { width: 20px; height: 20px; }
.card .menu-list { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.card .menu-list .btn { justify-content: flex-start; padding-left: 22px; }
.inl { display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -0.2em; }

/* thẻ mục tiêu: miếng vá con vật, lưu ý, ba sao thêu */
/* tối đa 4 miếng vá một hàng (màn cuối: ruồi, bọ rùa, ong bắp cày, chim), mỗi miếng không rộng quá 92px */
.goal-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 2px 0 14px; }
.goal-tiles .g > div { display: flex; flex-wrap: wrap; justify-content: center; }
.goal-tiles .g { position: relative; flex: 1 1 64px; min-width: 64px; max-width: 116px; padding: 8px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-radius: 20px; background: rgba(255, 250, 235, .45); }
.goal-tiles .g::after { content: ""; position: absolute; inset: 3px; border-radius: inherit; border: 1.6px dashed rgba(122, 95, 66, .65); pointer-events: none; }
.goal-tiles .g img.who { width: 52px; height: 52px; }
.goal-tiles .g .mark { position: absolute; right: 3px; top: 1px; width: 24px; height: 24px; }
.goal-tiles .g b { display: flex; align-items: center; gap: 3px; font: 800 19px/1 var(--serif); min-height: 24px; }
.goal-tiles .g b .ic { width: 22px; height: 22px; }
.goal-tiles .g.warn { background: rgba(214, 150, 135, .35); }
.goal-tiles .g.warn::after { border-color: rgba(163, 64, 46, .7); }
.goal-tiles .g.foe { background: rgba(226, 182, 72, .25); }
.goal-tiles .g.foe::after { border-color: rgba(156, 106, 24, .7); }
.notes { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.notes li { display: flex; align-items: center; gap: 9px; font: 600 15px/1.28 var(--sans); color: var(--ink); background: rgba(255, 250, 235, .4); border-radius: 3px; padding: 5px 10px 5px 6px; }
.notes li .ic { width: 24px; height: 24px; filter: var(--engrave); }
.notes li.warn { background: rgba(163, 64, 46, .11); }
.rules { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.rules li { display: flex; align-items: center; gap: 10px; font: 700 16px/1.25 var(--sans); }
.rules li .ic { width: 26px; height: 26px; }
.rules li .ic.sm { width: 22px; height: 22px; filter: var(--engrave); }
.rules li.leafok { color: #3E5130; }
.tipline { display: flex; align-items: center; gap: 10px; text-align: left; font: 500 italic 16.5px/1.3 var(--serif); color: #3E5130;
  background: rgba(85, 112, 63, .12); border-left: 3px solid rgba(85, 112, 63, .6); border-radius: 2px; padding: 8px 12px; margin: 0 0 4px; }
.tipline img { width: 32px; height: 32px; flex: none; }
/* thẻ dày (nhiều ô/lưu ý) và màn hình thấp: gọn lại để vừa một màn */
.card.dense { padding: 28px 16px 16px; }
.card.dense h2 { font-size: 24px; }
.card.dense .chap-tag { margin-bottom: 10px; font-size: 15px; }
.card.dense .goal-tiles { gap: 6px; margin-bottom: 10px; }
.card.dense .goal-tiles .g { padding: 6px 3px 4px; }
.card.dense .goal-tiles .g img.who { width: 42px; height: 42px; }
.card.dense .goal-tiles .g .mark { width: 21px; height: 21px; }
.card.dense .notes { gap: 4px; margin-bottom: 10px; }
.card.dense .notes li { font-size: 13.5px; padding: 3px 8px 3px 5px; }
.card.dense .notes li .ic { width: 21px; height: 21px; }
.card.dense .rules { gap: 4px; margin-bottom: 10px; }
.card.dense .rules li { font-size: 14.5px; }
.card.dense .rules li .ic { width: 22px; height: 22px; }
.card.dense .rules li .ic.sm { width: 19px; height: 19px; }
.card.dense .tipline { font-size: 15px; padding: 5px 9px; }
.card.dense .tipline img { width: 28px; height: 28px; }
.card.dense .actions { margin-top: 12px; }

/* phiếu thua & bảng kết quả gọn */
.stat-list { list-style: none; margin: 8px 0 14px; padding: 0; text-align: left; }
.stat-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1.5px dashed rgba(122, 95, 66, .4); font: 700 15px var(--sans); }
.stat-list li em { font-style: normal; color: var(--ink-soft); font-weight: 700; display: flex; align-items: center; gap: 4px; }
.stat-list li .ic { width: 22px; height: 22px; }

/* ---------- bưu thiếp khi thắng ---------- */
.card.postcard { width: min(100%, 352px); padding: 12px 12px 16px; transform: rotate(-1.2deg); filter: drop-shadow(0 24px 40px rgba(0, 0, 0, .55)); }
.card.postcard::before { background-color: #F3EAD6; box-shadow: 0 3px 0 #B49A72; }
.card.postcard::after { inset: 4px; }
.pc-pic { position: relative; height: clamp(170px, 30vh, 250px); border-radius: 2px; overflow: hidden; background: #22342A; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.pc-pic canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pc-stamp { position: absolute; right: 8px; top: 6px; width: 74px; height: 90px; transform: rotate(4deg); filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .3)); }
.pc-stamp img { position: absolute; left: 13px; top: 12px; width: 48px; }
.pc-mark { position: absolute; right: 62px; top: 46px; width: 92px; height: 92px; border-radius: 50%; border: 3px solid rgba(163, 64, 46, .75); color: rgba(163, 64, 46, .85);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; font: 800 12px/1.15 var(--sans); transform: rotate(-14deg); }
.pc-mark::before, .pc-mark::after { content: ""; position: absolute; left: -54px; width: 80px; height: 2.5px; background: repeating-linear-gradient(90deg, rgba(163, 64, 46, .7) 0 13px, transparent 13px 19px); }
.pc-mark::before { top: 38px; } .pc-mark::after { top: 52px; }
.pc-stars { display: flex; justify-content: center; align-items: flex-end; gap: 6px; margin: -30px 0 0; position: relative; }
.pc-stars .ic { width: 50px; height: 50px; transform: scale(0); animation: starIn .45s cubic-bezier(.2, 1.6, .4, 1) forwards; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .3)); }
.pc-stars .ic:nth-child(2) { width: 62px; height: 62px; animation-delay: .18s; }
.pc-stars .ic:nth-child(3) { animation-delay: .36s; }
.pc-stars .ic.off { opacity: .35; filter: grayscale(1); }
.rm .pc-stars .ic { animation: none; transform: none; }
@keyframes starIn { to { transform: scale(1); } }
.pc-note { text-align: left; padding: 4px 6px 0; }
.pc-note .hand { display: flex; align-items: center; gap: 6px; font: 800 27px/1.1 var(--serif); }
.pc-note .hand .ic { width: 26px; height: 26px; }
.pc-note small { display: block; margin-top: 2px; font: 500 italic 15px var(--serif); color: var(--ink-soft); }
.pc-stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.pc-stats span { position: relative; display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 11px 0 5px; border-radius: 16px; font: 800 15px/1 var(--sans); background: rgba(214, 198, 163, .55); }
.pc-stats span::after { content: ""; position: absolute; inset: 2.5px; border-radius: 14px; border: 1.4px dashed rgba(122, 95, 66, .55); pointer-events: none; }
.pc-stats span.ok { background: rgba(165, 190, 130, .45); }
.pc-stats img, .pc-stats .ic { width: 24px; height: 24px; }
.fact-new { display: flex; gap: 9px; align-items: flex-start; text-align: left; background: rgba(85, 112, 63, .12); border-left: 3px solid rgba(85, 112, 63, .55); border-radius: 2px; padding: 8px 10px; margin: 10px 0 0; }
.fact-new .ic { width: 26px; height: 26px; filter: var(--engrave); }
.fact-new b { display: block; font: 800 15px/1.2 var(--sans); margin-bottom: 2px; }
.fact-new span { font: 500 14px/1.32 var(--sans); color: var(--ink-soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pc-actions { display: flex; flex-direction: row !important; gap: 10px !important; align-items: center; }
.pc-actions .grow { flex: 1; font-size: 20px; padding: 0 12px; }

/* ---------- bản đồ: mẫu thêu trên vải lanh, mỗi màn là một chiếc cúc ---------- */
.chapter { position: relative; isolation: isolate; border-radius: 4px; padding: 20px 18px 14px; margin: 8px 2px 22px; color: var(--ink);
  background-color: var(--linen); background-image: var(--weave); box-shadow: 0 3px 0 #8E7550, 0 14px 26px rgba(0, 0, 0, .4); }
.chapter::after { content: ""; position: absolute; inset: 6px; z-index: -1; border: 10px solid transparent; border-image: var(--stitch-ink) 10 round; pointer-events: none; }
.ch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; position: relative; }
.ch-head small { display: block; font: 500 italic 15px/1.2 var(--serif); color: var(--ink-soft); }
.ch-head h2 { margin: 1px 0 4px; font: 800 26px/1.08 var(--serif); color: var(--ink); }
.ch-head p { margin: 0; font: 500 14.5px/1.38 var(--sans); color: var(--ink-soft); }
.ch-stars { position: relative; display: flex; align-items: center; gap: 4px; height: 32px; padding: 0 11px 0 5px; border-radius: 16px; white-space: nowrap;
  font: 800 15px var(--sans); color: var(--ink); background: rgba(255, 250, 235, .5); }
.ch-stars::after { content: ""; position: absolute; inset: 2.5px; border-radius: 14px; border: 1.4px dashed rgba(122, 95, 66, .6); pointer-events: none; }
.ch-stars .ic { width: 22px; height: 22px; }
.ch-lock { position: relative; margin: 12px 0 0; padding: 8px 12px 8px 8px; border-radius: 3px; display: inline-flex; align-items: center; gap: 7px;
  font: 700 14.5px var(--sans); color: var(--ivory); background-color: var(--madder); background-image: var(--rib); box-shadow: inset 0 0 0 1.5px rgba(245, 236, 216, .3), 0 2px 0 #5E2218; }
.ch-lock .ic { width: 20px; height: 20px; filter: var(--to-ivory); }
.ch-lock .ic.inl { filter: none; }
.trail { position: relative; margin-top: 6px; }
.trail svg.thread { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; }
.chapter.closed .trail { opacity: .5; }
.dn { position: absolute; width: 60px; height: 60px; margin: -30px 0 0 -30px; padding: 0; border: none; background: none; cursor: pointer; display: grid; place-items: center; font-family: inherit; }
.dn .drop { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 3px 3px rgba(40, 26, 10, .35)); }
.dn .num { position: relative; font: 800 22px/1 var(--serif); color: var(--ink); text-shadow: 0 1px 0 rgba(255, 250, 235, .6); }
.dn.locked { cursor: default; }
.dn.locked .drop { filter: none; }
.dn.locked .num { color: rgba(110, 84, 54, .55); text-shadow: none; }
.dn .st { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); display: flex; gap: 1px; }
.dn .st .ic { width: 18px; height: 18px; }
.dn .st .ic.off { opacity: .3; filter: grayscale(1); }
.dn .nm { position: absolute; top: 50%; transform: translateY(-50%); width: max-content; max-width: 130px; font: 700 15px/1.18 var(--sans); color: var(--ink); text-align: left; }
.dn.r .nm { left: 68px; }
.dn.l .nm { right: 68px; text-align: right; }
.dn.locked .nm { color: rgba(106, 88, 67, .6); }
.dn .leafb { position: absolute; left: -6px; top: -2px; width: 22px; height: 22px; }
.dn.current::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2.5px dashed var(--thread, var(--indigo)); animation: pulse 1.6s ease-in-out infinite; pointer-events: none; }
.rm .dn.current::after { animation: none; }
@keyframes pulse { 50% { transform: scale(1.1); opacity: .5; } }
.dn .buddy { position: absolute; left: 38px; top: -26px; width: 40px; transform: rotate(-8deg); pointer-events: none; }
.dn .say { position: absolute; left: 68px; top: -50px; display: flex; gap: 1px; align-items: center; padding: 3px 8px; border-radius: 3px; pointer-events: none;
  background-color: #F3EAD6; box-shadow: 0 2px 0 rgba(120, 95, 60, .5), 0 6px 12px rgba(0, 0, 0, .3); }
.dn .say::after { content: ""; position: absolute; left: 10px; bottom: -7px; border: 8px solid transparent; border-top-color: #F3EAD6; border-bottom: 0; }
.dn .say img { width: 30px; height: 30px; }
.dn .say .ic { width: 16px; height: 16px; margin-top: -10px; }

/* ---------- sổ tay: phiếu vải ghi chép ---------- */
.journal { display: flex; flex-direction: column; gap: 14px; }
.fact { position: relative; isolation: isolate; display: flex; gap: 12px; color: var(--ink); border-radius: 3px; padding: 16px 16px 14px;
  background-color: var(--linen); background-image: var(--weave); box-shadow: 0 2px 0 #8E7550, 0 8px 16px rgba(0, 0, 0, .35); }
.fact h3 { margin: 0 0 4px; font: 800 19px/1.15 var(--serif); }
.fact p { margin: 0 0 4px; font: 500 15px/1.45 var(--sans); color: #4E3F31; }
.fact small { color: var(--ink-soft); font: 500 italic 13.5px var(--serif); }
/* số trang: cúc sừng nhỏ */
.fact-num { flex: none; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font: 800 17px var(--serif); color: var(--ink);
  background: radial-gradient(circle at 34% 28%, #F6EBD3 0 18%, #E2CFAC 46%, #BFA37A 78%, #8E7352 100%); box-shadow: inset 0 -2px 3px rgba(80, 55, 30, .35), 0 2px 0 #6E5639; }
.fact.locked { background: rgba(245, 236, 216, .07); color: var(--ivory); box-shadow: none; }
.fact.locked::after { content: ""; position: absolute; inset: 0; border-radius: 3px; border: 1.6px dashed rgba(245, 236, 216, .3); pointer-events: none; }
.fact.locked p { color: var(--ivory); opacity: .6; }
.fact.locked .fact-num { background: none; color: rgba(245, 236, 216, .6); box-shadow: inset 0 0 0 1.6px rgba(245, 236, 216, .3); }

/* ---------- bộ sưu tập: ảnh lưới kẹp trên dây ---------- */
.gallery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-content: start; top: calc(118px + var(--safe-t)); }
.g-card { border: none; border-radius: 2px; overflow: hidden; background: #F3EAD6; cursor: pointer; padding: 7px 7px 0; color: var(--ink); font-family: inherit; text-align: left; box-shadow: 0 2px 0 #B49A72, 0 10px 18px rgba(0, 0, 0, .35); }
.g-card:nth-child(odd) { transform: rotate(-1.2deg); } .g-card:nth-child(even) { transform: rotate(1deg); }
.g-card canvas { display: block; width: 100%; aspect-ratio: 3 / 4; border-radius: 1px; }
.g-card div { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; padding: 6px 2px 8px; font: 500 italic 15px/1.15 var(--serif); }
.g-card div .ic { width: 15px; height: 15px; }
.g-empty { grid-column: 1 / -1; text-align: center; opacity: .8; padding: 40px 10px; font: 500 italic 17px/1.5 var(--serif); }
.viewer canvas { width: 100%; aspect-ratio: 3 / 4; border-radius: 2px; display: block; touch-action: none; }
.seg { display: flex; gap: 6px; justify-content: center; margin-top: 12px; }
.seg button { position: relative; border: none; border-radius: 3px; padding: 7px 12px; font: 800 15px var(--sans); color: var(--ink); cursor: pointer; background-color: rgba(214, 198, 163, .7); }
.seg button.on { color: var(--ivory); background-color: var(--indigo); background-image: var(--rib); box-shadow: inset 0 0 0 1.5px rgba(245, 236, 216, .3), 0 2px 0 #111C2C; }

/* ---------- cài đặt: dải vải, công tắc là con nhện bò trên sợi chỉ ---------- */
.settings { display: flex; flex-direction: column; gap: 10px; }
.settings h3 { display: flex; align-items: center; gap: 8px; margin: 14px 4px 0; font: 800 21px var(--serif); color: var(--ivory); }
.settings h3 .ic { width: 24px; height: 24px; filter: var(--to-ivory); }
.settings h3 .ic[src$="heart.svg"], .settings h3 .ic[src$="globe.svg"] { filter: none; }
.toggle { position: relative; isolation: isolate; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px 13px 16px; border-radius: 3px; cursor: pointer; color: var(--ink);
  background-color: var(--linen); background-image: var(--weave); box-shadow: 0 2px 0 #8E7550, 0 6px 12px rgba(0, 0, 0, .3); }
.toggle span { display: flex; flex-direction: column; gap: 3px; }
.toggle b { font: 800 17px/1.15 var(--sans); }
.toggle small { color: var(--ink-soft); font: 500 14px/1.3 var(--sans); }
.toggle input { display: none; }
.toggle i { position: relative; flex: none; width: 76px; height: 40px; }
.toggle i::before { content: ""; position: absolute; left: 6px; right: 6px; top: 19px; height: 0; border-top: 2px dashed rgba(110, 84, 54, .65); transition: border-color .2s; }
.toggle i::after { content: ""; position: absolute; left: -2px; top: 0; width: 40px; height: 40px; background: url(../assets/spider.svg) center / contain no-repeat; transition: transform .35s cubic-bezier(.5, 1.6, .4, 1); filter: grayscale(.7) brightness(.95); }
.worm .toggle i::after { background-image: url(../assets/silkworm.svg); }
.toggle input:checked + i::before { border-top: 2.6px solid var(--saffron); }
.toggle input:checked + i::after { transform: translateX(38px); filter: none; }
.rm .toggle i::after { transition: none; }
.settings .btn.danger { margin-top: 18px; }
/* chọn ngôn ngữ: mác vải lanh như hàng bật/tắt, hai nút kiểu .seg */
.lang-pick { display: flex; gap: 8px; padding: 10px; border-radius: 3px; background-color: var(--linen); background-image: var(--weave); box-shadow: 0 2px 0 #8E7550, 0 6px 12px rgba(0, 0, 0, .3); }
.lang-pick button { flex: 1; position: relative; border: none; border-radius: 3px; padding: 10px 8px; font: 800 17px var(--sans); color: var(--ink); cursor: pointer; background-color: rgba(214, 198, 163, .7); }
.lang-pick button.on { color: var(--ivory); background-color: var(--indigo); background-image: var(--rib); box-shadow: inset 0 0 0 1.5px rgba(245, 236, 216, .3), 0 2px 0 #111C2C; }

@media (max-height: 700px) {
  .btn.big { min-height: 58px; font-size: 22px; }
  .menu-buttons { gap: 12px; }
  .menu-title { margin-top: 1vh; }
  .wordmark { font-size: clamp(64px, 20vw, 84px); }
  .subtitle { font-size: 19px; margin-top: 3px; }
  .menu-buttons .row.icons .btn.icon.round { width: 52px; min-width: 52px; height: 52px; min-height: 52px; }
  .tool { width: 58px; height: 58px; }
  .tool .ic { width: 58px; height: 58px; }
  .go { width: 76px; height: 76px; }
  .bubble { font-size: 16px; padding: 9px 13px 9px 54px; }
  .bubble::before { width: 34px; height: 34px; left: 11px; }
  /* thẻ mục tiêu gọn hơn cho màn thấp (iPhone SE) */
  .card { padding: 28px 16px 16px; }
  .card h2 { font-size: 24px; }
  .chap-tag { margin-bottom: 10px; font-size: 15px; }
  .goal-tiles { gap: 6px; margin-bottom: 10px; }
  .goal-tiles .g { padding: 6px 3px 4px; }
  .goal-tiles .g img.who { width: 42px; height: 42px; }
  .goal-tiles .g .mark { width: 21px; height: 21px; }
  .notes { gap: 4px; margin-bottom: 10px; }
  .notes li { font-size: 13.5px; padding: 3px 8px 3px 5px; }
  .notes li .ic { width: 21px; height: 21px; }
  .rules { gap: 4px; margin-bottom: 10px; }
  .rules li { font-size: 14.5px; }
  .rules li .ic { width: 22px; height: 22px; }
  .rules li .ic.sm { width: 19px; height: 19px; }
  .tipline { font-size: 15px; padding: 5px 9px; }
  .tipline img { width: 28px; height: 28px; }
  .card .actions { margin-top: 12px; }
}
@media (max-width: 380px) {
  .tools { gap: 4px; }
  .tool { width: 58px; height: 58px; }
  .tool .ic { width: 58px; height: 58px; }
  .silk-meter .bar { flex-basis: 84px; width: 84px; }
  .chip { padding-right: 8px; }
  .menu-buttons .row.icons { gap: 22px; }
}

/* HUD và khay nằm đè canvas đang chạy: bóng ngắn để trình duyệt vẽ lại nhẹ hơn */
.hud .btn.icon.round { box-shadow: inset 0 0 0 2px rgba(255, 248, 230, .35), inset 0 -3px 5px rgba(80, 55, 30, .35), 0 3px 0 #6E5639, 0 5px 6px rgba(10, 6, 2, .4); }
.tray .btn { box-shadow: inset 0 1px 0 rgba(255, 252, 240, .6), 0 3px 0 #A58A63, 0 5px 6px rgba(12, 8, 3, .38); }
.tray .btn.icon.round { box-shadow: inset 0 0 0 2px rgba(255, 248, 230, .35), inset 0 -3px 5px rgba(80, 55, 30, .35), 0 3px 0 #6E5639, 0 5px 6px rgba(10, 6, 2, .4); }
.tray .btn.on:not(.icon) { box-shadow: inset 0 1px 0 rgba(160, 185, 220, .25), 0 3px 0 #111C2C, 0 5px 6px rgba(0, 0, 0, .4); }
.tray #btn-stop { box-shadow: inset 0 1px 0 rgba(255, 200, 180, .25), 0 3px 0 #5E2218, 0 5px 6px rgba(0, 0, 0, .4); }

/* khay công cụ theo từng màn (tối đa 4 suốt chỉ): 4 cái thì thu nhỏ cho vừa iPhone SE */
.tool-list { display: flex; gap: 6px; align-items: flex-end; }
.tools.many .tool-list { gap: 2px; }
.tools.many .tool { width: 50px; height: 50px; }
.tools.many .tool .ic { width: 50px; height: 50px; }
.tools.many .tool span { font-size: 11px; padding: 3px 5px 2px; }
@media (max-width: 360px) {
  .tools.many .tool { width: 44px; height: 44px; }
  .tools.many .tool .ic { width: 44px; height: 44px; }
}

/* bản đồ: tiêu đề vùng (10 vùng × 5 chương) — mác vải dệt có sọc màu chỉ của vùng */
.region-head { margin: 22px 14px 10px; padding: 12px 16px 11px 20px; border-radius: 3px; position: relative; color: var(--ink, #2E231A);
  background: linear-gradient(180deg, #F3E7CF, #E6D6B4); box-shadow: 0 3px 8px rgba(0, 0, 0, .35), inset 0 0 0 1.5px rgba(110, 84, 54, .25); }
.region-head::before { content: ''; position: absolute; left: 6px; top: 7px; bottom: 7px; width: 5px; border-radius: 2px; background: var(--rc, #A3402E); }
.region-head small { display: block; font-size: 12px; letter-spacing: .04em; opacity: .7; }
.region-head h2 { margin: 1px 0 2px; font-size: 21px; line-height: 1.15; }
.region-head p { margin: 0; font-size: 13.5px; line-height: 1.35; opacity: .85; }
.region-head.soon { opacity: .8; margin-bottom: 30px; }
.region-head.soon::before { background: rgba(110, 84, 54, .45); }

/* ---------- bản đồ gập/mở theo vùng + sổ tay theo vùng ---------- */
.region { margin: 0 0 12px; }
.reg-tab { position: relative; isolation: isolate; width: 100%; min-height: 72px; display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  padding: 11px 14px 11px 24px; border: none; border-radius: 3px; color: var(--ink); font-family: inherit;
  background-color: var(--linen); background-image: var(--rib), linear-gradient(180deg, #F0E4CB, #E0CFAB);
  box-shadow: inset 0 0 0 1.5px rgba(110, 84, 54, .28), 0 3px 0 #8E7550, 0 8px 14px rgba(0, 0, 0, .35); }
.reg-tab:active { transform: translateY(2px); box-shadow: inset 0 0 0 1.5px rgba(110, 84, 54, .28), 0 1px 0 #8E7550, 0 3px 6px rgba(0, 0, 0, .35); }
.reg-tab::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 6px; border-radius: 3px; background: var(--rc, #A3402E);
  box-shadow: inset 0 0 0 1px rgba(46, 35, 26, .25), 1px 0 0 rgba(255, 250, 235, .5); }
.reg-tab:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; }
.reg-body { flex: 1 1 auto; min-width: 0; display: block; }
.reg-body small { display: block; font: 500 italic 14px/1.2 var(--serif); color: var(--ink-soft); }
.reg-body b { display: block; font: 800 21px/1.12 var(--serif); }
.reg-body em { display: block; margin-top: 2px; font: 500 13.5px/1.3 var(--sans); font-style: normal; color: var(--ink-soft); }
.reg-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.reg-st { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 3px; font: 700 12.5px/1.3 var(--sans); white-space: nowrap;
  color: var(--ivory); background-color: var(--indigo); background-image: var(--rib); }
.reg-st.locked { background-color: var(--madder); }
.reg-st.soon { background-color: #8E7550; }
.reg-st .ic { width: 14px; height: 14px; filter: var(--to-ivory); }
.reg-stars { display: inline-flex; align-items: center; gap: 3px; font: 800 14.5px var(--sans); white-space: nowrap; }
.reg-stars .ic { width: 20px; height: 20px; }
.reg-chev { flex: none; width: 10px; height: 10px; margin: 0 2px 3px 2px; border: solid var(--ink-soft); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); transition: transform .2s; }
.region.open > .reg-tab .reg-chev { transform: rotate(-135deg); margin-bottom: -3px; }
.rm .reg-chev { transition: none; }
.region.s-soon .reg-tab { opacity: .55; cursor: default; filter: saturate(.5); box-shadow: inset 0 0 0 1.5px rgba(110, 84, 54, .28); }
.region.s-soon .reg-chev { visibility: hidden; }
.region.s-soon .reg-tab:disabled { pointer-events: none; }
.region.s-locked:not(.open) .reg-tab { filter: saturate(.7); }
.region.s-paywall .reg-chev { visibility: hidden; }
.reg-chapters { padding-top: 12px; }
.reg-chapters .chapter { margin-top: 0; }
.ch-soon { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 0 4px 12px; padding: 9px 14px; border-radius: 3px; border: 1.6px dashed rgba(245, 236, 216, .35);
  color: var(--ivory); font: 700 14.5px/1.3 var(--sans); }
.ch-soon em { font: 500 italic 14px var(--serif); opacity: .7; white-space: nowrap; }

.j-region { margin: 0 0 22px; }
.j-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; position: relative; padding: 10px 14px 10px 24px; margin-bottom: 12px; border-radius: 3px; color: var(--ink);
  background-color: var(--linen); background-image: var(--rib), linear-gradient(180deg, #F0E4CB, #E0CFAB); box-shadow: inset 0 0 0 1.5px rgba(110, 84, 54, .28), 0 3px 0 #8E7550; }
.j-head::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 6px; border-radius: 3px; background: var(--rc, #A3402E); }
.j-head small { display: block; font: 500 italic 14px/1.2 var(--serif); color: var(--ink-soft); }
.j-head h2 { margin: 0; font: 800 21px/1.12 var(--serif); }
.j-n { flex: none; font: 700 13.5px var(--sans); color: var(--ink-soft); white-space: nowrap; }
.j-chap { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.j-ch { margin: 4px 4px 0; font: 700 italic 17px/1.2 var(--serif); color: var(--ivory); opacity: .9; }
.fact-more { margin: 0; padding: 10px 14px; border-radius: 3px; border: 1.6px dashed rgba(245, 236, 216, .3); color: var(--ivory); opacity: .75; font: 500 14.5px/1.4 var(--sans); }

/* ---------- thẻ mua bản đầy đủ + cổng người lớn ---------- */
.card.offer .say { margin: 4px 0 10px; font: 500 italic 17px/1.35 var(--serif); color: var(--ink); }
.card .perks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.card .perks li { display: flex; align-items: flex-start; gap: 8px; font: 600 15px/1.3 var(--sans); color: var(--ink); }
.card .perks .ic { flex: none; width: 20px; height: 20px; margin-top: 0; }
.card.offer p.mod { margin-top: 12px; }
.card.offer .actions { margin-top: 14px; gap: 12px; }
.card.offer .actions .btn { min-height: 48px; }
.card.offer .actions > .btn.primary { white-space: normal; text-align: center; line-height: 1.15; padding: 8px 14px; }
.card.offer .actions .row .btn { white-space: normal; line-height: 1.1; font-size: 16px; }
.gate-q { margin: 12px 0 8px; font: 800 38px/1.1 var(--serif); color: var(--ink); letter-spacing: .02em; }
.gate-in { display: block; width: 130px; min-height: 52px; margin: 0 auto; text-align: center; font: 800 26px var(--sans); color: var(--ink);
  background: #FBF4E2; border: 2px dashed rgba(110, 84, 54, .7); border-radius: 3px; }
.gate-in:focus { outline: 3px solid var(--saffron); outline-offset: 2px; }
.gift-code { display: block; box-sizing: border-box; width: 100%; min-height: 104px; resize: vertical; padding: 12px;
  font: 16px/1.4 var(--sans); color: var(--ink); background: #FBF4E2; border: 2px dashed rgba(110, 84, 54, .7); border-radius: 3px;
  overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }
.gift-code:focus { outline: 3px solid var(--saffron); outline-offset: 2px; }
.store-row { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.store-row .hint { margin: 0; }
.store-row .hint .ic { filter: var(--to-ivory); }
.card.offer .actions .row { flex-direction: column; gap: 12px; }

/* chính sách quyền riêng tư trong Cài đặt */
iframe.policy{width:100%;height:min(56vh,460px);border:0;border-radius:10px;background:#17271F;margin:6px 0 4px}
#btn-privacy{margin:10px 0 2px}
.card.offer .btn[disabled]{opacity:.5;filter:grayscale(.4)}
