:root {
  --bg: #f4efe6;
  --bg-accent: #efe7da;
  --panel: #ffffff;
  --text: #1f1c19;
  --muted: #6b5f55;
  --primary: #2f6edb;
  --primary-dark: #1b4aa5;
  --accent: #f07a2a;
  --accent-soft: #ffd9b5;
  --border: #e4d9c9;
  --shadow: 0 24px 50px rgba(31, 28, 25, 0.14);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  background: radial-gradient(circle at top left, #ffffff, var(--bg)) fixed;
  color: var(--text);
}

.map {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(47, 110, 219, 0.12), transparent 45%),
    radial-gradient(circle at 82% 82%, rgba(240, 122, 42, 0.14), transparent 48%),
    linear-gradient(135deg, #f8f9ff 0%, #f9f4ec 100%);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.map-viewport {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

.map-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.map-lines line {
  stroke: rgba(46, 110, 210, 0.55);
  stroke-width: 2;
}

.map-lines line.line-grid {
  stroke: rgba(46, 110, 210, 0.65);
  stroke-width: 2.2;
}

.map-lines line.line-person {
  stroke: rgba(46, 110, 210, 0.35);
  stroke-width: 1.6;
}

.map-lines line.line-dashed {
  stroke-dasharray: 4 6;
}

.map-nodes {
  position: absolute;
  inset: 0;
}

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 12px 24px rgba(31, 28, 25, 0.16);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.node.is-dragging {
  transform: translate(-50%, -50%) scale(1.04);
  box-shadow: 0 18px 30px rgba(31, 28, 25, 0.2);
}

.node.user {
  width: 140px;
  height: 140px;
  color: #fff;
  background: radial-gradient(circle at 30% 30%, #5e8cff, #2b5ec9);
  letter-spacing: 1px;
}

.node.user .node-title {
  font-size: 24px;
  font-weight: 700;
}

.node.user .node-sub {
  font-size: 12px;
  opacity: 0.8;
}

.node.grid {
  width: 86px;
  height: 86px;
  color: #fff;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--accent);
  cursor: pointer;
}

.node.grid .node-title {
  font-size: 12px;
  letter-spacing: 1px;
}

.node.grid .node-sub {
  font-size: 11px;
  opacity: 0.85;
}

.node.person {
  width: 38px;
  height: 38px;
  background: #ffd66a;
  color: #6b3d00;
  font-size: 18px;
  border: 2px solid #fff;
  cursor: pointer;
}

.dev-banner {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  background: #fff4e6;
  border: 1px solid #ffd7b3;
  padding: 12px 16px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 30;
}

.dev-input {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dev-input input {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-family: inherit;
}

button {
  border: none;
  font-family: inherit;
  cursor: pointer;
}

.primary {
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
}

.ghost {
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px dashed var(--border);
}

.icon-button {
  border: 1px solid var(--border);
  background: transparent;
  padding: 6px 10px;
  border-radius: 10px;
}

.fab {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: radial-gradient(circle at top, #e4f2ff, #bddcff);
  color: #1b4aa5;
  font-size: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 30px rgba(20, 35, 66, 0.2);
  transition: transform 0.2s ease;
  z-index: 25;
}

.fab.is-open {
  transform: rotate(45deg);
}

.fab-menu {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 80px);
  display: grid;
  gap: 10px;
  z-index: 25;
}

.fab-item {
  background: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  border: 1px solid var(--border);
  box-shadow: 0 14px 24px rgba(31, 28, 25, 0.12);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 30, 0.18);
  backdrop-filter: blur(2px);
  z-index: 30;
}

.sheet {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 520px;
  background: #fff;
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
  z-index: 31;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-header h3 {
  margin: 0;
}

.sheet-form {
  display: grid;
  gap: 12px;
}

.person-card {
  display: grid;
  gap: 14px;
}

.person-hero {
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
  padding: 8px 0 4px;
  border-radius: 18px;
}

.person-emoji {
  width: 88px;
  height: 88px;
  border-radius: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  background: radial-gradient(circle at 30% 30%, #ffe7b8, #f3c06a);
  box-shadow: 0 14px 24px rgba(31, 28, 25, 0.18);
}

.person-name {
  font-size: 20px;
  font-weight: 700;
}

.person-sub {
  font-size: 12px;
  color: var(--muted);
}

.person-fields {
  display: grid;
  gap: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}

.grid-card {
  display: grid;
  gap: 14px;
}

.grid-hero {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-radius: 18px;
  color: #fff;
}

.grid-title {
  font-size: 20px;
  font-weight: 700;
}

.grid-sub {
  font-size: 13px;
  opacity: 0.9;
}

.grid-meta {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.grid-meta-value {
  font-weight: 600;
  color: var(--text);
}

.person-field {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.person-field:last-child {
  border-bottom: none;
}

.person-field-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.person-field-value {
  font-weight: 600;
  color: var(--text);
}

.person-field.empty {
  grid-template-columns: 1fr;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.sheet-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.sheet-form input,
.sheet-form textarea,
.sheet-form select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

.palette {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
}

.palette-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.palette-note {
  font-weight: 600;
  color: var(--text);
}

.palette-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.palette-swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  box-shadow: 0 8px 16px rgba(31, 28, 25, 0.12);
}

.palette-swatch.is-selected {
  border-color: #111;
  transform: scale(1.05);
}

.field-group {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 16px;
  background: var(--bg-accent);
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.field-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-count {
  font-weight: 600;
  color: var(--text);
}

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

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

.field-remove {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.field-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

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

.ghost.compact {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 999px;
}

.ghost.full {
  width: 100%;
}

.danger {
  background: #ef476f;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hidden {
  display: none;
}

@media (max-width: 720px) {
  .node.user {
    width: 124px;
    height: 124px;
  }
}

@media (max-width: 520px) {
  .person-field {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .field-row {
    grid-template-columns: 1fr;
  }

  .field-remove {
    justify-self: end;
  }
}
