:root {
  --ink: #222429;
  --muted: #6b7280;
  --line: #d7dde7;
  --surface: #fbfcff;
  --panel: rgba(255, 255, 255, 0.86);
  --wood: #8c5a35;
  --blue: #2f80ed;
  --green: #1f9d71;
  --rose: #d94a64;
  --amber: #f5c44f;
  --shadow: 0 18px 45px rgba(35, 43, 63, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 18%, rgba(31, 157, 113, 0.11), transparent 26%),
    radial-gradient(circle at 88% 10%, rgba(217, 74, 100, 0.10), transparent 24%),
    linear-gradient(135deg, #f7faf8 0%, #edf3fb 52%, #fff8df 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid rgba(31, 41, 55, 0.15);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(35, 43, 63, 0.14);
}

button:active {
  transform: translateY(0);
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border-bottom: 1px solid rgba(92, 104, 124, 0.2);
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 35px rgba(35, 43, 63, 0.10);
}

.brand {
  min-width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border: 2px solid #2d3748;
  border-radius: 7px;
  background:
    linear-gradient(90deg, transparent 48%, rgba(45, 55, 72, 0.24) 49% 51%, transparent 52%),
    linear-gradient(0deg, transparent 48%, rgba(45, 55, 72, 0.24) 49% 51%, transparent 52%),
    #fff6b8;
  box-shadow: 4px 4px 0 #bfe6d5;
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.primary-btn,
.icon-btn {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 800;
}

.primary-btn {
  background: #232b3f;
  color: #fff;
}

.icon-btn[aria-pressed="true"],
.draw-toggle[aria-pressed="true"] {
  color: #fff;
  background: var(--blue);
  border-color: transparent;
}

.color-input {
  width: 42px;
  height: 40px;
  padding: 4px;
  border: 1px solid rgba(31, 41, 55, 0.15);
  border-radius: var(--radius);
  background: #fff;
}

.search-wrap {
  flex: 1 1 260px;
  min-width: 180px;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(31, 41, 55, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-weight: 800;
}

.search-wrap label {
  color: var(--muted);
}

.search-wrap input {
  width: 100%;
  min-width: 80px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search-nav {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 7px;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.search-nav:disabled {
  opacity: 0.38;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.match-count {
  flex: 0 0 42px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.board-tools {
  margin-left: auto;
}

#zoomLabel {
  width: 54px;
  text-align: center;
  font-weight: 800;
  color: var(--muted);
}

.viewport {
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

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

.world {
  position: absolute;
  left: 0;
  top: 0;
  width: 8000px;
  height: 8000px;
  transform-origin: 0 0;
  background:
    linear-gradient(rgba(71, 85, 105, 0.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(71, 85, 105, 0.11) 1px, transparent 1px),
    linear-gradient(rgba(71, 85, 105, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(71, 85, 105, 0.05) 1px, transparent 1px),
    #fbfdff;
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.75);
}

.world::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(6deg, rgba(80, 67, 47, 0.018) 0 1px, transparent 1px 9px),
    repeating-linear-gradient(96deg, rgba(38, 60, 89, 0.015) 0 1px, transparent 1px 11px);
  mix-blend-mode: multiply;
}

.connections,
.notes-layer {
  position: absolute;
  inset: 0;
}

.connections {
  overflow: visible;
  pointer-events: none;
}

.connection-line {
  fill: none;
  stroke-linecap: round;
  stroke-width: 7;
  filter: drop-shadow(0 3px 2px rgba(35, 43, 63, 0.15));
}

.note {
  position: absolute;
  width: 300px;
  min-height: 350px;
  display: grid;
  grid-template-rows: auto 1fr 178px auto;
  border: 1px solid rgba(108, 88, 32, 0.18);
  border-radius: 6px;
  background:
    linear-gradient(rgba(98, 76, 18, 0.055) 1px, transparent 1px) 0 76px / 100% 28px,
    linear-gradient(100deg, rgba(255, 255, 255, 0.7), transparent 42%),
    #fff2a8;
  box-shadow: var(--shadow), 0 4px 0 rgba(166, 135, 44, 0.18);
  transform: rotate(var(--tilt, -1deg));
  animation: noteIn 260ms cubic-bezier(.2, .8, .2, 1);
  overflow: hidden;
}

.note:nth-child(3n + 1) {
  background:
    linear-gradient(rgba(42, 82, 59, 0.05) 1px, transparent 1px) 0 76px / 100% 28px,
    linear-gradient(100deg, rgba(255, 255, 255, 0.68), transparent 42%),
    #c9f0d9;
}

.note:nth-child(3n + 2) {
  background:
    linear-gradient(rgba(53, 79, 126, 0.05) 1px, transparent 1px) 0 76px / 100% 28px,
    linear-gradient(100deg, rgba(255, 255, 255, 0.68), transparent 42%),
    #d9e9ff;
}

.note.is-dragging,
.note.is-match {
  z-index: 10;
}

.note.is-dragging {
  box-shadow: 0 28px 70px rgba(35, 43, 63, 0.25);
}

.note.is-match {
  outline: 4px solid rgba(47, 128, 237, 0.45);
  outline-offset: 6px;
}

.note.is-active-match {
  outline-color: rgba(217, 74, 100, 0.72);
  box-shadow: 0 22px 60px rgba(217, 74, 100, 0.22), var(--shadow);
}

.note.is-connect-source {
  outline: 4px solid rgba(31, 157, 113, 0.58);
  outline-offset: 6px;
}

.note-top {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.30);
  border-bottom: 1px solid rgba(118, 96, 34, 0.14);
}

.note-handle {
  width: 32px;
  height: 26px;
  padding: 0;
  border-radius: 7px;
  background:
    radial-gradient(circle, #232b3f 1.5px, transparent 2px) 6px 6px / 9px 9px,
    rgba(255, 255, 255, 0.56);
  cursor: grab;
}

.note-date {
  flex: 1;
  color: rgba(45, 55, 72, 0.72);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.note-delete {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  font-weight: 900;
}

.note-text-wrap {
  position: relative;
  width: 100%;
  min-height: 124px;
}

.note-highlight,
.note-text {
  width: 100%;
  min-height: 124px;
  padding: 18px 20px 10px;
  color: #24211c;
  font: inherit;
  font-size: 18px;
  line-height: 28px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.note-highlight {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  color: transparent;
}

.note-highlight mark {
  border-radius: 4px;
  background: rgba(245, 196, 79, 0.82);
  color: transparent;
}

.note-text {
  position: relative;
  z-index: 1;
  display: block;
  border: 0;
  resize: none;
  outline: 0;
  background: transparent;
}

.note-canvas {
  width: 260px;
  height: 178px;
  margin: 0 auto;
  border: 1px dashed rgba(35, 43, 63, 0.24);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.20);
  touch-action: none;
  cursor: crosshair;
  opacity: 0.92;
}

.note-canvas.is-locked {
  pointer-events: none;
  cursor: default;
}

.note-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
}

.note-actions button {
  min-height: 34px;
  border-radius: 7px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.68);
}

.empty-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 8px;
  padding: 18px 20px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(31, 41, 55, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.8);
  color: var(--muted);
  text-align: center;
  box-shadow: 0 14px 45px rgba(35, 43, 63, 0.13);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.empty-hint strong {
  color: var(--ink);
  font-size: 22px;
}

.empty-hint.is-hidden {
  opacity: 0;
}

@keyframes noteIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.94) rotate(0deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(var(--tilt, -1deg));
  }
}

@media (max-width: 820px) {
  .topbar {
    flex-wrap: wrap;
  }

  .brand {
    width: 100%;
  }

  .search-wrap {
    order: 4;
    max-width: none;
    flex-basis: 100%;
  }

  .board-tools {
    margin-left: 0;
  }

  .primary-btn,
  .icon-btn {
    min-height: 38px;
    padding: 0 11px;
  }

  .note {
    width: 278px;
  }

  .note-canvas {
    width: 240px;
  }
}
