:root {
  --bg-a: #f7f1e8;
  --bg-b: #ece3d6;
  --ink: #1f2229;
  --ink-muted: #575f6d;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(31, 34, 41, 0.14);
  --accent: #146c5f;
  --accent-soft: rgba(20, 108, 95, 0.16);
  --warning: #9f3418;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", "Helvetica Neue", sans-serif;
  min-height: 100vh;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 900px at 90% -20%, rgba(20, 108, 95, 0.24), transparent 62%),
    radial-gradient(900px 700px at -10% 110%, rgba(159, 52, 24, 0.18), transparent 58%),
    linear-gradient(180deg, var(--bg-a), var(--bg-b));
  z-index: -1;
}

.layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px 18px 40px;
  display: grid;
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.title-block {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.title-logo {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  display: block;
}

.title-copy {
  min-width: 0;
  display: grid;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3.4vw, 2.2rem);
  letter-spacing: 0.01em;
  font-family: "Atkinson Hyperlegible", "Helvetica Neue", sans-serif;
}

h2,
h3 {
  margin: 0 0 8px;
  font-family: "Atkinson Hyperlegible", "Helvetica Neue", sans-serif;
  letter-spacing: 0.01em;
}

p {
  margin: 6px 0 0;
  color: var(--ink-muted);
}

.topbar-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
  min-width: 340px;
}

.topbar-actions h2 {
  margin-bottom: 0;
  font-size: 0.92rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.combo-picker {
  display: grid;
  gap: 7px;
  justify-items: end;
  min-width: 320px;
}

.combo-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.combo-row-label {
  color: var(--ink-muted);
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-width: 80px;
  text-align: right;
}

.combo-row-options {
  display: flex;
  gap: 8px;
}

.combo-option {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 6px 11px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
  font: inherit;
}

.combo-option:hover {
  transform: translateY(-1px);
  border-color: rgba(20, 108, 95, 0.4);
}

.combo-option.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.runtime-message {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.runtime-message[data-level="warning"] {
  border-color: rgba(159, 52, 24, 0.36);
  color: #9f3418;
}

.runtime-message[data-level="error"] {
  border-color: rgba(159, 52, 24, 0.5);
  color: #8a2b12;
  background: rgba(255, 243, 238, 0.9);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 360px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.timeline-panel {
  --lane-pad: 34px;
  --lane-node: 14px;
  --lane-center-left: calc(var(--lane-pad) + var(--lane-node) / 2);
  --lane-center-right: calc(100% - var(--lane-pad) - var(--lane-node) / 2);
  position: sticky;
  top: 12px;
  padding: 18px 20px 22px;
}

.timeline-header {
  display: grid;
  gap: 8px;
  margin-bottom: 0;
}

.timeline-lanes {
  position: relative;
  min-height: 46px;
  color: var(--ink-muted);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.timeline-lanes::before,
.timeline-lanes::after {
  content: "";
  position: absolute;
  top: 28px;
  bottom: 0;
  width: 2px;
  border-left: 2px dashed rgba(31, 34, 41, 0.28);
}

.timeline-lanes::before {
  left: var(--lane-center-left);
}

.timeline-lanes::after {
  left: var(--lane-center-right);
}

.timeline-lanes span {
  position: absolute;
  top: 0;
  min-width: 84px;
  text-align: center;
  padding: 4px 8px;
  border: 1px solid rgba(31, 34, 41, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  transform: translateX(-50%);
}

.timeline-lanes span:first-child {
  left: var(--lane-center-left);
}

.timeline-lanes span:last-child {
  left: var(--lane-center-right);
}

.timeline-nav {
  position: relative;
  display: grid;
  gap: 6px;
  padding: 0 0 10px;
}

.timeline-nav::before,
.timeline-nav::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  border-left: 2px dashed rgba(31, 34, 41, 0.28);
  z-index: 0;
}

.timeline-nav::before {
  left: var(--lane-center-left);
}

.timeline-nav::after {
  left: var(--lane-center-right);
}

.timeline-row {
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 6px var(--lane-pad);
  display: grid;
  grid-template-columns: var(--lane-node) minmax(0, 1fr) var(--lane-node);
  align-items: center;
  gap: 0;
  cursor: pointer;
  text-align: left;
  position: relative;
  z-index: 1;
  width: 100%;
}

.timeline-row:hover {
  background: rgba(20, 108, 95, 0.08);
}

.timeline-row:focus-visible {
  outline: 2px solid rgba(20, 108, 95, 0.65);
  outline-offset: 2px;
}

.timeline-row.is-active {
  background: rgba(20, 108, 95, 0.18);
}

.timeline-lane-cell {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.timeline-index {
  position: absolute;
  right: calc(100% + 8px);
  color: var(--ink-muted);
  font-size: 0.72rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.timeline-node {
  width: var(--lane-node);
  height: var(--lane-node);
  border-radius: 50%;
  border: 2px solid rgba(31, 34, 41, 0.62);
  background: rgba(255, 255, 255, 0.96);
  transform: translateX(1px);
}

.timeline-node.is-source {
  background: rgba(20, 108, 95, 0.94);
  border-color: rgba(20, 108, 95, 0.96);
}

.timeline-node.is-target {
  background: rgba(255, 255, 255, 0.95);
}

.timeline-mid {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.timeline-arrow {
  position: relative;
  top: -1px;
  height: 2px;
  margin: 0 3px;
  background: rgba(31, 34, 41, 0.72);
}

.timeline-arrow.is-right-to-left {
  margin-left: 5px;
}

.timeline-arrow.is-return {
  background: repeating-linear-gradient(
    to right,
    rgba(31, 34, 41, 0.74),
    rgba(31, 34, 41, 0.74) 7px,
    transparent 7px,
    transparent 11px
  );
}

.timeline-arrow::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  border-top: 2px solid rgba(31, 34, 41, 0.88);
  border-right: 2px solid rgba(31, 34, 41, 0.88);
  right: 0;
  transform: translateY(-50%) rotate(45deg);
}

.timeline-arrow.is-right-to-left::after {
  right: auto;
  left: 0;
  transform: translateY(-50%) rotate(225deg);
}

.timeline-label {
  color: #1f2229;
  font-size: 0.8rem;
  line-height: 1.2;
  display: grid;
  gap: 1px;
}

.timeline-title {
  display: block;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-seq {
  display: block;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.72rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.content {
  display: grid;
  gap: 14px;
}

.detail-content {
  min-width: 0;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(2px);
  padding: 14px;
  box-shadow:
    0 1px 1px rgba(31, 34, 41, 0.04),
    0 4px 10px rgba(31, 34, 41, 0.035);
  transition: box-shadow 180ms ease;
}

.card:hover {
  box-shadow:
    0 1px 2px rgba(31, 34, 41, 0.05),
    0 6px 14px rgba(31, 34, 41, 0.045);
}

.split {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr 1fr;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
}

.summary-grid dt {
  color: var(--ink-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.summary-grid dd {
  margin: 2px 0 0;
  font-size: 0.95rem;
}

.raw-hex {
  --hexdump-row-bytes: 8;
  margin: 0;
  overflow-x: auto;
  padding: 6px 6px 4px;
  font-family: "IBM Plex Mono", "Menlo", monospace;
  font-size: 0.85rem;
  color: #283244;
}

.hexdump {
  display: grid;
  gap: 6px;
  min-width: 560px;
}

.hexdump-row {
  display: grid;
  grid-template-columns: 5ch minmax(0, 2.2fr) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.hexdump-offset {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.hexdump-hex,
.hexdump-ascii {
  display: grid;
  grid-template-columns: repeat(var(--hexdump-row-bytes), minmax(0, 1fr));
  gap: 4px;
}

.hexdump-ascii {
  border-left: 1px dashed var(--line);
  padding-left: 8px;
}

.byte-token {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(31, 34, 41, 0.18);
  border-radius: 6px;
  padding: 3px 4px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.byte-token-hex {
  min-width: 2.3ch;
  font-variant-numeric: tabular-nums;
}

.byte-token-ascii {
  min-width: 1.85ch;
  padding: 3px 0;
}

.byte-token-empty {
  visibility: hidden;
  pointer-events: none;
  border-color: transparent;
  background: transparent;
}

.byte-token:hover,
.byte-token:focus-visible {
  border-color: rgba(20, 108, 95, 0.44);
  outline: none;
}

.byte-token-hex:hover,
.byte-token-hex:focus-visible,
.byte-token-ascii:hover,
.byte-token-ascii:focus-visible {
  box-shadow: 0 0 0 4px rgba(20, 108, 95, 0.18);
}

.byte-token.is-hover-active {
  background: rgba(20, 108, 95, 0.16);
  border-color: rgba(20, 108, 95, 0.58);
}

.byte-token.is-byte-focus {
  color: #111217;
  border-color: rgba(159, 52, 24, 0.62);
}

.byte-token.is-group-selected {
  background: rgba(159, 52, 24, 0.16);
  border-color: rgba(159, 52, 24, 0.56);
}

.byte-token.is-subfield-active {
  background: rgba(20, 108, 95, 0.22);
  border-color: rgba(20, 108, 95, 0.72);
}

.byte-explainer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  color: var(--ink-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.byte-explainer strong {
  color: var(--ink);
}

.byte-subfields-title {
  margin-top: 10px;
  color: var(--ink);
  font-weight: 700;
}

.byte-subfields {
  margin: 8px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
}

.byte-subfield-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

.byte-subfield-button:hover,
.byte-subfield-button:focus-visible,
.byte-subfield-button.is-active {
  border-color: rgba(20, 108, 95, 0.65);
  background: rgba(20, 108, 95, 0.16);
  outline: none;
}

.byte-subfield-description {
  margin-top: 3px;
  color: var(--ink-muted);
}

.field-tree {
  display: grid;
  gap: 6px;
  font-family: "IBM Plex Mono", "Menlo", monospace;
  font-size: 0.83rem;
}

.field-node {
  border-left: 1px solid var(--line);
  padding-left: 10px;
}

.field-node.is-hover-active {
  border-left-color: rgba(20, 108, 95, 0.75);
  background: rgba(20, 108, 95, 0.1);
}

.field-node .meta {
  color: var(--ink-muted);
}

.stack {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 5px;
}

.stack li {
  color: var(--ink-muted);
}

.stack li.warn {
  color: var(--warning);
}

@media (max-width: 900px) {
  .workspace,
  .split {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    justify-items: start;
    min-width: 0;
  }

  .combo-picker {
    justify-items: start;
    min-width: 0;
  }

  .combo-row-label {
    min-width: 74px;
    text-align: left;
  }

  .timeline-panel {
    position: static;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hexdump {
    min-width: 500px;
  }
}

@media (max-width: 640px) {
  .raw-hex {
    --hexdump-row-bytes: 4;
  }

  .hexdump {
    min-width: 0;
    gap: 4px;
  }

  .hexdump-row {
    grid-template-columns: 4ch minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
  }

  .hexdump-hex,
  .hexdump-ascii {
    gap: 3px;
  }

  .hexdump-ascii {
    padding-left: 6px;
  }

  .byte-token {
    padding: 2px 3px;
  }

  .byte-token-ascii {
    padding: 2px 0;
  }
}
