:root {
  color-scheme: dark;
  --ink: #16120e;
  --ink-2: #211914;
  --paper: #f5ead9;
  --muted: #bda994;
  --line: rgba(245, 234, 217, 0.18);
  --line-strong: rgba(245, 234, 217, 0.34);
  --red: #d65a42;
  --gold: #d6a64f;
  --jade: #6aa28d;
  --blue: #5c79a8;
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.42);
  font-family: "Noto Serif SC", "Songti SC", "Microsoft YaHei", serif;
}

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

html {
  min-height: 100%;
  background: var(--ink);
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--paper);
  background:
    linear-gradient(110deg, rgba(214, 90, 66, 0.2), transparent 28%),
    radial-gradient(circle at 86% 12%, rgba(106, 162, 141, 0.28), transparent 34%),
    radial-gradient(circle at 16% 78%, rgba(214, 166, 79, 0.2), transparent 36%),
    var(--ink);
}

button,
select,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.mbti-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0 42px;
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.45fr);
  gap: 24px;
  align-items: stretch;
}

.intro-panel,
.workbench {
  position: relative;
  border: 1px solid var(--line);
  background:
    linear-gradient(145deg, rgba(245, 234, 217, 0.1), rgba(245, 234, 217, 0.035)),
    rgba(22, 18, 14, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.intro-panel {
  min-height: 640px;
  padding: 28px;
  overflow: hidden;
}

.intro-panel::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(214, 166, 79, 0.26);
  pointer-events: none;
}

.intro-panel::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  right: -72px;
  bottom: -54px;
  border: 1px solid rgba(245, 234, 217, 0.22);
  border-radius: 50%;
  box-shadow:
    0 0 0 24px rgba(214, 90, 66, 0.06),
    0 0 0 58px rgba(106, 162, 141, 0.05);
}

.brand-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.back-link {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--paper);
  text-decoration: none;
  border: 1px solid var(--line-strong);
  background: rgba(245, 234, 217, 0.07);
  transition: transform 180ms ease, border-color 180ms ease;
}

.back-link:focus-visible,
.primary-action:focus-visible,
.secondary-action:focus-visible,
.add-person:focus-visible,
.remove-person:focus-visible,
.topic-card:focus-within,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(214, 166, 79, 0.82);
  outline-offset: 3px;
}

.back-link:hover {
  transform: translateX(-2px);
  border-color: rgba(214, 166, 79, 0.72);
}

.brand-mark {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow {
  position: relative;
  z-index: 1;
  margin: 112px 0 18px;
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.intro-title {
  position: relative;
  z-index: 1;
  max-width: 13em;
  margin: 0;
  color: #fff6e9;
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 1.12;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.intro-copy {
  position: relative;
  z-index: 1;
  max-width: 28rem;
  margin: 22px 0 0;
  color: #d8c6af;
  font-size: 1rem;
  line-height: 1.85;
  overflow-wrap: anywhere;
}

.workbench {
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr);
  gap: 18px;
  padding: 24px;
  min-width: 0;
}

.consult-form {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.people-section {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.people-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.people-header span {
  color: #fff2df;
  font-size: 0.95rem;
  font-weight: 800;
}

.people-list {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.person-card {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(245, 234, 217, 0.16);
  background:
    linear-gradient(135deg, rgba(214, 166, 79, 0.08), transparent 44%),
    rgba(10, 8, 6, 0.25);
}

.person-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.person-card__head strong {
  color: var(--gold);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.person-card .form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field span,
.question-set legend {
  color: #fff2df;
  font-size: 0.95rem;
  font-weight: 700;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--paper);
  background-color: rgba(10, 8, 6, 0.58);
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

select {
  min-height: 48px;
  padding: 0 40px 0 14px;
  appearance: none;
  border-radius: 0;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) 21px,
    calc(100% - 14px) 21px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

textarea {
  min-height: 138px;
  resize: vertical;
  padding: 14px;
  line-height: 1.7;
  border-radius: 0;
  overflow-wrap: anywhere;
}

textarea::placeholder {
  color: rgba(245, 234, 217, 0.42);
}

select:focus,
textarea:focus {
  border-color: rgba(214, 166, 79, 0.72);
  box-shadow: 0 0 0 3px rgba(214, 166, 79, 0.18);
  background: rgba(10, 8, 6, 0.68);
}

.question-set {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.question-set legend {
  grid-column: 1 / -1;
  width: 100%;
  margin-bottom: 8px;
  white-space: nowrap;
  writing-mode: horizontal-tb;
}

.topic-card {
  position: relative;
  min-height: 74px;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(245, 234, 217, 0.055);
  color: #e9d8c1;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.topic-card input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.topic-card:has(input:checked) {
  color: #1a120b;
  border-color: transparent;
  background: linear-gradient(135deg, var(--gold), #eecb78);
}

.topic-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
}

.action-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-action,
.secondary-action,
.add-person,
.remove-person {
  min-height: 48px;
  border: 1px solid transparent;
  padding: 0 22px;
  cursor: pointer;
  border-radius: 0;
  transition: transform 180ms ease, filter 180ms ease, border-color 180ms ease;
}

.primary-action {
  flex: 1 1 180px;
  color: #170f08;
  font-weight: 800;
  background: linear-gradient(135deg, var(--red), var(--gold));
}

.secondary-action {
  color: var(--paper);
  background: rgba(245, 234, 217, 0.06);
  border-color: var(--line);
}

.add-person,
.remove-person {
  min-height: 38px;
  color: var(--paper);
  background: rgba(245, 234, 217, 0.075);
  border-color: var(--line);
  white-space: nowrap;
}

.add-person {
  color: #170f08;
  font-weight: 800;
  background: linear-gradient(135deg, var(--jade), var(--gold));
}

.remove-person {
  padding: 0 14px;
  color: #f2c7bd;
}

.primary-action:hover,
.secondary-action:hover,
.add-person:hover,
.remove-person:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.primary-action:disabled {
  cursor: progress;
  transform: none;
  filter: grayscale(0.35);
  opacity: 0.7;
}

.status-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-line.is-error {
  color: #ffb0a1;
}

.answer-panel {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(106, 162, 141, 0.14), transparent 44%),
    rgba(10, 8, 6, 0.35);
  min-height: 280px;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.answer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.answer-header span {
  color: #fff2df;
  font-weight: 800;
}

.answer-header small {
  min-width: 0;
  color: var(--muted);
  text-align: right;
  overflow-wrap: anywhere;
}

.answer-output {
  min-width: 0;
  padding: 20px;
  color: #efe0cd;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.answer-output p {
  margin: 0;
}

.answer-output .placeholder {
  color: rgba(245, 234, 217, 0.48);
}

.answer-output.is-loading::before {
  content: "";
  width: 30px;
  height: 30px;
  display: block;
  margin-bottom: 14px;
  border: 2px solid rgba(245, 234, 217, 0.22);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

@media (max-width: 900px) {
  .mbti-shell {
    grid-template-columns: 1fr;
  }

  .intro-panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .mbti-shell {
    width: min(100% - 20px, 1180px);
    padding: 10px 0 28px;
  }

  .intro-panel,
  .workbench {
    padding: 18px;
  }

  .intro-panel {
    min-height: auto;
  }

  .eyebrow {
    margin-top: 56px;
  }

  .intro-title {
    max-width: 100%;
    font-size: clamp(1.75rem, 9vw, 2.45rem);
    line-height: 1.18;
  }

  .intro-copy {
    font-size: 0.95rem;
  }

  .question-set legend {
    display: block;
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
  }

  .form-grid,
  .question-set {
    grid-template-columns: 1fr;
  }

  .topic-card {
    min-height: 52px;
  }

  .answer-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .answer-header small {
    text-align: left;
  }
}

@media (max-width: 390px) {
  .brand-row {
    gap: 10px;
  }

  .brand-mark {
    font-size: 0.65rem;
    letter-spacing: 0.1em;
  }

  .intro-panel {
    padding-bottom: 18px;
  }
}

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