:root {
  color-scheme: light;
  --bg: #f8f6f2;
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(78, 96, 128, 0.18);
  --text: #1f2933;
  --muted: #667085;
  --blue: #2f7df6;
  --cyan: #3bc7e8;
  --green: #18a66a;
  --amber: #d8943d;
  --pink: #d95f9f;
  --violet: #8b7cf6;
  --radius: 8px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 8%, rgba(47, 125, 246, 0.10), transparent 28%),
    radial-gradient(circle at 90% 24%, rgba(216, 148, 61, 0.11), transparent 28%),
    linear-gradient(180deg, #fbfaf7 0%, var(--bg) 58%, #efe8dd 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(rgba(91, 111, 139, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 111, 139, 0.055) 1px, transparent 1px);
  background-size: 86px 86px;
}

button,
a,
input {
  font: inherit;
}

button,
a {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.map-app {
  width: min(1740px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 26px 30px 42px;
}

.map-topbar,
.map-summary article,
.map-sidebar,
.graph-panel,
.word-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(72, 83, 104, 0.10);
  backdrop-filter: blur(12px);
}

.map-topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 16px;
}

.brand,
.top-actions,
.brand-mark {
  display: flex;
  align-items: center;
}

.brand {
  gap: 14px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  justify-content: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #5cccff, #775cff 72%);
  color: #ffffff;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(47, 125, 246, 0.18);
}

.brand strong {
  display: block;
  color: #182230;
  font-size: clamp(24px, 2vw, 34px);
  line-height: 1.1;
}

.brand small,
.panel-head p,
.map-summary span,
.search-box span,
.legend-card p,
.word-panel > p,
.word-panel > span,
.detail-grid span {
  color: var(--muted);
}

.top-actions {
  justify-content: flex-end;
  gap: 10px;
}

.top-actions a,
.top-actions button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(47, 125, 246, 0.24);
  border-radius: var(--radius);
  background: rgba(47, 125, 246, 0.08);
  color: #255fa8;
  padding: 0 14px;
  font-weight: 800;
}

.top-actions button:disabled {
  cursor: default;
  opacity: 0.64;
}

.audio-cache-status {
  margin-top: 12px;
  border: 1px solid rgba(47, 125, 246, 0.18);
  border-radius: var(--radius);
  background: rgba(47, 125, 246, 0.07);
  color: #35618f;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
}

.audio-cache-status.is-running {
  border-color: rgba(216, 148, 61, 0.30);
  background: rgba(216, 148, 61, 0.10);
  color: #83551d;
}

.audio-cache-status.is-ready {
  border-color: rgba(24, 166, 106, 0.30);
  background: rgba(24, 166, 106, 0.09);
  color: #15764c;
}

.audio-cache-status.has-error {
  border-color: rgba(224, 105, 105, 0.34);
  background: rgba(224, 105, 105, 0.10);
  color: #a04444;
}

.map-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.map-summary article {
  padding: 16px;
}

.map-summary strong {
  display: block;
  margin-top: 6px;
  color: #182230;
  font-size: clamp(30px, 3vw, 48px);
  line-height: 0.95;
}

.map-shell {
  display: grid;
  grid-template-columns: minmax(250px, 0.58fr) minmax(620px, 1.7fr) minmax(300px, 0.7fr);
  gap: 16px;
  align-items: stretch;
}

.map-sidebar,
.word-panel {
  padding: 18px;
}

.panel-head h1 {
  margin: 5px 0 0;
  color: #182230;
  font-size: 30px;
  line-height: 1.1;
}

.search-box {
  display: grid;
  gap: 8px;
  margin: 18px 0;
}

.search-box input {
  min-height: 44px;
  border: 1px solid rgba(78, 96, 128, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.76);
  color: #182230;
  padding: 0 12px;
}

.view-note {
  margin: -4px 0 14px;
  border: 1px solid rgba(47, 125, 246, 0.16);
  border-radius: var(--radius);
  background: rgba(47, 125, 246, 0.07);
  color: #35618f;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
}

.group-list {
  display: grid;
  gap: 8px;
}

.group-button {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(78, 96, 128, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.58);
  color: #263243;
  padding: 0 12px;
  text-align: left;
}

.group-button::before {
  content: "";
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--group-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--group-color) 16%, transparent);
}

.group-button span {
  flex: 1;
  font-weight: 800;
}

.group-button b {
  color: var(--muted);
  font-size: 13px;
}

.group-button.is-active {
  border-color: color-mix(in srgb, var(--group-color) 48%, transparent);
  background: color-mix(in srgb, var(--group-color) 12%, white 80%);
}

.legend-card {
  margin-top: 18px;
  border: 1px solid rgba(78, 96, 128, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.54);
  padding: 14px;
}

.legend-card strong {
  color: #182230;
}

.legend-card p {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.65;
}

.graph-panel {
  min-height: 680px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 46%, rgba(47, 125, 246, 0.08), transparent 34%),
    rgba(255, 255, 255, 0.62);
}

#graphSvg {
  width: 100%;
  height: 100%;
  min-height: 680px;
  display: block;
}

.graph-link {
  stroke: rgba(84, 99, 125, 0.30);
  stroke-linecap: round;
}

.graph-link.is-contrast {
  stroke-dasharray: 6 7;
}

.graph-link.is-active {
  stroke: #2f7df6;
  stroke-opacity: 0.78;
}

.graph-node {
  cursor: pointer;
}

.graph-node circle {
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 2.5;
  filter: drop-shadow(0 7px 14px rgba(51, 70, 100, 0.20));
}

.graph-node.is-known circle {
  stroke: #0f6f48;
  stroke-width: 3;
  filter: drop-shadow(0 9px 17px rgba(24, 166, 106, 0.26));
}

.graph-node text {
  fill: #182230;
  font-size: 13px;
  font-weight: 850;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.82);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.graph-node .known-mark {
  fill: #ffffff;
  font-size: 17px;
  font-weight: 950;
  stroke: none;
  pointer-events: none;
}

.graph-node.is-muted,
.graph-link.is-muted {
  opacity: 0.18;
}

.graph-node.is-active circle {
  stroke: #182230;
  stroke-width: 3;
}

.graph-node.is-neighbor circle {
  stroke: #2f7df6;
}

.link-label {
  fill: #667085;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
}

.word-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.word-panel h2 {
  margin: 0;
  color: #182230;
  font-size: clamp(34px, 3vw, 50px);
  line-height: 0.96;
  overflow-wrap: anywhere;
}

.word-panel > p,
.word-panel > span {
  margin: 0;
}

.word-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.word-actions button {
  min-height: 42px;
  border: 1px solid rgba(47, 125, 246, 0.24);
  border-radius: var(--radius);
  background: rgba(47, 125, 246, 0.08);
  color: #255fa8;
  font-weight: 850;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.word-actions button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(47, 125, 246, 0.42);
  background: rgba(47, 125, 246, 0.13);
}

.word-actions button.is-speaking {
  position: relative;
  border-color: rgba(24, 166, 106, 0.36);
  background: rgba(24, 166, 106, 0.10);
  color: #15764c;
  opacity: 1;
}

.word-actions button.is-speaking::before {
  content: "";
  width: 9px;
  height: 9px;
  margin-right: 7px;
  display: inline-block;
  border-radius: 999px;
  background: #18a66a;
  box-shadow: 0 0 0 0 rgba(24, 166, 106, 0.36);
  animation: speakingPulse 1s ease-in-out infinite;
}

.word-actions button:disabled {
  cursor: default;
  opacity: 0.5;
}

.word-actions button.is-speaking:disabled {
  opacity: 1;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-grid div {
  border: 1px solid rgba(78, 96, 128, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.54);
  padding: 12px;
}

.detail-grid strong,
.detail-grid span {
  display: block;
}

.detail-grid strong {
  color: #182230;
  font-size: 20px;
}

.example-card {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(47, 125, 246, 0.16);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(47, 125, 246, 0.08), rgba(255, 255, 255, 0.62)),
    rgba(255, 255, 255, 0.56);
  padding: 14px;
}

.example-card strong {
  color: #182230;
}

.example-card p {
  margin: 0;
  color: #344054;
  font-size: 16px;
  line-height: 1.65;
}

.neighbors {
  display: grid;
  gap: 10px;
}

.neighbors > strong {
  color: #182230;
}

#neighborList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.neighbor-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(47, 125, 246, 0.20);
  border-radius: 999px;
  background: rgba(47, 125, 246, 0.08);
  color: #255fa8;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

@keyframes speakingPulse {
  0%,
  100% {
    transform: scale(0.82);
    box-shadow: 0 0 0 0 rgba(24, 166, 106, 0.34);
  }
  50% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(24, 166, 106, 0);
  }
}

@media (max-width: 1180px) {
  .map-shell,
  .map-summary {
    grid-template-columns: minmax(0, 1fr);
  }

  .graph-panel,
  #graphSvg {
    min-height: 560px;
  }
}

@media (max-width: 680px) {
  .map-app {
    padding: 16px;
  }

  .map-topbar,
  .top-actions {
    display: grid;
    justify-content: stretch;
  }
}
