/* 買衫啦小遊戲「屋企有喇」。所有 class 用 g- 開頭，費事同 style.css 撞名。 */
.g-body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
.g-wrap { padding-top: max(var(--space-4), env(safe-area-inset-top)); padding-bottom: var(--space-6); }
.g-sign { max-width: 300px; margin-bottom: var(--space-4); }
.g-sign .plate { font-size: clamp(1.9rem, 10vw, 2.6rem); }
.g-playing .g-sign { max-width: 168px; margin-bottom: var(--space-3); }
.g-playing .g-sign .tubes i { height: 5px; }
.g-playing .g-sign .board { padding: 5px; box-shadow: 0 4px 0 var(--ink); }
.g-playing .g-sign .plate { font-size: 1.25rem; border-width: 2px; }

/* 衫 */
/* 像素畫，放大嗰陣保持一格格 */
.g-tile svg, .g-mini svg, .g-closet li svg, .g-fly svg, .g-ward svg, .g-snd svg { image-rendering: pixelated; shape-rendering: crispEdges; }

/* 開始 */
.g-start { padding: var(--space-5) var(--space-4); }
.g-how { display: grid; gap: var(--space-3); margin-bottom: var(--space-5); }
.g-how li { position: relative; display: grid; grid-template-columns: 144px 1fr; align-items: center; gap: var(--space-3); font-weight: 700; font-size: var(--text-base); line-height: 1.35; max-width: none; background: #fff; border: var(--bd); padding: var(--space-3) var(--space-3) var(--space-3) 22px; }
.g-how li > b { position: absolute; left: -9px; top: -9px; width: 26px; height: 26px; background: var(--primary); color: #fff; border: 2px solid var(--ink); display: grid; place-content: center; font-family: var(--font-display); font-size: 0.875rem; line-height: 1; }
.g-demo { display: flex; justify-content: flex-start; gap: 6px; }
.g-mini { position: relative; display: block; width: 44px; height: 44px; background: var(--paper); border: 2px solid var(--ink); padding: 3px; }
.g-mini svg { width: 100%; height: 100%; }
.g-demo-full { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; background: var(--ink); border: 2px solid var(--ink); }
.g-demo-full .g-mini { width: auto; height: auto; aspect-ratio: 1; border: 0; padding: 1px; }

/* 玩緊：關數、分數 */
.g-hud { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.g-hud .g-chip:first-child { margin-right: auto; }
.g-snd { width: 44px; height: 44px; flex: none; display: grid; place-items: center; padding: 0; background: var(--paper); color: var(--ink); border: var(--bd); border-radius: 0; box-shadow: 0 3px 0 var(--ink); cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.g-snd svg { width: 28px; height: 28px; display: block; }
.g-snd .g-off, .g-snd.g-mute .g-on { display: none; }
.g-snd.g-mute .g-off { display: block; }
.g-snd.g-mute { background: #e9dccb; }
.g-snd:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.g-snd:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.g-chip { display: inline-flex; align-items: center; gap: 0.3em; min-height: 36px; padding: 0 var(--space-3); background: var(--paper); border: var(--bd); box-shadow: 0 3px 0 var(--ink); font-weight: 700; font-size: var(--text-sm); white-space: nowrap; max-width: none; }
.g-chip b { font-family: var(--font-display); font-weight: 900; font-size: var(--text-lg); line-height: 1; font-variant-numeric: tabular-nums lining-nums; min-width: 1ch; text-align: center; }
.g-dots { display: inline-flex; gap: 4px; margin-left: 6px; }
.g-dots i { width: 10px; height: 10px; border: 2px solid var(--ink); background: transparent; }
.g-dots i.on { background: var(--primary); }

/* 衣櫃：買重咗嘅衫，滿十件就爆 */
.g-closet { background: var(--accent); border: var(--bd); box-shadow: 0 4px 0 var(--ink); padding: 6px 8px 8px; margin: var(--space-3) 0; }
.g-closet p { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: var(--text-xs); line-height: 1.3; max-width: none; margin-bottom: 4px; }
.g-closet p b { font-variant-numeric: tabular-nums lining-nums; }
.g-closet ol { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.g-closet li { aspect-ratio: 1; background: rgba(255, 255, 255, 0.45); border: 2px dashed rgba(43, 20, 32, 0.45); max-width: none; }
.g-closet li.on { background: #fff; border: 2px solid var(--ink); padding: 1px; }
.g-closet li svg { width: 100%; height: 100%; }
.g-closet li.pop { animation: g-pop 380ms cubic-bezier(0.2, 1.4, 0.4, 1); }
.g-closet.g-hot { background: #ff9d6c; }
.g-closet.g-hot p { color: var(--ink); }
.g-closet.g-boom { animation: g-shake 110ms linear infinite; background: var(--primary); }
.g-closet.g-boom p { color: #fff; }

/* 舞台 */
.g-stage { padding: var(--space-3) var(--space-3) var(--space-4); }
.g-ask { min-height: 1.5em; text-align: center; font-family: var(--font-display); font-weight: 900; font-size: var(--text-lg); line-height: 1.5; max-width: none; }
.g-ph-good .g-ask { color: var(--ok); }
.g-ph-bad .g-ask, .g-ph-burst .g-ask { color: var(--warn); }
.g-bar { height: 12px; border: 2px solid var(--ink); background: #fff; margin: var(--space-2) 0 var(--space-3); overflow: hidden; }
.g-bar i { display: block; height: 100%; background: var(--ink); transform-origin: left center; }
.g-bar.g-pick i { background: var(--primary); }
.g-bar.g-low i { background: var(--warn); animation: g-blink 260ms steps(2) infinite; }
.g-bar.g-off { visibility: hidden; }
.g-grid { --gap: 10px; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: var(--gap); min-height: 236px; margin: 0 auto; }
.g-grid.g-c2 { max-width: 246px; }
.g-grid.g-c2 .g-tile { width: calc((100% - var(--gap)) / 2); }
.g-grid.g-c3 .g-tile { width: calc((100% - var(--gap) * 2) / 3);; padding: 6px; }
.g-grid.g-c4 .g-tile { width: calc((100% - var(--gap) * 3) / 4);; padding: 4px; }
.g-grid.g-c1 .g-tile { width: 112px; }
.g-tile { position: relative; aspect-ratio: 1; background: #fff; border: var(--bd); box-shadow: 0 4px 0 var(--ink); padding: 8px; display: grid; place-items: center; border-radius: 0; animation: g-in 160ms cubic-bezier(0.2, 1.2, 0.4, 1) both; animation-delay: calc(var(--d) * 25ms); }
.g-tile svg { width: 100%; height: 100%; pointer-events: none; }
button.g-tile { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
@media (hover: hover) { button.g-tile:not(:disabled):hover { background: #fff6dc; } }
button.g-tile:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button.g-tile:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.g-tile.g-dim { opacity: 0.4; }
.g-tile.g-ok { outline: 4px solid var(--ok); outline-offset: -1px; }
.g-tile.g-miss { animation: g-wobble 360ms ease-in-out; }
/* 剔：買啱嗰件 */
.g-tile.g-ok::after, .g-mini.g-ok::after { content: ''; position: absolute; right: -8px; top: -8px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12.5 4 4 8-9'/%3E%3C/svg%3E") center / 16px no-repeat; animation: g-pop 300ms cubic-bezier(0.2, 1.4, 0.4, 1); }
/* 印：屋企有 */
.g-tile.g-dup::after, .g-mini.g-dup::after { content: '屋企有'; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-12deg); background: var(--warn); color: #fff; border: 2px solid #fff; padding: 1px 6px; font-weight: 700; font-size: 0.8125rem; line-height: 1.35; white-space: nowrap; box-shadow: 0 2px 0 var(--ink); }
.g-mini.g-dup::after { font-size: 0.625rem; padding: 0 3px; border-width: 1px; }
.g-mini.g-ok::after { width: 18px; height: 18px; right: -7px; top: -7px; background-size: 11px; animation: none; }
.g-tile.g-dup svg, .g-mini.g-dup svg { opacity: 0.55; }
.g-banner { align-self: center; font-family: var(--font-display); font-weight: 900; font-size: 2rem; line-height: 1.2; text-align: center; max-width: none; animation: g-pop 320ms cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.g-banner b { font-size: 3.5rem; color: var(--primary); margin: 0 0.08em; }

/* 完 */
.g-over { text-align: center; padding: var(--space-4) var(--space-4) var(--space-5); }
.g-over h2 { font-size: var(--text-xl); margin: var(--space-2) 0 var(--space-3); outline: 0; }
.g-burst { position: relative; height: 236px; overflow: hidden; }
.g-ward { position: absolute; left: 50%; top: 50%; width: 128px; height: 128px; margin: -64px 0 0 -64px; }
.g-ward svg { width: 100%; height: 100%; }
.g-fly { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; transform: translate(var(--x), var(--y)) rotate(var(--r)); animation: g-fly 520ms cubic-bezier(0.2, 1.3, 0.4, 1) both; animation-delay: calc(var(--d) * 35ms); }
.g-fly svg { width: 100%; height: 100%; }
.g-final { display: flex; justify-content: center; align-items: baseline; gap: 0.3em; font-weight: 700; font-size: var(--text-base); max-width: none; line-height: 1; }
.g-final b { font-family: var(--font-display); font-weight: 900; font-size: 4rem; line-height: 1; color: var(--primary); font-variant-numeric: tabular-nums lining-nums; }
.g-sub { font-weight: 700; font-size: var(--text-sm); margin: var(--space-2) auto var(--space-5); max-width: none; }

/* 排行榜：頭 10 名 */
.g-cup { display: inline-block; flex: none; width: 28px; height: 28px; }
.g-cup svg { display: block; width: 100%; height: 100%; image-rendering: pixelated; shape-rendering: crispEdges; }
/* 爆機後收手：唔使爆櫃動畫，放返個購物袋 */
.g-quit .g-burst { height: 150px; }
.g-quit h2 { color: var(--primary); letter-spacing: 0.12em; }
.g-board { margin-top: var(--space-5); background: var(--paper); color: var(--ink); border: var(--bd); box-shadow: 0 6px 0 var(--ink); padding: var(--space-4); }
.g-board[hidden], .g-nohome .g-board { display: none; }
.g-board h2 { display: flex; align-items: center; justify-content: center; gap: var(--space-2); font-size: var(--text-lg); letter-spacing: 0.1em; margin: 0 0 var(--space-3); }
.g-board ol { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.g-board li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); min-height: 40px; max-width: none; background: #fff; border: 2px solid var(--ink); padding-right: var(--space-3); font-weight: 700; font-size: var(--text-base); line-height: 1.2; }
.g-board li b { align-self: stretch; display: grid; place-content: center; background: var(--ink); color: #fff; font-family: var(--font-display); font-size: var(--text-sm); font-variant-numeric: tabular-nums lining-nums; }
.g-board li:nth-child(-n+3) b { background: var(--primary); }
.g-board li:first-child b { background: var(--accent); color: var(--ink); border-right: 2px solid var(--ink); }
.g-board li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-board li em { font-style: normal; font-family: var(--font-display); font-weight: 900; white-space: nowrap; font-variant-numeric: tabular-nums lining-nums; }
.g-board li.g-me { background: var(--accent); box-shadow: 0 3px 0 var(--ink); }
.g-board li.g-me b { border-right: 2px solid var(--ink); }
.g-board-empty { text-align: center; font-weight: 700; font-size: var(--text-sm); margin: 0; max-width: none; padding: var(--space-3) 0 var(--space-2); }
.g-board-empty[hidden] { display: none; }

/* 入到頭 10：輸入個名 */
.g-vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.g-name { margin: 0 0 var(--space-4); padding: var(--space-3); background: var(--accent); border: var(--bd); text-align: left; }
.g-name[hidden], .g-name-err[hidden], .g-ranked[hidden] { display: none; }
.g-name-t { display: flex; align-items: center; justify-content: center; gap: var(--space-2); font-family: var(--font-display); font-weight: 900; font-size: var(--text-lg); letter-spacing: 0.06em; margin: 0 0 var(--space-2); max-width: none; }
.g-name-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); }
.g-name input { width: 100%; min-width: 0; height: 48px; background: #fff; color: var(--ink); border: var(--bd); border-radius: 0; padding: 0 var(--space-3); font-size: 1rem; font-weight: 700; }
.g-name input::placeholder { color: #8b8672; font-weight: 400; }
.g-name input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.g-name button { min-height: 48px; padding: 0 var(--space-4); background: var(--primary); color: #fff; border: var(--bd); border-radius: 0; font-family: var(--font-display); font-weight: 900; font-size: var(--text-base); letter-spacing: 0.08em; white-space: nowrap; cursor: pointer; touch-action: manipulation; }
.g-name button:disabled { background: #b9b39a; color: #5d5a4c; border-color: #6d6a5a; cursor: default; }
.g-name button:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.g-name-err { margin: var(--space-2) 0 0; background: var(--warn); color: #fff; font-weight: 700; font-size: var(--text-sm); line-height: 1.4; padding: var(--space-2) var(--space-3); max-width: none; }
.g-ranked { display: flex; align-items: center; justify-content: center; gap: var(--space-2); margin: 0 0 var(--space-4); padding: var(--space-2) var(--space-3); background: var(--ok); color: #fff; font-weight: 700; font-size: var(--text-base); max-width: none; }
.g-over .g-sub:has(+ .g-name:not([hidden])), .g-over .g-sub:has(+ .g-name + .g-ranked:not([hidden])) { margin-bottom: var(--space-4); }

@media (max-width: 359px) {
  .g-name-row { grid-template-columns: minmax(0, 1fr); }   /* 細手機：掣放落下面，8 個字先睇得晒 */
}

/* 返回首頁：玩緊同爆機畫面收埋（費事撳錯；爆機畫面要一版睇晒） */
.g-home { text-align: center; margin: var(--space-4) auto 0; max-width: none; font-size: var(--text-sm); font-weight: 700; }
.g-home a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--space-3); color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
.g-nohome .g-home { display: none; }

/* 爆機 */
.g-win h2 { color: var(--primary); font-size: var(--text-2xl, 2rem); letter-spacing: 0.12em; }
.g-party { position: relative; height: 150px; overflow: hidden; }
.g-party i { position: absolute; top: -12px; width: 8px; height: 8px; animation: g-fall var(--t) linear infinite; animation-delay: calc(var(--d) * -140ms); }
.g-bag { position: absolute; left: 50%; top: 50%; width: 128px; height: 128px; margin: -64px 0 0 -64px; animation: g-hop 700ms steps(2, jump-none) infinite; }
.g-bag svg { width: 100%; height: 100%; image-rendering: pixelated; shape-rendering: crispEdges; }
.g-ghost { display: block; width: 100%; min-height: 48px; margin-top: var(--space-3); background: transparent; color: var(--ink); border: 0; border-radius: 0; font-weight: 700; font-size: var(--text-base); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.g-ghost:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.g-win .g-sub { margin-bottom: var(--space-4); }
@keyframes g-fall { from { transform: translateY(0) rotate(0deg); } to { transform: translateY(210px) rotate(270deg); } }
@keyframes g-hop { from { transform: translateY(0); } to { transform: translateY(-6px); } }

@keyframes g-in { from { transform: scale(0.82); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes g-pop { from { transform: scale(0.4); } to { transform: none; } }
@keyframes g-wobble { 0%, 100% { transform: none; } 20% { transform: translateX(-6px) rotate(-3deg); } 50% { transform: translateX(6px) rotate(3deg); } 80% { transform: translateX(-3px); } }
@keyframes g-shake { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(-3px, 1px); } 75% { transform: translate(3px, -1px); } }
@keyframes g-blink { from { opacity: 1; } to { opacity: 0.45; } }
@keyframes g-fly { from { transform: translate(0, 0) scale(0.2) rotate(0deg); opacity: 0; } to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 1; } }

@media (max-width: 359px) {
  .g-how li { grid-template-columns: 120px 1fr; font-size: var(--text-sm); }
  .g-mini { width: 36px; height: 36px; }
  .g-grid { --gap: 8px; min-height: 200px; }
  .g-grid.g-c2 { max-width: 208px; }
  .g-burst { height: 210px; transform: scale(0.88); }
}
@media (max-height: 620px) {
  .g-grid { min-height: 200px; }
  .g-grid.g-c2 { max-width: 208px; }
}
@media (prefers-reduced-motion: reduce) {
  .g-tile, .g-banner, .g-fly, .g-closet li.pop, .g-closet.g-boom, .g-tile.g-miss, .g-bar.g-low i, .g-tile.g-ok::after { animation: none; }
  .g-bag { animation: none; }
  .g-party i { animation: none; top: calc(8% + var(--d) * 5%); }
}

/* 爆機畫面：矮身或者窄身嘅手機，收細啲，唔使捲動 */
@media (max-width: 359px), (max-height: 620px) {
  .g-party { height: 104px; }
  .g-bag { width: 96px; height: 96px; margin: -48px 0 0 -48px; }
  .g-win { padding-top: var(--space-3); padding-bottom: var(--space-3); }
  .g-win h2 { margin: 0 0 var(--space-2); }
  .g-win .g-final b { font-size: 3.25rem; }
  .g-win .g-sub { margin-bottom: var(--space-3); }
  .g-win .g-ghost { min-height: 44px; margin-top: var(--space-2); }
}
