:root {
  color-scheme: light;
  --ink: #20241f;
  --muted: #60685e;
  --paper: #f4f1e8;
  --card: #fffdf7;
  --line: #d8d4c7;
  --primary: #2b5f52;
  --primary-dark: #17463b;
  --danger: #9c332e;
  --danger-soft: #fff0ec;
  --encounter: #765300;
  --encounter-soft: #fff7d9;
  --gap: #345b8c;
  --gap-soft: #eef5ff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
}

button, input, select, textarea { font: inherit; }
button, .file-button {
  min-height: 44px;
  padding: .55rem .85rem;
  border: 1px solid #92998f;
  border-radius: .5rem;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}
button:hover, .file-button:hover { background: #f0f3ef; }
button:disabled { cursor: not-allowed; opacity: .55; }
button.primary { border-color: var(--primary); color: #fff; background: var(--primary); }
button.primary:hover { background: var(--primary-dark); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .file-button:focus-within {
  outline: 3px solid #e1932d;
  outline-offset: 2px;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: .55rem .65rem;
  border: 1px solid #8c938a;
  border-radius: .4rem;
  color: var(--ink);
  background: #fff;
}
textarea { resize: vertical; }
label { display: block; font-weight: 700; }

.skip-link {
  position: absolute;
  z-index: 10;
  top: -5rem;
  left: 1rem;
  padding: .6rem 1rem;
  color: #fff;
  background: var(--ink);
}
.skip-link:focus { top: 1rem; }

.site-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 25rem);
  gap: 2rem;
  align-items: end;
  padding: 2.5rem max(1rem, calc((100% - 1180px) / 2));
  color: #fff;
  background: var(--primary-dark);
}
.site-header h1 { margin: .1rem 0; font-size: clamp(1.8rem, 5vw, 3.2rem); line-height: 1.2; }
.site-header p { margin: .3rem 0; }
.eyebrow, .step { font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.title-field input { margin-top: .35rem; border-color: #fff; }

main { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; }
.status {
  min-height: 2.8rem;
  margin: 1rem 0;
  padding: .55rem .8rem;
  border-left: 4px solid var(--primary);
  background: var(--card);
}
.status[data-kind="error"] { border-color: var(--danger); color: #6d1f1b; }
.panel { margin: 1rem 0; padding: clamp(1rem, 3vw, 1.6rem); border: 1px solid var(--line); border-radius: .8rem; background: var(--card); box-shadow: 0 4px 18px #3643370d; }
.section-heading { display: flex; gap: 2rem; align-items: end; justify-content: space-between; margin-bottom: 1.2rem; }
.section-heading h2, .section-heading p { margin: 0; }
.section-heading > p { max-width: 40rem; color: var(--muted); }
.timeline-intro { max-width: 40rem; color: var(--muted); text-align: right; }
.timeline-intro p { margin: 0 0 .5rem; }
.step { color: var(--primary); }
.count { display: inline-block; margin-left: .25rem; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; vertical-align: middle; color: #fff; background: var(--primary); }

.master-grid, .analysis-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.2rem; }
.master-grid > div { padding: 1rem; border: 1px solid var(--line); border-radius: .6rem; }
.master-grid h3, .result-card h3 { margin-top: 0; }
.inline-controls { display: flex; gap: .5rem; }
.tag-list { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.tag-list li:not(.empty) { display: flex; gap: .35rem; align-items: center; padding-left: .7rem; border: 1px solid var(--line); border-radius: 999px; background: #f8faf7; }
.small { min-height: 36px; padding: .3rem .6rem; font-size: .85rem; }
.danger-button { color: var(--danger); }
.tag-list .danger-button { border: 0; border-left: 1px solid var(--line); border-radius: 0 999px 999px 0; }
.empty { color: var(--muted); }

.action-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.description-field, .form-error, .form-actions { grid-column: 1 / -1; }
.form-error { min-height: 1.5rem; margin: 0; color: var(--danger); font-weight: 700; }
.form-actions, .item-controls, .output-controls, .data-groups > div { display: flex; flex-wrap: wrap; gap: .5rem; }

.timeline { position: relative; }
.timeline::before { position: absolute; top: 0; bottom: 0; left: 7.5rem; width: 3px; content: ""; background: #a8bdb5; }
.timeline-item { position: relative; display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: 2rem; padding: .6rem 0; }
.timeline-item::before { position: absolute; top: 1.4rem; left: 7.13rem; width: .75rem; height: .75rem; border: 3px solid var(--card); border-radius: 50%; content: ""; background: var(--primary); }
.timeline-time { margin: .65rem 0 0; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.timeline-body { padding: .8rem 1rem; border: 1px solid var(--line); border-radius: .55rem; background: #fff; }
.timeline-body h3, .timeline-body p { margin: 0 0 .5rem; overflow-wrap: anywhere; }
.empty-block { padding: 2rem; border: 2px dashed var(--line); border-radius: .5rem; color: var(--muted); text-align: center; }

.threshold { min-width: 12rem; }
.threshold label > span { display: flex; align-items: center; gap: .4rem; }
.threshold input { width: 6rem; }
.threshold-error { min-height: 1.5rem; margin: .25rem 0 0; color: var(--danger); font-size: .85rem; font-weight: 700; }
.analysis-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.result-card { padding: 1rem; border: 1px solid var(--line); border-top-width: 5px; border-radius: .55rem; }
.result-card ul { padding-left: 1.25rem; }
.result-card li { margin: .5rem 0; overflow-wrap: anywhere; }
.result-card.danger { border-top-color: var(--danger); background: var(--danger-soft); }
.result-card.encounter { border-top-color: var(--encounter); background: var(--encounter-soft); }
.result-card.gap { border-top-color: var(--gap); background: var(--gap-soft); }

.output-controls { align-items: end; }
.output-controls label { min-width: 12rem; }
.text-output { min-height: 12rem; max-height: 28rem; overflow: auto; margin: 1rem 0 0; padding: 1rem; border: 1px solid var(--line); border-radius: .5rem; white-space: pre-wrap; overflow-wrap: anywhere; color: #ecf4ed; background: #1f2923; }
.data-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.data-groups > div { align-content: start; padding: 1rem; border: 1px solid var(--line); border-radius: .55rem; }
.data-groups h3 { flex-basis: 100%; margin: 0; }
.file-button { display: inline-flex; align-items: center; font-weight: 400; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

footer { padding: 2rem 1rem 3rem; color: var(--muted); text-align: center; }

@media (max-width: 800px) {
  .site-header, .master-grid, .analysis-grid, .data-groups { grid-template-columns: 1fr; }
  .section-heading { display: block; }
  .section-heading > p, .threshold, .timeline-intro { margin-top: .6rem; }
  .timeline-intro { text-align: left; }
  .action-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  main { width: min(100% - 1rem, 1180px); }
  .panel { padding: .85rem; }
  .action-form { grid-template-columns: 1fr; }
  .action-form > * { grid-column: 1; }
  .inline-controls { align-items: stretch; }
  .timeline::before { left: .45rem; }
  .timeline-item { display: block; padding-left: 1.6rem; }
  .timeline-item::before { left: .08rem; }
  .timeline-time { text-align: left; }
  .item-controls button { flex: 1 1 40%; }
  .output-controls > button, .output-controls > label, .data-groups button, .file-button { width: 100%; }
}
