:root {
  --bg: #f6f7f3;
  --surface: #ffffff;
  --ink: #202321;
  --muted: #656b68;
  --line: #dfe4df;
  --wood: #6fa43f;
  --fire: #d96f32;
  --earth: #c6923d;
  --metal: #667685;
  --water: #2f8fc6;
  --focus: #26758a;
  --danger: #a84f3f;
  --shadow: 0 24px 70px rgba(36, 45, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(120deg, rgba(111, 164, 63, 0.16), transparent 32%),
    linear-gradient(240deg, rgba(47, 143, 198, 0.14), transparent 35%),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

.protected {
  -webkit-user-select: none;
  user-select: none;
}

.app-shell {
  width: min(100%, 1040px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 34px 18px 22px;
  display: grid;
  align-items: center;
}

.test-card {
  width: min(100%, 820px);
  min-width: 0;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(32, 35, 33, 0.08);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(24px, 5vw, 52px);
}

.screen {
  display: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 260ms ease, transform 260ms ease;
}

.screen.is-active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.is-hidden {
  display: none !important;
}

.brand-line,
.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.86rem;
  letter-spacing: 0;
}

.brand-line {
  justify-content: flex-start;
  margin-bottom: 18px;
}

.brand-mark {
  width: 34px;
  height: 8px;
  display: inline-grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
}

.brand-mark,
.brand-mark::before,
.brand-mark::after {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--wood), var(--fire), var(--earth), var(--metal), var(--water));
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3,
.lead,
.summary-main,
.answer-button {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}

h1 {
  max-width: 720px;
  margin-bottom: 14px;
  font-size: clamp(1.45rem, 2.6vw, 2.05rem);
  line-height: 1.18;
  letter-spacing: 0;
  text-wrap: balance;
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  line-height: 1.12;
  letter-spacing: 0;
  text-wrap: balance;
}

h3 {
  margin: 26px 0 16px;
  font-size: clamp(1.16rem, 2.5vw, 1.55rem);
  line-height: 1.28;
  letter-spacing: 0;
}

.lead {
  max-width: 670px;
  color: var(--muted);
  font-size: clamp(0.98rem, 1.75vw, 1.12rem);
  line-height: 1.55;
}

.access-pending .start-form,
.access-denied .start-form {
  display: none;
}

.access-gate {
  display: none;
  max-width: 670px;
  margin: 28px 0 10px;
  padding: 18px 20px;
  border: 1px solid rgba(47, 111, 125, 0.2);
  border-radius: 8px;
  background: rgba(47, 111, 125, 0.06);
  color: var(--muted);
}

.access-gate h2 {
  margin-bottom: 8px;
  font-size: clamp(1.2rem, 2.2vw, 1.55rem);
  line-height: 1.2;
  color: var(--ink);
}

.access-gate p {
  margin-bottom: 0;
  line-height: 1.52;
}

.access-pending .access-gate,
.access-denied .access-gate {
  display: block;
}

.access-granted .access-gate {
  display: none;
}

.start-form {
  display: grid;
  gap: 18px;
  margin-top: 32px;
}

.start-form label:not(.consent-line) {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fbfcfa;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible,
.answer-button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 111, 125, 0.18);
}

.consent-line {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 12px;
  align-items: start;
  margin-top: 6px;
  color: var(--ink);
  line-height: 1.45;
}

.consent-line input {
  width: 18px;
  min-height: 18px;
  margin-top: 3px;
  accent-color: var(--focus);
}

.consent-details {
  margin: -8px 0 0 32px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.primary-button,
.secondary-button {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  padding: 0 22px;
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, background 180ms ease;
}

.primary-button {
  color: #fff;
  background: #24362f;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary-button:not(:disabled):hover,
.secondary-button:hover,
.answer-button:hover {
  transform: translateY(-1px);
}

.secondary-button {
  color: var(--ink);
  background: #edf1ee;
}

.progress-track {
  width: 100%;
  height: 8px;
  margin: 12px 0 24px;
  overflow: hidden;
  background: #edf0ec;
  border-radius: 999px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--wood), var(--fire), var(--earth), var(--metal), var(--water));
  transition: width 280ms ease;
}

.question-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 0;
}

.back-button {
  min-height: 38px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fbfcfa;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.back-button:hover {
  transform: translateY(-1px);
}

.back-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.answer-status {
  margin: -8px 0 18px;
  padding: 10px 12px;
  border: 1px solid rgba(47, 111, 125, 0.18);
  border-radius: 8px;
  background: rgba(47, 111, 125, 0.06);
  color: var(--focus);
  font-size: 0.9rem;
  line-height: 1.4;
}

.scene-visual {
  position: relative;
  min-height: 220px;
  margin-bottom: 28px;
  overflow: hidden;
  border: 1px solid rgba(32, 35, 33, 0.08);
  border-radius: 8px;
  isolation: isolate;
  --tone-a: rgba(111, 164, 63, 0.38);
  --tone-b: rgba(192, 120, 74, 0.24);
  --tone-c: rgba(47, 143, 198, 0.32);
  background:
    radial-gradient(circle at 18% 22%, var(--tone-a), transparent 30%),
    radial-gradient(circle at 78% 18%, var(--tone-b), transparent 32%),
    radial-gradient(circle at 62% 76%, var(--tone-c), transparent 36%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.86), rgba(242, 246, 244, 0.52));
}

.scene-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0));
}

.scene-grid {
  position: absolute;
  inset: -20%;
  z-index: 1;
  opacity: 0.36;
  background-image:
    linear-gradient(rgba(32, 35, 33, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 35, 33, 0.08) 1px, transparent 1px);
  background-size: 44px 44px;
  transform: rotate(-7deg);
  animation: sceneGridShift 16s linear infinite;
}

.scene-polygon-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.scene-poly {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--size);
  aspect-ratio: 1;
  border: 1px solid rgba(32, 35, 33, 0.12);
  background: var(--fill);
  box-shadow: 0 24px 70px rgba(32, 35, 33, 0.08);
  opacity: 0;
  clip-path: polygon(50% 0%, 92% 28%, 78% 88%, 22% 92%, 7% 34%);
  transform: translate(-50%, -50%) rotate(var(--rotation)) scale(0.72);
  animation:
    scenePolyAppear 900ms ease forwards,
    scenePolyDrift var(--duration) ease-in-out infinite alternate,
    scenePolyMorph var(--morph-duration) ease-in-out infinite alternate;
  animation-delay: var(--delay), var(--delay), var(--delay);
}

.scene-poly::after {
  content: "";
  position: absolute;
  inset: 18%;
  border: 1px solid rgba(255, 255, 255, 0.52);
  clip-path: polygon(50% 4%, 96% 42%, 62% 96%, 12% 72%, 16% 20%);
}

.scene-signal {
  position: absolute;
  z-index: 3;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(32, 35, 33, 0.24), transparent);
  transform-origin: left center;
  animation: sceneSignalMove 5.8s ease-in-out infinite;
}

.scene-signal-a {
  --line-rotation: -8deg;
  width: 54%;
  left: -12%;
  top: 34%;
  transform: rotate(-8deg);
}

.scene-signal-b {
  --line-rotation: 11deg;
  width: 38%;
  right: -8%;
  bottom: 28%;
  transform: rotate(11deg);
  animation-delay: -2s;
}

@keyframes sceneGridShift {
  from { transform: translate3d(0, 0, 0) rotate(-7deg); }
  to { transform: translate3d(44px, 44px, 0) rotate(-7deg); }
}

@keyframes scenePolyAppear {
  to { opacity: 0.92; }
}

@keyframes scenePolyDrift {
  from { transform: translate(-50%, -50%) rotate(var(--rotation)) scale(0.82); }
  to { transform: translate(calc(-50% + var(--drift-x)), calc(-50% + var(--drift-y))) rotate(calc(var(--rotation) + 22deg)) scale(1.08); }
}

@keyframes scenePolyMorph {
  0% { clip-path: polygon(50% 0%, 92% 28%, 78% 88%, 22% 92%, 7% 34%); }
  45% { clip-path: polygon(26% 8%, 86% 10%, 96% 58%, 54% 98%, 8% 72%); }
  100% { clip-path: polygon(48% 6%, 98% 42%, 68% 96%, 14% 82%, 10% 18%); }
}

@keyframes sceneSignalMove {
  0%, 100% { opacity: 0.2; transform: translateX(0) rotate(var(--line-rotation, -8deg)); }
  50% { opacity: 0.72; transform: translateX(34%) rotate(var(--line-rotation, -8deg)); }
}

.scene-kicker {
  margin-bottom: 8px;
  color: var(--focus);
  font-size: 0.84rem;
}

.visual-description,
.situation {
  color: var(--muted);
  line-height: 1.62;
}

.situation {
  padding-left: 16px;
  border-left: 3px solid rgba(47, 143, 198, 0.32);
}

.answers {
  display: grid;
  gap: 12px;
}

.answer-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  color: var(--ink);
  background: #fbfcfa;
  cursor: pointer;
  text-align: left;
  line-height: 1.5;
  transition:
    transform 180ms ease,
    border-color 220ms ease,
    background-color 320ms ease,
    color 180ms ease,
    box-shadow 220ms ease;
}

.answer-button.is-loading {
  pointer-events: none;
  opacity: 0.7;
}

.answer-button.is-selected {
  border-color: var(--answer-state-border, var(--focus));
  color: var(--answer-state-text, var(--ink));
  background: var(--answer-state-bg, rgba(47, 143, 198, 0.08));
  box-shadow: 0 14px 34px color-mix(in srgb, var(--answer-state-bg, var(--focus)) 18%, transparent);
}

.answer-button.is-selected[data-background-state="neutral"] {
  color: var(--ink);
  background: rgba(47, 143, 198, 0.08);
  box-shadow: 0 10px 26px rgba(47, 143, 198, 0.1);
}

.choice-followup {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid rgba(38, 117, 138, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(111, 164, 63, 0.08), transparent 46%),
    linear-gradient(225deg, rgba(47, 143, 198, 0.1), transparent 52%),
    #fbfcfa;
}

.choice-followup-title {
  margin: 0 0 8px;
  color: var(--ink);
  font-weight: 700;
}

.choice-preview {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.48;
}

.choice-control {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.choice-help {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.choice-scale,
.choice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-scale button,
.choice-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.choice-scale button {
  min-width: 64px;
  padding: 0;
  border-radius: 999px;
}

.choice-scale button.is-active {
  color: #fff;
  border-color: var(--focus);
  background: var(--focus);
  box-shadow: 0 8px 22px rgba(31, 107, 74, 0.15);
}

.background-state-matrix-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.background-state-indicator {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(32, 35, 33, 0.16);
  border-radius: 999px;
  background: var(--active-state-color, #fff);
  box-shadow: 0 8px 18px rgba(32, 35, 33, 0.12);
  transition: background-color 0.28s ease, border-color 0.28s ease, box-shadow 0.28s ease, transform 0.28s ease;
}

.background-state-indicator:not([data-background-state="neutral"]) {
  border-color: var(--active-state-color, var(--focus));
  box-shadow: 0 10px 24px color-mix(in srgb, var(--active-state-color, var(--focus)) 34%, transparent);
}

.background-state-indicator[data-background-state="neutral"] {
  border-color: #bfc7c1;
  background: #fff;
  box-shadow: inset 0 0 0 3px rgba(111, 121, 112, 0.18);
}

.background-states {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.background-states button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 40px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  text-align: center;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.background-states button.is-active {
  border-color: var(--state-color, var(--focus));
  background: var(--state-color, var(--focus));
  box-shadow: 0 8px 22px rgba(31, 107, 74, 0.15);
  transition: background-color 0.22s ease, border-color 0.22s ease, color 0.22s ease;
}

.background-states .state-neutral {
  grid-column: 1 / -1;
  justify-content: center;
}

.background-states button[data-background-state="neutral"].is-active {
  color: var(--ink);
  border-color: #bfc7c1;
  background: #fff;
  box-shadow: inset 0 0 0 2px rgba(111, 121, 112, 0.28);
}

.background-states button[data-background-state="inspiration"].is-active,
.background-states button[data-background-state="depletion"].is-active,
.background-states button[data-background-state="habituality"].is-active,
.background-states button[data-background-state="anxiety"].is-active {
  color: var(--ink);
}

.background-states button[data-background-state="aspiration"].is-active,
.background-states button[data-background-state="conviction"].is-active,
.background-states button[data-background-state="apprehension"].is-active,
.background-states button[data-background-state="irritation"].is-active {
  color: #fff;
}

.choice-actions {
  margin-top: 16px;
}

.choice-actions .primary-button,
.choice-actions .secondary-button {
  width: auto;
  flex: 1 1 180px;
}

.result-summary {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 26px;
  align-items: center;
  margin: 26px 0;
}

.donut {
  width: 180px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--wood) 0 20%, var(--fire) 20% 40%, var(--earth) 40% 60%, var(--metal) 60% 80%, var(--water) 80% 100%);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: 50%;
  background: var(--surface);
}

.summary-main {
  margin-bottom: 10px;
  font-size: clamp(1.3rem, 3vw, 2rem);
  font-weight: 700;
}

.summary-text p {
  margin-bottom: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.score-list {
  display: grid;
  gap: 18px;
  margin: 34px 0;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.36fr) minmax(180px, 0.9fr) 52px;
  gap: 22px;
  align-items: center;
}

.score-label {
  font-weight: 650;
  line-height: 1.16;
}

.score-track {
  height: 7px;
  max-width: 760px;
  overflow: hidden;
  border-radius: 999px;
  background: #ecefed;
}

.score-bar {
  height: 100%;
  border-radius: inherit;
  transition: width 300ms ease;
}

.score-value {
  color: var(--muted);
  text-align: right;
}

.report-text {
  margin: 30px 0;
  color: #303532;
  line-height: 1.68;
}

.report-text p {
  margin-bottom: 16px;
}

.print-meta {
  display: none;
}

.print-kicker {
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.print-note {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.result-actions .secondary-button {
  flex: 1 1 180px;
}

.copyright {
  width: min(100%, 820px);
  margin: 14px auto 0;
  color: rgba(32, 35, 33, 0.52);
  font-size: 0.78rem;
  text-align: center;
}

@media (max-width: 680px) {
  .app-shell {
    padding: 16px 12px 18px;
    align-items: start;
  }

  .test-card {
    padding: 22px 16px;
  }

  .brand-line {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 14px;
  }

  h1 {
    font-size: clamp(1.35rem, 6vw, 1.68rem);
    line-height: 1.2;
  }

  h2 {
    font-size: clamp(1.35rem, 6vw, 1.85rem);
    line-height: 1.16;
  }

  .lead {
    font-size: 0.98rem;
    line-height: 1.5;
  }

  .background-states {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .background-state-matrix-row {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 8px;
  }

  .background-state-indicator {
    width: 18px;
    height: 18px;
  }

  .background-states button {
    min-height: 58px;
    padding: 6px 5px;
    white-space: normal;
    line-height: 1.02;
    font-size: clamp(0.62rem, 2.45vw, 0.74rem);
  }

  .result-summary {
    grid-template-columns: 1fr;
  }

  .donut {
    width: 150px;
  }

  .score-row {
    grid-template-columns: 1fr 48px;
    gap: 8px 12px;
  }

  .score-label {
    grid-column: 1 / -1;
  }
}

@media print {
  @page {
    margin: 16mm;
  }

  body {
    background: #fff;
    color: #151816;
  }

  body.print-report-mode * {
    visibility: hidden !important;
  }

  body.print-report-mode #resultScreen,
  body.print-report-mode #resultScreen * {
    visibility: visible !important;
    user-select: text !important;
  }

  body.print-report-mode #resultScreen {
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    max-width: none;
    min-height: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  body.print-report-mode .print-meta {
    display: block;
    margin-bottom: 12mm;
    padding-bottom: 6mm;
    border-bottom: 1px solid #d7ddd7;
  }

  body.print-report-mode .print-meta p {
    visibility: visible !important;
  }

  body.print-report-mode .brand-line {
    display: none !important;
  }

  .result-actions,
  .copyright {
    display: none !important;
  }

  .score-track,
  .score-bar,
  .donut {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .report-text {
    color: #151816;
    line-height: 1.55;
  }

  .result-summary,
  .score-row,
  .report-text p {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .score-list {
    gap: 10px;
    margin: 22px 0;
  }

  .score-row {
    grid-template-columns: minmax(145px, 0.32fr) minmax(180px, 1fr) 46px;
    gap: 14px;
  }

  h2 {
    font-size: 24pt;
  }
}
