:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --panel-strong: #f1eee6;
  --ink: #1f2428;
  --muted: #68706a;
  --line: #d9d2c4;
  --accent: #166a72;
  --accent-dark: #0f4d55;
  --rose: #8c4351;
  --gold: #a76f18;
  --shadow: 0 18px 45px rgba(31, 36, 40, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1480px;
  margin: 0 auto;
}

.input-panel,
.output-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  align-self: start;
  position: sticky;
  top: 24px;
  padding: 20px;
}

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.05;
}

h2 {
  font-size: 22px;
  line-height: 1.18;
}

h3 {
  font-size: 16px;
  line-height: 1.25;
}

.person-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.field input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(22, 106, 114, 0.14);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.primary-button,
.ghost-button {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  flex: 1;
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  background: var(--panel-strong);
  border-color: var(--line);
  color: var(--ink);
  padding: 0 12px;
}

.ghost-button:hover {
  border-color: var(--accent);
}

.ghost-button.is-success {
  border-color: rgba(22, 106, 114, 0.35);
  background: rgba(22, 106, 114, 0.12);
  color: var(--accent-dark);
}

.ghost-button.is-error {
  border-color: rgba(140, 67, 81, 0.45);
  background: rgba(140, 67, 81, 0.1);
  color: var(--rose);
}

.output-panel {
  min-height: calc(100vh - 48px);
  padding: 20px;
}

.empty-state {
  display: grid;
  min-height: 300px;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.report-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.report-header p {
  color: var(--muted);
  margin-bottom: 0;
}

.report-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.report-badges span {
  border: 1px solid rgba(22, 106, 114, 0.22);
  border-radius: 999px;
  background: rgba(22, 106, 114, 0.08);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
}

.interpretive-note {
  display: grid;
  gap: 5px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid rgba(195, 153, 80, 0.4);
  border-radius: 8px;
  background: rgba(195, 153, 80, 0.11);
}

.interpretive-note b {
  color: var(--accent-dark);
}

.interpretive-note p {
  margin-bottom: 0;
  line-height: 1.45;
}

.scenario-principle {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding: 16px;
  border: 1px solid rgba(22, 106, 114, 0.35);
  border-radius: 8px;
  background: #fff;
}

.scenario-principle h2 {
  margin-bottom: 0;
  color: var(--accent-dark);
}

.scenario-principle p {
  max-width: 980px;
  margin-bottom: 0;
  line-height: 1.55;
}

.scenario-principle blockquote {
  max-width: 980px;
  margin: 4px 0 0;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: rgba(22, 106, 114, 0.08);
  color: var(--accent-dark);
  font-weight: 800;
  line-height: 1.45;
}

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

.code-card,
.analysis-band,
.plain-report {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.code-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.code-card.primary {
  border-color: rgba(22, 106, 114, 0.45);
}

.role-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.code-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
}

.code-number {
  color: var(--accent-dark);
  font-size: 32px;
  font-weight: 850;
}

.code-name {
  font-size: 18px;
  font-weight: 800;
}

.metric-list {
  display: grid;
  gap: 8px;
}

.metric {
  display: grid;
  gap: 3px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.metric b {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metric span {
  line-height: 1.42;
}

.analysis-band {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding: 16px;
}

.extended-report {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding: 16px;
  border: 1px solid rgba(22, 106, 114, 0.32);
  border-radius: 8px;
  background: #fff;
}

.narrative-report {
  display: grid;
  gap: 16px;
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.section-title h2 {
  margin-bottom: 0;
}

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

.formula-card,
.extended-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.formula-card {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.formula-card.strong {
  border-color: rgba(22, 106, 114, 0.45);
  background: rgba(22, 106, 114, 0.08);
}

.formula-card b {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.formula-card span {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.28;
}

.extended-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.extended-card.self {
  background: #fff;
}

.extended-card-header h3,
.extended-columns h4 {
  margin-bottom: 0;
}

.extended-columns > div {
  display: grid;
  gap: 8px;
}

.extended-columns p {
  margin-bottom: 0;
  line-height: 1.45;
}

.extended-columns ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
}

.deep-profile-highlights,
.deep-parent-echo {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.deep-parent-echo {
  display: grid;
  gap: 8px;
}

.deep-parent-echo h4 {
  margin-bottom: 0;
}

.deep-parent-echo ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
}

.scenario-differentiation {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid rgba(22, 106, 114, 0.28);
  border-radius: 8px;
  background: rgba(22, 106, 114, 0.05);
}

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

.scenario-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.scenario-card.self {
  border-color: rgba(22, 106, 114, 0.42);
}

.scenario-card.inherited {
  background: var(--panel-strong);
}

.scenario-card h3,
.scenario-card h4 {
  margin-bottom: 0;
}

.scenario-card p {
  margin-bottom: 0;
  line-height: 1.5;
}

.scenario-card ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
}

.scenario-question {
  color: var(--accent-dark);
  font-weight: 800;
}

.vector-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.vector-pills span {
  border: 1px solid rgba(22, 106, 114, 0.22);
  border-radius: 999px;
  background: rgba(22, 106, 114, 0.07);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
}

.narrative-flow {
  display: grid;
  gap: 18px;
}

.narrative-section {
  max-width: 880px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.narrative-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.narrative-section h3 {
  margin-bottom: 10px;
  color: var(--accent-dark);
  font-size: 19px;
}

.narrative-section p {
  margin-bottom: 12px;
  line-height: 1.62;
}

.narrative-section blockquote {
  margin: 14px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: rgba(22, 106, 114, 0.08);
  color: var(--accent-dark);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.45;
}

.narrative-section ul {
  display: grid;
  gap: 8px;
  margin: 0 0 4px;
  padding-left: 20px;
}

.narrative-section li {
  line-height: 1.48;
}

.narrative-shadow {
  color: var(--rose);
  font-weight: 700;
}

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

.analysis-block {
  padding: 14px;
  border-radius: 8px;
  background: var(--panel-strong);
}

.analysis-block ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.strategy-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 20px;
}

.strategy-list li::marker {
  color: var(--gold);
  font-weight: 800;
}

.plain-report {
  margin-top: 14px;
  overflow: hidden;
}

.plain-report-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-strong);
}

.plain-report-header h3 {
  margin-bottom: 0;
}

textarea {
  display: block;
  width: 100%;
  min-height: 300px;
  padding: 16px;
  border: 0;
  resize: vertical;
  color: var(--ink);
  background: #fff;
  line-height: 1.45;
}

.error-box {
  border: 1px solid rgba(140, 67, 81, 0.45);
  border-radius: 8px;
  background: rgba(140, 67, 81, 0.08);
  color: var(--rose);
  padding: 14px;
}

@media (max-width: 980px) {
  .workspace,
  .card-grid,
  .analysis-grid,
  .formula-grid,
  .extended-grid,
  .extended-columns,
  .scenario-grid {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }

  .output-panel {
    min-height: 420px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .title-row,
  .report-header,
  .plain-report-header,
  .section-title {
    grid-template-columns: 1fr;
    display: grid;
  }

  h1 {
    font-size: 24px;
  }

  .actions {
    flex-direction: column;
  }
}
