/* Mobile first: one column at a time, swiping sideways. From 720px up, columns share the row.
   Dark by default; light when the device is set to light. */
:root {
  color-scheme: dark;
  --bg: #121212;
  --btn: #1e1e1e;
  --btn-hover: #2a2a2a;
  --text: #e2e2e2;
  --muted: #888;
  --line: #262626;
  --line-strong: #333;
  --well: #161616;
  --panel: #1a1a1a;
  --panel-line: #2c2c2c;
  --link-line: transparent;
  --accent: #ff3d9a;            /* hot pink: the highlight color */
  --accent-top: #ff63ae;
  --accent-glow: rgba(255, 61, 154, .45);
  --danger: #ff6b6b;
  --title: #6f92ac;             /* group titles: muted blue-gray (Daring Fireball link color #4a6b82, lifted for dark) */
  --title-glow: 0 0 6px rgba(111, 146, 172, .16);
  --bg-grad: radial-gradient(120% 60% at 0% 0%, #1d1a1e 0%, rgba(29, 26, 30, 0) 60%), linear-gradient(180deg, #171717 0%, #0d0d0d 100%);
  --btn-grad: linear-gradient(180deg, #2a2a2c 0%, #1b1b1d 100%);
  --btn-hover-grad: linear-gradient(180deg, #343437 0%, #232326 100%);
  --panel-grad: linear-gradient(180deg, #212123 0%, #171719 100%);
  --edge: inset 0 1px 0 rgba(255, 255, 255, .07), 0 1px 2px rgba(0, 0, 0, .45);
  --scrim: rgba(0, 0, 0, .6);
  --gap: 10px;
  --col-size: 84vw;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f5f2;
    --btn: #ffffff;
    --btn-hover: #ecebe6;
    --text: #1d1c1a;
    --muted: #6b675f;
    --line: #e2dfd8;
    --line-strong: #cfccc3;
    --well: #ecebe6;
    --panel: #ffffff;
    --panel-line: #dcd9d1;
    --link-line: #e2dfd8;
    --accent: #e0197d;
    --accent-top: #f0479a;
    --accent-glow: rgba(224, 25, 125, .3);
    --danger: #d43b3b;
    --title: #4a6b82;
    --title-glow: none;
    --bg-grad: radial-gradient(120% 60% at 0% 0%, #ffffff 0%, rgba(255, 255, 255, 0) 60%), linear-gradient(180deg, #faf9f6 0%, #ebe9e2 100%);
    --btn-grad: linear-gradient(180deg, #ffffff 0%, #f0eee8 100%);
    --btn-hover-grad: linear-gradient(180deg, #ffffff 0%, #e6e3db 100%);
    --panel-grad: linear-gradient(180deg, #ffffff 0%, #f4f2ec 100%);
    --edge: inset 0 1px 0 rgba(255, 255, 255, .9), 0 1px 2px rgba(60, 50, 30, .12);
    --scrim: rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  min-height: 100%;
  color: var(--text);
  font: 14px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- phone column strip ---------- */

#top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding-top: max(10px, env(safe-area-inset-top));
}

/* Top row: the edit pencil (always in the upper left) and the spaces. */
#top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}
#edit-toggle {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--btn-grad);
  box-shadow: var(--edge), inset 0 0 0 1px var(--link-line);
  color: var(--muted);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#edit-toggle:hover { color: var(--accent); }
.editing #edit-toggle { background: linear-gradient(180deg, var(--accent-top), var(--accent)); color: #fff; box-shadow: 0 0 12px var(--accent-glow); }

/* Spaces: the top-level contexts (one set of columns each). */
#spaces {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
#spaces::-webkit-scrollbar { display: none; }
.space {
  flex: none;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 7px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.space[aria-current] { background: var(--btn-grad); color: var(--text); box-shadow: var(--edge), inset 0 -2px 0 var(--accent), 0 2px 10px -4px var(--accent-glow); }
.space-tool { display: none; flex: none; border: 1px dashed var(--line-strong); border-radius: 8px; background: none; color: var(--muted); font: inherit; font-size: 13px; padding: 5px 10px; margin-left: 4px; cursor: pointer; }
.space + .space-tool { margin-left: 10px; }
.editing .space-tool { display: block; }
.editing .space { cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* Phone column strip */
#tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  border: 0;
  border-radius: 16px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab[aria-current] { background: var(--btn-grad); color: var(--text); box-shadow: var(--edge), inset 0 -2px 0 var(--accent), 0 2px 10px -4px var(--accent-glow); }

/* ---------- board and columns ---------- */

#board {
  display: flex;
  align-items: flex-start;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: max(16px, env(safe-area-inset-left));
  scrollbar-width: none;
  padding: 12px max(16px, env(safe-area-inset-right)) 96px max(16px, env(safe-area-inset-left));
}
#board::-webkit-scrollbar { display: none; }
.editing #board { scroll-snap-type: none; } /* snapping fights drag-to-scroll */

.column {
  flex: 0 0 var(--col-size);
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 0 var(--gap);
  scroll-snap-align: start;
}
.column:first-child { padding-left: 0; }
.column + .column, .column + .column-new { border-left: 1px solid var(--line); }
.editing .column { min-height: 120px; }

.column-head {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 28px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.column.untitled .column-head { display: none; }
.editing .column.untitled .column-head { display: flex; }

.column-title-text {
  flex: 1;
  min-width: 1ch;
  outline: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
}
.column-title-text:empty::before { content: "Column"; opacity: .5; }
.column-title-text[contenteditable="true"] { cursor: text; user-select: text; -webkit-user-select: text; }

.col-btn {
  display: none;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font: inherit;
  font-size: 16px;
  line-height: 1;
  padding: 6px 5px;
  cursor: pointer;
}
.col-btn:hover { color: var(--text); background: var(--btn-grad); }
.editing .col-btn { display: block; }
.grip { cursor: grab; touch-action: none; }

.column-new { display: none; flex: 0 0 9rem; padding: 0 var(--gap); }
.editing .column-new { display: block; }
.column-new .add { width: 100%; }

.column-items,
.group-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 8px;
}
.editing .column-items { min-height: 36px; }

/* ---------- groups and links ---------- */

.group { display: flex; flex-direction: column; gap: 6px; }
.column-items > .group:not(:first-child) { margin-top: 6px; } /* 12px between groups, double the usual gap */

.group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--title);
  text-shadow: var(--title-glow);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 2px 0;
}
.group-title span { flex: 1; outline: none; min-width: 1ch; }
.group-title span:empty::before { content: "Group"; opacity: .5; }

.link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 12px;
  background: var(--btn-grad);
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  box-shadow: var(--edge), inset 0 0 0 1px var(--link-line);
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow .15s, background .15s;
}
.link:hover { background: var(--btn-hover-grad); box-shadow: var(--edge), inset 0 0 0 1px var(--accent), 0 0 10px var(--accent-glow); }
.link:focus-visible, #dock button:focus-visible, #edit-toggle:focus-visible, .space:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link > span:not(.fav) { flex: 1; min-width: 0; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.link.has-note::before { content: ''; order: 1; flex: none; width: 6px; height: 6px; border-radius: 50%; background: #000; box-shadow: 0 0 0 1px rgba(255, 255, 255, .22); }

.fav {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}

.fav.pending { visibility: hidden; }
.fav.dot { border-radius: 50%; width: 12px; height: 12px; margin: 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); }
.fav.emoji { width: auto; min-width: 16px; font-size: 15px; line-height: 16px; text-align: center; }

.drop-target { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 10px; }

/* Edit-only controls */
.add, .group-delete { display: none; }
.editing .add, .editing .group-delete { display: block; }

.add {
  background: none;
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px;
  font: inherit;
  cursor: pointer;
}
.add:hover { color: var(--text); border-color: var(--muted); }

.group-delete {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.editing .link, .editing .group-title { cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.group-title span[contenteditable="true"] { cursor: text; user-select: text; -webkit-user-select: text; color: var(--text); }
/* A grip on every button while editing, so it's clear they can be dragged. */
.editing .link::after { order: 2; content: '\283F'; flex: none; margin-left: 8px; color: var(--muted); font-size: 15px; line-height: 1; }
.sortable-fallback { opacity: .9 !important; }

.column-add { display: none; gap: 6px; }
.editing .column-add { display: flex; }
.column-add .add { flex: 1; }

.sortable-ghost { opacity: .35; }
.sortable-chosen .link, .link.sortable-chosen { background: var(--btn-hover-grad); }
.editing .group-links:empty { min-height: 36px; border-radius: 8px; background: var(--well); }

/* ---------- bottom-right dock ---------- */

#dock {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
#dock button {
  height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  border: 0;
  background: var(--btn-grad);
  box-shadow: var(--edge), inset 0 0 0 1px var(--link-line);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
#dock button:hover { color: var(--text); box-shadow: var(--edge), inset 0 0 0 1px var(--accent); }

/* Signed out: always offer sign in. Signed in: sign out only while editing. */
#dock .edit-only, #account, #settings { display: none; }
.editing #dock .edit-only { display: block; }
body.signed-in #settings { display: block; }
#account:not([data-signed-in]):not(:empty),
.editing #account:not(:empty) { display: block; }

/* ---------- dialog ---------- */

dialog {
  background: var(--panel-grad);
  color: var(--text);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  padding: 16px;
  width: min(360px, calc(100% - 32px));
}
dialog::backdrop { background: var(--scrim); }
dialog textarea { resize: vertical; min-height: 4.5em; }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog input, dialog textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
}
dialog input:focus, dialog textarea:focus, .settings select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
::selection { background: var(--accent-glow); }
:root { accent-color: var(--accent); caret-color: var(--accent); }
.dialog-actions { display: flex; gap: 8px; }
.dialog-actions span { flex: 1; }
.dialog-actions button {
  background: var(--btn-grad);
  color: var(--text);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--edge), inset 0 0 0 1px var(--link-line);
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}
.dialog-actions button[value="save"] { background: linear-gradient(180deg, var(--accent-top), var(--accent)); color: #fff; box-shadow: 0 0 10px var(--accent-glow); }
.dialog-actions .danger { color: var(--danger); order: -1; width: 8.5em; text-align: center; padding-left: 0; padding-right: 0; }
.dialog-actions .danger.armed { background: var(--danger); color: #fff; }

/* Icon picker in the link dialog: fixed sizes throughout so nothing reflows while icons load or buttons are clicked. */
#link-dialog { max-height: calc(100dvh - 32px); overflow-y: auto; }
.icon-pick { display: flex; flex-direction: column; gap: 6px; }
.icon-label { font-size: 12px; color: var(--muted); }
.icon-row { display: flex; gap: 4px; height: 30px; overflow: hidden; }
.root-row { display: flex; gap: 4px; height: 42px; }
.emoji-grid { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px; height: 128px; overflow-y: auto; padding: 4px; border-radius: 8px; background: var(--bg); box-shadow: inset 0 0 0 1px var(--line-strong); }
.icon-opt { flex: none; display: flex; align-items: center; justify-content: center; gap: 6px; width: 28px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: var(--btn-grad); box-shadow: var(--edge), inset 0 0 0 1px var(--link-line); color: var(--text); font: inherit; font-size: 16px; cursor: pointer; }
.icon-opt .fav { margin: 0; }
.icon-opt .slot { flex: none; display: grid; place-items: center; width: 16px; height: 16px; overflow: hidden; }
.icon-opt .label { font-size: 12px; white-space: nowrap; }
.icon-opt .root-mark { font-size: 15px; line-height: 1; color: var(--muted); }
.icon-opt.site { width: 58px; }
.icon-opt.pick { flex: 1; min-width: 0; height: 42px; justify-content: flex-start; padding: 0 8px; }
.icon-opt.pick:disabled { cursor: default; opacity: .55; }
.icon-opt.pick .two { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.25; }
.icon-opt.pick .label { font-size: 11px; color: var(--muted); }
.icon-opt.pick .domain { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text); min-height: 1.25em; }
.icon-opt.on { box-shadow: inset 0 0 0 2px var(--accent), 0 0 8px var(--accent-glow); }
.emoji-grid .icon-opt { background: none; box-shadow: none; width: 30px; }
.emoji-grid .icon-opt.on { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- settings dialog ---------- */

#settings-dialog { width: min(420px, calc(100% - 32px)); }
.settings h2 { margin: 0; font-size: 18px; }
.settings h3 { margin: 6px 0 0; font-size: 14px; }
.settings p { margin: 0; }
.settings .muted { color: var(--muted); font-size: 13px; line-height: 1.4; }
.settings .fine { font-size: 12px; }
.settings .field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.settings select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  font-size: 16px;
}
#share-members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#share-members li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; background: var(--btn-grad); box-shadow: var(--edge), inset 0 0 0 1px var(--link-line); font-size: 14px; }
#share-members li span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#share-members em { font-style: normal; font-size: 12px; color: var(--muted); }
.share-remove { border: 0; background: none; color: var(--muted); font: inherit; font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px; }
.share-remove:hover { color: var(--danger); }
#share-add { display: flex; gap: 8px; }
#share-add[hidden], #share-leave[hidden] { display: none; }
#share-add input { flex: 1; min-width: 0; }
#share-add button, #share-leave {
  background: var(--btn-grad);
  color: var(--text);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--edge), inset 0 0 0 1px var(--link-line);
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}
#share-leave { align-self: flex-start; color: var(--danger); }
#share-error { color: var(--danger); font-size: 13px; min-height: 0; }
.space.shared::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; }

/* ---------- tablet and desktop: columns share the row (7 fit from about 1400px) ---------- */

@media (min-width: 720px) {
  :root { --col-size: 11.5rem; }
  #board {
    scroll-snap-type: none;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
    padding-top: max(16px, env(safe-area-inset-top));
  }
  #board::-webkit-scrollbar { display: block; height: 8px; }
  #board::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
  .column { flex: 1 0 var(--col-size); max-width: 18rem; }
}

/* Column tabs stay until all columns comfortably fit on screen. */
@media (min-width: 1000px) {
  #tabs { display: none; }
}

/* Editing: let the space tools wrap onto a second row instead of hiding off to the right. */
.editing #spaces { flex-wrap: wrap; overflow: visible; row-gap: 6px; }

/* Search (press /) */
#search-dialog { margin-top: 12vh; width: min(460px, calc(100% - 32px)); }
#search-results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#search-results:empty { display: none; }
#search-results li { display: flex; align-items: baseline; gap: 10px; padding: 9px 12px; border-radius: 8px; background: var(--btn-grad); box-shadow: var(--edge); cursor: pointer; }
#search-results li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results li em { font-style: normal; font-size: 12px; color: var(--muted); white-space: nowrap; }
#search-results li.on { box-shadow: var(--edge), inset 0 0 0 1px var(--accent), 0 0 10px var(--accent-glow); }

/* What a signed-out visitor sees on an empty board: say what this site is. */
#about { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; pointer-events: none; color: var(--muted); }
#about[hidden] { display: none; }
#about h1 { margin: 0; font-size: 20px; color: var(--text); }
#about p { margin: 0; max-width: 34rem; font-size: 14px; line-height: 1.5; }
#about .about-contact { font-size: 13px; }

/* Edit mode: our own dragging, never the browser's drag of a link. */
.editing .link, .editing .link *, .editing .group-title { -webkit-user-drag: none; user-drag: none; }
