:root {
  --form-accent: #1f5c5a;
  --form-accent-deep: #173f3e;
  --form-accent-soft: #e8f1f0;
  --form-gold: #9a7430;
  --form-gold-soft: #f5f0e5;
  --form-page: #f7f4ed;
  --form-border: #d6ddda;
  --form-ink: #202626;
  --form-muted: #5a6262;
  --form-focus: #173f3e;
}

body {
  background: var(--form-page);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  width: min(1260px, calc(100% - 32px));
  margin: 28px auto 18px;
  color: var(--form-ink);
}

.home-navigation {
  margin-bottom: 10px;
}

.home-navigation a,
.home-after-download {
  color: var(--form-accent);
  font-weight: 750;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.home-navigation a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  font-size: 13px;
}

.home-navigation a:hover,
.home-after-download:hover {
  color: var(--form-accent-deep);
}

.home-navigation a:focus-visible,
.home-after-download:focus-visible {
  border-radius: 3px;
  outline: 3px solid rgb(31 92 90 / 28%);
  outline-offset: 3px;
}

.app-header h1,
.app-header p {
  margin: 0;
}

.app-header h1 {
  margin-top: 3px;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.3;
}

.app-header > p:last-child {
  margin-top: 7px;
  color: var(--form-muted);
  font-size: 14px;
}

.app-kicker {
  color: var(--form-gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
}

.compact-step-indicator {
  display: none;
}

.compact-screen-note {
  display: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  align-items: start;
  gap: 24px;
  width: min(1260px, calc(100% - 32px));
  margin: 0 auto 40px;
}

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

.form-card {
  padding: 20px;
  background: #fff;
  border: 1px solid var(--form-border);
  border-radius: 14px;
  box-shadow: 0 2px 12px rgb(23 63 62 / 6%);
}

.form-card-heading {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 11px;
  margin-bottom: 18px;
}

.form-card-heading > span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--form-accent);
  color: #fff;
  font-size: 16px;
  font-weight: 850;
}

.form-card-heading h2,
.form-card-heading p {
  margin: 0;
}

.form-card-heading h2 {
  color: var(--form-ink);
  font-size: 18px;
  line-height: 1.45;
}

.form-card-heading p {
  margin-top: 3px;
  color: var(--form-muted);
  font-size: 12px;
  line-height: 1.55;
}

.field-grid,
.feature-inputs {
  display: grid;
  gap: 15px;
}

.field-grid-2 {
  grid-template-columns: 1fr 1fr;
}

.field-full {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--form-ink);
}

.field-label {
  font-size: 13px;
  font-weight: 750;
}

.field-label em,
.field-label .optional {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-style: normal;
  font-weight: 750;
  line-height: 1.25;
  vertical-align: .1em;
}

.field-label em {
  background: var(--form-gold-soft);
  color: #77571d;
}

.field-label .optional {
  background: #f2f3f3;
  color: #5a6262;
}

.field input:not([type="checkbox"]):not([type="file"]),
.field select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #aab3b2;
  border-radius: 8px;
  color: #181513;
  outline: none;
}

/* iOS の日付入力が持つ固有の最小幅でカード外へはみ出すのを防ぐ。 */
.field input[type="date"] {
  display: block;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
}

@supports (-webkit-touch-callout: none) {
  .field input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
  }

  .field input[type="date"]::-webkit-date-and-time-value {
    min-width: 0;
    margin: 0;
  }
}

.field input[type="file"] {
  width: 100%;
  padding: 7px;
  background: #fff;
  border: 1px dashed #9eacab;
  border-radius: 8px;
  font-size: 12px;
}

.field input[type="file"]::file-selector-button {
  min-height: 36px;
  margin-right: 10px;
  padding: 6px 12px;
  background: var(--form-accent-soft);
  border: 1px solid #b7cecc;
  border-radius: 6px;
  color: var(--form-accent-deep);
  font-weight: 700;
}

.field input:focus-visible,
.field select:focus-visible,
button:focus-visible {
  border-color: var(--form-focus);
  box-shadow: 0 0 0 3px rgb(31 92 90 / 20%);
  outline: none;
}

.field input[aria-invalid="true"],
.field select[aria-invalid="true"] {
  background: #fff9f9;
  border-color: #ba2d3e;
}

.field select:disabled {
  background: #efedeb;
  color: #8a817d;
}

.field small,
.field-help {
  color: var(--form-muted);
  font-size: 11px;
  line-height: 1.5;
}

.field-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.field-meta small:last-child {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.field-meta .is-at-limit,
.inline-input .is-at-limit {
  color: #a82d3c;
  font-weight: 800;
}

.field-meta-end {
  justify-content: flex-end;
}

.inline-input {
  position: relative;
  display: block;
}

.inline-input input {
  padding-right: 58px !important;
}

.inline-input small {
  position: absolute;
  top: 50%;
  right: 11px;
  transform: translateY(-50%);
  font-variant-numeric: tabular-nums;
}

.photo-input-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 12px;
  padding: 14px;
  background: #fbfaf6;
  border: 1px solid #e1ddd2;
  border-radius: 10px;
}

.photo-input-card + .photo-input-card {
  margin-top: 12px;
}

.photo-input-card .field-help {
  grid-column: 1 / -1;
  margin: -2px 0 0;
}

.photo-error,
.crop-editor {
  grid-column: 1 / -1;
}

.photo-error {
  margin: 0;
  padding: 10px 12px;
  background: #fff0f1;
  border: 1px solid #d66572;
  border-radius: 8px;
  color: #8b2633;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
}

.photo-error[hidden],
.crop-editor[hidden] {
  display: none;
}

.crop-editor {
  padding: 13px;
  background: #fff;
  border: 1px solid #cbd5d2;
  border-radius: 9px;
}

.crop-editor-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.crop-editor-heading strong {
  color: var(--form-ink);
  font-size: 13px;
}

.crop-editor-heading span {
  color: var(--form-muted);
  font-size: 10px;
  text-align: right;
}

.crop-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  margin: 0 auto;
  overflow: hidden;
  background: #f2f3f3;
  border: 1px solid #aab3b2;
  border-radius: 7px;
  touch-action: none;
}

.crop-stage[data-ratio="1:1"] {
  width: min(100%, 340px);
  aspect-ratio: 1;
}

.crop-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.crop-canvas.is-dragging {
  cursor: grabbing;
}

.crop-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px 12px;
  margin-top: 11px;
}

.crop-controls label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  grid-column: 1 / -1;
  color: var(--form-ink);
  font-size: 11px;
  font-weight: 750;
}

.crop-controls output {
  color: var(--form-accent);
  font-variant-numeric: tabular-nums;
}

.crop-controls input[type="range"] {
  width: 100%;
  min-height: 34px;
  margin: 0;
  accent-color: var(--form-accent);
}

.crop-controls button {
  min-height: 38px;
  padding: 6px 11px;
  background: #fff;
  border: 1px solid #aab3b2;
  border-radius: 7px;
  color: #394443;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.crop-advice {
  margin: 9px 0 0;
  color: var(--form-muted);
  font-size: 10.5px;
  line-height: 1.6;
}

.ratio-field {
  align-content: start;
}

.form-advice {
  margin: 16px 0 0;
  padding: 11px 12px;
  background: var(--form-accent-soft);
  border-radius: 8px;
  color: #354b4a;
  font-size: 11px;
  line-height: 1.65;
}

.age-row {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 8px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  font-size: 12px;
  font-weight: 650;
}

.check-field input {
  width: 20px;
  height: 20px;
  accent-color: var(--form-accent);
}

.form-actions {
  position: sticky;
  bottom: 10px;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  background: rgb(255 255 255 / 94%);
  border: 1px solid var(--form-border);
  border-radius: 12px;
  box-shadow: 0 5px 20px rgb(23 63 62 / 14%);
  backdrop-filter: blur(10px);
}

.primary-button,
.secondary-button,
.preview-header button {
  min-height: 46px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.primary-button {
  background: var(--form-accent);
  border: 1px solid var(--form-accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--form-accent-deep);
}

.secondary-button,
.preview-header button {
  background: #fff;
  border: 1px solid #aab3b2;
  color: #34403f;
}

.preview-header .pdf-button {
  background: var(--form-accent);
  border-color: var(--form-accent);
  color: #fff;
}

.preview-header .pdf-button:hover {
  background: var(--form-accent-deep);
}

.preview-header .pdf-button:disabled {
  cursor: wait;
  opacity: .72;
}

.normalized-preview {
  color: var(--form-accent) !important;
  font-weight: 800;
}

.form-errors {
  padding: 13px 15px;
  background: #fff1f2;
  border: 1px solid #cb5260;
  border-radius: 10px;
  color: #822634;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.preview-area {
  position: sticky;
  top: 14px;
  min-width: 0;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 210mm;
  max-width: 100%;
  margin: 0 auto 10px;
  color: var(--form-ink);
}

.preview-header h2,
.preview-header p {
  margin: 0;
}

.preview-header h2 {
  font-size: 20px;
}

.preview-header p {
  color: var(--form-accent);
  font-size: 11px;
  font-weight: 800;
}

.preview-header button {
  min-height: 40px;
}

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

#back-to-form {
  display: none;
}

.screen-note small {
  display: block;
  margin-top: 4px;
  color: var(--form-muted);
  font-size: 11px;
}

.screen-note .device-save-guide {
  margin-top: 7px;
  color: var(--form-accent);
  font-weight: 750;
}

.screen-note .qr-check-guide {
  color: var(--form-gold);
  font-weight: 750;
}

.screen-note .print-status {
  display: block;
  margin-top: 9px;
  padding: 9px 11px;
  background: #fff8e9;
  border: 1px solid #d8bd83;
  border-radius: 7px;
  color: #6f501b;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.6;
}

.screen-note .print-status[hidden] {
  display: none;
}

.screen-note .print-status.is-success {
  background: #eef8f3;
  border-color: #8ebda5;
  color: #275f45;
}

.screen-note .print-status.is-error {
  background: #fff1f2;
  border-color: #cb7a84;
  color: #822634;
}

.home-after-download {
  display: none;
  width: fit-content;
  margin-top: 10px;
  font-size: 12px;
}

.screen-note .print-status.is-success + .home-after-download {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
}

@media (max-width: 1180px) {
  .app-shell {
    display: block;
    width: min(820px, calc(100% - 24px));
  }

  .app-header {
    width: min(820px, calc(100% - 24px));
  }

  .compact-step-indicator {
    display: flex;
    align-items: center;
    width: min(760px, calc(100% - 24px));
    margin: 0 auto 18px;
    color: var(--form-muted);
    font-size: 12px;
    font-weight: 750;
  }

  .compact-step-indicator > span:not(.step-connector) {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
  }

  .compact-step-indicator b {
    display: grid;
    place-items: center;
    width: 25px;
    height: 25px;
    border: 1px solid #b9c3c0;
    border-radius: 50%;
    background: #fff;
    color: var(--form-muted);
    font-size: 11px;
  }

  .compact-step-indicator [aria-current="step"] {
    color: var(--form-accent);
  }

  .compact-step-indicator [aria-current="step"] b {
    background: var(--form-accent);
    border-color: var(--form-accent);
    color: #fff;
  }

  .step-connector {
    flex: 1 1 auto;
    height: 1px;
    margin: 0 10px;
    background: #c5cecb;
  }

  .input-form {
    width: min(760px, 100%);
    margin: 0 auto;
  }

  .preview-area {
    position: static;
    display: none;
    width: 100%;
  }

  body.is-preview-mode .input-form {
    display: none;
  }

  body.is-preview-mode .preview-area {
    display: block;
  }

  #back-to-form {
    display: block;
  }

  .preview-header {
    position: sticky;
    top: 0;
    z-index: 8;
    width: 100%;
    margin-bottom: 0;
    padding: 10px 2px;
    background: rgb(247 244 237 / 96%);
    backdrop-filter: blur(8px);
  }

  .wide-screen-note {
    display: none;
  }

  .compact-screen-note {
    display: inline;
  }

  .screen-note {
    margin: 7px auto 12px;
    padding: 0 6px;
    font-size: 12px;
    line-height: 1.6;
  }

  .preview-viewport {
    overflow: hidden;
  }

  .flyer-scale {
    margin-right: auto;
    margin-left: auto;
  }

  .flyer-page {
    margin: 0;
    transform-origin: top left;
  }
}

@media (max-width: 560px) {
  .app-header {
    margin-top: 20px;
  }

  .app-shell {
    gap: 20px;
  }

  .form-card {
    padding: 17px 15px;
    border-radius: 12px;
  }

  .field-grid-2,
  .photo-input-card {
    grid-template-columns: 1fr;
  }

  .photo-input-card .field-help {
    grid-column: 1;
  }

  .crop-editor-heading {
    display: grid;
    gap: 3px;
  }

  .crop-editor-heading span {
    text-align: left;
  }

  .form-actions {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 6px;
    padding: 8px;
  }

  .form-actions button {
    min-height: 44px;
    padding: 7px 8px;
    font-size: 11.5px;
  }

  .preview-header {
    display: grid;
    gap: 8px;
  }

  .preview-header h2 {
    font-size: 17px;
  }

  .preview-header button {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 11px;
  }

  .preview-header-actions {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    width: 100%;
    gap: 6px;
  }
}

@media print {
  html,
  body {
    width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    background: #fff !important;
  }

  .app-header,
  .input-form,
  .preview-header,
  .compact-step-indicator,
  .home-after-download {
    display: none !important;
  }

  .app-shell,
  .preview-area {
    position: static !important;
    display: block !important;
    width: 210mm;
    min-height: 0 !important;
    margin: 0;
  }

  body.is-ios-print,
  body.is-ios-print .app-shell,
  body.is-ios-print .preview-area,
  body.is-ios-print .preview-viewport,
  body.is-ios-print .flyer-scale {
    height: 285.12mm !important;
    min-height: 0 !important;
    max-height: 285.12mm !important;
    overflow: hidden !important;
  }
}
