:root {
  color-scheme: light dark;
  --bg: #f6f8fa;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --text: #24292f;
  --muted: #57606a;
  --border: #d0d7de;
  --shadow: 0 10px 32px rgba(31, 35, 40, 0.12);
  --owner: #54aeff;
  --group: #0969da;
  --repository: #2da44e;
  --language: #8250df;
  --topic: #bf8700;
  --relation: #bc4c00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --panel: rgba(22, 27, 34, 0.9);
    --panel-solid: #161b22;
    --text: #f0f6fc;
    --muted: #8b949e;
    --border: #30363d;
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.35);
    --owner: #58a6ff;
    --group: #1f6feb;
    --repository: #3fb950;
    --language: #a371f7;
    --topic: #d29922;
    --relation: #f0883e;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100vw;
  height: 100vh;
}

.toolbar {
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-solid);
}

.toolbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: flex;
  align-items: end;
  gap: 10px;
}

.search {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.search input {
  width: min(320px, 42vw);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
  background: var(--panel-solid);
  color: var(--text);
}

.search input:focus {
  border-color: var(--owner);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--owner) 22%, transparent);
}

button,
.open-link {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-solid);
  color: var(--text);
  text-decoration: none;
}

button {
  padding: 8px 12px;
  cursor: pointer;
}

button:hover,
.open-link:hover {
  border-color: var(--muted);
}

.workspace {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#graph {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#graph.dragging {
  cursor: grabbing;
}

.details {
  position: absolute;
  top: 18px;
  right: 18px;
  width: min(320px, calc(100% - 36px));
  max-height: calc(100% - 90px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.details h2 {
  margin: 0 0 8px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.details p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.details dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 14px 0;
  font-size: 12px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.open-link {
  display: inline-block;
  margin-top: 14px;
  padding: 7px 10px;
  font-size: 12px;
}

.legend {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  backdrop-filter: blur(12px);
}

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

.legend i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend .owner { background: var(--owner); }
.legend .group { background: var(--group); }
.legend .repository { background: var(--repository); }
.legend .language { background: var(--language); }
.legend .topic { background: var(--topic); }
.legend .relation {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: var(--relation);
}

.status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--muted);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.status[hidden] {
  display: none;
}

footer {
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--muted);
  font-size: 11px;
}

footer a {
  color: inherit;
}

@media (max-width: 720px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .controls {
    align-items: stretch;
  }

  .search {
    flex: 1;
  }

  .search input {
    width: 100%;
  }

  .details {
    top: 10px;
    right: 10px;
    width: min(280px, calc(100% - 20px));
    max-height: 42%;
  }

  .legend {
    left: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
  }

  footer {
    padding: 7px 12px;
  }
}
