:root {
  color-scheme: light;
  --bg: #f5f4ee;
  --surface: #ffffff;
  --surface-soft: #ece8dc;
  --ink: #171b1c;
  --muted: #60696b;
  --line: #d8d4c8;
  --teal: #0f766e;
  --teal-dark: #07534d;
  --redwood: #a14d33;
  --gold: #b28a24;
  --blue: #2c5e8f;
  --focus: #1b6ca8;
  --shadow: 0 18px 48px rgba(23, 27, 28, 0.08);
  --radius: 8px;
  --font-body: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-display: "Georgia", "Times New Roman", "Songti SC", serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(23, 27, 28, 0.035) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  outline-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(27, 108, 168, 0.34);
  outline-offset: 2px;
}

a {
  color: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fffaf0;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  letter-spacing: 0;
}

.brand-name,
.brand-note {
  display: block;
}

.brand-name {
  font-weight: 760;
}

.brand-note {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.button,
.button-link,
.copy-button,
.delete-button,
.text-button,
.icon-button,
.chip,
.tag-chip,
.card-tag {
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
}

.button,
.button-link,
.copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 720;
}

.button.primary {
  background: var(--ink);
  color: #fffaf0;
}

.button.secondary {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.button-icon {
  display: inline-grid;
  width: 18px;
  height: 18px;
  place-items: center;
  font-family: var(--font-mono);
  line-height: 1;
}

.workspace {
  display: grid;
  gap: 16px;
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
  gap: 24px;
  align-items: stretch;
  min-height: 210px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intro-copy {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--redwood);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 0;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 6vw, 4.75rem);
  font-weight: 650;
  letter-spacing: 0;
  line-height: 0.98;
}

.signal-map {
  display: grid;
  min-height: 150px;
  place-items: center;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(0deg, rgba(44, 94, 143, 0.07) 1px, transparent 1px) 0 0 / 28px 28px,
    #f8f5ec;
  overflow: hidden;
}

.signal-map svg {
  width: 100%;
  height: 100%;
  min-height: 150px;
}

.map-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}

.line-a {
  stroke: var(--teal);
}

.line-b {
  stroke: var(--blue);
  stroke-dasharray: 9 11;
}

.map-node circle {
  stroke: #fffaf0;
  stroke-width: 4;
}

.node-a circle,
.node-c circle {
  fill: var(--redwood);
}

.node-b circle {
  fill: var(--gold);
}

.node-d circle {
  fill: var(--teal);
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 230px);
  gap: 12px;
  align-items: center;
}

.search-field,
.select-field {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
}

.search-field {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
}

.search-icon {
  display: grid;
  height: 100%;
  place-items: center;
  color: var(--teal-dark);
  font-size: 1.2rem;
}

.search-field input,
.select-field select {
  width: 100%;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.search-field input {
  padding: 0 14px 0 0;
}

.select-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding-left: 12px;
}

.select-field span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.overview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.metric-value {
  font-family: var(--font-display);
  font-size: 2rem;
  line-height: 1;
}

.metric-label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.content-grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.filter-panel,
.results-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
}

.filter-panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 22px;
  padding: 16px;
}

.filter-panel h2,
.results-head h2 {
  margin-bottom: 10px;
  font-size: 0.94rem;
  font-weight: 800;
}

.chip-list,
.tag-list,
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.tag-chip,
.card-tag {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
}

.chip,
.tag-chip {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.9rem;
}

.chip[aria-pressed="true"],
.tag-chip[aria-pressed="true"] {
  border-color: var(--teal);
  background: #dcefe8;
  color: var(--teal-dark);
}

.results-panel {
  min-width: 0;
  padding: 16px;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.results-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.text-button {
  min-height: 34px;
  padding: 0 8px;
  background: transparent;
  color: var(--blue);
  font-weight: 760;
}

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

.link-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 252px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.card-top,
.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.category-pill,
.favorite-mark {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 780;
}

.category-pill {
  background: var(--surface-soft);
  color: var(--ink);
}

.favorite-mark {
  background: #f6e5b6;
  color: #6d4d00;
}

.link-card h3 {
  margin: 16px 0 8px;
  font-size: 1.1rem;
  line-height: 1.25;
}

.card-title {
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.card-description {
  flex: 1;
  margin-bottom: 14px;
  color: var(--muted);
  line-height: 1.55;
}

.card-tag {
  min-height: 28px;
  padding: 0 8px;
  color: var(--teal-dark);
  font-size: 0.78rem;
}

.card-actions {
  margin-top: 16px;
}

.button-link {
  flex: 1;
  background: var(--teal-dark);
  color: #fffaf0;
}

.copy-button {
  flex: 1;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
}

.delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(161, 77, 51, 0.32);
  border-radius: var(--radius);
  background: #fff7f3;
  color: var(--redwood);
  font-weight: 720;
}

.empty-state {
  padding: 48px 16px;
  text-align: center;
}

.empty-state h3 {
  margin-bottom: 8px;
}

.empty-state p {
  margin-bottom: 0;
  color: var(--muted);
}

.link-dialog {
  width: min(720px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.link-dialog::backdrop {
  background: rgba(23, 27, 28, 0.42);
}

.link-dialog form {
  padding: 22px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.dialog-head h2 {
  margin-bottom: 0;
  font-family: var(--font-display);
  font-size: 2rem;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
}

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

.form-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 740;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-grid input,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--ink);
}

.form-grid input {
  min-height: 42px;
  padding: 0 12px;
}

.form-grid textarea {
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.5;
}

.checkbox-line {
  display: flex !important;
  grid-column: 1 / -1;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: start;
}

.checkbox-line input {
  width: 18px;
  min-height: 18px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fffaf0;
  box-shadow: var(--shadow);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (hover: hover) {
  .button,
  .button-link,
  .copy-button,
  .delete-button,
  .chip,
  .tag-chip,
  .card-tag,
  .text-button,
  .icon-button {
    transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
  }

  .button:hover,
  .button-link:hover,
  .copy-button:hover,
  .delete-button:hover,
  .chip:hover,
  .tag-chip:hover,
  .card-tag:hover,
  .text-button:hover,
  .icon-button:hover {
    transform: translateY(-1px);
  }
}

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

@media (max-width: 820px) {
  .topbar,
  .results-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .button {
    flex: 1;
  }

  .intro-panel,
  .controls,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .filter-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-bottom: 28px;
  }

  .intro-panel,
  .results-panel,
  .filter-panel,
  .link-dialog form {
    padding: 14px;
  }

  h1 {
    font-size: 2.2rem;
  }

  .overview,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 64px;
  }

  .link-grid {
    grid-template-columns: 1fr;
  }

  .card-actions,
  .dialog-actions {
    flex-direction: column;
    align-items: stretch;
  }
}
