.event-timing-lab {
  --timing-navy: #0c3153;
  --timing-blue: #007f99;
  --timing-orange: #d16612;
  --timing-ink: #17324a;
  --timing-muted: #60758a;
  margin: 1.5rem 0;
  border: 1px solid #cddce8;
  border-top: 4px solid #ef7a16;
  border-radius: 18px;
  overflow: hidden;
  background: #f8fbfd;
  box-shadow: 0 18px 44px rgba(11, 45, 98, .09);
}

.event-timing-lab * { box-sizing: border-box; }
.event-timing-lab button, .event-timing-lab input, .event-timing-lab textarea { font: inherit; }
.timing-lab-header { padding: 1.25rem 1.4rem; color: white; background: linear-gradient(120deg, #0c3153, #135579); }
.timing-lab-eyebrow { margin: 0 0 .3rem; color: #7fe3e9; font-size: .76rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.timing-lab-header h3 { margin: 0; color: white; font-size: clamp(1.2rem, 3vw, 1.65rem); }
.timing-lab-header p:last-child { margin: .5rem 0 0; max-width: 62rem; color: #e6f4fa; }
.timing-mode { display: flex; flex-wrap: wrap; gap: .55rem; padding: 1rem 1.25rem 0; border: 0; }
.timing-mode legend { width: 100%; color: var(--timing-ink); font-weight: 800; }
.timing-mode label { display: inline-flex; align-items: center; gap: .45rem; min-height: 42px; padding: .55rem .8rem; border: 1px solid #b9cfdd; border-radius: 999px; background: white; color: var(--timing-ink); cursor: pointer; }
.timing-mode label:has(input:checked) { border-color: #147d94; background: #e8f7f8; box-shadow: inset 0 0 0 1px #147d94; }
.timing-mode input { inline-size: 1.05rem; block-size: 1.05rem; accent-color: #087e99; }
.timing-field-alert { margin: .75rem 1.25rem 0; padding: .75rem .9rem; border-left: 4px solid #d16612; border-radius: 8px; background: #fff5e9; color: #704014; }
.timing-presets { display: flex; flex-wrap: wrap; gap: .5rem; padding: .8rem 1.25rem 0; }
.timing-presets button, .timing-actions button { min-height: 42px; padding: .55rem .8rem; border: 1px solid #9eb9cb; border-radius: 9px; background: white; color: #123b5a; font-weight: 750; cursor: pointer; }
.timing-presets button:hover, .timing-actions button:hover { border-color: #087e99; background: #effafb; }
.timing-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(17rem, .8fr); gap: 1rem; padding: 1rem 1.25rem 1.25rem; }
.timing-stage, .timing-controls { min-width: 0; border: 1px solid #d4e1ea; border-radius: 14px; background: white; }
.timing-stage { padding: .85rem; }
.timing-stage-top { display: flex; align-items: start; justify-content: space-between; gap: .8rem; margin-bottom: .45rem; }
.timing-stage-top strong { color: var(--timing-ink); }
.timing-stage-top span { color: var(--timing-muted); font-size: .83rem; text-align: right; }
.timing-chart { display: block; width: 100%; min-height: 310px; border-radius: 10px; background: #f8fbfd; touch-action: none; user-select: none; }
.timing-chart .grid { stroke: #d9e5ed; stroke-width: 1; }
.timing-chart .axis { stroke: #7590a5; stroke-width: 1.25; }
.timing-chart .axis-label, .timing-chart .row-label { fill: #4b657a; font-size: 13px; }
.timing-chart .row-label { font-weight: 800; }
.timing-chart .range-a { fill: #b7edf0; stroke: var(--timing-blue); }
.timing-chart .range-b { fill: #ffe0bd; stroke: var(--timing-orange); }
.timing-chart .range { stroke-width: 3; stroke-linecap: round; }
.timing-chart .center { stroke-width: 3; }
.timing-chart .handle { cursor: ew-resize; outline: none; }
.timing-chart .handle circle { stroke: white; stroke-width: 3; filter: drop-shadow(0 2px 3px rgba(13, 48, 73, .28)); }
.timing-chart .handle[data-handle$="center"] { cursor: grab; }
.timing-chart .handle[data-handle$="center"]:active { cursor: grabbing; }
.timing-chart .handle:focus circle { stroke: #102f4d; stroke-width: 5; }
.timing-chart .handle-label { fill: #123b5a; font-size: 11px; font-weight: 800; pointer-events: none; }
.timing-chart .range, .timing-chart .center, .timing-chart .handle { animation: timing-chart-refresh 160ms ease-out both; }
.timing-chart-help { margin: .7rem .1rem .1rem; color: var(--timing-muted); font-size: .84rem; }
.timing-controls { padding: .9rem; }
.timing-event-card + .timing-event-card { margin-top: .85rem; padding-top: .85rem; border-top: 1px solid #dbe6ed; }
.timing-event-card h4 { margin: 0 0 .65rem; color: var(--timing-ink); }
.timing-event-card.a h4 { color: var(--timing-blue); }
.timing-event-card.b h4 { color: var(--timing-orange); }
.timing-input-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .55rem; }
.timing-input-row label, .timing-meta label { display: grid; gap: .3rem; color: #4b6479; font-size: .76rem; font-weight: 750; }
.timing-input-row input, .timing-meta input, .timing-meta textarea { width: 100%; min-height: 42px; padding: .55rem .6rem; border: 1px solid #abc0cf; border-radius: 8px; background: #fff; color: #16334b; }
.timing-input-row input:focus, .timing-meta input:focus, .timing-meta textarea:focus { outline: 3px solid rgba(0, 127, 153, .18); border-color: #087e99; }
.timing-meta { display: grid; gap: .65rem; margin-top: .9rem; padding-top: .9rem; border-top: 1px solid #dbe6ed; }
.timing-meta textarea { min-height: 70px; resize: vertical; }
.timing-result { margin: 0 1.25rem 1rem; padding: 1rem; border: 1px solid #bcd3df; border-left: 5px solid #087e99; border-radius: 12px; background: white; }
.timing-result[data-relation="a-before-b"], .timing-result[data-relation="b-before-a"] { border-left-color: #22834d; background: #f4fbf7; }
.timing-result h4 { margin: 0; color: var(--timing-ink); font-size: 1.1rem; }
.timing-result > p { margin: .35rem 0 0; color: #4d6578; }
.timing-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; margin: .8rem 0 0; }
.timing-metrics div { padding: .65rem; border-radius: 9px; background: #eef5f8; }
.timing-metrics dt { color: #60758a; font-size: .72rem; font-weight: 800; }
.timing-metrics dd { margin: .15rem 0 0; color: #113d5d; font-weight: 850; overflow-wrap: anywhere; }
.timing-formula { margin: .75rem 0 0; padding: .65rem .75rem; border-radius: 8px; background: #0f3150; color: #effbff; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; overflow-x: auto; }
.timing-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; padding: 0 1.25rem 1.2rem; }
.timing-actions button[data-copy] { border-color: #087e99; background: #087e99; color: white; }
.timing-actions button[data-copy]:hover { background: #066a81; }
.timing-copy-status { color: #356276; font-size: .85rem; }
.timing-boundary { margin: 0; padding: .95rem 1.25rem; border-top: 1px solid #d5e3eb; background: #eef4f8; color: #425d71; font-size: .87rem; }
.timing-boundary strong { color: #173a55; }

@media (max-width: 760px) {
  .timing-grid { grid-template-columns: 1fr; padding-inline: .75rem; }
  .timing-mode, .timing-presets { padding-inline: .75rem; }
  .timing-field-alert, .timing-result { margin-inline: .75rem; }
  .timing-actions { padding-inline: .75rem; }
  .timing-input-row { grid-template-columns: 1fr; }
  .timing-metrics { grid-template-columns: 1fr; }
  .timing-chart { min-height: 280px; }
  .timing-stage-top { display: block; }
  .timing-stage-top span { display: block; margin-top: .25rem; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .event-timing-lab * { scroll-behavior: auto !important; transition: none !important; }
  .timing-chart .range, .timing-chart .center, .timing-chart .handle { animation: none !important; }
}

@keyframes timing-chart-refresh {
  from { opacity: .58; }
  to { opacity: 1; }
}
