:root {
  --bg: #08090b;
  --fg: #f1f2f4;
  --muted: #8b8f98;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.25);
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.07);
  --dot: rgba(255, 255, 255, 0.14);
  --node-bg: #111317;
  --group-bg: rgba(255, 255, 255, 0.012);
  --group-line: rgba(255, 255, 255, 0.09);
  --edge: rgba(255, 255, 255, 0.2);
  --shadow: rgba(0, 0, 0, 0.45);
  --glow: rgba(255, 255, 255, 0.055);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f7f7f4;
  --fg: #111214;
  --muted: #6b6f77;
  --line: rgba(0, 0, 0, 0.12);
  --line-strong: rgba(0, 0, 0, 0.3);
  --surface: rgba(0, 0, 0, 0.025);
  --surface-2: rgba(0, 0, 0, 0.055);
  --dot: rgba(0, 0, 0, 0.15);
  --node-bg: #ffffff;
  --group-bg: rgba(0, 0, 0, 0.015);
  --group-line: rgba(0, 0, 0, 0.1);
  --edge: rgba(0, 0, 0, 0.22);
  --shadow: rgba(0, 0, 0, 0.12);
  --glow: rgba(0, 0, 0, 0.045);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  background-image: radial-gradient(circle at center, var(--dot) 1px, transparent 1.15px);
  background-size: 26px 26px;
  transition: background-color 0.45s ease, color 0.45s ease;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(60% 44% at 50% 38%, var(--glow), transparent 70%);
  z-index: 0;
}

.ambient {
  position: fixed;
  inset: -30vh -20vw auto;
  height: 80vh;
  pointer-events: none;
  background: radial-gradient(40% 60% at 50% 50%, var(--glow), transparent 72%);
  filter: blur(30px);
  opacity: 0.7;
  z-index: 0;
}

#app, .topbar, .theme-toggle { position: relative; z-index: 1; }

a { color: inherit; }

button { font: inherit; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

/* ---------------- landing ---------------- */

.landing {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.landing-inner {
  width: 100%;
  text-align: center;
  transform: translateY(-5vh);
}

.kicker {
  margin: 0 0 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
  animation: fade-up 0.8s 0.15s both cubic-bezier(0.2, 0.8, 0.2, 1);
}

.title {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(3.1rem, 10.5vw, 8.2rem);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.075em;
  text-indent: -0.05em;
  white-space: nowrap;
}

.title .caret {
  display: inline-block;
  width: 2px;
  height: 0.72em;
  margin-left: 0.09em;
  vertical-align: -0.04em;
  background: var(--fg);
  opacity: 0.55;
  animation: blink 1.05s steps(1) infinite;
}

.subtitle {
  margin: 18px auto 0;
  max-width: 520px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: fade-up 0.9s 0.7s both cubic-bezier(0.2, 0.8, 0.2, 1);
}

.oval {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: min(430px, 82vw);
  height: 68px;
  margin-top: 54px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
  font-size: 15px;
  letter-spacing: 0.01em;
  overflow: hidden;
  isolation: isolate;
  transition: color 0.35s ease, border-color 0.35s ease, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  animation: fade-up 1s 1.05s both cubic-bezier(0.2, 0.8, 0.2, 1);
}

.oval::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--fg);
  transform: translateY(102%);
  transition: transform 0.42s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.oval:hover,
.oval:focus-visible {
  color: var(--bg);
  border-color: var(--fg);
  transform: translateY(-2px);
}

.oval:hover::before,
.oval:focus-visible::before { transform: translateY(0); }

.oval .arrow {
  display: inline-block;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.oval:hover .arrow { transform: translateX(7px); }

.landing-meta {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 26px;
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 0 20px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  animation: fade-in 1.2s 1.3s both;
}

.landing-meta span:not(:last-child)::after {
  content: "·";
  margin-left: 18px;
  opacity: 0.5;
}

/* ---------------- theme toggle ---------------- */

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 60;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.theme-toggle:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  transform: rotate(12deg) scale(1.05);
}

.theme-toggle:active { transform: scale(0.94); }

.theme-toggle .ico {
  position: absolute;
  width: 19px;
  height: 19px;
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

html[data-theme="dark"] .ico-sun { opacity: 0; transform: rotate(-70deg) scale(0.4); }
html[data-theme="dark"] .ico-moon { opacity: 1; transform: rotate(0) scale(1); }
html[data-theme="light"] .ico-sun { opacity: 1; transform: rotate(0) scale(1); }
html[data-theme="light"] .ico-moon { opacity: 0; transform: rotate(70deg) scale(0.4); }

/* ---------------- top bar ---------------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 66px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 86px 0 26px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: slide-down 0.5s both cubic-bezier(0.2, 0.8, 0.2, 1);
}

@supports not (background: color-mix(in srgb, red, blue)) {
  .topbar { background: var(--bg); }
}

.brand {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.04em;
  text-decoration: none;
  color: var(--fg);
  white-space: nowrap;
  transition: opacity 0.25s ease;
}

.brand:hover { opacity: 0.62; }

.topbar-meta {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.07em;
  margin-left: auto;
  white-space: nowrap;
}

.viewer-bar .viewer-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.viewer-title strong {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-title span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.ghost-link {
  margin-left: auto;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.25s ease, border-color 0.25s ease;
}

.ghost-link:hover { color: var(--fg); border-color: var(--line-strong); }

/* ---------------- catalog ---------------- */

.catalog {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 128px 0 80px;
  animation: view-in 0.55s both cubic-bezier(0.2, 0.8, 0.2, 1);
}

.catalog-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  flex-wrap: wrap;
}

.catalog-head h1 {
  margin: 0;
  font-size: clamp(2.7rem, 6.4vw, 5rem);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.catalog-meta {
  margin: 12px 0 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.catalog-count {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  padding-bottom: 8px;
  white-space: nowrap;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 28px 0 30px;
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: color 0.25s ease, background 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
}

.chip:hover { color: var(--fg); border-color: var(--line-strong); transform: translateY(-1px); }

.chip.active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 190px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--node-bg);
  color: var(--fg);
  text-decoration: none;
  overflow: hidden;
  animation: card-in 0.55s both cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-delay: calc(var(--i) * 28ms);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.3s ease, background 0.3s ease, box-shadow 0.35s ease;
}

.card::after {
  content: "↗";
  position: absolute;
  right: 18px;
  bottom: 16px;
  color: var(--muted);
  font-size: 15px;
  opacity: 0;
  transform: translate(-4px, 4px);
  transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.card:hover,
.card:focus-visible {
  transform: translateY(-5px);
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--node-bg) 86%, var(--fg));
  box-shadow: 0 18px 50px -24px var(--shadow);
  outline: none;
}

.card:hover::after,
.card:focus-visible::after { opacity: 1; transform: translate(0, 0); }

.card-top {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background:
    radial-gradient(120% 120% at 20% 15%, rgba(255, 255, 255, 0.35), transparent 45%),
    linear-gradient(140deg, hsl(var(--h) 58% 48%), hsl(calc(var(--h) + 46) 48% 25%));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.avatar.has-logo {
  background: #fff;
  padding: 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.avatar.has-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card:hover .avatar { transform: scale(1.07) rotate(-4deg); }

.card-name {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-region {
  margin-top: 5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.card-bottom {
  margin-top: auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.score b {
  font-size: 42px;
  font-weight: 500;
  line-height: 0.8;
  letter-spacing: -0.07em;
}

.score span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.card-date {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.05em;
  padding-bottom: 3px;
  white-space: nowrap;
}

.card.is-top { border-color: color-mix(in srgb, var(--fg) 22%, var(--line)); }

.card.is-top .card-name::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 7px 2px 0;
  border-radius: 50%;
  background: var(--fg);
  opacity: 0.65;
}

/* ---------------- viewer ---------------- */

.viewer {
  position: fixed;
  inset: 0;
  padding-top: 66px;
  animation: view-in 0.45s both cubic-bezier(0.2, 0.8, 0.2, 1);
}

.canvas-wrap {
  position: absolute;
  inset: 66px 0 0 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background-image: radial-gradient(circle at center, var(--dot) 1px, transparent 1.15px);
  background-size: 24px 24px;
  background-position: 0 0;
  transition: background-color 0.4s ease;
}

.canvas-wrap.dragging { cursor: grabbing; }

.world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.group {
  position: absolute;
  border: 1px solid var(--group-line);
  border-radius: 14px;
  background: var(--group-bg);
  pointer-events: none;
}

.group-label {
  position: absolute;
  top: 11px;
  left: 14px;
  padding: 0 4px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}

.edge-layer {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

.edge {
  stroke: var(--edge);
  stroke-width: 1.1;
  fill: none;
}

.edge-label {
  fill: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.05em;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.node {
  position: absolute;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--node-bg);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.36;
  white-space: pre-wrap;
  overflow: auto;
  box-shadow: 0 8px 28px -18px var(--shadow);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  animation: node-in 0.5s both cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-delay: calc(var(--i) * 7ms);
}

.node::-webkit-scrollbar { width: 5px; height: 5px; }
.node::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

.node strong { font-weight: 600; }

.node.c1 { border-left: 3px solid #df5d55; background: color-mix(in srgb, #df5d55 6%, var(--node-bg)); }
.node.c2 { border-left: 3px solid #e9914c; background: color-mix(in srgb, #e9914c 6%, var(--node-bg)); }
.node.c3 { border-left: 3px solid #d6b84e; background: color-mix(in srgb, #d6b84e 6%, var(--node-bg)); }
.node.c4 { border-left: 3px solid #5eaa72; background: color-mix(in srgb, #5eaa72 6%, var(--node-bg)); }
.node.c5 { border-left: 3px solid #55a9b8; background: color-mix(in srgb, #55a9b8 6%, var(--node-bg)); }
.node.c6 { border-left: 3px solid #9a7bc4; background: color-mix(in srgb, #9a7bc4 6%, var(--node-bg)); }

.canvas-controls {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fade-up 0.6s 0.2s both;
}

.ctrl {
  width: 36px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.ctrl:hover { background: var(--surface-2); transform: translateY(-1px); }
.ctrl:active { transform: scale(0.92); }

.ctrl.fit { width: auto; padding: 0 10px; font-size: 10px; letter-spacing: 0.08em; }

.zoom-value {
  min-width: 48px;
  text-align: center;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
}



.viewer-loading {
  position: absolute;
  inset: 66px 0 0 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.viewer-loading .dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

.error-box {
  margin: 120px auto;
  max-width: 520px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
  color: var(--muted);
}

/* ---------------- animation ---------------- */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes view-in { from { opacity: 0; transform: translateY(14px) scale(0.995); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes card-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes node-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

@media (max-width: 720px) {
  .landing-inner { transform: translateY(-3vh); }
  .title { font-size: clamp(2.8rem, 13vw, 4.6rem); }
  .subtitle { font-size: 11px; letter-spacing: 0.07em; }
  .catalog { width: calc(100% - 32px); padding-top: 104px; }
  .topbar { padding-left: 18px; height: 60px; }
  .viewer { padding-top: 60px; }
  .canvas-wrap { inset: 60px 0 0 0; }
  .grid { grid-template-columns: 1fr; }
  .card { min-height: 172px; }
  .canvas-controls { left: 12px; bottom: 12px; }
  .viewer-title span, .ghost-link, .topbar-meta { display: none; }
  .landing-meta { gap: 8px; font-size: 10px; }
  .landing-meta span:not(:last-child)::after { margin-left: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
}
