:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #edf2ef;
  --ink: #171717;
  --muted: #5f6863;
  --line: #d8ded9;
  --accent: #007f73;
  --accent-strong: #005e56;
  --accent-soft: #d9f2ee;
  --danger: #b42318;
  --danger-soft: #ffe4df;
  --warning: #7a4a00;
  --warning-soft: #fff1cc;
  --shadow: 0 18px 45px rgba(22, 29, 25, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(217, 242, 238, 0.58), rgba(246, 247, 244, 0) 360px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}

a {
  color: var(--accent-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--ink);
}

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

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  border-bottom: 1px solid rgba(216, 222, 217, 0.72);
  background: rgba(246, 247, 244, 0.88);
  backdrop-filter: blur(16px);
  /* Pin topbar to default palette so it stays readable on all site themes */
  color: #171717;
}

/* Hard-pin topbar child elements so site themes can't affect them */
.topbar .brand,
.topbar .brand:hover {
  color: #171717;
}

.topbar .brand-mark {
  color: #ffffff;
  background: #171717;
}

.topbar .nav-actions a,
.topbar .nav-actions button {
  color: #171717;
}

.topbar-inner {
  width: min(1120px, calc(100% - 32px));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--ink);
  font-size: 14px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 0 64px;
  flex: 1;
}

.narrow {
  width: min(720px, calc(100% - 32px));
}

.page-header {
  margin-bottom: 28px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(2.1rem, 1.8rem + 1.4vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin: 0 0 16px;
  font-size: 1.35rem;
  line-height: 1.2;
  letter-spacing: 0;
}

p {
  margin: 0;
}

.lede {
  max-width: 680px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 1.05rem;
}

.stack {
  display: grid;
  gap: 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 18px;
}

.span-7 {
  grid-column: span 7;
}

.span-5 {
  grid-column: span 5;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-body {
  padding: 18px;
}

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

.button,
button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 13px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}

.button:hover,
button:hover {
  color: #ffffff;
  background: var(--accent-strong);
}

.button-secondary,
.button-secondary:hover {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.button-danger,
.button-danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #ffc6bd;
}

.button-ghost,
.button-ghost:hover {
  color: var(--accent-strong);
  background: transparent;
  border-color: transparent;
}

.inline-form {
  display: inline-flex;
}

.messages {
  width: min(1120px, calc(100% - 32px));
  margin: 18px auto 0;
  padding: 0;
  display: grid;
  gap: 10px;
  list-style: none;
}

.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--ink);
}

.site-list,
.link-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  list-style: none;
}

.site-row,
.link-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--surface);
}

.site-row-main,
.link-row-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.site-name,
.link-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.link-thumb {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.muted,
.meta {
  color: var(--muted);
}

.meta {
  font-size: 0.92rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.order-save-status {
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 60px;
  text-align: right;
}

.drag-handle {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-muted);
  cursor: grab;
}

.drag-handle::before {
  width: 14px;
  height: 12px;
  content: "";
  background:
    linear-gradient(currentColor, currentColor) 0 0 / 14px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 5px / 14px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 10px / 14px 2px no-repeat;
}

.link-row.is-dragging {
  opacity: 0.58;
  box-shadow: none;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
}

.icon-deactivate,
.icon-activate {
  width: 17px;
  height: 17px;
  display: inline-block;
  border: 2px solid currentColor;
  border-radius: 999px;
  position: relative;
}

.icon-deactivate::before {
  width: 11px;
  height: 2px;
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.icon-activate::before,
.icon-activate::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.icon-activate::before {
  width: 9px;
  height: 2px;
}

.icon-activate::after {
  width: 2px;
  height: 9px;
}

.icon-delete {
  color: var(--danger);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 0.82rem;
  font-weight: 800;
}

.pill-warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.pill-muted {
  color: var(--muted);
  background: var(--surface-muted);
}

.empty-state {
  border: 1px dashed #b9c5bf;
  border-radius: 8px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
}

.form-panel {
  max-width: 720px;
}

.form-grid {
  display: grid;
  gap: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  font-weight: 800;
}

.field input:not([type="checkbox"]),
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: var(--surface);
}

.field textarea {
  min-height: 132px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: 3px solid rgba(0, 127, 115, 0.2);
  border-color: var(--accent);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.helptext {
  color: var(--muted);
  font-size: 0.9rem;
}

.errorlist {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--danger);
  font-weight: 700;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.public-body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(217, 242, 238, 0.78), rgba(246, 247, 244, 0) 330px),
    var(--bg);
}

.public-theme-night.public-body {
  background:
    linear-gradient(180deg, rgba(30, 53, 48, 0.55), rgba(18, 20, 15, 0) 330px),
    var(--bg);
}

.public-theme-night {
  --bg: #12140f;
  --surface: #1d221a;
  --surface-muted: #252b22;
  --ink: #f7f8f0;
  --muted: #bdc6b7;
  --line: #3a4334;
  --accent: #8fd9c7;
  --accent-strong: #c7f4e7;
  --accent-soft: #1e3530;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
}

.public-theme-stage {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --ink: #151515;
  --muted: #5b6470;
  --line: #d4dbe3;
  --accent: #276ef1;
  --accent-strong: #174fb6;
}

.public-page {
  width: min(520px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 52px 0;
  display: flex;
  align-items: center;
}

.public-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--ink);
  font-size: 1.4rem;
  font-weight: 900;
}

.public-card h1 {
  margin-top: 18px;
  font-size: 2.4rem;
  text-align: center;
}

.public-bio {
  margin-top: 12px;
  color: var(--muted);
  text-align: center;
}

.public-links {
  width: 100%;
  margin: 24px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
  list-style: none;
}

.public-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 850;
  text-decoration: none;
}

.public-link-main {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.public-link-image {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.public-link:hover {
  color: var(--ink);
  border-color: var(--accent);
}

.public-url {
  margin-top: 24px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 760px) {

  .topbar-inner,
  .main,
  .messages,
  .narrow,
  .public-page {
    width: min(100% - 24px, 1120px);
  }

  .main {
    padding-top: 32px;
  }

  .page-header,
  .section-head,
  .site-row,
  .link-row {
    align-items: stretch;
    flex-direction: column;
  }

  .row-actions,
  .form-actions {
    justify-content: flex-start;
  }

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

  .span-7,
  .span-5 {
    grid-column: 1;
  }

  .button,
  button {
    width: 100%;
  }

  .inline-form,
  .inline-form button {
    width: 100%;
  }

  .link-row .inline-form,
  .link-row .inline-form .icon-button,
  .link-row .icon-button {
    width: 38px;
  }
}

/* Avatar: round image variant */
.avatar--image {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
  display: block;
}

/* Form image preview (link image + site avatar) */
.form-image-preview {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  display: block;
}

.form-image-preview--round {
  border-radius: 50%;
}

/* Drag ghost (SortableJS) */
.is-drag-ghost {
  background: var(--accent-soft) !important;
  border: 1px solid var(--accent) !important;
  opacity: 1;
}

/* Site theme applied to builder body (same vars as public themes) */
.site-theme-night {
  --bg: #12140f;
  --surface: #1d221a;
  --surface-muted: #252b22;
  --ink: #f7f8f0;
  --muted: #bdc6b7;
  --line: #333b2e;
  --accent: #8fd9c7;
  --accent-strong: #c7f4e7;
  --accent-soft: #1e3530;
  --warning: #e8b84b;
  --warning-soft: #2e2208;
}

.site-theme-stage {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #eaecf0;
  --ink: #151515;
  --muted: #5b6470;
  --line: #d4dbe3;
  --accent: #276ef1;
  --accent-strong: #174fb6;
  --accent-soft: #dce8fd;
}

/* Preview bar */
.preview-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--ink);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 700;
}

.preview-bar-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 0.7;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

.preview-bar-back {
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.preview-bar-back:hover {
  color: var(--accent-soft);
  text-decoration: underline;
}

.public-page--preview {
  padding-top: calc(52px + 44px);
}

/* Theme picker */
.theme-picker-form {
  display: grid;
  gap: 14px;
}

.theme-options {
  display: flex;
  gap: 10px;
}

.theme-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  transition: border-color 0.1s;
}

.theme-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-option--active,
.theme-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line);
  display: block;
}

.theme-swatch--clean {
  background: linear-gradient(135deg, #f6f7f4 50%, #007f73 50%);
}

.theme-swatch--night {
  background: linear-gradient(135deg, #12140f 50%, #8fd9c7 50%);
}

.theme-swatch--stage {
  background: linear-gradient(135deg, #f4f6f7 50%, #276ef1 50%);
}

/* Social links — public page row */
.social-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.social-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}

.social-link svg {
  width: 18px;
  height: 18px;
}

.social-link:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Social links — builder sidebar list */
.social-link-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  list-style: none;
}

.social-link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.social-link-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--muted);
}

.social-link-icon svg {
  width: 20px;
  height: 20px;
}

.social-link-label {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Appearance: layout ──────────────────────────────────────────────────── */

.public-links--horizontal {
  grid-template-columns: 1fr 1fr;
}

/* ── Appearance: link button styles ─────────────────────────────────────── */

/* Soft — pill shape, no border, muted fill */
.public-link--soft {
  border-radius: 999px;
  border-color: transparent;
  background: var(--surface-muted);
}

.public-link--soft:hover {
  background: var(--accent-soft);
  border-color: transparent;
}

/* Outline — transparent bg, accent border */
.public-link--outline {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}

.public-link--outline:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* Fill — solid accent bg, white text */
.public-link--fill {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.public-link--fill:hover {
  background: var(--accent-strong);
  border-color: transparent;
  color: #fff;
}

/* ── Appearance: icon size ───────────────────────────────────────────────── */

.public-links--icon-large .link-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
}

/* ── Appearance: preset picker ───────────────────────────────────────────── */

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.preset-tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px 8px;
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  background: var(--bg);
  transition: border-color 0.1s;
}

.preset-tile:hover {
  border-color: var(--accent);
}

.preset-tile--active,
.preset-tile.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.preset-tile-name {
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.current-preset-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 10px;
}

/* Mini link mockup inside preset tiles */
.preset-mock {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preset-mock-link {
  height: 18px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
}

/* Style variants for mock links */
.preset-mock--soft .preset-mock-link {
  border-radius: 999px;
  border-color: transparent;
  background: var(--surface-muted);
}

.preset-mock--outline .preset-mock-link {
  background: transparent;
  border: 1.5px solid var(--accent);
}

.preset-mock--fill .preset-mock-link {
  background: var(--accent);
  border-color: transparent;
}

/* Horizontal mock */
.preset-mock--horizontal {
  flex-direction: row;
  flex-wrap: wrap;
}

.preset-mock--horizontal .preset-mock-link {
  flex: 1 1 calc(50% - 2px);
}

/* Dark bg mock */
.preset-mock--dark {
  background: #1a1a1a;
  border-radius: 4px;
  padding: 4px;
}

.preset-mock--dark .preset-mock-link {
  background: var(--accent);
  border-color: transparent;
}

/* Appearance customise section */
.appearance-customise {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 4px;
}

.appearance-customise>summary {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  list-style: none;
  /* hide default arrow in some browsers */
  display: flex;
  align-items: center;
  gap: 6px;
}

.appearance-customise>summary::before {
  content: '▸';
  font-size: 0.7em;
  transition: transform 0.15s;
}

.appearance-customise[open]>summary::before {
  transform: rotate(90deg);
}

.appearance-customise-body {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.appearance-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.appearance-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.appearance-option {
  padding: 5px 12px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--ink);
  transition: border-color 0.1s, background 0.1s;
}

.appearance-option:hover {
  border-color: var(--accent);
}

.appearance-option--active,
.appearance-option.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.bg-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.bg-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid var(--line);
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}

.bg-swatch:hover,
.bg-swatch.is-active {
  border-color: var(--accent);
  transform: scale(1.1);
}

.bg-swatch--none {
  background: repeating-linear-gradient(45deg,
      var(--line) 0px, var(--line) 1px,
      transparent 1px, transparent 6px);
  border-style: dashed;
}
