/* 經年織房：整站是一台正在織的織布機（場景式，不往下捲） */
:root {
  --font-zh: "PingFang TC", "Noto Sans TC", "Source Han Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --display: "WDXL Lubrifont TC", var(--font-zh);
  --bg: #e3dac8;
  --paper: #f6f1e7;
  --ink: #2a2321;
  --muted: #5b544d;
  --accent: #b43f4f;
  --accent-ink: #fff7f2;
  --pink: #e7b7ae;
  --line: rgba(42, 35, 33, .16);
  --chip: rgba(255, 255, 255, .55);
  --yarn: #b43f4f;
  --radius: 2px;
  --cl: 72px;
  --cw: 400px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --z-scene: 0;
  --z-content: 4;
  --z-header: 10;
  --z-menu: 8;
  --z-tag: 30;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--font-zh); }
body { -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
.display { font-family: var(--display); font-weight: 400; letter-spacing: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 60; padding: 10px 14px; background: var(--paper); color: var(--ink); }
.skip-link:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* 場景 */
.scene-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: var(--z-scene); }
/* 沒有 WebGL2 時的備用圖：1440×900 截的，靠左對齊，布才不會跑到左邊文字底下 */
.scene-fallback { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 0 50%; z-index: var(--z-scene); }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 22px; border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); font-size: 15px; line-height: 1.3; text-decoration: none; cursor: pointer; transition: background-color .2s ease, box-shadow .2s ease; }
.btn:hover { background: #9c3343; }
.btn-line { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-line:hover { background: var(--chip); box-shadow: inset 0 0 0 1px var(--ink); }
.btn-text { display: inline-flex; align-items: center; min-height: 44px; padding: 0; border: 0; background: none; color: var(--ink); font-size: 15px; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 5px; text-decoration-thickness: 1px; }
.btn-text:hover { text-decoration-color: var(--accent); }

/* 頁首 */
.masthead { position: fixed; left: 0; right: 0; top: 0; z-index: var(--z-header); display: flex; align-items: center; gap: 14px; padding: 20px var(--cl) 0; pointer-events: none; }
.masthead > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 46px; height: 18px; flex: none; }
.brand-name { display: block; font-size: 26px; line-height: 1.2; }
.brand small { display: block; font-size: 12px; line-height: 1.4; color: var(--muted); }
.masthead-links { display: flex; gap: 6px; margin-left: 36px; margin-right: auto; }
.masthead-links button { min-height: 44px; padding: 0 12px; border: 0; background: none; font-size: 15px; cursor: pointer; border-radius: var(--radius); }
.masthead-links button:hover { background: var(--chip); }
.masthead .btn { min-height: 44px; }
.menu-open { display: none; }
.menu-open .when-open, .menu-open[aria-expanded="true"] .when-closed { display: none; }
.menu-open[aria-expanded="true"] .when-open { display: inline; }

/* 各站內容（左邊空地） */
.station { position: fixed; left: var(--cl); top: calc(50% + 24px); width: var(--cw); z-index: var(--z-content); transform: translate(0, calc(-50% + 14px)); opacity: 0; pointer-events: none; transition: opacity .32s ease, transform .32s ease; }
.station.is-active { opacity: 1; transform: translate(0, -50%); pointer-events: auto; transition-delay: .18s; }
.tag-on .station.is-active { opacity: 0; transition-delay: 0s; }
.station-name:focus { outline: none; }
.station-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }
.station-name { margin: 0; font-size: max(56px, min(8.4vw, 12.5vh, 132px)); line-height: 1.15; color: var(--ink); }
.has-tiles .station-name { color: transparent; background-repeat: repeat; -webkit-background-clip: text; background-clip: text; animation: cloth-run 9s linear infinite; }
@keyframes cloth-run { to { background-position: 0 var(--tile-h, 192px); } }
.station-title { margin: 10px 0 0; font-size: clamp(22px, 2.1vw, 30px); line-height: 1.35; text-wrap: balance; }
.station-body { margin: 14px 0 0; font-size: 15.5px; line-height: 1.8; color: var(--muted); text-wrap: pretty; max-width: 40em; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-top: 24px; }
.next { display: none; }

.dyes { margin-top: 18px; border-top: 1px solid var(--line); }
.dye { display: grid; grid-template-columns: 64px 3em 1fr; gap: 14px; align-items: center; width: 100%; min-height: 48px; padding: 8px 0; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.dye i { height: 10px; border-radius: 5px; background-image: repeating-linear-gradient(115deg, rgba(255, 255, 255, .22) 0 2px, rgba(0, 0, 0, .14) 2px 4px); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .2s ease; }
.dye b { font-size: 16px; font-weight: 500; }
.dye span { font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.dye:hover i { transform: scaleY(1.4); }
.dye[aria-pressed="true"] i { transform: scaleY(1.8); }
.dye[aria-pressed="true"] b { color: var(--accent); font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }
.station .actions-tight { margin-top: 14px; }

.treadles { display: flex; gap: 8px; margin-top: 16px; }
.treadles button { min-height: 44px; padding: 0 18px; border: 0; border-radius: var(--radius); background: var(--chip); box-shadow: inset 0 0 0 1px var(--line); font-size: 15px; cursor: pointer; }
.treadles button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.draft { display: grid; gap: 6px; margin-top: 16px; grid-template-columns: auto auto; grid-template-areas: "th tu" "dd tr"; justify-content: start; }
.draft .grid { display: grid; gap: 1px; }
.draft .cell { width: var(--dc, 9px); height: var(--dc, 9px); background: var(--chip); box-shadow: inset 0 0 0 1px var(--line); transition: transform .2s ease; }
.draft .cell.on { background: var(--ink); box-shadow: none; }
.draft .dd .cell { box-shadow: none; }
.draft .hl { outline: 1px solid var(--accent); }
.draft .dd .cell.hit { position: relative; z-index: 1; transform: scale(1.5); outline: 2px solid var(--accent); }
.draft-note { margin: 8px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }

.goods { list-style: none; margin: 18px 0 0; padding: 0; border-top: 1px solid var(--line); }
.goods button { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 14px; width: 100%; min-height: 48px; padding: 11px 0; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.goods b { font-size: 16px; font-weight: 500; }
.goods span { font-size: 13px; color: var(--muted); }
.goods em { grid-row: span 2; align-self: center; font-style: normal; font-variant-numeric: tabular-nums; }
.goods .tag-icon { grid-row: span 2; align-self: center; width: 14px; height: 20px; color: var(--muted); transition: transform .25s var(--ease-out), color .2s ease; }
.goods button:hover .tag-icon { transform: rotate(-8deg); color: var(--accent); }
.goods button:hover b { color: var(--accent); }

.courses { margin: 18px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.courses li { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.courses b { font-size: 16px; font-weight: 500; }
.courses em { grid-row: span 2; align-self: center; font-style: normal; font-variant-numeric: tabular-nums; }
.courses span { font-size: 13.5px; color: var(--muted); }
.info { margin: 14px 0 0; font-size: 13px; line-height: 1.7; color: var(--muted); }

/* 右緣的縮小布樣（站點選單） */
.cloth-nav { position: fixed; right: 30px; top: 50%; z-index: var(--z-content); display: flex; gap: 10px; align-items: stretch; transform: translateY(-50%); }
.cloth-nav canvas { width: 14px; height: min(58vh, 420px); image-rendering: pixelated; box-shadow: 0 0 0 1px var(--line); }
.cloth-nav ol { position: relative; width: 44px; margin: 0; padding: 0; list-style: none; }
.cloth-nav li button { position: absolute; right: 0; min-height: 44px; padding: 0; border: 0; background: none; font-size: 14px; color: var(--muted); white-space: nowrap; cursor: pointer; transform: translateY(-50%); }
.cloth-nav li button:hover { color: var(--ink); }
.cloth-nav li button[aria-current="step"] { color: var(--ink); }
.cloth-nav li button[aria-current="step"]::after { content: ""; position: absolute; right: -16px; top: 50%; width: 10px; height: 1px; background: var(--accent); }

.hint { position: fixed; left: var(--cl); bottom: 28px; z-index: var(--z-content); margin: 0; font-size: 13px; color: var(--muted); transition: opacity .4s ease; }
.hint.is-gone { opacity: 0; }

/* 布料吊牌（細節面板） */
.tag-layer { position: fixed; inset: 0; z-index: var(--z-tag); }
.tag-layer[hidden] { display: none; }
.tag-scrim { position: absolute; inset: 0; background: rgba(42, 35, 33, .26); opacity: 0; transition: opacity .35s ease; }
.tag-layer.is-open .tag-scrim { opacity: 1; }
.tag-hang { position: absolute; left: calc(var(--cl) - 10px); top: 0; bottom: 20px; width: min(460px, calc(100vw - 32px)); display: flex; flex-direction: column; pointer-events: none; transform-origin: 50% 0; transform: translateX(calc(-100% - var(--cl) - 60px)) rotate(-4deg); transition: transform .6s var(--ease-out); filter: drop-shadow(0 18px 28px rgba(42, 35, 33, .22)) drop-shadow(0 2px 4px rgba(42, 35, 33, .12)); }
.tag-layer.is-open .tag-hang { transform: none; }
.tag-string { flex: none; align-self: center; width: 40px; height: 130px; margin-bottom: -40px; position: relative; z-index: 2; overflow: visible; }
.tag-string path { fill: none; stroke: var(--yarn); stroke-width: 2.2; stroke-linecap: round; }
.tag-string circle { fill: var(--yarn); }
.tag { position: relative; flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; pointer-events: auto; clip-path: polygon(24px 0, calc(100% - 24px) 0, 100% 24px, 100% 100%, 0 100%, 0 24px); -webkit-mask: radial-gradient(circle at 50% 24px, transparent 6.5px, #000 7.5px); mask: radial-gradient(circle at 50% 24px, transparent 6.5px, #000 7.5px); }
.tag::before { content: ""; position: absolute; z-index: 1; left: 50%; top: 24px; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; background: radial-gradient(circle, transparent 6.6px, #6f5a35 7.2px, #c9ac72 8.6px, #ead9a8 9.6px, #a98a52 11.4px, #7d6540 12.4px, transparent 13px); box-shadow: 0 1px 1px rgba(42, 35, 33, .2); pointer-events: none; }
.tag:focus { outline: none; }
.tag-close { position: absolute; right: 30px; top: 6px; z-index: 2; min-width: 44px; min-height: 44px; padding: 0 8px; border: 0; background: none; font-size: 15px; color: var(--ink); cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 5px; }
.tag-close:hover { text-decoration-color: var(--ink); }
.tag-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 56px 30px 24px; background: var(--paper); transition: opacity .18s ease; }
.tag-layer.is-swapping .tag-body { opacity: 0; }
.tag-photo { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; background: var(--bg); }
.tag-body h2 { margin: 20px 0 0; font-size: 34px; line-height: 1.25; }
.tag-body h2:first-child { margin-top: 0; }
.tag-price { margin: 4px 0 0; font-size: 17px; font-variant-numeric: tabular-nums; color: var(--accent); }
.tag-body > p:not(.tag-price):not(.tag-note) { margin: 12px 0 0; font-size: 15px; line-height: 1.8; color: var(--muted); text-wrap: pretty; }
.tag-rows { margin: 16px 0 0; }
.tag-rows div { display: grid; grid-template-columns: 4.5em 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px dotted rgba(42, 35, 33, .3); }
.tag-rows dt { font-size: 13.5px; color: var(--muted); }
.tag-rows dd { margin: 0; font-size: 14.5px; line-height: 1.6; }
.tag-note { margin: 14px 0 0; font-size: 13px; line-height: 1.7; color: var(--muted); }
.tag-body > .btn { margin-top: 20px; width: 100%; }
.tag-foot { flex: none; display: flex; align-items: center; gap: 10px; margin: 0; padding: 13px 30px 16px; background: var(--paper) linear-gradient(90deg, rgba(42, 35, 33, .35) 50%, transparent 50%) 0 0 / 8px 1px repeat-x; font-size: 12px; color: var(--muted); -webkit-mask: radial-gradient(circle at 0 0, transparent 7px, #000 7.5px) left / 51% 100% no-repeat, radial-gradient(circle at 100% 0, transparent 7px, #000 7.5px) right / 51% 100% no-repeat; mask: radial-gradient(circle at 0 0, transparent 7px, #000 7.5px) left / 51% 100% no-repeat, radial-gradient(circle at 100% 0, transparent 7px, #000 7.5px) right / 51% 100% no-repeat; }
.tag-foot svg { width: 30px; height: 12px; }

.order-swatch { display: block; width: 100%; height: auto; margin-top: 16px; image-rendering: pixelated; box-shadow: 0 0 0 1px var(--line); }
.tag-form { display: grid; gap: 14px; margin-top: 16px; }
.tag-form[hidden] { display: none; }
.tag-form label { display: grid; gap: 2px; min-width: 0; font-size: 14px; font-weight: 500; color: var(--ink); }
.tag-form input, .tag-form select { width: 100%; min-height: 44px; padding: 0 2px; border: 0; border-bottom: 1px solid rgba(42, 35, 33, .45); border-radius: 0; background: transparent; color: var(--ink); font-size: 16px; font-weight: 400; }
.tag-form select { appearance: none; padding-right: 22px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%232a2321' stroke-width='1.4'/%3E%3C/svg%3E") right 4px center / 10px 6px no-repeat; text-overflow: ellipsis; }
.tag-form input:hover, .tag-form select:hover { border-bottom-color: var(--ink); }
.tag-form input:focus-visible, .tag-form select:focus-visible { outline: none; border-bottom: 2px solid var(--accent); }
.tag-form [aria-invalid="true"], .tag-form input:user-invalid { border-bottom: 2px solid var(--accent); }
.field-hint { font-size: 13px; font-weight: 400; color: var(--muted); }
.field-hint[hidden] { display: none; }
.field-error { font-size: 13px; font-weight: 400; line-height: 1.5; color: var(--accent); }
.tag-form .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.order-total { display: flex; justify-content: space-between; align-items: baseline; margin: 4px 0 0; padding-top: 10px; border-top: 1px dotted rgba(42, 35, 33, .3); font-size: 14px; }
.order-total output { font-size: 18px; font-variant-numeric: tabular-nums; }
.tag-form .btn { margin-top: 4px; }
.form-done { margin-top: 18px; }
.form-done:focus { outline: none; }
.form-done[hidden] { display: none; }
.stamp { display: inline-block; margin: 0; padding: 4px 14px; border: 2px solid var(--accent); border-radius: 4px; color: var(--accent); font-size: 30px; line-height: 1.2; transform: rotate(-6deg); animation: stamp-in .4s var(--ease-out) both; }
@keyframes stamp-in { from { opacity: 0; transform: rotate(-6deg) scale(1.35); } }
.form-done > p:not(.stamp) { margin: 16px 0 0; font-size: 15px; line-height: 1.8; color: var(--muted); }
.form-done .btn { width: 100%; margin-top: 20px; }
.tag-back { margin-top: 12px; }

/* 手機全螢幕選單：直條像經線一樣依序垂下 */
.menu { position: fixed; inset: 0; z-index: var(--z-menu); }
.menu[hidden] { display: none; }
.menu-warp { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(5, 1fr); }
.menu-warp i { position: relative; display: block; background: var(--paper); transform: scaleY(0); transform-origin: 50% 0; transition: transform .5s var(--ease-out); }
.menu-warp i::after { content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 2px; background: var(--c); opacity: .7; }
.menu.is-open .menu-warp i::after { opacity: 0; transition: opacity .4s ease .62s; }
.menu-warp i:nth-child(2) { transition-delay: .05s; }
.menu-warp i:nth-child(3) { transition-delay: .1s; }
.menu-warp i:nth-child(4) { transition-delay: .15s; }
.menu-warp i:nth-child(5) { transition-delay: .2s; }
.menu.is-open .menu-warp i { transform: none; }
.menu.is-closing .menu-warp i { transition-duration: .32s; transition-delay: 0s; }
.menu-inner { position: relative; display: flex; flex-direction: column; height: 100%; overflow-y: auto; padding: 72px 18px 24px; opacity: 0; transition: opacity .25s ease; }
.menu.is-open .menu-inner { opacity: 1; transition-delay: .28s; }
.menu.is-closing .menu-inner { transition-duration: .12s; }
.menu-list { margin: 0; padding: 0; list-style: none; }
.menu-list li { opacity: 0; transform: translateY(14px); transition: opacity .4s ease, transform .5s var(--ease-out); }
.menu.is-open .menu-list li { opacity: 1; transform: none; }
.menu.is-open .menu-list li:nth-child(1) { transition-delay: .32s; }
.menu.is-open .menu-list li:nth-child(2) { transition-delay: .37s; }
.menu.is-open .menu-list li:nth-child(3) { transition-delay: .42s; }
.menu.is-open .menu-list li:nth-child(4) { transition-delay: .47s; }
.menu.is-open .menu-list li:nth-child(5) { transition-delay: .52s; }
.menu-list button { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 4px 18px; width: 100%; min-height: 76px; padding: 16px 0; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.menu-list b { font-family: var(--display); font-weight: 400; font-size: 40px; line-height: 1.2; }
.menu-list span { font-size: 14px; line-height: 1.6; color: var(--muted); }
.menu-list button[aria-current="step"] b { color: var(--accent); }
.menu-foot { margin-top: auto; padding-top: 24px; display: grid; gap: 14px; }
.menu-foot .btn { width: 100%; }
.menu-foot p { margin: 0; font-size: 13px; line-height: 1.7; color: var(--muted); }

/* 窄螢幕：布在上半、內容在下半 */
@media (max-width: 899px), (max-aspect-ratio: 19/20) {
  :root { --cl: 18px; }
  .masthead { gap: 8px; padding: 8px var(--cl); background: var(--paper); box-shadow: 0 1px 0 var(--line); }
  .brand { margin-right: auto; min-height: 44px; }
  .brand-name { font-size: 21px; }
  .brand small, .masthead-links, .masthead-cta { display: none; }
  .menu-open { display: inline-flex; padding: 0 16px; }
  .station { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 52%; overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px 28px; background: var(--paper); box-shadow: 0 -1px 0 var(--line); transform: translateY(14px); }
  .station.is-active { transform: none; }
  .station-name { font-size: 56px; }
  .has-tiles .station-name { background-size: 90px auto; }
  .station-title { font-size: 21px; }
  .station-body { font-size: 15px; }
  .station:has(.next) { padding-bottom: 0; }
  .next { position: sticky; bottom: 0; display: flex; gap: 8px; width: 100%; min-height: 56px; margin-top: 12px; padding: 14px 0 18px; border-radius: 0; box-shadow: none; background: linear-gradient(to bottom, rgba(246, 241, 231, 0), var(--paper) 36%); font-size: 15px; }
  .next:hover { background: linear-gradient(to bottom, rgba(246, 241, 231, 0), var(--paper) 36%); box-shadow: none; }
  .next::after { content: "\2193"; }
  .cloth-nav, .hint { display: none; }
  .scene-fallback { height: 50%; object-position: 72% 50%; }
  .tag-close { right: 26px; }
  .tag-hang { left: 10px; right: 10px; width: auto; bottom: 10px; }
  .tag-body { padding: 54px 20px 20px; }
  .tag-foot { padding: 10px 20px 14px; }
  .tag-body h2 { font-size: 30px; }
}
@media (max-height: 780px) and (min-width: 900px) and (min-aspect-ratio: 19/20) {
  .draft-note { display: none; }
  .draft { --dc: 8px; }
  .station-title { margin-top: 4px; }
  .station-body { margin-top: 8px; }
  .actions { margin-top: 18px; }
}

/* 截備用圖時只留布 */
.is-capture .masthead, .is-capture .station, .is-capture .cloth-nav, .is-capture .hint, .is-capture .cxdigi-language-link { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .has-tiles .station-name { animation: none; }
  .stamp { animation: none; }
  .station, .station.is-active { transform: translate(0, -50%); transition: opacity .2s ease; }
  .tag-hang, .tag-layer.is-open .tag-hang { transform: none; transition: none; }
  .tag-layer .tag-hang { opacity: 0; transition: opacity .2s ease; }
  .tag-layer.is-open .tag-hang { opacity: 1; }
  .menu-warp i, .menu.is-open .menu-warp i { transform: none; transition: none; }
  .menu-warp, .menu-inner { opacity: 0; transition: opacity .2s ease; }
  .menu.is-open .menu-warp, .menu.is-open .menu-inner { opacity: 1; transition-delay: 0s; }
  .menu-list li, .menu.is-open .menu-list li { transform: none; transition: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) and ((max-width: 899px) or (max-aspect-ratio: 19/20)) {
  .station, .station.is-active { transform: none; }
}
