:root {
  color-scheme: light;
  --paper: #f4f7fb;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8e0ea;
  --teal: #0f766e;
  --teal-dark: #0a5752;
  --blue: #2854a3;
  --amber: #b86b18;
  --coral: #c8503f;
  --shadow: 0 18px 55px rgba(30, 43, 65, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--paper), #eef3f8);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--teal);
  outline: 2px solid rgba(15, 118, 110, 0.18);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
}

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

.kicker {
  margin-bottom: 6px;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.privacy-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.tab {
  min-height: 46px;
  font-weight: 750;
}

.tab.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.surface,
.score-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.surface {
  padding: 24px;
}

.surface.narrow {
  max-width: 780px;
  margin: 0 auto;
}

.panel-grid {
  display: grid;
  gap: 14px;
}

.score-grid {
  grid-template-columns: minmax(0, 1fr) 330px;
  align-items: stretch;
}

.tracker-grid,
.relapse-grid {
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}

.section-heading {
  margin-bottom: 18px;
}

.stack {
  display: grid;
  gap: 14px;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(160px, 2fr) 36px;
  align-items: center;
  gap: 14px;
  min-height: 42px;
}

.range-row span,
.field span {
  color: var(--muted);
  font-weight: 720;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

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

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  padding: 11px 12px;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--teal);
  outline: 2px solid rgba(15, 118, 110, 0.16);
}

.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  font-weight: 800;
}

.score-card {
  display: grid;
  align-content: center;
  min-height: 360px;
  padding: 28px;
}

.score-number {
  margin: 8px 0 2px;
  font-size: 82px;
  font-weight: 900;
  line-height: 0.95;
}

.score-label {
  margin-bottom: 26px;
  color: var(--amber);
  font-weight: 850;
}

.score-detail {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.score-detail span {
  color: var(--muted);
}

.score-note {
  margin-top: 16px;
  border-left: 4px solid var(--blue);
  padding: 10px 12px;
  background: #f2f6ff;
  color: #344054;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.toolbar .section-heading {
  margin-bottom: 0;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.progress-wrap {
  margin-bottom: 18px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 780;
}

.progress-bar {
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e7edf5;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.day-item {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.day-item.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(40, 84, 163, 0.12);
}

.day-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-weight: 850;
}

.day-select {
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font-weight: 850;
  text-align: left;
}

.day-select:hover,
.day-select:focus-visible {
  outline: 2px solid rgba(40, 84, 163, 0.16);
}

.day-title span:last-child {
  color: var(--teal-dark);
}

.mini-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.mini-check input,
.check-item input {
  accent-color: var(--teal);
}

.checklist {
  display: grid;
  gap: 10px;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfdff;
}

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

.prompt-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdff;
}

.prompt-card h3 {
  margin: 0;
  font-size: 18px;
}

.prompt-card p {
  color: var(--muted);
}

.contract-form {
  display: grid;
  gap: 14px;
}

.daily-log {
  position: sticky;
  top: 16px;
}

.status-line {
  min-height: 22px;
  color: var(--teal-dark);
  font-weight: 750;
}

.relapse-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #17202a;
  color: white;
  box-shadow: var(--shadow);
  padding: 24px;
}

.relapse-card .kicker {
  color: #8ee3d8;
}

.relapse-card h2 {
  margin-bottom: 18px;
}

.relapse-card dl {
  display: grid;
  gap: 12px;
  margin: 0 0 18px;
}

.relapse-card div {
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding-top: 12px;
}

.relapse-card dt {
  color: #b7c3d4;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.relapse-card dd {
  margin: 4px 0 0;
  font-weight: 760;
}

.relapse-card button {
  width: 100%;
  background: white;
  color: var(--ink);
}

@media print {
  body {
    background: white;
  }

  body.printing-relapse .topbar,
  body.printing-relapse .tabs,
  body.printing-relapse .surface,
  body.printing-relapse #copy-relapse,
  body.printing-contract .topbar,
  body.printing-contract .tabs,
  body.printing-contract .panel:not(#contract) {
    display: none;
  }

  body.printing-relapse .panel,
  body.printing-contract #contract {
    display: block;
  }

  .relapse-card {
    box-shadow: none;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 22px, 760px);
    padding-top: 18px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 28px;
  }

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

  .score-grid,
  .tracker-grid,
  .relapse-grid,
  .prompt-grid,
  .day-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .toolbar-actions {
    flex-wrap: wrap;
  }

  .daily-log {
    position: static;
  }

  .range-row {
    grid-template-columns: 1fr 42px;
  }

  .range-row input {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .range-row strong {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
  }
}
