:root {
  --bg: #f7f5ee;
  --paper: #fffdf7;
  --ink: #20231f;
  --muted: #5d635b;
  --line: #d9d4c7;
  --soft: #ede8da;
  --green: #1f8a58;
  --green-2: #d9f2df;
  --blue: #146c94;
  --yellow: #f1c84b;
  --coral: #d85f45;
  --shadow: 0 24px 80px rgba(32, 35, 31, 0.12);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
}

body.focus-mode {
  --bg: #f1efe7;
  --paper: #fffefb;
  --soft: #e7e1d1;
}

a {
  color: inherit;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 16px;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  z-index: 20;
}

.skip-link:focus {
  top: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(18px, 4vw, 48px);
  background: rgba(247, 245, 238, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 6px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  gap: 18px;
  color: var(--muted);
  font-size: 14px;
}

.nav a {
  text-decoration: none;
}

.nav a:hover {
  color: var(--ink);
}

.theme-toggle,
.copy-button,
.mode-switch button,
button,
select,
input {
  font: inherit;
}

.theme-toggle,
.copy-button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.section {
  padding: clamp(56px, 8vw, 104px) clamp(18px, 5vw, 72px);
  max-width: 1240px;
  margin: 0 auto;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: clamp(32px, 5vw, 72px);
  align-items: center;
  min-height: calc(100vh - 72px);
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--green);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
}

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

h1 {
  max-width: 760px;
  font-size: clamp(42px, 6vw, 82px);
  line-height: 0.95;
  letter-spacing: 0;
  margin-bottom: 22px;
}

h2 {
  font-size: clamp(30px, 4vw, 54px);
  line-height: 1.02;
  letter-spacing: 0;
  margin-bottom: 16px;
}

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

.lead {
  max-width: 680px;
  color: var(--muted);
  font-size: clamp(18px, 2vw, 23px);
}

.hero-actions,
.trust-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 999px;
  padding: 12px 18px;
  border: 1px solid var(--line);
  text-decoration: none;
  cursor: pointer;
  font-weight: 750;
}

.button.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

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

.trust-row span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 253, 247, 0.6);
  font-size: 13px;
}

.loop-machine {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.machine-header,
.output-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
}

.machine-header strong {
  color: var(--ink);
}

.prompt-card {
  border: 1px dashed var(--line);
  background: var(--soft);
  border-radius: var(--radius);
  padding: 18px;
}

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

.prompt-card p {
  margin: 8px 0 0;
  font-family: var(--mono);
}

.flow-arrow {
  height: 44px;
  position: relative;
}

.flow-arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  width: 1px;
  height: 28px;
  background: var(--line);
}

.flow-arrow::after {
  content: "";
  position: absolute;
  left: calc(50% - 5px);
  bottom: 5px;
  width: 10px;
  height: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}

.loop-stack {
  display: grid;
  gap: 10px;
}

.loop-stack div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: #f9faf2;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 6px;
}

.loop-stack span {
  color: var(--muted);
  text-align: right;
}

.intro-grid,
.starter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
  gap: 28px;
  align-items: start;
}

.principle-panel,
.starter-form,
.prompt-output,
.template-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

.principle-panel ul {
  padding-left: 20px;
  margin: 0;
  color: var(--muted);
}

.section-heading {
  max-width: 820px;
  margin-bottom: 28px;
}

.section-heading p {
  color: var(--muted);
}

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

.ladder-grid article,
.anatomy-grid article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.ladder-grid span {
  color: var(--coral);
  font-weight: 900;
  font-size: 13px;
}

.ladder-grid p,
.anatomy-grid p {
  color: var(--muted);
  margin: 0;
}

.starter-form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

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

pre {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
}

.prompt-output pre,
.template-panel pre {
  background: #1f241f;
  color: #f6f1df;
  border-radius: 6px;
  padding: 18px;
}

.library-heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  max-width: none;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 4px;
  border-radius: 999px;
}

.mode-switch button {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}

.mode-switch button.is-active {
  background: var(--ink);
  color: var(--paper);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 190px 180px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.result-count {
  color: var(--muted);
  margin: 14px 0;
  font-size: 14px;
}

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

.loop-card {
  display: grid;
  gap: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 340px;
}

.loop-card header {
  display: grid;
  gap: 8px;
}

.loop-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
  background: #fffef9;
}

.loop-card h3 {
  font-size: 20px;
  margin: 0;
}

.loop-card p {
  margin: 0;
  color: var(--muted);
}

.loop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.loop-actions button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffef9;
  padding: 8px 10px;
  cursor: pointer;
}

.loop-actions button:first-child {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.details-block {
  display: none;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.loop-card.is-open .details-block {
  display: grid;
  gap: 10px;
}

.details-block strong {
  color: var(--ink);
}

.template-panel {
  display: grid;
  gap: 16px;
}

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

details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

summary {
  cursor: pointer;
  font-weight: 850;
}

details p {
  color: var(--muted);
  margin: 12px 0 0;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 34px clamp(18px, 5vw, 72px);
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.footer p {
  margin: 4px 0 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

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

@media (max-width: 980px) {
  .hero,
  .intro-grid,
  .starter-grid {
    grid-template-columns: 1fr;
  }

  .loop-machine {
    order: -1;
  }

  .ladder-grid,
  .anatomy-grid,
  .loop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .theme-toggle {
    margin-left: auto;
  }

  .section {
    padding-left: 16px;
    padding-right: 16px;
  }

  .hero {
    min-height: auto;
    padding-top: 38px;
  }

  h1 {
    font-size: 44px;
  }

  .ladder-grid,
  .anatomy-grid,
  .loop-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .library-heading,
  .footer {
    display: grid;
  }
}
