:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f2430;
  --text: #f5f2eb;
  --muted: #a8a29a;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #d7b56d;
  --accent-2: #f2d999;
  --danger: #ff6b6b;
  --success: #76d191;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.light {
  --bg: #f6f2ea;
  --surface: #fffaf1;
  --surface-2: #f0e8da;
  --text: #17130d;
  --muted: #716a60;
  --line: rgba(31, 26, 17, 0.11);
  --accent: #9b6b24;
  --accent-2: #c89746;
  --shadow: 0 18px 50px rgba(84, 64, 28, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(215, 181, 109, 0.13), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 18px 12px;
  backdrop-filter: blur(18px);
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 92%, transparent), color-mix(in srgb, var(--bg) 65%, transparent));
  border-bottom: 1px solid var(--line);
}

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

h1 {
  font-size: 27px;
  letter-spacing: -0.06em;
  line-height: 0.95;
}

h2 {
  font-size: clamp(24px, 7vw, 38px);
  letter-spacing: -0.055em;
  line-height: 1.02;
}

h3 {
  font-size: 17px;
  letter-spacing: -0.02em;
}

p,
li {
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 8px;
  color: var(--accent-2);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
  font-size: 11px;
  color: var(--accent);
}

.main-content {
  padding: 18px 14px calc(98px + var(--safe-bottom));
}

.view {
  display: none;
  animation: fadeUp 220ms ease-out;
}

.view.active {
  display: block;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.card,
.form-card,
.map-card {
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 96%, white 4%), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.card,
.form-card {
  padding: 16px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.segmented-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  margin-bottom: 14px;
}

.tab-button {
  border: 0;
  min-height: 44px;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 750;
}

.tab-button.active {
  background: var(--surface-2);
  color: var(--text);
}

.capture-panel {
  display: none;
}

.capture-panel.active {
  display: block;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}

input,
textarea,
select {
  width: 100%;
  background: color-mix(in srgb, var(--surface-2) 78%, var(--bg));
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  resize: vertical;
  min-height: 128px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, white 10%);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}

.dump-box {
  min-height: 230px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.button-row.wrap {
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.danger-button,
.file-button,
.icon-button,
.small-button,
.chip-button {
  border: 0;
  border-radius: 999px;
  min-height: 46px;
  padding: 0 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #15120b;
  flex: 1;
}

.ghost-button,
.file-button,
.icon-button,
.small-button,
.chip-button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.danger-button {
  background: color-mix(in srgb, var(--danger) 18%, var(--surface-2));
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.icon-button {
  width: 46px;
  padding: 0;
  flex: 0 0 auto;
}

.small-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
}

.file-button input {
  display: none;
}

.stat-pill,
.importance-pill,
.category-pill,
.tag-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.category-pill {
  color: var(--text);
}

.importance-pill.core {
  color: var(--accent-2);
}

.importance-pill.important {
  color: var(--success);
}

.digest-review {
  margin-top: 14px;
}

.suggestion-card {
  border-left: 3px solid var(--accent);
}

.suggestion-card.rejected {
  opacity: 0.55;
  border-left-color: var(--danger);
}

.suggestion-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.connection-checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
}

.checkbox-row {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
}

.checkbox-row input {
  width: auto;
  margin-top: 2px;
}

.filter-card {
  margin-bottom: 14px;
}

.tag-filter-wrap,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-button {
  min-height: 34px;
  padding: 0 11px;
  color: var(--muted);
  font-size: 12px;
}

.chip-button.active {
  color: #15120b;
  background: var(--accent);
}

.note-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-card {
  padding: 15px;
}

.note-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.note-card h3 {
  font-size: 18px;
  line-height: 1.2;
}

.note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
}

.note-preview {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.map-controls {
  margin-bottom: 14px;
}

.map-card {
  position: relative;
  height: min(68vh, 640px);
  overflow: hidden;
}

#mindMapSvg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

.map-node circle {
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.22));
}

.map-node text {
  fill: var(--text);
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
}

.map-line {
  stroke: color-mix(in srgb, var(--accent) 45%, var(--muted));
  stroke-width: 1.5;
  opacity: 0.62;
}

.link-manager {
  margin-top: 12px;
}

.link-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
  background: var(--surface-2);
}

.insights-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.insight-card h3 {
  margin-bottom: 10px;
}

.insight-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.insight-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.insight-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.ask-card {
  margin-top: 12px;
}

.mock-response {
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.clean-list {
  margin: 0;
  padding-left: 18px;
}

.empty-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 50;
  width: min(100%, 980px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(22px);
}

.nav-item {
  min-height: 58px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 800;
}

.nav-item span {
  font-size: 18px;
}

.nav-item small {
  font-size: 10px;
}

.nav-item.active {
  color: var(--text);
  background: var(--surface-2);
}

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

.note-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(7px);
}

.dialog-content {
  padding: 18px;
}

.dialog-body {
  white-space: pre-wrap;
  color: var(--text);
  line-height: 1.65;
}

.dialog-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 100;
  box-shadow: var(--shadow);
  font-weight: 800;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 720px) {
  .main-content {
    padding-inline: 24px;
  }

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

  .insights-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .primary-button {
    flex: 0 0 auto;
  }
}
