* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: #111827;
}

body {
  display: flex;
  flex-direction: column;
  background: #fafafa;
}

header {
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  position: relative;
  z-index: 10;
}

.search-wrap {
  position: relative;
  flex: 1 1 260px;
  min-width: 220px;
}

#search {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
}

#search:focus {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

#suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

#suggestions div {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 14px;
}

#suggestions div:hover,
#suggestions div.active {
  background: #eef2ff;
  color: #4338ca;
}

.control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #374151;
}

#depth {
  width: 90px;
}

#depthVal {
  display: inline-block;
  min-width: 1ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

#reset {
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 6px;
  cursor: pointer;
}

#reset:hover {
  background: #f3f4f6;
}

#status {
  font-size: 12px;
  color: #6b7280;
  margin-left: auto;
  min-width: 160px;
}

main {
  flex: 1;
}

.graph-container {
  flex: 1;
  position: relative;
  min-width: 0;
}

#cy {
  position: absolute;
  inset: 0;
  background: #fafafa;
}

/* --- Workspace: graph + sidebar ------------------------------------- */

.workspace {
  flex: 1;
  display: flex;
  min-height: 0; /* let children shrink inside flex */
  position: relative;
}

#sidebar {
  width: 340px;
  max-width: 40vw;
  flex-shrink: 0;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.03);
  transition: width 0.22s ease, opacity 0.15s ease;
}

#sidebar.hidden {
  width: 0;
  border-left: none;
  box-shadow: none;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid #eef2f7;
  background: linear-gradient(#ffffff, #fafbfd);
  position: sticky;
  top: 0;
  z-index: 1;
}

#sidebar-word {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: #111827;
  word-break: break-word;
  line-height: 1.2;
}

#sidebar-close {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  margin-left: 8px;
}

#sidebar-close:hover {
  color: #111827;
  background: #f3f4f6;
}

.sidebar-section {
  padding: 14px 18px;
  border-bottom: 1px solid #f3f4f6;
}

.sidebar-section:last-of-type {
  border-bottom: none;
  padding-bottom: 24px;
}

.sidebar-section h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
}

.sidebar-defs ol {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  color: #1f2937;
}

.sidebar-defs li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.sidebar-defs li::marker {
  color: #9ca3af;
}

.sidebar-defs .pos {
  display: inline-block;
  font-style: italic;
  font-size: 11px;
  color: #4f46e5;
  background: #eef2ff;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 8px;
  vertical-align: 1px;
}

.sidebar-defs .empty {
  color: #9ca3af;
  font-style: italic;
  font-size: 14px;
}

.sidebar-etym {
  font-size: 14px;
  line-height: 1.55;
  color: #1f2937;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.sidebar-etym.loading,
.sidebar-etym.missing {
  color: #9ca3af;
  font-style: italic;
}

#sidebar-wiktionary {
  display: inline-block;
  font-size: 13px;
  color: #4f46e5;
  text-decoration: none;
  font-weight: 500;
}

#sidebar-wiktionary:hover {
  text-decoration: underline;
}

footer {
  padding: 8px 14px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  color: #6b7280;
}
