:root {
  color-scheme: light;
  --bg: #f5f0e8;
  --card: #fffdf8;
  --ink: #241916;
  --muted: #74665d;
  --line: #dfd3c5;
  --red: #8d1f27;
  --red-2: #b2363d;
  --green: #1f7452;
  --shadow: 0 18px 48px rgba(55, 36, 28, .1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 100% 0, rgba(157, 32, 39, .15), transparent 34rem),
    linear-gradient(180deg, #fbf7f0, var(--bg));
  color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
}

.page {
  width: min(880px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(96px, env(safe-area-inset-bottom));
}

.hero {
  padding: 12px 4px 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
}

h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", Georgia, serif;
  font-size: clamp(28px, 8vw, 42px);
  line-height: 1.08;
}

.hero p {
  max-width: 720px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.card {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid rgba(223, 211, 197, .95);
  border-radius: 18px;
  background: rgba(255, 253, 248, .96);
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-family: "Songti SC", "STSong", Georgia, serif;
  font-size: 19px;
}

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

.meta-grid label:last-child {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

input,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
}

input[aria-invalid="true"] {
  border-color: #b73535;
  box-shadow: 0 0 0 3px rgba(183, 53, 53, .1);
}

.required {
  color: #b73535;
}

textarea {
  min-height: 70px;
  resize: vertical;
}

.detection {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #eadfd4;
  border-radius: 11px;
  background: #fbf7f1;
  color: var(--muted);
  font-size: 12px;
}

.detection strong {
  flex: none;
  color: var(--red);
  font-size: 11px;
  letter-spacing: .04em;
}

.detection span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.detection span.error {
  color: #a82222;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 8px;
}

.metric {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid #eadfd4;
  border-radius: 12px;
  background: #fbf7f1;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .05em;
}

.metric strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: #39251f;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  min-height: 24px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.status.ok { color: var(--green); }
.status.error { color: #a3262d; }

.toast {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  z-index: 20;
  width: min(520px, calc(100vw - 28px));
  padding: 14px 18px;
  border: 1px solid rgba(31, 116, 82, .35);
  border-radius: 14px;
  background: #1f7452;
  color: #fff;
  box-shadow: 0 18px 55px rgba(24, 64, 47, .28);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.45;
  text-align: center;
  transform: translateX(-50%);
  white-space: pre-line;
}

.toast.error {
  border-color: rgba(163, 38, 45, .35);
  background: #a3262d;
  box-shadow: 0 18px 55px rgba(120, 24, 31, .28);
}

.toast[hidden] {
  display: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 15px;
  background: #fff;
  color: var(--ink);
  font: 600 13px/1 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
}

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

button:active { transform: translateY(1px); }
button:disabled { opacity: .52; }

pre {
  max-height: 56vh;
  margin: 0;
  overflow: auto;
  padding: 13px;
  border-radius: 12px;
  background: #211917;
  color: #f5eadc;
  font: 11px/1.55 "SFMono-Regular", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.note {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 11px;
  background: #fff2e8;
  color: #734b35;
  font-size: 11px;
}

.sticky-save {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  padding: 10px max(16px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid rgba(223, 211, 197, .8);
  background: rgba(255, 253, 248, .94);
  backdrop-filter: blur(18px);
}

.sticky-save .inner {
  width: min(848px, 100%);
  margin: 0 auto;
}

.sticky-save button {
  width: 100%;
  min-height: 48px;
  font-size: 15px;
}

code {
  padding: 1px 4px;
  border-radius: 4px;
  background: #eee5da;
  font-size: .92em;
}

@media (max-width: 600px) {
  .page { padding-right: 12px; padding-left: 12px; }
  .card { padding: 14px; border-radius: 16px; }
  .meta-grid { grid-template-columns: 1fr; }
  .meta-grid label:last-child { grid-column: auto; }
}
