:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --line: #d8e0e7;
  --line-strong: #bdcad5;
  --text: #14202b;
  --muted: #607081;
  --accent: #2764d8;
  --accent-strong: #174db4;
  --event: #d76b20;
  --danger: #c23737;
  --success: #287c54;
  --shadow: 0 18px 50px rgba(22, 39, 58, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(247, 248, 251, 0.95)),
    var(--bg);
}

button,
textarea,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.input-panel,
.timeline-frame,
.event-list-panel,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  padding: 20px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.2;
}

h3 {
  font-size: 1rem;
  line-height: 1.25;
}

.primary-button {
  min-width: 116px;
  min-height: 44px;
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
}

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

.secondary-button {
  min-height: 44px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 800;
  cursor: pointer;
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: var(--line-strong);
  background: #e8eef4;
}

.input-body {
  display: block;
}

.input-panel.is-collapsed {
  padding-top: 14px;
  padding-bottom: 10px;
}

.input-panel.is-collapsed h1 {
  font-size: 1.15rem;
}

.input-panel.is-collapsed .eyebrow {
  display: none;
}

.input-panel.is-collapsed .input-body {
  display: none;
}

.input-panel.is-collapsed .message {
  min-height: 18px;
  margin-top: 6px;
  font-size: 0.82rem;
}

.json-input {
  display: block;
  width: 100%;
  min-height: 180px;
  margin-top: 18px;
  padding: 14px;
  color: var(--text);
  background: #fbfcfe;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  line-height: 1.5;
  resize: vertical;
}

.json-input:focus {
  outline: 3px solid rgba(39, 100, 216, 0.18);
  border-color: var(--accent);
}

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

.message.error {
  color: var(--danger);
}

.message.success {
  color: var(--success);
}

.empty-state {
  margin-top: 18px;
  padding: 28px;
}

.empty-state p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.viewer {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.viewer.is-hidden,
.is-hidden {
  display: none;
}

.legend {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
}

.legend-ex {
  background: var(--accent);
}

.legend-event {
  background: var(--event);
}

.legend-ns {
  background: #0d9488;
}

.legend-disabled {
  background: repeating-linear-gradient(45deg, #98a5b1 0 4px, #c9d1d8 4px 8px);
}

.timeline-frame,
.event-list-panel {
  padding: 18px;
}

.timeline-frame {
  min-width: 0;
}

.timeline-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.timeline-name {
  max-width: 620px;
  margin: 0 0 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
}

.timeline-meta div {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  min-height: 26px;
  padding: 4px 8px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.timeline-meta dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.timeline-meta dd {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 900;
}

.display-mode-control select {
  min-height: 22px;
  padding: 0 22px 0 7px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font-size: 0.76rem;
  font-weight: 900;
}

.timeline-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.timeline-scale-control {
  display: inline-grid;
  grid-template-columns: auto minmax(180px, 280px) 48px;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.timeline-scale-control input {
  width: 100%;
  accent-color: var(--accent);
}

.timeline-scale-control output {
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.timeline-scroll {
  width: 100%;
  margin-top: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
}

.timeline-chart {
  position: relative;
  --lane-label-width: 168px;
  --timeline-track-width: 780px;
  min-width: calc(var(--lane-label-width) + var(--timeline-track-width));
  padding: 0;
}

.time-axis,
.lane {
  display: grid;
  grid-template-columns: var(--lane-label-width) minmax(var(--timeline-track-width), 1fr);
}

.time-axis {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 42px;
  color: var(--muted);
  background: #fbfcfe;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
}

.axis-spacer,
.lane-label {
  position: sticky;
  left: 0;
  z-index: 4;
  border-right: 1px solid var(--line);
}

.axis-spacer {
  background: #fbfcfe;
}

.lane-label {
  background: #fff;
}

.axis-track,
.lane-track-stack,
.lane-track {
  position: relative;
  min-width: var(--timeline-track-width);
}

.lane-track-stack {
  display: grid;
  grid-template-rows: 76px;
}

.lane.has-ns-lane .lane-track-stack {
  grid-template-rows: 76px 42px;
}

.lane-track {
  min-height: 76px;
}

.lane-track-ns {
  min-height: 42px;
  background: rgba(13, 148, 136, 0.04);
  border-top: 1px dashed var(--line);
}

.axis-mark {
  position: absolute;
  top: 0;
  height: 100%;
  transform: translateX(-50%);
  white-space: nowrap;
}

.axis-mark::before {
  content: "";
  position: absolute;
  top: 24px;
  left: 50%;
  width: 1px;
  height: 12px;
  background: var(--line-strong);
}

.selection-guides {
  position: absolute;
  top: 42px;
  bottom: 0;
  left: var(--lane-label-width);
  z-index: 1;
  width: calc(100% - var(--lane-label-width));
  min-width: var(--timeline-track-width);
  pointer-events: none;
}

.selection-guides.is-hidden {
  display: none;
}

.selection-guide-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 2px solid rgba(194, 55, 55, 0.72);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.72);
}

.selection-guide-line.is-end {
  border-left-style: dashed;
}

.lane {
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(216, 224, 231, 0.5) 1px, transparent 1px),
    #fff;
  background-size: var(--grid-step, 130px) 100%;
}

.lane.has-ns-lane {
  min-height: 118px;
}

.lane:last-child {
  border-bottom: 0;
}

.lane-label {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-content: start;
  align-items: start;
  gap: 10px;
  min-width: 0;
  padding: 10px 12px;
}

.lane-icon-wrap {
  display: inline-grid;
  place-items: center;
}

.lane-text {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.lane-name {
  display: block;
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lane-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
}

.lane-ex-landing-control,
.lane-ex-effect-adjustment-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 3px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  white-space: nowrap;
}

.lane-ex-landing-control input,
.lane-ex-effect-adjustment-control input {
  width: 100%;
  min-width: 0;
  min-height: 22px;
  padding: 2px 5px;
  color: var(--text);
  background: #fbfcfe;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font: inherit;
  font-weight: 900;
}

.lane-ns-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  margin-top: 0;
}

.lane-ns-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #0f766e;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.lane-ns-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #0f766e;
}

.lane-ns-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  min-width: 0;
  margin-top: 2px;
}

.lane-ns-fields.is-hidden {
  display: none;
}

.lane-ns-fields label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 3px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.lane-ns-fields input {
  width: 100%;
  min-width: 0;
  min-height: 24px;
  padding: 2px 5px;
  color: var(--text);
  background: #fbfcfe;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font: inherit;
  font-weight: 900;
}

.event-chip {
  position: absolute;
  top: 12px;
  z-index: 2;
  min-width: 76px;
  max-width: 160px;
  height: 42px;
  padding: 7px 9px;
  color: #fff;
  background: var(--chip-color, var(--accent));
  border: 0;
  border-radius: 6px;
  box-shadow: 0 8px 16px rgba(16, 33, 52, 0.18);
  cursor: pointer;
  text-align: left;
}

.event-chip.has-target {
  padding-right: 30px;
}

.lane-icon,
.event-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  object-fit: cover;
  background: #dce5ee;
  border: 1px solid rgba(20, 32, 43, 0.18);
  border-radius: 999px;
}

.lane-icon.icon-fallback,
.event-icon.icon-fallback {
  color: var(--muted);
  font-weight: 900;
}

.ex-event {
  appearance: none;
  position: absolute;
  top: 8px;
  z-index: 2;
  height: 64px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  min-width: 42px;
}

.ex-event:hover,
.ex-event:focus-visible,
.ex-event.is-selected {
  outline: 0;
}

.ex-event.is-disabled {
  filter: grayscale(0.9);
  opacity: 0.62;
}

.ex-event.has-duration {
  min-width: 0;
}

.ex-effect-bar {
  position: absolute;
  top: 3px;
  left: var(--ex-effect-left, 0);
  z-index: 1;
  width: var(--ex-effect-width, 100%);
  min-width: 0;
  height: 36px;
  background: color-mix(in srgb, var(--chip-color) 72%, white);
  border-radius: 0;
  opacity: 0.48;
}

.ex-icon-marker {
  position: absolute;
  top: 0;
  left: var(--ex-marker-x, 21px);
  transform: translateX(-50%);
  z-index: 2;
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: var(--chip-color);
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 8px 16px rgba(16, 33, 52, 0.2);
}

.ex-event.is-rio-copy-ex .ex-icon-marker {
  box-shadow:
    0 0 0 2px rgba(165, 243, 252, 0.72),
    0 0 18px rgba(77, 208, 255, 0.62),
    0 8px 16px rgba(16, 33, 52, 0.2);
}

.ex-icon-core {
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  overflow: hidden;
  border-radius: 999px;
}

.ex-event.is-rio-copy-ex .ex-icon-core {
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.62), transparent 26%),
    linear-gradient(135deg, rgba(46, 230, 255, 0.72), rgba(46, 230, 255, 0.36) 54%, rgba(166, 255, 255, 0.5)),
    var(--chip-color);
}

.ex-event.is-rio-copy-ex .ex-icon-core::before,
.ex-event.is-rio-copy-ex .ex-icon-core::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 999px;
}

.ex-event.is-rio-copy-ex .ex-icon-core::before {
  inset: 0;
  z-index: 2;
  background:
    linear-gradient(180deg, rgba(46, 230, 255, 0.42), rgba(46, 230, 255, 0.42)),
    radial-gradient(circle at 14% 24%, rgba(255, 255, 255, 0.18) 0 1px, transparent 2px),
    radial-gradient(circle at 68% 72%, rgba(255, 255, 255, 0.14) 0 1px, transparent 2px);
  background-size: auto, 7px 9px, 11px 13px;
  mix-blend-mode: color;
  opacity: 0.88;
}

.ex-event.is-rio-copy-ex .ex-icon-core::after {
  inset: 0;
  z-index: 3;
  background:
    repeating-linear-gradient(180deg, rgba(166, 255, 255, 0.36) 0 1px, transparent 1px 4px),
    linear-gradient(112deg, transparent 24%, rgba(255, 255, 255, 0.34) 43%, rgba(166, 255, 255, 0.28) 50%, transparent 66%);
  opacity: 0.72;
  mix-blend-mode: screen;
}

.ex-event:hover .ex-icon-marker,
.ex-event:focus-visible .ex-icon-marker,
.ex-event.is-selected .ex-icon-marker {
  outline: 3px solid rgba(20, 32, 43, 0.24);
  outline-offset: 3px;
}

.ex-icon-marker .event-icon {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  border: 0;
}

.ex-event.is-rio-copy-ex .event-icon {
  opacity: 0.88;
  filter: saturate(1.08) contrast(1.05) brightness(1.02);
}

.target-icon-badge {
  position: absolute;
  right: -5px;
  bottom: -5px;
  z-index: 4;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  overflow: hidden;
  background: #fff;
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 3px 8px rgba(16, 33, 52, 0.24);
  pointer-events: none;
}

.event-target-badge {
  right: 5px;
  bottom: 5px;
  width: 20px;
  height: 20px;
}

.target-icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #dce5ee;
  border: 0;
  border-radius: 999px;
}

.target-icon.icon-fallback {
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 900;
}

.ns-event {
  appearance: none;
  position: absolute;
  top: 9px;
  z-index: 2;
  min-width: 0;
  height: 24px;
  padding: 0;
  overflow: hidden;
  color: #fff;
  background: rgba(13, 148, 136, 0.66);
  border: 0;
  border-radius: 0;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  text-align: left;
}

.ns-event:hover,
.ns-event:focus-visible,
.ns-event.is-selected {
  outline: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.38);
}

.ns-event span {
  display: block;
  padding: 0 2px;
  overflow: hidden;
  line-height: 24px;
  text-overflow: clip;
}

.ns-delay-control {
  display: inline-grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  align-items: center;
  gap: 5px;
  width: 100%;
  max-width: 150px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.ns-delay-control input,
.ex-event-effect-control input {
  width: 100%;
  min-height: 28px;
  padding: 3px 7px;
  color: var(--text);
  background: #fbfcfe;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font: inherit;
  font-weight: 900;
}

.ex-event-effect-control {
  display: inline-grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  align-items: center;
  gap: 5px;
  width: 100%;
  max-width: 150px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.ex-cost-label {
  position: absolute;
  top: 45px;
  left: var(--ex-marker-x, 21px);
  transform: translateX(-50%);
  z-index: 3;
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  min-height: 18px;
  padding: 0 7px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(20, 32, 43, 0.14);
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(16, 33, 52, 0.12);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
}

.event-chip.event-type-event {
  background: var(--event);
}

.event-chip.is-disabled {
  background: repeating-linear-gradient(45deg, #718090 0 6px, #909daa 6px 12px);
}

.event-chip:hover,
.event-chip:focus-visible,
.event-chip.is-selected {
  outline: 3px solid rgba(20, 32, 43, 0.2);
  outline-offset: 2px;
}

.chip-title,
.chip-time {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-time {
  font-size: 0.72rem;
  font-weight: 800;
  opacity: 0.92;
}

.chip-title {
  margin-top: 1px;
  font-size: 0.82rem;
  font-weight: 800;
}

.detail-grid {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 8px 12px;
}

.detail-grid dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-grid dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.detail-popover {
  position: fixed;
  z-index: 1000;
  width: min(320px, calc(100vw - 24px));
  max-height: min(520px, calc(100vh - 24px));
  padding: 14px;
  overflow: auto;
  color: var(--text);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 20px 55px rgba(16, 33, 52, 0.22);
  line-height: 1.45;
}

.event-list-panel {
  grid-column: 1 / -1;
}

.table-wrap {
  width: 100%;
  margin-top: 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.event-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

.event-table th,
.event-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.event-table th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.event-table tbody tr {
  cursor: pointer;
}

.event-table tbody tr:hover,
.event-table tbody tr.is-selected {
  background: #eef5ff;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.event {
  background: var(--event);
}

@media (max-width: 920px) {
  .viewer {
    grid-template-columns: 1fr;
  }

  .timeline-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .timeline-meta {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 14px;
  }

  .input-panel,
  .timeline-frame,
  .event-list-panel,
  .empty-state {
    padding: 14px;
  }

  .section-heading {
    display: block;
  }

  .primary-button {
    width: 100%;
    margin-top: 14px;
  }

  .timeline-toolbar {
    justify-content: flex-start;
  }

  .timeline-scale-control {
    grid-template-columns: auto minmax(0, 1fr) 48px;
    width: 100%;
  }

  .timeline-chart {
    --lane-label-width: 132px;
  }
}
