:root {
  --bg: #0E0E13; --surface: #16161D; --surface-2: #1E1E27; --line: #2A2A33;
  --gold: #E3B65A; --gold-hi: #F2CB7A; --gold-ink: #0E0E13; --gold-soft: #C9B07A;
  --card: #1B1710; --card-line: #5A4620;
  --text: #F4F1EA; --muted: #A9A7B0; --dim: #C9C7CE;
  --ok: #6FD39A; --ok-bg: #15321E; --err: #F0A0A0; --err-bg: #2A1414; --err-line: #5A2424;
  --r: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: "Noto Sans Thai", system-ui, -apple-system, sans-serif; font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); gap: 18px; }
a { color: var(--gold); text-decoration: none; }
button, input { font: inherit; color: inherit; }
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 38px; height: 38px; border-radius: 11px; background: var(--gold); display: grid; place-items: center; flex-shrink: 0; }
.brand b { display: block; font-size: 16px; letter-spacing: .5px; color: var(--gold); line-height: 1.2; }
.brand small { display: block; font-size: 12px; color: var(--muted); }
.back { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; background: none; border: 0; cursor: pointer; font-size: 17px; font-weight: 700; }

/* cards */
.card { border-radius: 20px; padding: 20px; background: var(--card); border: 1px solid var(--card-line); display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.label { font-size: 12px; color: var(--gold-soft); }
.big { font-size: 20px; font-weight: 700; line-height: 1.3; word-break: break-word; }
.val { font-size: 15px; font-weight: 600; }
.badge { padding: 5px 12px; border-radius: 999px; background: var(--gold); color: var(--gold-ink); font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.off { background: var(--surface-2); color: var(--muted); }
.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; border: 2px solid var(--card-line); flex-shrink: 0; }

/* buttons */
.btn { width: 100%; min-height: 52px; border: 0; border-radius: 14px; background: var(--gold); color: var(--gold-ink); font-size: 16px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; text-align: center; }
.btn:hover { background: var(--gold-hi); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; border: 1px solid var(--card-line); color: var(--gold); }
.btn.ghost:hover { background: var(--card); }
.btn.line { background: #06C755; color: #fff; }
.btn.small { min-height: 44px; font-size: 14px; width: auto; }
.btn.danger { background: transparent; border: 1px solid var(--err); color: var(--err); }
.cta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-radius: var(--r); background: var(--gold); color: var(--gold-ink);
  border: 0; width: 100%; text-align: left; cursor: pointer; min-height: 72px; }
.cta:hover { background: var(--gold-hi); }
.cta:disabled { background: var(--surface-2); color: var(--muted); cursor: default; }
.cta b { display: block; font-size: 17px; }
.cta small { display: block; font-size: 12px; font-weight: 500; }

/* lists */
.section { display: flex; flex-direction: column; gap: 10px; }
.section h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.item { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
button.item { width: 100%; text-align: left; cursor: pointer; }
button.item:hover { border-color: var(--card-line); }
.item .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--surface-2); }
.item .ico.on { background: var(--ok-bg); }
.item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item .t { font-size: 15px; font-weight: 600; }
.item .s { font-size: 12px; color: var(--muted); }
.pill { padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: #33270F; color: var(--gold); }
.pill.err { background: var(--err-bg); color: var(--err); }
.empty { padding: 16px; border-radius: 14px; background: var(--surface); color: var(--muted); font-size: 13px; text-align: center; }

/* code */
.codebox { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 24px; font-weight: 700; letter-spacing: 2px; padding: 16px; border-radius: 12px;
  background: var(--bg); border: 1px dashed var(--gold); color: var(--gold); text-align: center; word-break: break-all; user-select: all; }
.steps { counter-reset: s; display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.steps li { counter-increment: s; display: flex; gap: 12px; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 50%; background: var(--gold); color: var(--gold-ink); font-size: 13px; font-weight: 700;
  display: grid; place-items: center; flex-shrink: 0; }
.steps b { display: block; font-size: 14px; }
.steps span { display: block; font-size: 12px; color: var(--muted); }
.notice { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 14px; background: var(--err-bg); border: 1px solid var(--err-line); font-size: 13px; }
.notice.info { background: var(--surface); border-color: var(--line); }

/* forms */
form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--dim); font-weight: 500; }
.input { min-height: 52px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; width: 100%; }
.input:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: transparent; }
.input.pin { letter-spacing: 10px; text-align: center; font-size: 22px; font-weight: 700; }
textarea.input { min-height: 88px; padding: 12px 14px; font-size: 15px; resize: vertical; }
.err { color: var(--err); font-size: 13px; margin: 0; }
.err:empty { display: none; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
h1 { margin: 0; font-size: 22px; line-height: 1.3; }
p { margin: 0; }
.muted { color: var(--muted); }
.foot { margin-top: auto; display: flex; justify-content: center; gap: 16px; padding-top: 8px; }
.link { background: none; border: 0; color: var(--muted); font-size: 13px; min-height: 44px; padding: 0 8px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 10; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
