:root {
  --paper-w: 4in;
  --paper-h: 6in;
  --card-w: 6in;
  --card-h: 4in;
  --header-y: 0.42in;
  --body-y: 0.70in;
  --line-spacing: 0.25in;
  --blue-rule-height: 3.5in;
  --left-margin: 0.18in;
  --right-margin: 0.18in;
  --ink: #222;
  --paper: #fffdf8;
  --line-blue: rgba(42, 113, 199, 0.55);
  --line-red: rgba(197, 43, 43, 0.7);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f4f5f7;
  color: #1d2430;
  font-family: Arial, Helvetica, sans-serif;
}

.drop-overlay {
  position: fixed;
  inset: 14px;
  z-index: 100;
  display: none;
  place-items: center;
  border: 3px dashed #1f5fbf;
  border-radius: 12px;
  background: rgba(238, 244, 255, 0.9);
  color: #174174;
  font-size: 24px;
  font-weight: 700;
  pointer-events: none;
}

body.dragging-file .drop-overlay {
  display: grid;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(360px, 1fr);
  gap: 18px;
  padding: 18px;
}

.editor-panel,
.preview-panel {
  min-width: 0;
}

.brand-row,
.preview-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
}

h2 {
  font-size: 18px;
}

p {
  margin-top: 5px;
  color: #667085;
  line-height: 1.35;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-weight: 700;
}

.field-heading {
  display: block;
}

.field-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cfd5df;
  border-radius: 8px;
  background: #fff;
  color: #111827;
  padding: 9px 10px;
}

textarea {
  min-height: 390px;
  line-height: 1.45;
  resize: vertical;
}

.plain-source {
  display: none;
}

.format-toolbar {
  display: flex;
  gap: 6px;
}

.format-button {
  width: 34px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  background: #e7edf7;
  color: #174174;
}

.format-button:hover {
  background: #d7e2f2;
}

.rich-editor {
  width: 100%;
  min-height: clamp(280px, 42vh, 340px);
  overflow: auto;
  border: 1px solid #cfd5df;
  border-radius: 8px;
  background: #fff;
  color: #111827;
  padding: 9px 10px;
  line-height: 1.45;
  font-weight: 400;
  white-space: pre-wrap;
}

.editor-column-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.24in;
  height: 1.25em;
  margin: 0 0.04in;
  vertical-align: -0.18em;
  border: 1px solid rgba(31, 95, 191, 0.35);
  border-left: 2px dotted rgba(31, 95, 191, 0.8);
  border-radius: 4px;
  background: rgba(219, 234, 254, 0.65);
  color: #1f5fbf;
  cursor: pointer;
}

.editor-column-marker::after {
  content: "×";
  font: 700 11px/1 Arial, Helvetica, sans-serif;
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: #6b7280;
  pointer-events: none;
}

button {
  border: 0;
  border-radius: 8px;
  background: #1f5fbf;
  color: #fff;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: #174d9f;
}

.danger-button {
  background: #b42318;
}

.danger-button:hover {
  background: #912018;
}

.mini-button {
  padding: 6px 10px;
  border-radius: 6px;
  background: #e7edf7;
  color: #174174;
  font-size: 13px;
}

.mini-button:hover {
  background: #d7e2f2;
}

.ghost-button {
  background: #e7edf7;
  color: #174174;
}

.ghost-button:hover {
  background: #d7e2f2;
}

.calibration {
  border-top: 1px solid #d9dee7;
  padding-top: 10px;
}

.calibration summary {
  cursor: pointer;
  font-weight: 700;
}

.calibration-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.calibration-grid label {
  display: grid;
  gap: 5px;
  font-size: 13px;
  font-weight: 700;
}

.calibration-grid small {
  color: #667085;
  font-weight: 400;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.size-pill {
  flex: 0 0 auto;
  border: 1px solid #cfd5df;
  border-radius: 999px;
  color: #485466;
  padding: 7px 12px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
}

.preview-wrap {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 210px);
  padding: 8px;
  border: 1px solid #d9dee7;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #e7eaf0 25%, transparent 25%),
    linear-gradient(-45deg, #e7eaf0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e7eaf0 75%),
    linear-gradient(-45deg, transparent 75%, #e7eaf0 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.print-page {
  position: relative;
  width: min(70vw, 560px);
  aspect-ratio: 6 / 4;
  overflow: hidden;
  background: var(--paper);
  border: 4px solid #151515;
  box-shadow: 0 14px 28px rgba(17, 24, 39, 0.18);
}

.rotated-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: top left;
  transform: none;
  background: var(--paper);
  color: var(--ink);
}

.print-page.preview-rotated {
  width: min(52vh, 360px);
  aspect-ratio: 4 / 6;
}

.print-page.preview-rotated .rotated-card {
  width: 150%;
  height: 66.6667%;
  transform: translateY(150%) rotate(-90deg);
}

.print-page.actual-print-preview,
.print-page.lined-print-preview {
  border-color: #d8d8d8;
  background: #fff;
}

.print-page.actual-print-preview .rotated-card,
.print-page.lined-print-preview .rotated-card {
  background: #fff;
}

.print-page.actual-print-preview .rule,
.print-page.actual-print-preview .blue-rules {
  display: none;
}

.print-page.lined-print-preview .rule,
.print-page.lined-print-preview .blue-rules {
  display: block;
}

.rule {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
}

.red-rule {
  top: var(--header-y);
  background: var(--line-red);
}

.blue-rules {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--body-y);
  height: var(--blue-rule-height);
  overflow: hidden;
  background-size: 100% var(--line-spacing);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--line-blue) 0,
    var(--line-blue) 1px,
    transparent 1px,
    transparent var(--line-spacing)
  );
}

.recipe-title {
  position: absolute;
  left: var(--left-margin);
  right: var(--right-margin);
  top: calc(var(--header-y) - 0.25in);
  height: 0.24in;
  overflow: hidden;
  text-align: center;
  font-family: "Times New Roman", Times, serif;
  font-size: 16pt;
  font-weight: 700;
  line-height: 0.24in;
  white-space: nowrap;
}

.recipe-body {
  position: absolute;
  left: var(--left-margin);
  right: var(--right-margin);
  top: calc(var(--body-y) - 0.24in);
  height: var(--blue-rule-height);
  overflow: hidden;
  font-family: "Times New Roman", Times, serif;
  font-size: 11pt;
  line-height: var(--line-spacing);
  white-space: normal;
}

.recipe-line {
  display: block;
  width: 100%;
  min-height: var(--line-spacing);
  line-height: var(--line-spacing);
  white-space: normal;
  overflow-wrap: anywhere;
}

.recipe-column-row {
  display: grid;
  grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr));
  column-gap: 0.12in;
  width: 100%;
  min-height: var(--line-spacing);
  line-height: var(--line-spacing);
  white-space: normal;
}

.recipe-column-row span {
  position: relative;
  min-width: 0;
  overflow-wrap: anywhere;
}

.lined-print-preview .recipe-column-row span + span::before,
.actual-print-preview .recipe-column-row span + span::before {
  content: "";
  position: absolute;
  top: 0.04in;
  bottom: 0.04in;
  left: -0.06in;
  border-left: 1px dotted rgba(31, 95, 191, 0.65);
}

.recipe-divider {
  display: block;
  position: relative;
  width: 100%;
  height: var(--line-spacing);
}

.recipe-divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px solid var(--ink);
}

.action-bar {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid #d9dee7;
  backdrop-filter: blur(8px);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-modal {
  width: min(420px, 100%);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.28);
  padding: 22px;
}

.confirm-modal h2 {
  font-size: 22px;
}

.confirm-modal p {
  margin-top: 9px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.save-menu {
  position: relative;
}

.save-options {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  display: none;
  min-width: 220px;
  overflow: hidden;
  border: 1px solid #cfd5df;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(17, 24, 39, 0.18);
}

.save-options.open {
  display: grid;
}

.save-options button {
  border-radius: 0;
  background: #fff;
  color: #1d2430;
  text-align: left;
  font-weight: 600;
}

.save-options button:hover {
  background: #eef4ff;
}

@media (max-width: 850px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 20px 16px;
    gap: 18px;
  }

  .preview-wrap {
    min-height: auto;
  }

  .action-bar {
    flex-wrap: wrap;
  }

  .preview-toolbar {
    display: grid;
  }

  .preview-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 15px;
  }

  .app-shell {
    padding: 14px 10px;
  }

  .brand-row,
  .field-heading {
    display: grid;
    gap: 10px;
  }

  .editor-toolbar,
  .field-actions,
  .format-toolbar,
  .preview-actions,
  .action-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .field-actions .mini-button,
  .format-button,
  .preview-actions button,
  .action-bar > button,
  .action-bar .save-menu,
  .save-menu > button {
    width: 100%;
  }

  .rich-editor {
    min-height: 300px;
  }

  .preview-wrap {
    padding: 6px;
    overflow-x: auto;
    place-items: start center;
  }

  .print-page {
    width: min(calc(100vw - 34px), 600px);
  }

  .print-page.preview-rotated {
    width: min(calc(100vw - 34px), 400px);
  }

  .size-pill {
    text-align: center;
  }

  .save-options {
    left: auto;
    right: 0;
    min-width: min(230px, calc(100vw - 20px));
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: 4in 6in;
    margin: 0;
  }

  html,
  body {
    width: 4in;
    height: 6in;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #fff;
  }

  body * {
    visibility: hidden;
  }

  .print-page,
  .print-page * {
    visibility: visible;
  }

  .print-page {
    position: fixed;
    inset: 0;
    width: 4in;
    height: 6in;
    aspect-ratio: auto;
    margin: 0;
    padding: 0;
    overflow: hidden;
    box-shadow: none;
    border: 0;
    background: transparent;
  }

  .rotated-card {
    position: absolute;
    top: 0;
    left: 0;
    width: 6in;
    height: 4in;
    transform: translateY(6in) rotate(-90deg);
    background: transparent;
  }

  .rule,
  .blue-rules {
    display: none;
  }

  .recipe-column-row span + span::before {
    display: none;
  }
}
