/* 塞唔塞得落：顏色 token 跟設計 v1 第 3.1 節；字型第一版用系統字（設計 3.2 方案 A，粉圓 subset 未做） */
:root {
  --paper: #F5EFE3; --floor: #FFFCF5; --grid: #E2D9C6; --ink: #26232E; --ink-2: #5E5868;
  --line: #D8CFBC; --plan: #2D5B8C; --primary: #C2462A; --select: #F5C04A; --ok: #0F7A6C; --bad: #B8341F;
  --card: #FFFCF5;
  --font-ui: -apple-system, "PingFang HK", "Noto Sans CJK TC", "Noto Sans TC", sans-serif;
  --font-voice: "jf-openhuninn", "PingFang HK", "Noto Sans CJK TC", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; overflow: hidden; background: #E9E2D4; overscroll-behavior: none;
  font-family: var(--font-ui); color: var(--ink);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
body { position: fixed; inset: 0; touch-action: none; }
[hidden] { display: none !important; }

.phone {
  position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px; background: var(--paper); overflow: hidden;
  background-image: radial-gradient(rgba(45,91,140,.10) 1px, transparent 1px); background-size: 16px 16px;
}
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* 掣（設計 3.4） */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 16px; border-radius: 14px;
  font: 700 18px/1.1 var(--font-ui); text-decoration: none; cursor: pointer;
  border: 2px solid var(--ink); box-shadow: 0 3px 0 var(--ink); color: var(--ink);
  transition: transform .06s, box-shadow .06s; touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn-primary { background: var(--primary); color: #FFF; }
.btn-secondary { background: var(--card); }
.btn[disabled] { background: #E7E1D6; color: #8A8494; border-color: #A7A1AE; box-shadow: 0 3px 0 #A7A1AE; transform: none; }
.btn.on { background: var(--select); }
.btn.big { min-height: 60px; flex-direction: column; gap: 2px; font-size: 20px; }
.btn.big small { font-size: 13px; font-weight: 700; opacity: .9; }
.btn.big small:empty { display: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); border: 2px solid var(--ink); color: var(--ink); text-decoration: none; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }

/* 頂欄 */
.bar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 4px; }
.bar .ttl { text-align: center; line-height: 1.2; }
.bar .lv { font-size: 13px; color: var(--ink-2); font-weight: 700; }
.bar .nm { font-size: 18px; font-weight: 800; }

/* 對白泡泡（設計 3.9） */
.bubble {
  position: relative; width: 100%; background: #FFF; border: 2px solid var(--ink); border-radius: 18px;
  padding: 8px 12px; font-family: var(--font-voice); font-size: 15px; line-height: 1.4;
  box-shadow: 0 3px 0 rgba(38,35,46,.18); transition: opacity .2s;
}
.bubble .who { font-family: var(--font-ui); font-size: 13px; font-weight: 700; color: var(--ink-2); display: block; margin-bottom: 2px; }
.bubble::after {
  content: ""; position: absolute; width: 14px; height: 14px; background: #FFF;
  border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); left: 40px; bottom: -9px; transform: rotate(45deg);
}

/* 開始畫面（設計 5.1） */
.start { padding: calc(40px + env(safe-area-inset-top)) 20px calc(16px + env(safe-area-inset-bottom)); align-items: center; gap: 16px; }
.hero { font-family: var(--font-voice); font-size: 44px; line-height: 1.1; font-weight: 800; letter-spacing: .02em; }
.hero em { font-style: normal; color: var(--primary); }
.sub { font-size: 15px; color: var(--ink-2); font-weight: 700; text-align: center; margin-top: 6px; }
.start-top { text-align: center; }
.start-art { flex: 1; min-height: 120px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 0; }
.start-art canvas { width: 19%; aspect-ratio: 1; }
.start-bubble { max-width: 340px; margin-bottom: 8px; }
.start-btns { width: 100%; display: grid; gap: 12px; }
.foot { font-size: 13px; color: var(--ink-2); text-align: center; }
.foot a { color: var(--plan); text-decoration: underline; display: inline-block; min-height: 44px; line-height: 44px; }

/* 選關（設計 5.2） */
.level-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; overflow: auto; touch-action: pan-y; }
.level-card {
  display: block; text-decoration: none; color: var(--ink); background: var(--card); border: 2px solid var(--ink);
  border-radius: 16px; padding: 10px 12px; min-height: 84px; box-shadow: 0 3px 0 var(--ink);
}
.level-card .n { font-size: 13px; color: var(--ink-2); font-weight: 700; }
.level-card .t { font-size: 17px; font-weight: 800; margin: 4px 0; }
.level-card .s { font-size: 13px; font-weight: 700; }
.level-card.done .s { color: var(--ok); }
.level-card.now { background: #FFF6DB; box-shadow: 0 0 0 3px var(--select), 0 3px 0 var(--ink); }
.level-card.now .s { color: var(--primary); }
.level-card.locked { border-style: dashed; border-color: #A7A1AE; box-shadow: none; color: #8A8494; pointer-events: none; background: transparent; }
.levels-foot { text-align: center; font-size: 13px; color: var(--ink-2); padding: 8px 16px 24px; }

/* 遊戲中：UI 疊喺 canvas 上面；空位唔食手指，等 canvas 收到 */
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; z-index: 0; }
.game > .bar, .talk, .board, .tray, .controls { position: relative; z-index: 2; }
.game > .bar { pointer-events: none; }
.game > .bar > * { pointer-events: auto; }
.game > .bar .ttl { pointer-events: none; }
.talk { min-height: 64px; padding: 4px 16px 10px; display: flex; align-items: flex-end; pointer-events: none; }
.talk .bubble.dim { opacity: .25; }
.board { flex: 1; min-height: 0; pointer-events: none; }
.tray { padding: 8px 12px; background: rgba(255,252,245,.86); border-top: 2px solid var(--line); touch-action: none; }
.tray.drop-here { background: rgba(245,192,74,.35); }
.tray-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); font-weight: 700; margin: 0 2px 6px; }
.slots { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.slot { aspect-ratio: 1; border-radius: 12px; background: var(--card); border: 2px solid var(--line); position: relative; touch-action: none; min-width: 44px; }
.slot canvas { width: 100%; height: 100%; display: block; pointer-events: none; }
.slot .count { position: absolute; right: -4px; top: -6px; background: var(--ink); color: #FFF; font-size: 12px; font-weight: 800; border-radius: 10px; padding: 1px 6px; pointer-events: none; }
.slot.empty { background: transparent; border-style: dotted; }
.slot.dragging { border: 2px dashed #A7A1AE; background: transparent; }
.slot.dragging canvas { visibility: hidden; }
.slot.selected { border-color: var(--ink); box-shadow: 0 0 0 3px var(--select); }
.slot.hinted { border-color: var(--plan); border-style: dashed; }
.slot.next { display: flex; flex-direction: column; align-items: center; justify-content: center; font: 800 12px/1.2 var(--font-ui); color: var(--ink); cursor: pointer; border-color: var(--ink); text-align: center; padding: 2px; }
.slot.next svg { width: 18px; height: 18px; }
.controls { display: grid; grid-template-columns: 64px 88px 1fr; gap: 8px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); background: rgba(245,239,227,.92); }
.controls .btn { min-height: 56px; padding: 0 6px; }
.controls .rotate { font-size: 16px; white-space: nowrap; gap: 4px; }
.controls .rotate svg { width: 22px; height: 22px; flex: none; }
.controls #lockBtn { font-size: 15px; }
/* 梳化床「攤開／收埋」：只喺揀中梳化床先出；顏色同「轉向」（磚紅實心）分開，免撳錯（spec v4 9.2.4；樣式未經 app-design 定） */
.controls.has-form { grid-template-columns: 64px 76px 84px 1fr; }
.controls .form { background: #EFE8F8; color: #4B3A78; border: 2px solid #4B3A78; font-size: 15px; gap: 2px; flex-direction: column; }
.controls .form svg { width: 20px; height: 20px; flex: none; }
.controls .form[hidden] { display: none; }
.controls .hint { position: relative; font-size: 16px; }
.controls .hint .badge { position: absolute; top: -9px; right: -7px; background: var(--plan); color: #FFF; font-size: 12px; border-radius: 10px; padding: 2px 6px; border: 2px solid var(--paper); }
.rotate svg { width: 26px; height: 26px; }
@keyframes shake { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-6px) } 75% { transform: translateX(6px) } }
.shake { animation: shake .25s 1; }
.reduce-motion .shake { animation: none; }

/* 對話框、過關 */
.overlay { position: absolute; inset: 0; z-index: 8; background: rgba(38,35,46,.45); display: grid; place-items: center; padding: 16px; }
.card { background: var(--paper); border: 2px solid var(--ink); border-radius: 16px; padding: 16px; width: 100%; max-width: 380px; max-height: 94%; overflow: auto; touch-action: pan-y; }
.card h2 { font-size: 18px; margin-bottom: 12px; }
.card p { font-size: 15px; line-height: 1.5; color: var(--ink-2); }
.card .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.card .btns.one { grid-template-columns: 1fr; }
.clear-card { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.clear-lv { font-size: 13px; color: var(--ink-2); font-weight: 700; }
.cleared-title { font-family: var(--font-voice); font-size: 52px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.clear-ach { font-size: 15px; font-weight: 700; color: var(--ok); }
.clear-bubble { text-align: left; margin: 4px 0 6px; }
.clear-room { width: 100%; max-width: 240px; aspect-ratio: 1; align-self: center; border-radius: 12px; border: 2px solid var(--line); background: #e9e4da; }
.share-overlay { background: rgba(38,35,46,.85); }
.share-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #FFF; font-size: 14px; max-height: 100%; }
.share-wrap img { max-width: 100%; max-height: 70vh; border-radius: 10px; -webkit-touch-callout: default; pointer-events: auto; -webkit-user-select: auto; user-select: auto; }

/* 全通（設計 5.6） */
.allclear { padding: calc(28px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom)); align-items: center; gap: 10px; }
.allclear-title { font-family: var(--font-voice); font-size: 40px; font-weight: 800; color: var(--primary); }
.allclear-bubble { max-width: 360px; min-height: 64px; }
.ac-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px 6px; width: 100%; background: var(--card); border: 2px solid var(--ink); border-radius: 14px; padding: 8px; }
.ac-item { text-align: center; font-size: 10px; font-weight: 700; color: var(--ink-2); border-radius: 10px; padding: 2px 0; transition: background .2s; }
.ac-item canvas { width: 100%; aspect-ratio: 1; display: block; }
.ac-item.talking { background: #FFF1C9; color: var(--ink); }
.ac-btns { width: 100%; display: grid; gap: 10px; margin-top: auto; }

/* 設定・私隱 */
.about-body { padding: 8px 20px 32px; overflow: auto; touch-action: pan-y; -webkit-user-select: text; user-select: text; }
.about-body h2 { font-size: 18px; margin: 18px 0 8px; }
.about-body p { font-size: 15px; line-height: 1.6; color: var(--ink-2); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; font-size: 16px; font-weight: 700; }
.toggle small { display: block; font-size: 13px; color: var(--ink-2); font-weight: 400; }
.toggle input { width: 28px; height: 28px; accent-color: var(--primary); }
.license { white-space: pre-wrap; font-size: 11px; color: var(--ink-2); margin-top: 10px; font-family: ui-monospace, Menlo, monospace; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; font-size: 16px; color: var(--ink-2); background: var(--paper); z-index: 20; }

/* 實用性試玩（3 關） */
.proto-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.proto-btn small { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.proto-link { display: block; margin: 4px 16px 12px; text-align: center; }
.tray-use { color: #C4573A; }
.tray-use.all { color: var(--ok); }
