/* 對話框：深色玻璃面板（遊戲機系統選單） */
.dlg { border: 0; padding: 0; background: transparent; color: var(--ink); width: min(520px, calc(100vw - 24px)); max-width: none; max-height: calc(100dvh - 24px); overflow: visible; }
.dlg::backdrop { background: rgba(5, 2, 12, .62); -webkit-backdrop-filter: blur(10px) saturate(1.2); backdrop-filter: blur(10px) saturate(1.2); }
.dlg[open]::backdrop { animation: fade-in .25s ease both; }
.dlg-body {
  position: relative; max-height: calc(100dvh - 30px); overflow: auto;
  padding: 34px 30px 28px; border-radius: var(--radius-l);
  background: linear-gradient(180deg, rgba(44, 30, 72, .97), rgba(24, 15, 41, .98));
  border: 0; box-shadow: inset 0 0 0 1px var(--stroke-2), inset 0 1px 0 rgba(255, 255, 255, .12), var(--shadow-2);
  overscroll-behavior: contain;
}
.dlg-title { font-size: 26px; font-weight: 900; letter-spacing: .08em; line-height: 1.3; color: #fff; }
.dlg-close { position: absolute; right: 14px; top: 14px; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--stroke); display: grid; place-items: center; }
.dlg-close svg { width: 20px; height: 20px; }
.dlg-close:hover { background: rgba(255, 255, 255, .22); }
.dlg-close:focus-visible { outline: none; box-shadow: var(--glow-focus); }
.dlg-actions { display: flex; gap: 10px; margin-top: 22px; align-items: center; }
.dlg.is-busy .dlg-body { cursor: progress; }

/* ---------- 登入 ---------- */
.dlg-login { width: min(400px, calc(100vw - 24px)); }
.dlg-login .dlg-body { text-align: center; }
.login-avatar { width: 104px; height: 104px; margin: 0 auto 14px; border-radius: 50%; box-shadow: 0 0 0 4px var(--yellow), 0 0 26px 4px rgba(242, 207, 91, .6); container-type: inline-size; }
.login-meta { font-size: 14px; color: var(--ink-2); min-height: 1.4em; margin-top: 2px; }
.login-preview { margin-top: 18px; display: grid; gap: 16px; justify-items: center; }
.login-pin { margin-top: 16px; display: grid; gap: 12px; }
.pin-wrap { position: relative; }
.pin-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--ink); }
.pin-icon svg { width: 22px; height: 22px; }
.pin-input { width: 100%; height: 58px; text-align: center; font-size: 28px; letter-spacing: .5em; padding: 0 44px; border-radius: 16px; border: 0; background: rgba(0, 0, 0, .3); box-shadow: inset 0 0 0 1px var(--stroke-2); color: var(--text); font-family: var(--font-num); font-weight: 700; }
.pin-input::placeholder { font-size: 16px; letter-spacing: .2em; color: var(--muted); }
.pin-input:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--yellow), 0 0 24px -4px rgba(247, 208, 84, .6); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { height: 56px; border-radius: 16px; border: 0; background: var(--surface-2); font-family: var(--font-num); font-size: 24px; font-weight: 700; color: var(--text); display: grid; place-items: center; box-shadow: inset 0 0 0 1px var(--stroke), 0 3px 0 rgba(0, 0, 0, .35); transition: transform .12s var(--ease), box-shadow .12s, background-color .15s; }
.key:hover:not(:disabled) { background: rgba(255, 255, 255, .2); }
.key:focus-visible { outline: none; box-shadow: var(--glow-focus); }
.key:active:not(:disabled) { transform: translateY(1px) scale(.97); box-shadow: none; }
.key svg { width: 24px; height: 24px; }
.key:disabled { opacity: .45; }
.form-error { min-height: 1.6em; font-size: 14px; font-weight: 700; color: var(--danger); }

/* ---------- 開啟遊戲 ---------- */
.dlg-launch { width: min(620px, calc(100vw - 24px)); }
.dlg-launch .dlg-body { display: grid; grid-template-columns: 170px 1fr; gap: 26px; align-items: center; }
.launch-art .cover { width: 100%; aspect-ratio: 500 / 580; border-radius: 20px; border: 0; transform: rotate(-3deg); box-shadow: 0 24px 50px -16px rgba(0, 0, 0, .8), 0 0 50px -10px color-mix(in srgb, var(--accent) 80%, transparent); }
.launch-main { display: grid; gap: 16px; padding-right: 20px; }
.facts { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.launch-error { padding: 12px 14px; border-radius: 14px; background: rgba(255, 138, 160, .1); border: 1px solid rgba(255, 138, 160, .5); display: grid; gap: 10px; justify-items: start; }
.launch-error p { color: var(--danger); font-size: 14px; font-weight: 700; line-height: 1.7; }

/* ---------- 紀錄 ---------- */
.dlg-records { width: min(600px, calc(100vw - 24px)); }
.seg { display: inline-flex; gap: 4px; padding: 4px; margin: 0 0 18px; border-radius: 999px; background: rgba(0, 0, 0, .25); box-shadow: inset 0 0 0 1px var(--stroke); }
.seg-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 18px 0 14px; border: 0; border-radius: 999px; background: transparent; font-size: 15px; font-weight: 900; color: var(--text-2); }
.seg-btn svg { width: 20px; height: 20px; }
.seg-btn[aria-selected="true"] { background: var(--text); color: var(--on-yellow); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { display: grid; justify-items: center; gap: 2px; padding: 14px 10px; border-radius: 18px; border: 0; background: var(--surface); box-shadow: inset 0 0 0 1px var(--stroke); }
.stat svg { width: 22px; height: 22px; }
.stat strong { font-family: var(--font-num); font-size: 32px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat strong.is-empty { color: var(--text-3); }
.stat span { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.per-game { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 10px; }
.per-game li { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; }
.per-game .cover { width: 44px; aspect-ratio: 500 / 580; border-radius: 10px; border: 0; }
.pg-name { font-size: 15px; font-weight: 900; }
.pg-bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .12); margin-top: 6px; overflow: hidden; }
.pg-bar i { display: block; height: 100%; background: var(--yellow); transform-origin: left; }
.pg-score { font-family: var(--font-num); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.pg-score.is-empty { color: var(--text-3); }
.records-foot { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); margin-top: 10px; }
.records-foot svg { width: 16px; height: 16px; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.board li { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; padding: 8px 14px 8px 8px; border-radius: 16px; border: 0; background: var(--surface); }
.board li.is-me { background: var(--yellow-100); box-shadow: inset 0 0 0 2px rgba(247, 208, 84, .6); }
.board .rank { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-2); display: grid; place-items: center; font-family: var(--font-num); font-weight: 700; }
.board li:nth-child(1) .rank { background: var(--yellow); color: var(--on-yellow); }
.board .who { font-weight: 900; }
.board .pts { font-family: var(--font-num); font-weight: 700; font-variant-numeric: tabular-nums; }
.empty-state { text-align: center; padding: 10px 8px 4px; display: grid; justify-items: center; gap: 8px; }
.empty-icon { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; border: 0; background: var(--yellow-100); color: var(--yellow); box-shadow: inset 0 0 0 1px rgba(247, 208, 84, .35); }
.empty-icon svg { width: 32px; height: 32px; }
.empty-state h3 { font-size: 18px; font-weight: 900; }
.empty-state p { font-size: 14px; color: var(--ink-2); line-height: 1.7; max-width: 26em; }
.loading-line { display: grid; place-items: center; padding: 34px 0; color: var(--yellow); }

/* ---------- 設定 ---------- */
.dlg-settings { width: min(480px, calc(100vw - 24px)); }
.settings-list { margin-top: 12px; }
.setting-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--stroke); }
.setting-row > svg { width: 24px; height: 24px; flex: none; }
.setting-row label { flex: 1; font-size: 16px; font-weight: 900; cursor: pointer; }
.setting-row small { display: block; font-size: 12px; font-weight: 500; color: var(--text-3); }
.switch { appearance: none; -webkit-appearance: none; margin: 0; flex: none; width: 54px; height: 32px; border-radius: 999px; border: 0; background: rgba(255, 255, 255, .16); box-shadow: inset 0 0 0 1px var(--stroke-2); position: relative; cursor: pointer; transition: background-color .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 2px 6px rgba(0, 0, 0, .4); transition: transform .25s var(--ease-spring); }
.switch:checked { background: var(--yellow); }
.switch:checked::after { transform: translateX(22px); }
.switch:checked::after { background: var(--on-yellow); }
.switch:focus-visible { outline: none; box-shadow: var(--glow-focus); }
.settings-system { margin: 16px 0; font-size: 14px; }
.settings-system summary { cursor: pointer; font-weight: 900; display: inline-flex; align-items: center; gap: 6px; }
.settings-system summary svg { width: 18px; height: 18px; }
.sys-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 10px 0 0; }
.sys-list dt { color: var(--ink-2); }
.sys-list dd { margin: 0; font-weight: 900; }
.issues { margin: 8px 0 0; padding-left: 18px; color: var(--warn); }
.issue-error { color: var(--danger); }

/* ---------- 確認 ---------- */
.dlg-confirm { width: min(400px, calc(100vw - 24px)); }
.dlg-confirm .dlg-body { text-align: center; }
.confirm-icon { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; border: 0; background: var(--yellow-100); color: var(--yellow); box-shadow: inset 0 0 0 1px rgba(247, 208, 84, .35); }
.confirm-icon svg { width: 30px; height: 30px; }
#confirm-message { margin-top: 6px; font-size: 15px; color: var(--ink-2); line-height: 1.8; }
.dlg-confirm .dlg-actions { justify-content: center; }
.dlg-confirm .dlg-actions .btn { flex: 1; }

@media (max-width: 560px) {
  .dlg-body { padding: 30px 20px 22px; }
  .dlg-launch .dlg-body { grid-template-columns: 1fr; gap: 14px; justify-items: center; text-align: center; }
  .launch-art .cover { width: 116px; }
  .launch-main { padding-right: 0; justify-items: center; }
  .facts { justify-content: center; }
  .stat strong { font-size: 24px; }
}
.link-inline { border: 0; background: none; padding: 0; font: inherit; font-size: 12px; color: #cdb6ff; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }

/* ---------- 選擇頭像 ---------- */
.dlg-avatar { width: min(640px, calc(100vw - 24px)); }
.avatar-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px 10px; margin-top: 18px; }
.avatar-choice {
  position: relative; display: grid; justify-items: center; gap: 6px;
  padding: 8px 4px 6px; border: 0; border-radius: 20px; background: transparent; color: var(--ink);
  transition: transform .25s var(--ease-spring), background-color .2s;
}
.avatar-choice-pic { position: relative; width: 84px; max-width: 100%; aspect-ratio: 1; border-radius: 50%; display: block; transition: box-shadow .25s, transform .35s var(--ease-spring); }
.avatar-choice-name { font-size: 14px; font-weight: 900; color: var(--text-2); }
.avatar-choice.is-current .avatar-choice-name, .avatar-choice:focus-visible .avatar-choice-name { color: #fff; }
.avatar-choice:hover { background: var(--purple-50); transform: translateY(-3px); }
.avatar-choice:focus-visible { outline: none; background: var(--purple-50); }
.avatar-choice:focus-visible .avatar-choice-pic { box-shadow: 0 0 0 4px var(--focus), 0 0 28px 4px rgba(255, 255, 255, .4); transform: scale(1.06); }
.avatar-choice.is-current .avatar-choice-pic { box-shadow: 0 0 0 4px var(--yellow), 0 0 24px 4px rgba(242, 207, 91, .7); }
.avatar-choice.is-current::after {
  content: ""; position: absolute; top: 6px; right: calc(50% - 46px); width: 22px; height: 22px; border-radius: 50%;
  background: var(--purple) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 14px no-repeat;
  box-shadow: 0 0 0 2px #1c1230;
}
.avatar-choice.is-saving .avatar-choice-pic { opacity: .5; }
.avatar-choice-spin { position: absolute; top: 8px; left: 50%; width: 84px; aspect-ratio: 1; translate: -50% 0; display: grid; place-items: center; color: #fff; }
.avatar-choice-spin svg { width: 30px; height: 30px; }
.avatar-grid[aria-busy="true"] .avatar-choice:not(.is-saving) { opacity: .55; pointer-events: none; }
.avatar-status { display: flex; justify-content: center; align-items: center; gap: 6px; min-height: 24px; margin-top: 14px; font-size: 13px; font-weight: 500; color: var(--text-3); }
.avatar-status svg { width: 16px; height: 16px; }
.avatar-status[data-tone="error"] { color: var(--danger); }
@media (max-width: 560px) {
  .avatar-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
