:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #0b0b0b;
  --ink-soft: #2a2a2a;
  --muted: #6d6d6d;
  --line: rgba(12, 12, 12, 0.12);
  --line-strong: rgba(12, 12, 12, 0.22);
  --yellow: #ffdf2f;
  --yellow-soft: rgba(255, 223, 47, 0.22);
  --glass: rgba(255, 255, 255, 0.72);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.14);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter,
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    Arial,
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
}

[hidden] {
  display: none !important;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  isolation: isolate;
}

.toolbar {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-badge,
.icon-button,
.drawer-action,
.close-drawer,
.selection-head button,
.idea-button,
.canvas-controls,
.node-menu {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(18px) saturate(150%);
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border-radius: 999px;
  padding: 0 13px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.icon-button {
  min-width: 52px;
  min-height: 42px;
  border-radius: 999px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 900;
  transition:
    transform 180ms var(--ease),
    background 180ms var(--ease),
    border-color 180ms var(--ease);
}

.icon-button:hover,
.drawer-action:hover,
.close-drawer:hover,
.selection-head button:hover,
.idea-button:hover,
.canvas-controls button:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 0, 0, 0.28);
  background: rgba(255, 243, 147, 0.82);
}

.canvas {
  --grid-size: 44px;
  --grid-x: 0px;
  --grid-y: 0px;
  --pan-x: 50vw;
  --pan-y: 50vh;
  --zoom: 1;
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(8, 8, 8, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(8, 8, 8, 0.05) 1px, transparent 1px);
  background-position:
    var(--grid-x) var(--grid-y),
    var(--grid-x) var(--grid-y);
  background-size:
    var(--grid-size) var(--grid-size),
    var(--grid-size) var(--grid-size);
  cursor: grab;
  touch-action: none;
}

.canvas.is-panning {
  cursor: grabbing;
}

.canvas.is-selecting {
  cursor: crosshair;
}

.canvas-world {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  transform: translate3d(var(--pan-x), var(--pan-y), 0) scale(var(--zoom));
  transform-origin: 0 0;
  will-change: transform;
}

.link-layer {
  position: absolute;
  left: -50000px;
  top: -50000px;
  z-index: 1;
  width: 100000px;
  height: 100000px;
  overflow: visible;
  pointer-events: none;
}

.word-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.word-link {
  stroke: rgba(0, 0, 0, 0.18);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  transition:
    opacity 220ms ease,
    stroke 220ms ease;
}

.word-link.is-selected {
  stroke: rgba(255, 205, 0, 0.72);
  stroke-width: 2;
}

.word-link.is-loading {
  stroke: rgba(255, 205, 0, 0.95);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 2 10;
  animation: dashFlow 760ms linear infinite;
}

.empty-signal {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: min(44vw, 440px);
  aspect-ratio: 1;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.8;
  pointer-events: none;
  transition:
    opacity 320ms ease,
    transform 520ms var(--ease);
}

.empty-signal span {
  position: absolute;
  inset: 12%;
  border: 1px dashed rgba(0, 0, 0, 0.14);
  border-radius: 50%;
}

.app.has-map .empty-signal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.72);
}

.home-title {
  position: fixed;
  left: 50%;
  top: calc(50% - 156px);
  z-index: 18;
  margin: 0;
  color: var(--ink);
  font-size: clamp(44px, 5vw, 76px);
  font-weight: 950;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
  transition:
    opacity 320ms ease,
    transform 520ms var(--ease);
}

.app.has-map .home-title {
  opacity: 0;
  transform: translateX(-50%) translateY(-18px) scale(0.96);
}

.word-node {
  --scale: 1;
  position: absolute;
  left: calc(var(--x) * 1px);
  top: calc(var(--y) * 1px);
  z-index: 4;
  display: grid;
  justify-items: center;
  align-content: center;
  width: 152px;
  min-height: 74px;
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 999px;
  padding: 12px 18px 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.5)),
    rgba(255, 255, 255, 0.7);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.94),
    0 16px 35px rgba(0, 0, 0, 0.13);
  color: var(--ink);
  transform: translate(-50%, -50%) scale(var(--scale));
  transform-origin: center bottom;
  transition:
    left 180ms var(--ease),
    top 180ms var(--ease),
    transform 220ms var(--ease),
    background 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
  backdrop-filter: blur(18px) saturate(140%);
  cursor: grab;
  pointer-events: auto;
  user-select: none;
  touch-action: none;
}

.word-node::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -16px;
  z-index: -1;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.1);
  transform: translateX(-50%);
  filter: blur(0.1px);
  transition:
    width 180ms ease,
    height 180ms ease,
    background 180ms ease;
}

.word-node:hover {
  --scale: 1.04;
  border-color: rgba(0, 0, 0, 0.38);
}

.word-node.is-root,
.word-node.is-active,
.word-node.is-picked {
  --scale: 1.16;
  z-index: 8;
  width: 184px;
  min-height: 86px;
}

.word-node.is-root {
  border-color: rgba(0, 0, 0, 0.42);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.94),
    0 24px 55px rgba(0, 0, 0, 0.16);
}

.word-node.is-picked {
  border-color: rgba(0, 0, 0, 0.5);
  background:
    linear-gradient(180deg, rgba(255, 247, 168, 0.94), rgba(255, 220, 24, 0.86)),
    var(--yellow);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 20px 45px rgba(189, 145, 0, 0.25);
}

.word-node.is-picked::after {
  width: 58px;
  height: 58px;
  background: var(--yellow);
}

.word-node.is-active:not(.is-picked)::after,
.word-node.is-root::after {
  width: 52px;
  height: 52px;
  background: rgba(255, 219, 35, 0.56);
}

.word-node.is-loading {
  animation: nodePulse 1s ease-in-out infinite;
}

.word-node.is-loading::before {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid rgba(255, 208, 0, 0.8);
  border-right-color: transparent;
  border-radius: inherit;
  animation: spin 780ms linear infinite;
}

.word-node.is-jumping {
  animation: jumpShake 520ms var(--ease);
}

.word-node.is-dragging {
  cursor: grabbing;
  transition: none;
}

.word-cn {
  max-width: 100%;
  color: currentColor;
  font-size: 24px;
  font-weight: 950;
  line-height: 1.08;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  text-align: center;
}

.word-en {
  display: block;
  max-width: 100%;
  margin-top: 5px;
  color: rgba(0, 0, 0, 0.62);
  font-size: 13px;
  font-weight: 760;
  line-height: 1.15;
  overflow-wrap: anywhere;
  text-align: center;
}

.canvas-controls {
  position: fixed;
  left: 18px;
  top: 18px;
  z-index: 24;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  border-radius: 999px;
  padding: 5px;
}

.canvas-controls button {
  min-width: 34px;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 950;
}

.canvas-controls span {
  min-width: 50px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  text-align: center;
}

.selection-rect {
  position: fixed;
  z-index: 19;
  border: 1px solid rgba(0, 0, 0, 0.46);
  border-radius: 8px;
  background: rgba(255, 223, 47, 0.18);
  box-shadow: 0 0 0 1px rgba(255, 223, 47, 0.48) inset;
  pointer-events: none;
}

.prompt-composer {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 22;
  width: min(650px, calc(100vw - 28px));
  transform: translate(-50%, -50%);
  transition:
    top 640ms var(--ease),
    width 420ms var(--ease),
    opacity 240ms ease;
}

.app.has-map .prompt-composer {
  top: calc(100vh - 58px);
  width: min(760px, calc(100vw - 28px));
}

.composer-glass {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 74px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.55)),
    rgba(255, 255, 255, 0.78);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 20px 50px rgba(0, 0, 0, 0.16);
  padding: 9px 10px 9px 24px;
  backdrop-filter: blur(22px) saturate(160%);
}

.composer-glass input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: clamp(18px, 2.2vw, 24px);
  font-weight: 850;
}

.composer-glass input::placeholder {
  color: rgba(0, 0, 0, 0.44);
}

.composer-glass button {
  min-width: 92px;
  min-height: 54px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--yellow);
  font-size: 16px;
  font-weight: 950;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
  transition:
    transform 180ms var(--ease),
    background 180ms ease,
    color 180ms ease;
}

.composer-glass button:hover {
  transform: translateY(-1px);
  background: var(--yellow);
  color: var(--ink);
}

.selection-panel {
  display: none !important;
  position: fixed;
  left: 18px;
  bottom: 108px;
  z-index: 20;
  display: grid;
  gap: 12px;
  width: min(360px, calc(100vw - 36px));
  max-height: min(40vh, 380px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: var(--shadow);
  padding: 14px;
  backdrop-filter: blur(22px) saturate(145%);
}

.selection-head,
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selection-head strong,
.drawer-head strong {
  color: var(--ink);
  font-size: 17px;
  font-weight: 950;
}

.selection-head button,
.close-drawer {
  min-height: 34px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 850;
}

.selected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selected-list span {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 34px;
  border: 1px solid rgba(0, 0, 0, 0.28);
  border-radius: 999px;
  background: var(--yellow);
  padding: 6px 12px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.idea-button,
.drawer-action {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 950;
}

.idea-button {
  background: var(--ink);
  color: var(--yellow);
}

.idea-list {
  display: grid;
  gap: 10px;
}

.idea-card,
.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
}

.idea-card strong,
.history-item strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
  font-weight: 950;
  line-height: 1.35;
}

.idea-card p,
.history-item p {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.55;
}

.idea-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.idea-tags span {
  border-radius: 999px;
  background: rgba(255, 223, 47, 0.28);
  padding: 4px 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
}

.drawer {
  position: fixed;
  top: 72px;
  right: 18px;
  z-index: 34;
  width: min(390px, calc(100vw - 36px));
  max-height: calc(100vh - 98px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(22px) saturate(150%);
}

.node-menu {
  position: fixed;
  z-index: 42;
  display: grid;
  gap: 6px;
  width: min(320px, calc(100vw - 18px));
  max-height: min(72vh, 560px);
  overflow: auto;
  border-radius: 8px;
  padding: 8px;
}

.node-menu button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  text-align: left;
  padding: 0 10px;
}

.node-menu button:hover {
  background: var(--yellow);
}

.node-menu button:last-child:hover {
  background: #0b0b0b;
  color: var(--yellow);
}

.node-menu button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
}

.node-menu-divider {
  height: 1px;
  margin: 4px 2px;
  background: var(--line);
}

.node-menu-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 6px 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.4;
}

.node-menu-summary span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  max-width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 999px;
  background: var(--yellow);
  padding: 3px 9px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.menu-idea-list {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.menu-idea-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px;
}

.menu-idea-card strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 950;
  line-height: 1.35;
}

.menu-idea-card p {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: 0;
  background: rgba(255, 255, 255, 0.72);
  padding: 0 12px;
  color: var(--ink);
  font-weight: 760;
}

.field input:focus {
  border-color: rgba(255, 204, 0, 0.8);
  box-shadow: 0 0 0 4px var(--yellow-soft);
}

.drawer-action {
  width: 100%;
  margin-top: 16px;
  background: var(--yellow);
}

.drawer-action.ghost {
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.drawer-status {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.history-item {
  display: grid;
  gap: 9px;
}

.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.history-item button {
  justify-self: start;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  color: var(--yellow);
  padding: 0 13px;
  font-size: 13px;
  font-weight: 900;
}

.toast,
.loading-chip {
  position: fixed;
  left: 50%;
  z-index: 40;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 15, 15, 0.9);
  color: var(--yellow);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px);
}

.toast {
  bottom: 104px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 850;
}

.loading-chip {
  top: 22px;
  padding: 10px 15px;
  font-size: 13px;
  font-weight: 900;
}

.empty-text {
  color: var(--muted);
  font-size: 14px;
  font-weight: 760;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

@keyframes nodePulse {
  0%,
  100% {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.94),
      0 16px 35px rgba(0, 0, 0, 0.13);
  }
  50% {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.94),
      0 18px 40px rgba(255, 207, 0, 0.38);
  }
}

@keyframes dashFlow {
  to {
    stroke-dashoffset: -24;
  }
}

@keyframes jumpShake {
  0% {
    transform: translate(-50%, -50%) scale(var(--scale)) rotate(0deg);
  }
  25% {
    transform: translate(-50%, -64%) scale(calc(var(--scale) + 0.08)) rotate(-2deg);
  }
  52% {
    transform: translate(-50%, -45%) scale(calc(var(--scale) + 0.03)) rotate(2deg);
  }
  76% {
    transform: translate(-50%, -56%) scale(calc(var(--scale) + 0.04)) rotate(-1deg);
  }
  100% {
    transform: translate(-50%, -50%) scale(var(--scale)) rotate(0deg);
  }
}

@media (max-width: 820px) {
  .toolbar {
    top: 12px;
    right: 12px;
  }

  .mode-badge {
    display: none;
  }

  .canvas-controls {
    left: 12px;
    top: 12px;
  }

  .word-node {
    width: 132px;
    min-height: 68px;
    padding: 10px 14px 12px;
  }

  .word-node.is-root,
  .word-node.is-active,
  .word-node.is-picked {
    width: 158px;
    min-height: 80px;
  }

  .word-cn {
    font-size: 21px;
  }

  .word-en {
    font-size: 11px;
  }

  .selection-panel {
    left: 12px;
    right: 12px;
    bottom: 98px;
    width: auto;
    max-height: 36vh;
  }

  .drawer {
    top: 64px;
    right: 12px;
    width: calc(100vw - 24px);
  }

  .composer-glass {
    min-height: 64px;
    padding-left: 18px;
  }

  .composer-glass button {
    min-width: 78px;
    min-height: 48px;
  }

  .app.has-map .prompt-composer {
    top: calc(100vh - 50px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
