*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-15);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}

p { margin: 0; text-wrap: pretty; }
a { color: inherit; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-s);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Khung trang */
.wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--s-4);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 56px;
  padding-top: env(safe-area-inset-top);
}

.back {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  min-height: 44px;
  padding: 0 var(--s-2) 0 0;
  color: var(--ink-2);
  font-size: var(--fs-15);
  font-weight: 500;
  text-decoration: none;
}

.back svg { width: 20px; height: 20px; }

.icon { width: 20px; height: 20px; flex: none; }

/* Nút */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 48px;
  padding: 0 var(--s-5);
  border: 0;
  border-radius: var(--r-m);
  background: var(--accent, var(--ink));
  color: var(--on-ink);
  font-weight: 700;
  font-size: var(--fs-17);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }

.btn-quiet {
  background: var(--surface-2);
  color: var(--ink);
}

.btn-ghost {
  min-height: 44px;
  padding: 0 var(--s-3);
  background: transparent;
  color: var(--ink-2);
  font-size: var(--fs-15);
  font-weight: 500;
}

.btn-small {
  min-height: 44px;
  padding: 0 var(--s-4);
  font-size: var(--fs-15);
}

.btn .spin {
  width: 18px;
  height: 18px;
  border-radius: var(--r-full);
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Chọn một trong nhiều */
.choices {
  display: flex;
  gap: var(--s-2);
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(var(--s-4) * -1);
  padding: 0 var(--s-4);
}

.choices::-webkit-scrollbar { display: none; }

.choice {
  flex: none;
  min-height: 44px;
  padding: 0 var(--s-4);
  border: 0;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--fs-15);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.choice[aria-pressed="true"],
.choice[aria-checked="true"] {
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 700;
}

/* Ô nhập */
.field { display: grid; gap: var(--s-2); }

.label {
  font-size: var(--fs-13);
  font-weight: 700;
  color: var(--ink-2);
}

.input {
  width: 100%;
  min-height: 52px;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: var(--surface-2);
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}

.input:focus { outline: none; border-color: var(--focus); background: var(--surface); }
.hint { font-size: var(--fs-13); color: var(--ink-3); }
.hint-row { display: flex; justify-content: space-between; gap: var(--s-3); }
.error-text { font-size: var(--fs-13); color: var(--bad); font-weight: 500; }

/* Thông báo */
.notice {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-m);
  background: var(--bad-soft);
  color: var(--ink);
  font-size: var(--fs-15);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s-5) + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  max-width: calc(100% - var(--s-6));
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-m);
  background: var(--ink);
  color: var(--on-ink);
  font-size: var(--fs-15);
  box-shadow: var(--e-3);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  z-index: 50;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Hướng dẫn (dialog dạng sheet) */
dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--r-l) var(--r-l) 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--e-3);
}

dialog.sheet::backdrop { background: var(--scrim); }

@media (min-width: 720px) {
  dialog.sheet { margin: auto; border-radius: var(--r-l); }
}

.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4) var(--s-4) var(--s-2) var(--s-5);
  background: var(--surface);
}

.sheet-body { padding: 0 var(--s-5) var(--s-6); display: grid; gap: var(--s-5); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); counter-reset: st; }

.steps li {
  counter-increment: st;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: var(--s-3);
  align-items: start;
}

.steps li::before {
  content: counter(st);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: var(--fs-13);
}

.faq { display: grid; gap: var(--s-4); }
.faq h3 { font-family: var(--font-body); font-size: var(--fs-15); font-weight: 700; letter-spacing: 0; margin-bottom: var(--s-1); }
.faq p { color: var(--ink-2); }

.foot {
  padding: var(--s-6) 0 calc(var(--s-6) + env(safe-area-inset-bottom));
  color: var(--ink-3);
  font-size: var(--fs-13);
  display: grid;
  gap: var(--s-2);
}

.foot a { color: var(--ink-2); }

.skeleton {
  background: var(--surface-2);
  border-radius: var(--r-m);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
