/* --- Two Envelopes Lab module styles --- */
.tev {
  --bg: #f7f4ec;
  --surface: #ffffff;
  --surface-muted: #f0ebdf;
  --text: #1e1b15;
  --muted: #454138;
  --line: #d2c6ad;
  --accent: #7a5a14;
  --accent-2: #5c4209;
  --focus: #005fcc;
  --ok: #1f6b3e;
  --bad: #8a1d2b;
  --btn-bg: #fbf7ef;
  --btn-hover: #eee4ce;
  --btn-border: #bcae90;
  margin: 0;
  padding-bottom: 2rem;
}

.tev section {
  padding: 0;
}

.tev section + section {
  border-top: 0;
}

.tev :focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Envelope module: shared layout */
.tev-shell {
  width: min(1280px, 94vw);
  margin: 0 auto;
}

.tev-intro-shell {
  width: var(--tev-shell-width);
  display: grid;
  justify-items: center;
}

.tev-intro-block {
  padding: 1.2rem 0 0.6rem;
}

.tev-intro-shell > .tev-kicker,
.tev-intro-shell > h1,
.tev-intro-shell > .tev-part-subhead,
.tev-intro-shell > .tev-intro,
.tev-intro-shell > .lead,
.tev-intro-shell > .tev-problem-card,
.tev-intro-shell > .tev-intro-note,
.tev-intro-shell > .tev-quick-steps {
  width: var(--tev-copy-width);
  margin-inline: auto;
  text-align: left;
}

.tev-kicker {
  margin: 0 auto;
  color: var(--muted);
  font-size: 0.96rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tev-intro {
  margin: 0.4rem 0;
  color: var(--muted);
  max-width: 92ch;
  line-height: 1.58;
}

.tev-part-subhead {
  margin: 0 0 0.6rem;
  color: #5c4a27;
  font-size: 1rem;
  font-weight: 700;
}

.tev-quick-steps {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.tev-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.3rem;
  align-items: start;
  padding-top: 0.7rem;
}

.tev-tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  grid-column: 1 / 2;
}

.tev-tab {
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  background: var(--btn-bg);
  padding: 0.45rem 0.85rem;
  min-height: 2.5rem;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.tev-tab.is-active {
  background: #eadfca;
  border-color: #ab9a79;
}

.tev-panel {
  grid-column: 1 / -1;
}

.tev-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
  gap: 1.25rem;
}

.tev-lab-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.9fr);
  gap: 1.25rem;
  align-items: start;
}

.tev-lab-full {
  grid-column: 1 / -1;
}

.tev-lab-results-card .tev-table-wrap {
  margin-top: 0.55rem;
}

.tev-span-2 {
  grid-column: span 2;
}

.tev-sidebar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.1rem;
}

/* Envelope module: cards and copy */
.tev-card,
.tev-landing-card,
.tev-launch-block {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.tev-problem-card,
.tev-idea-box,
.tev-flow-card {
  border: 1px solid var(--tev-panel-line);
  border-radius: var(--radius-xl);
  background: var(--surface);
}

.tev-card {
  padding: 1.35rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.tev-start-card,
.tev-context-card {
  border-left: 1px solid var(--line);
}

.tev-context-card p {
  margin: 0.45rem 0 0;
  line-height: 1.5;
}

.tev-option-grid {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.55rem;
}

.tev-option,
.tev-generator-box,
.tev-inline-details,
.tev-fieldset,
.tev-control-box,
.tev-metrics > div,
.tev-note,
.tev-tree,
.tev-details,
.tev-kv-grid div {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.tev-option {
  padding: 0.55rem 0.62rem;
}

.tev-option h3 {
  margin: 0;
  font-size: 1.15rem;
}

.tev-option p {
  margin: 0.32rem 0 0;
  font-size: 1rem;
}

.tev-start-list {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.35rem;
}

.tev-generator-box {
  margin: 0.7rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  display: grid;
  gap: 0.38rem;
}

.tev-generator-box h3 {
  margin: 0;
  font-size: 1rem;
}

.tev-help {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.tev-inline-details {
  margin-top: 0.7rem;
  padding: 0.55rem 0.7rem;
}

.tev-inline-details summary {
  cursor: pointer;
  font-weight: 700;
}

.tev-inline-details[open] summary {
  margin-bottom: 0.45rem;
}

.tev-fieldset {
  margin: 0.7rem 0;
  padding: 0.55rem 0.7rem 0.7rem;
  display: grid;
  gap: 0.35rem;
}

.tev-fieldset legend {
  font-weight: 700;
  padding-inline: 0.2rem;
}

.tev-fieldset label:not(.tev-inline) {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  line-height: 1.45;
  min-width: 0;
}

.tev-fieldset input[type="radio"] {
  margin-top: 0;
  flex: 0 0 auto;
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.tev-choice-fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.75rem 0.7rem;
}

.tev-choice-fieldset legend {
  font-weight: 700;
  padding-inline: 0.2rem;
}

.tev-radio-row {
  display: grid;
  gap: 0.35rem;
}

.tev-radio-row-compact {
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.45rem 0.7rem;
}

.tev-radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

/* Envelope module: inputs and controls */
.tev-toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: stretch;
}

.tev-toggle-group .tev-toggle-button {
  flex: 1 1 12rem;
  min-height: 2.45rem;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.tev-toggle-group .tev-toggle-button.is-active,
.tev-toggle-group .tev-toggle-button[aria-pressed="true"] {
  background: #eadfca;
  border-color: #ab9a79;
}

.tev-toggle-group .tev-toggle-button:focus-visible {
  outline: 2px solid #ab9a79;
  outline-offset: 2px;
}

.tev-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 0.6rem;
  margin: 0.35rem 0 0.75rem;
}

.tev-form-grid-compact {
  margin: 0;
}

.tev-form-grid-tight {
  gap: 0.45rem;
}

.tev-control-box {
  margin-top: 0.5rem;
  padding: 0.55rem 0.7rem;
  display: grid;
  gap: 0.45rem;
}

.tev-control-box .tev-help {
  margin: 0;
}

.tev-control-box .tev-form-grid,
.tev-control-box .tev-fieldset {
  margin: 0;
}

.tev [hidden] {
  display: none !important;
}

.tev-form-grid label,
.tev-inline {
  display: grid;
  gap: 0.2rem;
  font-weight: 600;
}

.tev input,
.tev select,
.tev button {
  font: inherit;
  min-width: 0;
  max-width: 100%;
}

.tev input:not([type="radio"]):not([type="checkbox"]),
.tev select {
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  min-height: 2.3rem;
  padding: 0.3rem 0.5rem;
  background: #fffdf9;
  color: var(--text);
  width: 100%;
}

.tev-button-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.4rem, 1fr));
  gap: 0.55rem;
}

.tev-button-row-tight {
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 12rem));
  justify-content: start;
}

.tev-button-row + .tev-button-row {
  margin-top: 0.45rem;
}

.tev-action-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(9.5rem, 11rem);
  gap: 0.6rem;
  align-items: start;
}

.tev-action-strip .tev-choice-fieldset {
  height: 100%;
}

.tev-action-strip-button {
  display: grid;
}

.tev-action-strip-button button {
  height: 100%;
  min-height: 3.1rem;
}

.tev-manual-open-row {
  grid-template-columns: 1fr;
}

.tev-manual-actions-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tev button {
  min-height: 2.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  padding: 0.4rem 0.62rem;
  cursor: pointer;
  font-weight: 700;
  width: 100%;
  line-height: 1.25;
}

.tev button:hover {
  background: var(--btn-hover);
}

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

.tev-setup-summary {
  padding: 0.3rem 0 0.05rem;
  border-bottom: 1px solid var(--line);
}

.tev-setup-label {
  margin: 0 0 0.12rem;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.tev-setup-actions {
  display: grid;
  gap: 0.55rem;
}

.tev-lab-controls-card {
  display: grid;
  gap: 0.7rem;
}

.tev-lab-controls-card h2 {
  margin: 0;
}

.tev-control-section {
  display: grid;
  gap: 0.55rem;
}

.tev-control-section + .tev-control-section {
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.tev-setup-footer {
  display: grid;
  gap: 0.5rem;
  align-items: start;
}

.tev-setup-reset-row {
  margin-top: 0;
}

/* Envelope module: results and tables */
.tev-status {
  margin: 0;
  color: var(--muted);
}

.tev-chip {
  display: inline-block;
  width: auto;
  border-radius: 999px;
  border: 1px solid #ab9a79;
  background: #f1e5cb;
  padding: 0.14rem 0.52rem;
  font-weight: 700;
  vertical-align: middle;
}

.tev-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem;
}

.tev-metrics > div {
  padding: 0.55rem 0.65rem;
}

.tev-metrics p {
  margin: 0.32rem 0;
}

.tev-note,
.tev-tree,
.tev-details {
  margin-top: 0.6rem;
  padding: 0.65rem 0.75rem;
}

.tev code {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tev-note p,
.tev-tree p,
.tev-details p {
  margin: 0.35rem 0;
}

.tev-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.tev table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

.tev caption {
  text-align: left;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.tev th,
.tev td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.tev th {
  background: var(--surface-muted);
}

.tev-kv-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.tev-kv-grid div {
  padding: 0.5rem 0.6rem;
}

.tev-kv-grid dt {
  font-weight: 700;
  color: var(--muted);
}

.tev-kv-grid dd {
  margin: 0.2rem 0 0;
  font-weight: 700;
}

.tev-strategy-grid {
  display: grid;
  gap: 0.6rem;
}

.tev-strategy-row {
  display: grid;
  grid-template-columns: minmax(8.8rem, 10rem) minmax(0, 1fr) 4.4rem;
  gap: 0.5rem;
  align-items: center;
}

.tev-bar {
  position: relative;
  height: 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background:
    linear-gradient(to right, transparent 49.6%, #8d7d5c 49.6%, #8d7d5c 50.4%, transparent 50.4%),
    #fff;
  overflow: hidden;
}

.tev-bar > div {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #9a7733 0%, #6e500f 100%);
  width: 0;
  transition: width 200ms ease;
}

.tev-list {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.45rem;
}

.tev-list-compact {
  gap: 0.22rem;
}

/* Envelope module: responsive adjustments */
@media (max-width: 980px) {
  .tev-tabbar,
  .tev-panel,
  .tev-sidebar {
    grid-column: 1 / -1;
  }

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

  .tev-lab-workbench {
    grid-template-columns: 1fr;
  }

  .tev-sidebar {
    order: 3;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .tev-grid {
    grid-template-columns: 1fr;
  }

  .tev-span-2 {
    grid-column: span 1;
  }

  .tev-button-row {
    grid-template-columns: 1fr;
  }

  .tev-action-strip {
    grid-template-columns: 1fr;
  }

  .tev-manual-actions-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tev-sidebar {
    grid-template-columns: 1fr;
  }

  .tev-kv-grid {
    grid-template-columns: 1fr;
  }

  .tev-strategy-row {
    grid-template-columns: 1fr;
  }
}

/* Envelope module: landing pages */
.tev-landing section {
  padding: 1.4rem 0;
}

.tev-landing-minimal {
  background:
    radial-gradient(circle at 95% 2%, #ece4d4 0, transparent 30%),
    radial-gradient(circle at 4% 20%, #e7efe9 0, transparent 24%),
    #f7f4ec;
}

.tev-hero-clean {
  width: var(--tev-shell-width);
  margin: 0 auto;
  display: grid;
  justify-items: center;
}

.tev-hero-clean > .tev-kicker,
.tev-hero-clean > h1,
.tev-hero-clean > .tev-part-subhead,
.tev-hero-clean > .tev-module-nav,
.tev-hero-clean > .lead,
.tev-hero-clean > .tev-problem-card,
.tev-hero-clean > .tev-intro-note {
  width: var(--tev-copy-width);
  margin-inline: auto;
  text-align: left;
}

.tev-hero-clean > .tev-module-nav {
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
}

.tev-problem-card {
  width: var(--tev-copy-width);
  margin: 0.7rem auto 0.75rem;
  border-left: 5px solid #7a5a14;
  padding: 0.95rem 1rem;
  box-shadow: var(--tev-panel-shadow);
}

.tev-problem-label {
  margin: 0 0 0.35rem;
  font-size: 0.96rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: #6d5011;
}

.tev-problem-card .lead {
  margin: 0;
}

.tev-idea-box {
  width: var(--tev-copy-width);
  margin: 0.55rem auto 0;
  padding: 0.95rem 1rem;
}

.tev-idea-box p {
  margin: 0.45rem 0;
}

.tev-intro-note {
  margin: 0.15rem 0 0;
}

.tev-flow-shell {
  width: var(--tev-flow-width);
  margin: 0 auto;
  display: grid;
  gap: 0.85rem;
}

.tev-flow-card {
  padding: 1rem 1.1rem;
}

.tev-flow-card h2 {
  margin: 0 0 0.4rem;
}

.tev-flow-card p {
  margin: 0.45rem 0;
}

.tev-strategy-line {
  margin: 0.45rem 0 0.8rem;
  color: var(--muted);
}

.tev-example-stack {
  display: grid;
  gap: 0.7rem;
}

.tev-example-card {
  margin-top: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--tev-panel-line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.tev-example-card h3 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
}

.tev-example-card p:last-child,
.tev-example-card ul:last-child {
  margin-bottom: 0;
}

.tev-figure-block {
  margin: 0.8rem 0;
}

.tev-math-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.tev-math-table caption {
  caption-side: top;
  padding: 0 0 0.45rem;
  text-align: left;
  font-weight: 700;
  color: var(--text);
}

.tev-math-table thead th {
  background: #f4efe4;
}

.tev-math-table th,
.tev-math-table td {
  border: 1px solid var(--line);
  padding: 0.65rem 0.75rem;
  vertical-align: top;
  text-align: left;
}

.tev-math-table th {
  font-weight: 700;
}

.tev-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.4rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 700;
  text-transform: lowercase;
}

.tev-flag-good {
  background: #ebf7ef;
  color: #1f6b3e;
  border-color: #9dc8ac;
}

.tev-flag-bad {
  background: #f9ebee;
  color: #8a1d2b;
  border-color: #d4a5ad;
}

.tev-compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 0.8rem 0;
}

.tev-compare-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 0.85rem 0.9rem;
}

.tev-compare-card h3 {
  margin: 0 0 0.35rem;
}

.tev-compare-card p:last-child {
  margin-bottom: 0;
}

.tev-chain-block {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #f4efe4;
  padding: 0.8rem 0.9rem;
}

.tev-chain-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.38rem;
}

.tev-chain-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.tev-chain-arrow {
  color: var(--muted);
  font-weight: 700;
}

.tev-copy-plain {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.tev-copy-plain.tev-context-card,
.tev-copy-plain.tev-start-card {
  border-left: 0;
  background: transparent;
}

.tev-flow-alert-card {
  border-left: 4px solid #8a1d2b;
  background: #fcf3f3;
}

.tev-launch-row {
  width: var(--tev-flow-width);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: flex-start;
}

.tev-launch-row .tev-help {
  flex: 1 1 100%;
  margin: 0 0 0.1rem;
}

.tev-landing-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.tev-landing-card {
  padding: 1rem 1.05rem;
}

.tev-landing-card h2 {
  margin: 0 0 0.5rem;
}

.tev-landing-card p {
  margin: 0.5rem 0;
}

.tev-alert {
  border-left: 4px solid #8a1d2b;
  background: #fbefef;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
}

.tev-story-list {
  margin: 0.4rem 0;
  padding-left: 1.2rem;
}

.tev-story-list li {
  margin-bottom: 0.35rem;
}

.tev-page-nav {
  margin-top: 0.55rem;
}

.tev-page-nav-section {
  padding-top: 1.7rem;
  padding-bottom: 0;
}

.tev-page-nav-box {
  width: fit-content;
  max-width: min(780px, 94vw);
  margin: 0.55rem auto 0;
  padding: 0.55rem;
}

.tev-page-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(15.5rem, 1fr));
  gap: 0.65rem;
}

.tev-page-link {
  color: var(--text);
  min-width: 0;
}

.tev-page-link h3 {
  margin: 0;
}

.tev-page-link p {
  margin-top: 0.35rem;
}

.tev-page-link:hover,
.tev-page-link:focus-visible {
  color: var(--text);
}

.tev-launch-block {
  padding: 1rem 1.05rem;
}

.tev-launch-block.tev-page-nav-box {
  width: fit-content;
  max-width: min(780px, 94vw);
  margin: 0.55rem auto 0;
  padding: 0.55rem;
}

.tev-module-nav {
  width: var(--tev-flow-width);
  margin: 0 auto;
}

.tev .tev-module-nav {
  margin-top: 0;
  margin-bottom: 0;
}

.tev-landing .tev-module-section,
.tev .tev-module-section {
  padding-top: 0.75rem;
  padding-bottom: 0.45rem;
}

.tev-landing .tev-title-section,
.tev .tev-title-section {
  padding-top: 0.45rem;
  padding-bottom: 1rem;
}

.tev-title-section.tev-intro-block {
  padding-top: 0.45rem;
  padding-bottom: 1rem;
}

.tev-module-nav h2 {
  margin: 0 0 0.45rem;
}

.tev-module-nav .tev-help {
  margin: 0 0 0.7rem;
}

.tev-module-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: flex-start;
}

.tev-module-links .tev-launch {
  flex: 1 1 260px;
  font-size: 0.96rem;
  line-height: 1.25;
}

.tev-launch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.8rem;
  border-radius: 8px;
  border: 1px solid #bcae90;
  padding: 0.5rem 0.85rem;
  font-weight: 700;
  text-decoration: none;
  color: #1e1b15;
  background: #f1e5cb;
}

.tev-launch:hover {
  background: #ead9b6;
  color: #1e1b15;
}

.tev-launch-ghost {
  background: #fff;
}

.tev-launch-ghost:hover {
  background: #f6f0e4;
}

.tev-launch-current {
  background: #e8dcc1;
  border-color: #ab9a79;
  color: #1e1b15;
  pointer-events: none;
}

@media (max-width: 820px) {
  .tev-landing-grid {
    grid-template-columns: 1fr;
  }

  .tev-compare-grid {
    grid-template-columns: 1fr;
  }

  .tev-launch-row {
    flex-direction: column;
  }

  .tev-page-links {
    grid-template-columns: 1fr;
  }
}
