:root {
  color-scheme: light;
  --ink: #171714;
  --muted: #676c64;
  --faint: #8f968b;
  --line: #deded6;
  --paper: #f7f6f0;
  --panel: #ffffff;
  --panel-strong: #f2f5ee;
  --green: #26a64d;
  --green-dark: #168c3b;
  --green-soft: #e8f7ec;
  --amber: #c47b28;
  --coral: #d75d45;
  --blue: #526c9c;
  --shadow: 0 20px 54px rgba(23, 23, 20, 0.08);
  --shadow-soft: 0 8px 24px rgba(23, 23, 20, 0.06);
  --display-font: "Instrument Serif", ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  font-family:
    "SF Pro Text", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

ul {
  padding-left: 1.2rem;
}

.topbar {
  position: sticky;
  top: 10px;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(220px, 1fr);
  gap: 20px;
  align-items: center;
  width: min(1100px, calc(100% - 48px));
  min-height: 58px;
  margin: 12px auto 0;
  padding: 8px 12px;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  width: max-content;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(23, 23, 20, 0.12);
  border-radius: 7px;
  color: white;
  background: #171714;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.16);
  font-family: var(--display-font);
  font-size: 1.12rem;
  font-weight: 400;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.05;
}

.brand small {
  margin-top: 3px;
  color: var(--faint);
  font-size: 0.75rem;
  font-weight: 600;
}

.topnav {
  display: inline-flex;
  gap: 6px;
  justify-content: center;
  padding: 5px;
  border: 1px solid rgba(23, 23, 20, 0.08);
  border-radius: 999px;
  background: #f8f8f4;
}

.topnav a {
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.topnav a:hover,
.topnav a:focus-visible {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 5px rgba(23, 23, 20, 0.08);
  outline: none;
}

.status-strip {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  color: var(--faint);
  font-size: 0.78rem;
  font-weight: 650;
}

.status-strip span,
.card-title,
.tool-buttons,
.letter-meta,
.upload-row,
.action-row,
.toggle-row,
.section-heading,
.letter-toolbar,
.history-item-header {
  display: flex;
  align-items: center;
}

.status-strip span {
  gap: 6px;
  white-space: nowrap;
}

i[data-lucide] {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

main {
  width: min(1180px, calc(100% - clamp(24px, 5vw, 72px)));
  margin: 58px auto 72px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.88fr) minmax(430px, 1.12fr);
  gap: 22px;
  align-items: start;
}

.source-panel,
.output-panel,
.history-panel,
.playbook-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.source-panel,
.output-panel {
  padding: clamp(18px, 2.8vw, 30px);
}

.panel-heading,
.section-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 27px;
  margin: 0 0 12px;
  padding: 4px 10px;
  border: 1px solid rgba(38, 166, 77, 0.22);
  border-radius: 999px;
  color: var(--green-dark);
  background: var(--green-soft);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 620px;
  margin-bottom: 0;
  font-family: var(--display-font);
  font-size: clamp(2.85rem, 5vw, 4.9rem);
  font-weight: 400;
  line-height: 0.91;
  letter-spacing: 0;
}

h1 span {
  color: var(--green);
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.18rem, 1.5vw, 1.56rem);
  line-height: 1.1;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 0.96rem;
}

.hero-lede {
  max-width: 470px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.45;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.field-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

label span {
  line-height: 1.2;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid rgba(23, 23, 20, 0.11);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  outline: none;
  box-shadow: inset 0 1px 2px rgba(23, 23, 20, 0.02);
  font-weight: 500;
}

input,
select {
  min-height: 42px;
  padding: 0 11px;
  font-size: 0.88rem;
}

textarea {
  resize: vertical;
  min-height: 172px;
  padding: 12px 13px;
  font-size: 0.88rem;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(38, 166, 77, 0.58);
  box-shadow: 0 0 0 3px rgba(38, 166, 77, 0.12);
}

.textarea-label {
  margin-bottom: 12px;
}

.upload-row {
  justify-content: space-between;
  gap: 12px;
  margin: -2px 0 14px;
}

.upload-row p {
  margin: 0;
  color: var(--faint);
  font-size: 0.76rem;
  line-height: 1.35;
}

.file-drop {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-width: min(260px, 100%);
  width: max-content;
  padding: 10px 12px;
  border: 1px dashed rgba(38, 166, 77, 0.36);
  border-radius: 8px;
  color: var(--green-dark);
  background: linear-gradient(#ffffffcc, #eef8f0cc);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.file-drop.is-dragging {
  border-color: var(--green);
  background: rgba(38, 166, 77, 0.12);
  box-shadow: inset 0 0 0 2px rgba(38, 166, 77, 0.12);
}

.file-drop span {
  display: grid;
  gap: 2px;
}

.file-drop strong {
  line-height: 1.1;
}

.file-drop small {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  line-height: 1.2;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

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

.toggle-row {
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0 18px;
}

.toggle-row label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  width: max-content;
  padding: 7px 10px;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.86);
  font-size: 0.78rem;
  cursor: pointer;
  letter-spacing: 0;
}

.toggle-row input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--green);
}

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

.action-row .primary-button,
.action-row .secondary-button {
  flex: 1 1 150px;
}

button,
.secondary-button,
.primary-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 15px;
  font-size: 0.88rem;
}

.primary-button {
  color: white;
  background: var(--green);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.2),
    0 8px 18px rgba(38, 166, 77, 0.2);
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--green-dark);
  outline: none;
}

.secondary-button {
  border: 1px solid rgba(23, 23, 20, 0.11);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
}

.secondary-button:hover,
.secondary-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  border-color: rgba(38, 166, 77, 0.36);
  background: var(--green-soft);
  outline: none;
}

.compact-button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
}

.output-panel {
  position: sticky;
  top: 86px;
}

.score-band {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
  padding: 16px;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  background: linear-gradient(135deg, #f9fbf7, #fff);
}

.score-gauge {
  position: relative;
  display: grid;
  width: 118px;
  height: 118px;
  place-items: center;
}

.score-gauge svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-gauge circle {
  fill: none;
  stroke-width: 10;
}

.gauge-track {
  stroke: #e7e9e2;
}

.gauge-value {
  stroke: var(--green);
  stroke-linecap: round;
  stroke-dasharray: 302;
  stroke-dashoffset: 302;
  transition: stroke-dashoffset 280ms ease;
}

.score-gauge div {
  position: relative;
  display: grid;
  place-items: center;
}

.score-gauge strong {
  font-family: var(--display-font);
  font-size: 2.35rem;
  font-weight: 400;
  line-height: 1;
}

.score-gauge span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.score-copy p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.insight-card {
  min-height: 132px;
  padding: 14px;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.card-title {
  gap: 8px;
  margin-bottom: 12px;
}

.card-title h3 {
  margin: 0;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-list span {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--green-dark);
  background: var(--green-soft);
  font-size: 0.78rem;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.chip-list.warning span {
  color: #8d4b16;
  background: rgba(217, 139, 36, 0.14);
}

.chip-list .empty-state {
  color: var(--muted);
  background: transparent;
  padding: 0;
}

.letter-shell {
  margin-top: 12px;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.letter-toolbar {
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid rgba(23, 23, 20, 0.08);
}

.letter-toolbar h2 {
  font-size: 1.18rem;
}

.tool-buttons {
  gap: 7px;
}

#letterOutput {
  min-height: 520px;
  border: 0;
  border-radius: 0;
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  font-size: 1.01rem;
  line-height: 1.65;
}

#letterOutput:focus {
  box-shadow: inset 0 0 0 3px rgba(38, 166, 77, 0.12);
}

.letter-meta {
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid rgba(23, 23, 20, 0.08);
  color: var(--faint);
  font-size: 0.78rem;
  font-weight: 740;
}

.below-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(420px, 1.1fr);
  gap: 20px;
  margin-top: 20px;
}

.history-panel,
.playbook-panel {
  padding: clamp(18px, 3vw, 24px);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  text-align: left;
}

.history-item:hover {
  border-color: rgba(38, 166, 77, 0.36);
}

.history-item-header {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.history-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item small,
.history-item p {
  color: var(--muted);
}

.history-item p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.empty-state {
  color: var(--muted);
}

.rule-grid {
  display: grid;
  gap: 12px;
}

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

.rule-grid article {
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

.rule-grid article {
  padding: 16px;
}

.rule-grid i {
  margin-bottom: 12px;
  color: var(--green);
}

.rule-grid p {
  color: var(--muted);
  line-height: 1.5;
}

.tag {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 5px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--green);
  font-size: 0.73rem;
  font-weight: 850;
}

.tag.subtle {
  color: var(--ink);
  background: rgba(65, 105, 168, 0.13);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(23, 23, 20, 0.1);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
    top: 0;
    width: calc(100% - 24px);
    margin-top: 8px;
  }

  .topnav {
    width: 100%;
  }

  .status-strip {
    justify-content: flex-start;
  }

  .workspace,
  .below-grid {
    grid-template-columns: 1fr;
  }

  .output-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  main {
    width: min(100% - 24px, 1480px);
    margin-top: 16px;
  }

  .topbar {
    padding: 10px;
  }

  .topnav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .topnav a {
    padding: 8px 6px;
    text-align: center;
  }

  .status-strip {
    flex-wrap: wrap;
  }

  h1 {
    font-size: 2.82rem;
    line-height: 0.94;
  }

  .field-grid.compact,
  .controls,
  .score-band,
  .insight-grid,
  .rule-grid {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .section-heading,
  .letter-toolbar,
  .upload-row,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .tool-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .icon-button {
    width: 100%;
  }

  #letterOutput {
    min-height: 420px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .source-panel,
  .score-band,
  .insight-grid,
  .below-grid,
  .letter-toolbar,
  .letter-meta,
  .toast {
    display: none !important;
  }

  main,
  .workspace,
  .output-panel,
  .letter-shell,
  #letterOutput {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  #letterOutput {
    min-height: auto;
    white-space: pre-wrap;
  }
}
