/* PIN Prompt — ชิ้นส่วนชุดเดียวใช้ทั้งเว็บ (ธีมมืด ชมพู→ม่วง) */
:root {
  --canvas: #08080b;
  --surface: #14141c;
  --surface-2: #1c1c27;
  --line: #2c2c3b;
  --ink: #f5f4f9;
  --muted: #a5a2b8;
  --brand-a: #ff2d95;
  --brand-b: #8b3dff;
  --brand-soft: #cfaaff;
  --green: #3ddc84;
  --amber: #ffc457;
  --coral: #ff8378;
  --gradient: linear-gradient(120deg, var(--brand-a), var(--brand-b));
  --glow: 0 0 0 3px rgba(255, 45, 149, 0.28);
  --radius: 16px;
  --radius-lg: 22px;
  --tap: 46px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", Thonburi, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.35; }
h2 { font-size: 18px; line-height: 1.4; }
h3 { font-size: 16px; }
a { color: var(--brand-soft); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* โครงหน้า */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; min-height: 60px;
  background: rgba(8, 8, 11, 0.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--ink); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 10px; background: var(--gradient); }
.layout { display: block; }
.nav {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.nav a {
  display: flex; align-items: center; white-space: nowrap; min-height: 40px; padding: 0 14px;
  border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.main { width: 100%; max-width: 760px; margin: 0 auto; padding: 20px 16px 120px; }
.main.wide { max-width: 1040px; }
.foot { padding: 24px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

/* การ์ด */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.card-link { text-decoration: none; color: inherit; transition: border-color 0.15s; }
.card-link:hover { border-color: var(--brand-b); }
.cards { display: grid; gap: 12px; }

/* ปุ่ม */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface-2); color: var(--ink);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--brand-b); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--gradient); border-color: transparent; color: #fff; }
.btn-primary:hover { border-color: transparent; filter: brightness(1.08); }
.btn-danger { background: transparent; border-color: var(--coral); color: var(--coral); }
.btn-text { background: transparent; border-color: transparent; color: var(--brand-soft); padding: 0 10px; }
.btn-block { width: 100%; }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: 14px; }
:focus-visible { outline: 2px solid var(--brand-soft); outline-offset: 2px; box-shadow: var(--glow); }

/* ฟอร์ม */
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 700; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }
.error-text { color: var(--coral); font-size: 14px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  background: var(--canvas); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px;
  font: inherit;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-soft); box-shadow: var(--glow); }

/* ตัวเลือกแบบการ์ด */
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  min-height: var(--tap); padding: 12px 14px; cursor: pointer;
  background: var(--canvas); color: var(--ink); font: inherit;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.choice:hover { border-color: var(--brand-b); }
.choice[aria-pressed="true"] { border-color: var(--brand-a); background: rgba(139, 61, 255, 0.14); box-shadow: 0 0 0 1px var(--brand-a); }
.choice-dot { flex: 0 0 18px; height: 18px; margin-top: 4px; border-radius: 50%; border: 2px solid var(--muted); }
.choice[aria-pressed="true"] .choice-dot { border-color: var(--brand-a); background: radial-gradient(circle, var(--brand-a) 0 4px, transparent 5px); }
.choice-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choice-title { font-weight: 700; }
.choice-desc { color: var(--muted); font-size: 13px; }

/* ตัวเลือกแบบปุ่มเล็ก (เลือกได้หลายอัน) */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  min-height: var(--tap); padding: 8px 14px; cursor: pointer; text-align: left;
  background: var(--canvas); color: var(--ink); font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 999px;
}
.pill:hover:not(:disabled) { border-color: var(--brand-b); }
.pill[aria-pressed="true"] { border-color: var(--brand-a); background: rgba(139, 61, 255, 0.14); box-shadow: 0 0 0 1px var(--brand-a); font-weight: 700; }
.pill:disabled { opacity: 0.45; cursor: not-allowed; }

/* ป้าย */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip-good { color: var(--green); border-color: rgba(61, 220, 132, 0.45); }
.chip-warn { color: var(--amber); border-color: rgba(255, 196, 87, 0.45); }
.chip-bad { color: var(--coral); border-color: rgba(255, 131, 120, 0.45); }
.chip-brand { color: #fff; border-color: transparent; background: var(--gradient); }

/* กล่องแจ้งเตือน */
.notice { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); font-size: 14px; }
.notice-info { border-color: rgba(139, 61, 255, 0.55); background: rgba(139, 61, 255, 0.12); }
.notice-warn { border-color: rgba(255, 196, 87, 0.55); background: rgba(255, 196, 87, 0.08); }
.notice-error { border-color: rgba(255, 131, 120, 0.6); background: rgba(255, 131, 120, 0.08); }
.notice ul { margin: 6px 0 0; padding-left: 20px; }

details { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
summary { cursor: pointer; padding: 12px 14px; min-height: var(--tap); font-weight: 700; font-size: 14px; }
details > .details-body { padding: 0 14px 14px; font-size: 14px; }
ol.steps-list, ul.plain-list { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }

/* แถบขั้นตอน */
.stepper { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; overflow-x: auto; }
.stepper li { flex: 1 0 auto; }
.step-item {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--muted); font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.step-item:disabled { cursor: default; opacity: 0.6; }
.step-item[aria-current="step"] { color: var(--ink); border-color: var(--brand-a); }
.step-num {
  flex: 0 0 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 800; font-size: 12px;
}
.step-item[data-state="done"] .step-num { background: var(--green); color: #062012; }
.step-item[aria-current="step"] .step-num { background: var(--gradient); color: #fff; }
.step-label { display: none; }
.step-item[aria-current="step"] .step-label { display: inline; }

/* กล่องพรอมป์ต์ */
.promptbox { border: 1px solid var(--line); border-radius: var(--radius); background: var(--canvas); overflow: hidden; }
.promptbox-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.promptbox pre {
  margin: 0; padding: 12px 14px; max-height: 240px; overflow: auto;
  white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, "Noto Sans Thai", monospace; font-size: 12.5px; line-height: 1.55; color: var(--muted);
}

/* รายการติ๊ก */
.check { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--brand-a); flex: 0 0 auto; }

/* ตาราง: จอเล็กกลายเป็นการ์ด */
.table { width: 100%; border-collapse: collapse; }
.table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.table tbody { display: grid; gap: 12px; }
.table tr { display: grid; gap: 6px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0; text-align: right; }
.table td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: 0 0 auto; }
.table td.cell-block { display: block; text-align: left; }
.table td.cell-block::before { content: none; }
.table td.cell-labeled::before { content: attr(data-label); display: block; }
progress { width: 90px; height: 8px; accent-color: var(--brand-a); }

/* หน้าต่าง */
dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 18px; padding: 12px 14px; background: var(--canvas); border: 1px dashed var(--brand-soft); border-radius: var(--radius); user-select: all; }

/* แถบปุ่มหลัก: ติดขอบล่างบนมือถือ */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(8, 8, 11, 0.94); border-top: 1px solid var(--line);
}
.actionbar .btn-primary { flex: 1 1 auto; }

/* ข้อความลอย */
.toast {
  position: fixed; left: 50%; bottom: 90px; z-index: 40; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--brand-b); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 14px; font-weight: 700;
}
.toast-error { border-color: var(--coral); color: var(--coral); }

/* หน้าเข้าสู่ระบบ */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px 16px; }
.auth .card { width: min(400px, 100%); }

/* สรุปคำตอบ */
.summary { margin: 0; display: grid; gap: 8px; }
.summary div { display: grid; gap: 0; }
.summary dt { color: var(--muted); font-size: 12px; }
.summary dd { margin: 0; font-weight: 500; font-size: 14px; }
.aside { display: none; }

/* แท็บเล็ต */
@media (min-width: 768px) {
  .main { padding: 28px 24px 110px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choices.cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step-label { display: inline; }
  .table thead { position: static; width: auto; height: auto; overflow: visible; clip-path: none; display: table-header-group; }
  .table tbody { display: table-row-group; }
  .table tr { display: table-row; background: transparent; }
  .table th { text-align: left; padding: 10px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
  .table td, .table td.cell-block { display: table-cell; padding: 12px 10px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
  .table td::before, .table td.cell-labeled::before { content: none; }
  .table.story { font-size: 13px; }
  .table.story td { vertical-align: top; padding: 12px 8px; }
  .table.story th:first-child { width: 64px; }
  .table.story th:nth-child(2) { width: 13%; }
  .table.story th:nth-child(5) { width: 30%; }
  .actionbar { position: static; padding: 8px 0 0; background: transparent; border: 0; justify-content: flex-end; }
  .actionbar .btn-primary { flex: 0 0 auto; min-width: 220px; }
  .toast { bottom: 28px; }
}

/* คอมพิวเตอร์: เมนูซ้าย และสรุปคำตอบด้านขวา */
@media (min-width: 1024px) {
  .layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); align-items: start; }
  .nav {
    position: sticky; top: 60px; flex-direction: column; overflow: visible;
    height: calc(100dvh - 60px); padding: 20px 14px; border-bottom: 0; border-right: 1px solid var(--line);
  }
  .nav a { border-radius: 12px; }
  .with-aside { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; align-items: start; }
  .aside { display: flex; position: sticky; top: 88px; }
  .main.has-aside { max-width: 1120px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ระหว่างรอ: วงหมุนบนปุ่มและข้อความ แถบวิ่งบนสุดของจอ */
.btn[aria-busy="true"]:disabled { opacity: 0.8; cursor: progress; }
.btn[aria-busy="true"]::before, .waiting::before {
  content: ''; display: inline-block; width: 16px; height: 16px; margin-right: 8px; vertical-align: -3px; flex: 0 0 auto;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite;
}
.waiting::after, .loading-bar {
  height: 4px; background: var(--gradient) no-repeat, var(--canvas); background-size: 35% 100%, auto; animation: slide 1.4s ease-in-out infinite;
}
.waiting::after { content: ''; display: block; margin-top: 10px; border-radius: 2px; }
.loading-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 100; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { from { background-position: -55% 0, 0 0; } to { background-position: 155% 0, 0 0; } }
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"]::before, .waiting::before { animation-duration: 2.4s; } .waiting::after, .loading-bar { animation-duration: 4s; } }
