:root {
  --bg: #ece8df;
  --panel: #fffdf9;
  --line: #d9cfbc;
  --text: #201d18;
  --muted: #6f6658;
  --accent: #8f3f1a;
  --accent-soft: #f7e8dc;
  --axis: #b6a88c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Noto Serif KR", "Malgun Gothic", serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 10% 0%, #fff6e9 0%, #f1ebdf 44%, transparent 72%),
    linear-gradient(140deg, #f6f1e7, var(--bg));
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.95);
  backdrop-filter: blur(8px);
}

.title-group h1 {
  margin: 0;
  font-size: 21px;
}

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

.controls button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 6px 10px;
  cursor: pointer;
}

.controls input {
  width: 180px;
}

#cardSizeRange {
  width: 120px;
}

.timeline-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.88);
}

.legend-layout {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
}

.legend-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 0 2px;
}

.legend-controls {
  min-width: 180px;
}

.legend-search {
  min-width: 220px;
}

.legend-minimap {
  min-width: 250px;
}

.minimap-shell {
  border: 1px solid #2b3338;
  border-radius: 10px;
  padding: 6px;
  background:
    radial-gradient(circle at 12% 8%, rgba(91, 225, 187, 0.15), transparent 42%),
    linear-gradient(180deg, #152027, #11181e);
  box-shadow: inset 0 0 0 1px rgba(124, 222, 194, 0.1);
}

.minimap-track {
  position: relative;
  width: 240px;
  max-width: 100%;
  height: 54px;
  border-radius: 8px;
  border: 1px solid #2d3c40;
  background: linear-gradient(180deg, #0f151a, #0d1216);
  overflow: hidden;
  cursor: pointer;
}

.minimap-track.dragging {
  cursor: grabbing;
}

.minimap-layer {
  position: absolute;
  inset: 0;
}

.minimap-item {
  position: absolute;
  height: 4px;
  border-radius: 2px;
  border: 1px solid #56726c;
  opacity: 0.82;
}

.minimap-item.active {
  height: 6px;
  margin-top: -1px;
  border-width: 2px;
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(135, 243, 195, 0.28);
  z-index: 2;
}

.minimap-viewport {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40px;
  border: 2px solid #7fe2be;
  background: rgba(127, 226, 190, 0.12);
  box-shadow: inset 0 0 0 1px rgba(205, 255, 240, 0.36);
}

.legend-search-input {
  width: 100%;
  border: 1px solid #d7ccb9;
  border-radius: 8px;
  background: #fff;
  color: #4d4336;
  font-size: 12px;
  padding: 6px 8px;
}

.legend-search-input:focus-visible {
  outline: 2px solid #8f3f1a;
  outline-offset: 1px;
}

.legend-divider {
  width: 1px;
  background: #decfb7;
  align-self: stretch;
}

.legend-head {
  font-size: 12px;
  font-weight: 700;
  color: #5b4f3f;
  margin-top: 2px;
}

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

.legend-matrix {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}

.legend-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
}

.legend-grid-row {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) repeat(3, minmax(56px, 1fr));
  gap: 4px;
  align-items: center;
  min-width: max-content;
}

.legend-grid-row.head {
  margin-bottom: 2px;
}

.matrix-btn {
  border: 1px solid #d7ccb9;
  background: #fff;
  color: #4d4336;
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 11px;
  cursor: pointer;
  min-height: 26px;
}

.matrix-btn.compact {
  width: 100%;
  padding: 0;
  min-height: 26px;
}

.matrix-btn.compact:not(.active) {
  background: #f8f5ef;
}

.matrix-btn.active {
  border-color: var(--matrix-color, #8f3f1a);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--matrix-color, #8f3f1a) 22%, transparent);
}

.matrix-global-label {
  font-size: 12px;
  color: #5b4f3f;
  font-weight: 700;
  padding: 4px 6px;
}

.matrix-global-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.legend-actions {
  margin-bottom: 2px;
}

.matrix-global-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-action {
  border: 1px solid #d7ccb9;
  border-radius: 8px;
  background: #fff;
  color: #4d4336;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
}

.legend-action.active {
  border-color: #8f3f1a;
  box-shadow: 0 0 0 2px rgba(143, 63, 26, 0.16);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid #d7ccb9;
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
  color: #4d4336;
  cursor: pointer;
  user-select: none;
}

.legend-item.inactive {
  opacity: 0.45;
}

.legend-item.selected {
  box-shadow: 0 0 0 2px rgba(143, 63, 26, 0.16);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--legend-strong, #777);
  background: linear-gradient(180deg, var(--legend-start, #ddd), var(--legend-end, #aaa));
}

.legend-code {
  font-weight: 700;
  color: #2e281f;
}

.viewport-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.timeline-viewport {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  overflow: auto;
  min-height: 0;
  height: 100%;
  cursor: grab;
  box-shadow: 0 8px 18px rgba(95, 70, 42, 0.07);
}

.timeline-viewport.dragging {
  cursor: grabbing;
}

.timeline-world {
  position: relative;
  min-height: 920px;
  user-select: none;
  -webkit-user-select: none;
}

.era-band {
  position: absolute;
  top: 0;
  height: 100%;
  pointer-events: none;
}

.era-band.bce {
  background: linear-gradient(180deg, rgba(225, 204, 173, 0.18), rgba(225, 204, 173, 0.03));
}

.era-band.ce {
  background: linear-gradient(180deg, rgba(175, 210, 231, 0.14), rgba(175, 210, 231, 0.03));
}

.axis-layer {
  position: sticky;
  top: 0;
  z-index: 6;
  height: 84px;
  background: linear-gradient(180deg, rgba(255, 253, 249, 0.98), rgba(255, 253, 249, 0.93));
  border-bottom: 2px solid var(--axis);
}

.bar-layer {
  position: relative;
  height: 96px;
  border-bottom: 1px solid #eadfcb;
  background: linear-gradient(180deg, rgba(255, 252, 245, 0.9), rgba(255, 252, 245, 0.55));
}

.bar-item {
  position: absolute;
  height: 2px;
  border-radius: 999px;
  background: var(--event-bar-end, #d7a481);
  border: 0;
  opacity: 0.96;
  transition: transform 120ms ease, height 120ms ease, box-shadow 120ms ease;
}

.bar-item.active {
  height: 10px;
  border: 2px solid var(--event-border-strong, var(--event-bar-border, #d5a17d));
  transform: translateY(-4px);
  box-shadow: 0 0 0 2px var(--event-glow, rgba(143, 63, 26, 0.2));
  z-index: 2;
}

.bar-item.active .bar-chip {
  border-width: 4px;
  border-color: var(--event-border-strong, var(--event-border, #d5a17d));
  box-shadow: 0 0 0 2px var(--event-glow, rgba(143, 63, 26, 0.18));
}

.bar-item .bar-chip {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translate(50%, -50%);
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  border: 1px solid var(--event-border, #d5a17d);
  background: #fff;
  color: var(--event-ink, #6f3315);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  white-space: nowrap;
}

.axis-label {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.axis-tick {
  position: absolute;
  bottom: -2px;
  width: 1px;
  background: #ad9f84;
}

.axis-tick.minor {
  height: 10px;
  opacity: 0.4;
}

.axis-tick.major {
  height: 16px;
}

.axis-tick label {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  color: #6a6153;
  font-size: 11px;
  white-space: nowrap;
}

.event-layer {
  position: relative;
  min-height: 760px;
  padding-top: 18px;
}

.event-item {
  position: absolute;
  transform: translateX(-50%);
}

.event-item.active {
  z-index: 3;
}

.event-card {
  margin-top: 8px;
  width: 168px;
  margin-left: -84px;
  border: 1px solid var(--event-border, #e7dcc8);
  border-radius: 10px;
  background: linear-gradient(180deg, #fffefb, var(--event-soft, #f7e8dc));
  padding: 0;
  box-shadow: 0 3px 10px rgba(98, 75, 51, 0.08);
  cursor: pointer;
  transform: scale(var(--card-scale, 1));
  transform-origin: top center;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  overflow: hidden;
}

.event-card.mini {
  width: 72px;
  margin-left: -36px;
  min-height: 30px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transform: none;
}

.card-mini-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--event-ink, #473f31);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.event-card.dot {
  width: 22px;
  height: 22px;
  min-height: 22px;
  margin-top: 8px;
  margin-left: -11px;
  border-radius: 999px;
  padding: 0;
  display: grid;
  place-items: center;
  transform: none;
  background: transparent;
  border: 1px solid rgba(111, 79, 50, 0.22);
}

.event-card.dot::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--event-border, #b56f44);
  border: 1px solid var(--event-border-strong, #8d4f28);
}

.event-item.active .event-card {
  border-color: var(--event-border-strong, #c98055);
  border-width: 4px;
  box-shadow: 0 0 0 4px var(--event-glow, rgba(143, 63, 26, 0.15)), 0 4px 12px rgba(98, 75, 51, 0.12);
}

.event-item.active .event-card.mini {
  border-width: 3px;
}

.event-item.active .event-card.dot {
  border-color: var(--event-border-strong, #8d4f28);
  border-width: 2px;
  box-shadow: 0 0 0 3px var(--event-glow, rgba(143, 63, 26, 0.18));
}

.event-item.active .event-card.dot::before {
  width: 12px;
  height: 12px;
  border-width: 2px;
}

.event-card:focus-visible {
  outline: 2px solid #a15128;
  outline-offset: 2px;
}

.event-card .card-side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  justify-content: center;
  padding: 3px;
  background: linear-gradient(180deg, #f6efe5, #efe4d6);
  border-right: 1px solid var(--event-border-strong, #8d4f28);
}

.marker-row {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 12px;
  padding: 0 2px;
  border-radius: 4px;
  background: var(--marker-row-color, #6d6d6d);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  text-transform: lowercase;
}

.event-card .card-body {
  min-width: 0;
  padding: 8px 8px 7px;
}

.event-card .title {
  font-size: 12px;
  line-height: 1.35;
  color: var(--event-ink, #473f31);
}

.event-card .range {
  margin-top: 5px;
  font-size: 11px;
  color: #7d725f;
}

.event-info {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 14px;
  height: 100%;
  min-height: 0;
  overflow: auto;
  position: sticky;
  top: 90px;
  box-shadow: 0 8px 16px rgba(98, 75, 51, 0.06);
}

.event-info h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.event-info p {
  margin: 7px 0;
  line-height: 1.65;
}

.meta {
  font-size: 13px;
  color: var(--muted);
}

.search-result-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.search-result-item {
  text-align: left;
  border: 1px solid #dfd3c0;
  border-radius: 10px;
  background: #fff;
  color: #3f372c;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
}

.search-result-item:hover {
  border-color: #c79b7f;
  box-shadow: 0 0 0 2px rgba(143, 63, 26, 0.1);
}

.search-result-title {
  font-size: 13px;
  font-weight: 700;
}

.search-result-meta {
  font-size: 12px;
  color: #776b5b;
}

@media (max-width: 1160px) {
  body {
    height: auto;
    overflow: auto;
    display: block;
  }

  .viewport-wrap {
    grid-template-columns: 1fr;
    overflow: visible;
    min-height: auto;
  }

  .event-info {
    position: static;
    height: auto;
    overflow: visible;
  }

  .timeline-viewport {
    height: auto;
    min-height: calc(100vh - 160px);
  }

  .timeline-legend {
    padding-bottom: 8px;
  }
}
