:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #5d6575;
  --line: #d9dee6;
  --slot: #dfe4eb;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #c62828;
  --shadow: 0 1px 2px rgb(16 24 40 / .08), 0 4px 14px rgb(16 24 40 / .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a;
    --panel: #1a1e26;
    --ink: #e8eaef;
    --muted: #9aa3b2;
    --line: #2c323d;
    --slot: #1f242d;
    --accent: #6ea0ff;
    --accent-ink: #0b1220;
    --danger: #ff7a7a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 18px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 500 15px/1.45 Nunito, ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
code { font-size: .9em; }

button, .bookmarklet {
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .45em 1em;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.big { font-size: 1.1rem; padding: .7em 1.5em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5em .7em;
  width: 100%;
}
textarea { resize: vertical; }
label { display: grid; gap: .3em; font-weight: 700; font-size: .92rem; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: .45em; }
legend { font-weight: 700; font-size: .92rem; margin-bottom: .35em; padding: 0; }
.small { font-size: .88rem; color: var(--muted); }
.meta { color: var(--muted); font-size: .88rem; font-weight: 500; }
.error { color: var(--danger); margin: .6em 0 0; }

.banner {
  background: #fff4cc;
  color: #5c4500;
  text-align: center;
  padding: .45em 16px;
  font-size: .88rem;
}

/* header */
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.1rem; }
.logo { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 22px; height: 22px; }
.logo i { border-radius: 3px; }
.logo i:nth-child(1) { background: #e53935; }
.logo i:nth-child(2) { background: #039be5; }
.logo i:nth-child(3) { background: #33b679; }
.logo i:nth-child(4) { background: #f6bf26; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: thin; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: .4em .9em;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); background: var(--bg); }
.tab.on { color: var(--ink); background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); }
.tab.add { border: 1px dashed var(--line); background: transparent; color: var(--muted); }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: #33b679; }
.user-area { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; white-space: nowrap; }
.who { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .92rem; }
.who img { width: 28px; height: 28px; border-radius: 50%; }

/* landing */
.landing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 48px;
  align-items: center;
  max-width: 1080px;
  margin: 0 auto;
  padding: 64px 16px;
}
.hero h1 { font-size: clamp(2rem, 4.5vw, 3.2rem); font-weight: 800; letter-spacing: -.02em; }
.hero p { font-size: 1.1rem; color: var(--muted); max-width: 34em; }
.hero .small { font-size: .9rem; }
.hero-art {
  aspect-ratio: 4 / 3;
  border-radius: 20px;
  background:
    conic-gradient(from 90deg at 1px 1px, #0000 90deg, var(--bg) 0) 0 0 / 25% 33.4%,
    linear-gradient(135deg, #e53935 0 16%, #fb8c00 16% 32%, #f6bf26 32% 48%, #33b679 48% 64%, #039be5 64% 80%, #8e24aa 80%);
  box-shadow: var(--shadow);
}

/* board */
#app { padding: 16px 16px 32px; }
.boardbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  width: var(--grid-w);
  max-width: 100%;
  margin: 0 auto 14px;
}
.board-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.board-title h1 { font-size: 1.5rem; font-weight: 800; overflow-wrap: anywhere; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.grid-msg { text-align: center; color: var(--muted); margin: 64px 0; }

.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols, 12), minmax(0, 1fr));
  gap: clamp(8px, 1.3vw, 18px);
  width: var(--grid-w);
  margin: 0 auto;
}
/* tiles stay about the same size whatever the column count */
#app { --grid-w: min(100%, calc(var(--cols, 12) * 140px), 1680px); }
.cell { position: relative; aspect-ratio: 1; min-width: 0; }
/* The picture fills the tile on white; the tile's color is a ring around it. */
.tile {
  container-type: size;
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 18%;
  background: #fff;
  box-shadow: inset 0 0 0 max(3px, 4.5cqw) var(--c), 0 1px 3px rgb(0 0 0 / .25);
  color: var(--fg);
  text-decoration: none;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.cell:hover, .cell:focus-within { z-index: 4; }
a.tile:hover, a.tile:focus-visible {
  transform: scale(1.08);
  box-shadow: inset 0 0 0 max(3px, 4.5cqw) var(--c), 0 10px 24px rgb(0 0 0 / .35);
}
.art { position: absolute; inset: 12%; display: grid; place-items: center; }
.art img { width: 100%; height: 100%; object-fit: contain; }
.art img:not([src]) { visibility: hidden; }
.art.small img { width: 72%; height: 72%; } /* tiny logos get blurry when stretched */
.tile:has(.art.letter) { background: var(--c); }
.art.letter { inset: 0; color: var(--fg); font-weight: 800; font-size: 56cqw; line-height: 1; }

/* Name label: appears below the tile on mouse-over or keyboard focus. */
.label {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  translate: -50% 0;
  z-index: 6;
  width: max-content;
  max-width: min(16em, 70vw);
  padding: .45em .8em;
  border-radius: 10px;
  background: #1d2433;
  color: #fff;
  border: 1px solid rgb(255 255 255 / .15);
  box-shadow: 0 6px 18px rgb(0 0 0 / .3);
  font-weight: 800;
  font-size: 1rem;
  line-height: 1.2;
  text-align: center;
  display: none; /* hidden labels would still widen the page and make it scroll sideways */
  pointer-events: none;
}
.cell.edge-left .label { left: 0; translate: 0 0; }
.cell.edge-right .label { left: auto; right: 0; translate: 0 0; }
.tile:hover + .label, .tile:focus-visible + .label { display: block; }
#app { overflow-x: clip; }
@media (hover: none) { .label { display: none; } }
.edit {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .12s;
  z-index: 7;
}
.edit svg { width: 13px; height: 13px; }
.cell:hover .edit, .edit:focus-visible { opacity: 1; }
@media (hover: none) { .edit { opacity: 1; } }

.slot {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 18%;
  background: var(--slot);
  position: relative;
}
.slot::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1.6rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity .12s;
}
.slot:hover::after, .slot:focus-visible::after { opacity: 1; }
.slot:hover { box-shadow: inset 0 0 0 2px var(--line); }
.empty-hint {
  grid-column: 1 / -1;
  grid-row: 2;
  justify-self: center;
  margin: 8px 0 0;
  padding: .7em 1em;
  text-align: center;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  pointer-events: none;
}
.add-mobile { display: none; }

.grid.editable .cell { cursor: grab; touch-action: none; }
.cell.dragging { opacity: .3; }
.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.08);
  filter: drop-shadow(0 10px 18px rgb(0 0 0 / .3));
}
.drag-ghost .edit, .drag-ghost .label, body.is-dragging .label { display: none; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
.drop { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 18%; }

/* dialogs */
dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  border: 0;
  border-radius: 16px;
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / .3);
}
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(15 20 30 / .45); }
dialog h2 { font-size: 1.3rem; font-weight: 800; margin-bottom: 16px; }
dialog h3 { font-size: 1rem; font-weight: 800; margin-bottom: 8px; }
dialog form > label { margin-bottom: 8px; }
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.spacer { flex: 1; }

.tile-form { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 20px; }
.preview-wrap { padding-top: 22px; }
.preview .cell { width: 120px; margin-bottom: 64px; }
.preview .label { display: block; opacity: 1; max-width: 140px; }
.fields { display: grid; gap: 14px; }
.swatches { display: grid; grid-template-columns: repeat(6, 32px); gap: 8px; }
.swatch { width: 32px; height: 32px; padding: 0; border-radius: 8px; background: var(--c); border: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink); }
.radios { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.radios label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.radios input { width: auto; }

dialog h3.sub { margin: 22px 0 4px; }
.signin-button { min-height: 44px; margin: 16px 0 4px; }
.dev-login { display: grid; gap: 10px; }
.dev-login button { justify-self: start; }
.editor-list { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 2px; max-height: 180px; overflow: auto; }
.editor-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0 4px 10px; border-radius: 8px; overflow-wrap: anywhere; }
.editor-list li:nth-child(odd):not(.small) { background: var(--bg); }
.editor-list .ghost { color: var(--danger); font-size: .88rem; }
.tab-ico { width: 12px; height: 12px; flex: none; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 1rem; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.copyrow { display: flex; gap: 8px; }
.copyrow input:disabled { opacity: .5; }

.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.import-grid section { display: grid; align-content: start; gap: 8px; }
.steps { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; font-size: .92rem; }
.bookmarklet { display: inline-block; margin: 4px 0; text-decoration: none; background: var(--accent); color: var(--accent-ink); border-color: transparent; cursor: grab; }
.import-preview ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; max-height: 220px; overflow: auto; }
.import-preview label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.import-preview input { width: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: .7em 1.1em;
  border-radius: 12px;
  background: #1d2433;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 200;
}
.toast button { background: transparent; color: #9cc0ff; border: 0; padding: 0; }

/* phones: a simple 4-across list in board order, no dragging */
@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .landing { grid-template-columns: 1fr; padding-block: 32px; }
  #app { --grid-w: 100%; }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  .cell { grid-column: auto !important; grid-row: auto !important; }
  .slot, .empty-hint { display: none; }
  .add-mobile { display: block; grid-column: 1 / -1; order: 9999; }
  .tile-form, .import-grid { grid-template-columns: 1fr; }
  .preview-wrap { padding-top: 0; }
  .preview .cell { width: 96px; }
}
