:root {
  --bg-1: #f3f7fb;
  --bg-2: #e9f1f7;
  --surface: #ffffff;
  --ink: #0f2436;
  --ink-soft: #48627a;
  --muted: #8095a7;
  --line: #dbe6ef;
  --line-soft: #eaf1f7;
  --brand: #0f6f8f;
  --brand-strong: #0a5872;
  --brand-soft: #e7f3f8;
  --good: #1a8a5a;
  --warn: #b4611b;
  --alert: #c0392b;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow-sm: 0 2px 8px rgba(15, 36, 54, 0.06);
  --shadow: 0 14px 40px rgba(15, 36, 54, 0.1);
  --font: -apple-system, BlinkMacSystemFont, "Noto Sans Thai", "Sarabun",
    "Helvetica Neue", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -10%, #ffffff 0%, rgba(255, 255, 255, 0) 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 20px) 18px calc(env(safe-area-inset-bottom) + 24px);
}

.screen {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: rise 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.screen--center {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 18px;
  min-height: 80vh;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Typography --------------------------------------------------------------- */
.badge-logo {
  display: inline-block;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 8px 16px;
  border-radius: 999px;
}

.welcome-title,
.title-th {
  margin: 0;
  font-size: clamp(30px, 5.4vw, 46px);
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.lead {
  font-size: clamp(18px, 2.7vw, 22px);
  line-height: 1.7;
  color: var(--ink-soft);
  max-width: 620px;
  margin: 0;
}

.muted {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

/* Welcome facts ------------------------------------------------------------ */
.facts {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.fact {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px 22px;
  min-width: 120px;
  box-shadow: var(--shadow-sm);
}
.fact-num {
  font-size: 26px;
  font-weight: 800;
  color: var(--brand);
}
.fact-label {
  font-size: 14px;
  color: var(--muted);
}

/* Buttons ------------------------------------------------------------------ */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 15px 28px;
  font-size: 19px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  min-height: 54px;
  transition: transform 0.08s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}
.btn:active {
  transform: scale(0.985);
}
.btn--primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 111, 143, 0.28);
}
.btn--primary:hover {
  background: var(--brand-strong);
}
.btn--ghost {
  background: transparent;
  color: var(--brand);
  border-color: var(--line);
}
.btn--lg {
  padding: 18px 44px;
  font-size: 21px;
  min-height: 62px;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
.btn:focus-visible,
.scale-btn:focus-visible,
.chip:focus-visible,
.input:focus-visible {
  outline: 3px solid rgba(15, 111, 143, 0.35);
  outline-offset: 3px;
}

/* Progress ----------------------------------------------------------------- */
.progress {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 10px;
  z-index: 5;
}
.progress-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.progress-text {
  font-size: 18px;
  font-weight: 800;
  color: var(--brand);
}
.progress-remaining {
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}
.progress-track {
  height: 10px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--brand), #1597bd);
  border-radius: 999px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.progress-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.dot {
  width: 34px;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  transition: background-color 0.25s ease, transform 0.25s ease;
}
.dot--done {
  background: var(--brand);
}
.dot--current {
  background: #1597bd;
  transform: scaleY(1.9);
}

/* Question ----------------------------------------------------------------- */
.q-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  justify-content: center;
}
.q-chip {
  margin: 0;
  display: inline-block;
  align-self: flex-start;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 7px 14px;
  border-radius: 999px;
}
.q-question {
  margin: 0;
  font-size: clamp(24px, 4.3vw, 36px);
  line-height: 1.4;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.q-helper {
  margin: 0;
  font-size: 16px;
  color: var(--muted);
  line-height: 1.6;
}

.scale {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.scale-btn {
  font-family: inherit;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 800;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 68px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, border-color 0.12s ease, background-color 0.12s ease,
    color 0.12s ease;
}
.scale-btn:hover {
  border-color: #b9d4e2;
}
.scale-btn.is-selected {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 12px 26px rgba(15, 111, 143, 0.3);
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 8px;
}
.scale-label {
  font-size: 16px;
  font-weight: 700;
}
.scale-label--low {
  color: var(--alert);
}
.scale-label--high {
  color: var(--good);
}

.error-text {
  color: var(--alert);
  font-weight: 700;
  margin: 6px 0 0;
}
.error-text--prominent {
  background: #fdecec;
  border: 1px solid #f3c4c4;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.q-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

/* Concerns ----------------------------------------------------------------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 6px 0 10px;
}
.chip {
  font-family: inherit;
  font-size: 18px;
  padding: 13px 22px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-height: 50px;
  box-shadow: var(--shadow-sm);
  transition: all 0.12s ease;
}
.chip:hover {
  border-color: #b9d4e2;
}
.chip.is-selected {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-strong);
  font-weight: 800;
}
.field-label {
  font-size: 18px;
  font-weight: 700;
  margin-top: 8px;
  text-align: left;
}
.textarea {
  font-family: inherit;
  font-size: 18px;
  padding: 15px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  resize: vertical;
  width: 100%;
}
.textarea:focus {
  outline: 3px solid rgba(15, 111, 143, 0.25);
  border-color: var(--brand);
}
.char-count {
  text-align: right;
  color: var(--muted);
  font-size: 14px;
}

/* Standalone HN entry ------------------------------------------------------ */
.hn-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 420px;
  align-items: stretch;
  margin-top: 6px;
}
.hn-form .field-label {
  text-align: left;
}
.input {
  font-family: inherit;
  font-size: 22px;
  padding: 15px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: center;
  letter-spacing: 0.08em;
}
.input--lg {
  min-height: 58px;
}
.input:focus {
  outline: 3px solid rgba(15, 111, 143, 0.25);
  border-color: var(--brand);
}

/* Result ------------------------------------------------------------------- */
.result-header {
  display: flex;
  align-items: center;
  gap: 14px;
}
.check-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #e8f6ef;
  color: var(--good);
  flex: none;
}
.check-circle--lg {
  width: 76px;
  height: 76px;
}
.result-title {
  font-size: clamp(26px, 4.6vw, 38px);
  margin: 0;
  font-weight: 800;
}
.result-opening {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.result-scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.result-scores li {
  display: grid;
  grid-template-columns: minmax(120px, 1.1fr) 2fr auto;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 19px;
  box-shadow: var(--shadow-sm);
}
.score-name {
  font-weight: 600;
}
.score-bar {
  height: 10px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
}
.score-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.score-fill[data-band="needs_attention"] {
  background: var(--alert);
}
.score-fill[data-band="worth_improving"] {
  background: var(--warn);
}
.score-fill[data-band="doing_well"],
.score-fill[data-band="strong"] {
  background: var(--good);
}
.score-value {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 58px;
  text-align: right;
}
.score-value[data-band="needs_attention"] {
  color: var(--alert);
}
.score-value[data-band="worth_improving"] {
  color: var(--warn);
}
.score-value[data-band="doing_well"],
.score-value[data-band="strong"] {
  color: var(--good);
}

.result-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.result-block-title {
  margin: 0 0 8px;
  font-size: 19px;
  color: var(--brand);
  font-weight: 800;
}
.result-block-body {
  font-size: 18px;
  line-height: 1.8;
  color: var(--ink-soft);
  white-space: pre-line;
  margin: 0;
}
.result-focus-domains {
  font-size: 23px;
  font-weight: 800;
  margin: 0 0 10px;
}
.result-next {
  font-size: 19px;
  line-height: 1.7;
  background: var(--brand-soft);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  margin: 0;
  color: var(--brand-strong);
  font-weight: 600;
}
.safety-note {
  font-size: 16px;
  color: var(--ink-soft);
  border-left: 4px solid var(--warn);
  padding-left: 14px;
  margin: 0;
}
.disclaimer {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

/* Overlay / misc ----------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 36, 54, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.overlay-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 30px;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
}
.overlay-card h3 {
  margin-top: 0;
}
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Responsive --------------------------------------------------------------- */
@media (max-width: 560px) {
  .scale {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .q-footer {
    flex-direction: column-reverse;
  }
  .q-footer .btn {
    width: 100%;
  }
  .result-scores li {
    grid-template-columns: 1fr auto;
  }
  .result-scores .score-bar {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
