@page {
  size: Letter portrait;
  margin: 0.75in;
}

:root {
  --font-family: "Source Sans 3", "Segoe UI", Arial, sans-serif;
  --page-content-width: 7in;
  --page-content-height: 9.5in;
  --column-width: 3.25in;
  --column-gap: 0.5in;
  --answer-box-height: 1.25in;

  --text: #252525;
  --muted-text: #4f4f4f;
  --paper: #ffffff;
  --screen-background: #e9edf1;
  --box-fill: #f4f5f6;
  --box-border: #333333;
  --button-background: #222222;
  --button-text: #ffffff;
  --focus-ring: #1267a8;
  --screen-max-width: 1040px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--screen-background);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--screen-background);
  font-family: var(--font-family);
  font-size: 11pt;
  font-weight: 500;
  line-height: 1.25;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

/* Screen controls */
.screen-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 14px;
  background: rgba(233, 237, 241, 0.96);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(8px);
}


.toolbar-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  max-width: 760px;
}

.print-help {
  max-width: 360px;
  margin: 0;
  color: var(--muted-text);
  font-size: 0.9rem;
  line-height: 1.3;
}

.print-button {
  min-height: 46px;
  padding: 11px 22px;
  color: var(--button-text);
  background: var(--button-background);
  border: 0;
  border-radius: 9px;
  font-weight: 900;
  cursor: pointer;
}

.print-button:hover {
  opacity: 0.9;
}

.print-button:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

/* Desktop/tablet screen presentation */
#safety-plan-document {
  width: min(var(--screen-max-width), calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.print-page {
  position: relative;
  width: 100%;
  min-height: 0;
  margin: 0 0 28px;
  padding: clamp(24px, 4vw, 54px);
  overflow: visible;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.print-page:last-child {
  margin-bottom: 0;
}

.page-content {
  position: relative;
  z-index: 2;
  width: 100%;
  min-height: 0;
}

.document-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 28px;
  align-items: start;
  margin-bottom: 28px;
}

.document-title {
  margin: 0 0 10px;
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
}

.instructions {
  max-width: 44rem;
  margin: 0;
  color: var(--muted-text);
  font-size: 1rem;
  line-height: 1.4;
}

.client-logo {
  width: 110px;
  height: 110px;
  object-fit: contain;
  justify-self: end;
}

.plan-section {
  position: relative;
  z-index: 2;
  margin: 0 0 30px;
}

.plan-section:last-child {
  margin-bottom: 0;
}

.section-title {
  width: 100%;
  margin: 0 0 16px;
  padding-top: 8px;
  font-size: clamp(1.55rem, 2.6vw, 2rem);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.015em;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 22px;
  align-items: start;
}

.question-card {
  min-width: 0;
}

.question-text {
  min-height: 2.7em;
  margin: 0 0 8px;
  overflow: visible;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.25;
}

.answer-box {
  width: 100%;
  min-height: 150px;
  background: var(--box-fill);
  border: 1px solid var(--box-border);
  border-radius: 14px;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.fatal-message {
  max-width: 42rem;
  margin: 3rem auto;
  padding: 1rem;
  background: #fff;
  border: 1px solid #bbb;
}

/* Phone layout */
@media screen and (max-width: 700px) {
  .screen-toolbar {
    padding: 10px 12px;
  }


  .toolbar-content {
    flex-direction: column;
    gap: 8px;
  }

  .print-help {
    max-width: 520px;
    text-align: center;
    font-size: 0.84rem;
  }

  .print-button {
    width: 100%;
    max-width: 520px;
  }

  #safety-plan-document {
    width: 100%;
    padding: 0;
  }

  .print-page {
    margin: 0;
    padding: 24px 18px 34px;
    border-radius: 0;
    box-shadow: none;
    border-bottom: 10px solid var(--screen-background);
  }

  .document-header {
    grid-template-columns: minmax(0, 1fr) 74px;
    gap: 16px;
    margin-bottom: 24px;
  }

  .document-title {
    font-size: clamp(1.9rem, 9vw, 2.5rem);
  }

  .instructions {
    font-size: 0.98rem;
    line-height: 1.42;
  }

  .client-logo {
    width: 74px;
    height: 74px;
  }

  .plan-section {
    margin-bottom: 28px;
  }

  .section-title {
    margin-bottom: 14px;
    padding-top: 0;
    font-size: 1.55rem;
  }

  .question-grid {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .question-text {
    min-height: 0;
    margin-bottom: 8px;
    font-size: 1.02rem;
    line-height: 1.3;
  }

  .answer-box {
    min-height: 132px;
  }
}

@media screen and (max-width: 390px) {
  .print-page {
    padding-left: 14px;
    padding-right: 14px;
  }

  .document-header {
    grid-template-columns: minmax(0, 1fr) 62px;
  }

  .client-logo {
    width: 62px;
    height: 62px;
  }

  .answer-box {
    min-height: 120px;
  }
}

/* Print layout remains the original fixed three-page worksheet */
@media print {
  html,
  body {
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  .screen-only,
  noscript {
    display: none !important;
  }

  #safety-plan-document {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .print-page {
    width: var(--page-content-width);
    min-height: var(--page-content-height);
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #fff;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }

  .print-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .page-content {
    width: var(--page-content-width);
    min-height: var(--page-content-height);
  }

  .document-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 0.9in;
    gap: 0.25in;
    align-items: start;
    margin-bottom: 0.22in;
  }

  .document-title {
    margin: 0 0 0.08in;
    font-size: 24pt;
    line-height: 1;
  }

  .instructions {
    max-width: 5.7in;
    margin: 0;
    font-size: 10pt;
    line-height: 1.2;
  }

  .client-logo {
    width: 0.9in;
    height: 0.9in;
  }

  .plan-section {
    margin: 0 0 0.18in;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .section-title {
    margin: 0 0 0.1in;
    padding-top: 25pt;
    font-size: 17pt;
    line-height: 1;
  }

  .question-grid {
    display: grid;
    grid-template-columns: repeat(2, var(--column-width));
    column-gap: var(--column-gap);
    row-gap: 0.12in;
  }

  .question-card {
    width: var(--column-width);
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .question-text {
    height: 0.34in;
    min-height: 0;
    margin: 0 0 0.05in;
    overflow: hidden;
    font-size: 10pt;
    line-height: 1.15;
  }

  .answer-box {
    width: var(--column-width);
    height: var(--answer-box-height);
    min-height: 0;
    border-radius: 0.16in;
  }
}
