:root {
  --ink: #101715;
  --muted: #64706b;
  --paper: #f7f1e8;
  --card: #fffdf8;
  --line: #ded5c6;
  --charcoal: #17201d;
  --teal: #126a68;
  --mint: #dcefe8;
  --orange: #e35d32;
  --amber: #d49216;
  --red: #d64237;
  --green: #177a50;
  --soft-red: #fbe7e3;
  --soft-amber: #fff0c9;
  --soft-green: #e3f4ea;
  --shadow: 0 14px 34px rgba(34, 28, 20, 0.12);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.skip-link {
  position: absolute;
  left: 14px;
  top: -50px;
  z-index: 40;
  padding: 10px 13px;
  color: #fff;
  background: var(--charcoal);
  border-radius: var(--radius);
}

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

.wrap {
  width: min(1160px, calc(100% - 28px));
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  color: #fff;
  background: var(--charcoal);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.topbar-inner {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #25302c;
  border: 2px solid var(--orange);
  border-radius: 9px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 16px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.94rem;
}

.nav a,
.button,
.plain-button,
.footer-links a,
.legal-links a {
  text-decoration: none;
}

.nav a:hover,
.footer-links a:hover {
  color: var(--orange);
}

.emergency-strip {
  color: var(--ink);
  background: #f3dfb7;
  border-bottom: 1px solid #dfc386;
}

.emergency-inner {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.emergency-inner span {
  color: #4f4330;
}

.hero-tool {
  padding: 30px 0 44px;
}

.hero-tool-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.65fr) minmax(480px, 1.35fr);
  gap: 24px;
  align-items: start;
}

.intro {
  position: sticky;
  top: 98px;
}

.eyebrow,
.tiny-label {
  display: block;
  margin: 0 0 10px;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 18px;
  font-size: clamp(2.15rem, 4.4vw, 3.45rem);
  line-height: 1;
  letter-spacing: 0;
}

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

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

.lead {
  max-width: 620px;
  color: #35403c;
  font-size: 1.04rem;
}

.disclaimer-mini {
  display: grid;
  gap: 5px;
  max-width: 620px;
  margin-top: 22px;
  padding: 16px;
  background: #fff8e8;
  border: 1px solid #e6c780;
  border-radius: var(--radius);
  color: #6a4a08;
}

.tracker-panel,
.profile-card,
.disclaimer-card,
.flow-grid article,
.substance-chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tracker-panel {
  padding: 18px;
  box-shadow: var(--shadow);
}

.setup-card {
  max-width: 620px;
  justify-self: stretch;
}

.tracker-section {
  padding: 24px 0 56px;
  background: #fffaf0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.tracker-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.42fr) minmax(480px, 1fr);
  gap: 24px;
  align-items: start;
}

.tracker-intro {
  position: sticky;
  top: 92px;
}

.tracker-intro p {
  color: var(--muted);
}

.tracker-head,
.profile-head,
.footer-grid,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.tracker-head {
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.tracker-head strong {
  display: block;
  font-size: 1.32rem;
}

.plain-button {
  padding: 8px 10px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 800;
}

.log-form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: #3d4743;
  font-size: 0.88rem;
  font-weight: 900;
}

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

input:focus,
select:focus {
  border-color: var(--teal);
  outline: 3px solid rgba(18, 106, 104, 0.12);
}

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

.search-field {
  position: relative;
  display: grid;
  gap: 6px;
}

.substance-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 235px;
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf0;
}

.substance-option {
  display: grid;
  gap: 2px;
  padding: 10px;
  text-align: left;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.substance-option:hover,
.substance-option.active {
  border-color: var(--teal);
  background: var(--mint);
}

.substance-option strong {
  font-size: 0.95rem;
}

.substance-option span {
  color: var(--muted);
  font-size: 0.79rem;
}

.button {
  min-height: 45px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 950;
}

.button.primary {
  color: #fff;
  background: var(--charcoal);
}

.button.primary:hover {
  background: #24302c;
}

.button.secondary {
  color: var(--ink);
  background: var(--mint);
  border-color: #b7d7ce;
}

.wide {
  width: 100%;
}

.interaction-output {
  margin-top: 14px;
}

.warning-box {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.warning-box.green {
  background: var(--soft-green);
  border-color: #bfe1cd;
}

.warning-box.yellow {
  background: var(--soft-amber);
  border-color: #e5c36b;
}

.warning-box.red {
  background: var(--soft-red);
  border-color: #eeaca4;
}

.warning-box h3 {
  margin-bottom: 6px;
}

.warning-box p {
  margin-bottom: 0;
}

.warning-box + .warning-box {
  margin-top: 10px;
}

.timeline-output {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.entry-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.entry-card.active {
  border-color: #c99229;
  box-shadow: 0 0 0 3px rgba(212, 146, 22, 0.11);
}

.entry-card.high {
  border-color: #dd8b81;
}

.entry-top,
.entry-meta,
.countdown-row,
.entry-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.entry-title strong {
  display: block;
  font-size: 1.12rem;
}

.entry-title span,
.entry-meta,
.factor-note,
.empty-state {
  color: var(--muted);
  font-size: 0.91rem;
}

.phase-pill {
  flex: 0 0 auto;
  padding: 7px 9px;
  border-radius: 999px;
  font-size: 0.77rem;
  font-weight: 950;
}

.phase-pill.onset {
  color: #714d00;
  background: var(--soft-amber);
}

.phase-pill.peak {
  color: #7a1f19;
  background: var(--soft-red);
}

.phase-pill.offset {
  color: #105a39;
  background: var(--soft-green);
}

.phase-pill.done {
  color: #555;
  background: #eee8dd;
}

.countdown {
  font-size: clamp(1.7rem, 5vw, 3.2rem);
  line-height: 1;
  font-weight: 950;
}

.wearoff-time {
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
}

.bar {
  position: relative;
  height: 12px;
  overflow: hidden;
  display: grid;
  grid-template-columns: var(--onset, 20%) var(--peak, 22%) 1fr;
  border-radius: 999px;
  background: #efe7d9;
}

.bar span:nth-child(1) {
  background: var(--amber);
}

.bar span:nth-child(2) {
  background: var(--red);
}

.bar span:nth-child(3) {
  background: var(--green);
}

.bar-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  left: var(--progress, 0%);
  background: var(--charcoal);
  border-radius: 999px;
}

.feedback-box {
  display: grid;
  gap: 9px;
  padding: 11px;
  background: #fff8e8;
  border: 1px solid #ead59c;
  border-radius: var(--radius);
}

.feedback-box strong {
  font-size: 0.95rem;
}

.feedback-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback-button {
  padding: 8px 10px;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 850;
}

.feedback-button.good {
  border-color: #a8d8bd;
}

.feedback-button.rough {
  border-color: #e2bd5f;
}

.feedback-button.bad {
  border-color: #e49b92;
}

.feedback-saved {
  color: var(--muted);
  font-size: 0.91rem;
}

.remove-log {
  padding: 7px 10px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 800;
}

.section {
  padding: 66px 0;
}

.profile-card p,
.section-head p,
.disclaimer-card p,
.footer p,
.flow-grid p {
  color: var(--muted);
}

.profile-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.profile-head {
  display: grid;
  gap: 3px;
}

.profile-head span,
.profile-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.database-section {
  background: var(--paper);
}

.section-head {
  margin-bottom: 22px;
}

.section-head p {
  max-width: 520px;
  margin-bottom: 0;
}

.database-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.substance-chip {
  padding: 9px 11px;
  color: #33403b;
  font-size: 0.9rem;
}

.substance-chip strong {
  color: var(--ink);
}

.simple-flow {
  background: var(--charcoal);
  color: #fff;
}

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

.flow-grid article {
  min-height: 190px;
  padding: 18px;
  color: var(--ink);
}

.flow-grid span {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  margin-bottom: 34px;
  color: #fff;
  background: var(--orange);
  border-radius: 50%;
  font-weight: 950;
}

.disclaimer-section {
  padding-top: 40px;
}

.disclaimer-card {
  padding: clamp(22px, 5vw, 44px);
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.legal-links a {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 900;
}

.footer {
  padding: 34px 0;
  background: #fffaf0;
  border-top: 1px solid var(--line);
}

.footer-brand {
  margin-bottom: 10px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.footer-links a {
  color: var(--muted);
}

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

  .intro,
  .tracker-intro {
    position: static;
  }

  .section-head {
    display: grid;
  }
}

@media (max-width: 720px) {
  .wrap {
    width: min(100% - 22px, 1160px);
  }

  .nav {
    display: none;
  }

  .hero-tool {
    padding-top: 30px;
  }

  h1 {
    font-size: clamp(2.4rem, 14vw, 3.7rem);
  }

  .lead {
    font-size: 1.03rem;
  }

  .compact-grid,
  .flow-grid,
  .substance-results {
    grid-template-columns: 1fr;
  }

  .entry-top,
  .countdown-row,
  .footer-grid {
    display: grid;
    justify-content: stretch;
  }

  .wearoff-time {
    text-align: left;
  }

  .section {
    padding: 48px 0;
  }
}
