:root {
  --yellow: #ffcc00;
  --yellow-hover: #ffd633;
  --yellow-soft: #fff7cc;
  --black: #09090b;
  --ink: #18181b;
  --zinc-700: #3f3f46;
  --zinc-600: #52525b;
  --zinc-500: #71717a;
  --zinc-400: #a1a1aa;
  --zinc-300: #d4d4d8;
  --zinc-200: #e4e4e7;
  --zinc-100: #f4f4f5;
  --zinc-50: #fafafa;
  --red: #dc2626;
  --page: #f3f3f1;
  --tile: #ffffff;
  --shadow: 0 1px 2px rgba(9, 9, 11, .06), 0 1px 1px rgba(9, 9, 11, .04);
  --shadow-hover: 0 10px 24px rgba(9, 9, 11, .10), 0 2px 6px rgba(9, 9, 11, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f4f4f5; --zinc-600: #a1a1aa; --zinc-500: #a1a1aa; --zinc-300: #3f3f46; --zinc-200: #27272a; --zinc-100: #1f1f23; --zinc-50: #18181b;
    --page: #0f0f11; --tile: #18181b; --yellow-soft: #3a3000;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-hover: 0 10px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #f4f4f5; --zinc-600: #a1a1aa; --zinc-500: #a1a1aa; --zinc-300: #3f3f46; --zinc-200: #27272a; --zinc-100: #1f1f23; --zinc-50: #18181b;
  --page: #0f0f11; --tile: #18181b; --yellow-soft: #3a3000;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-hover: 0 10px 24px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.45;
}
button, input { font: inherit; color: inherit; }
.muted { color: var(--zinc-500); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---- Top bar ---- */
.top { position: sticky; top: 0; z-index: 20; background: var(--black); color: #fff; border-bottom: 4px solid var(--yellow); }
.top-inner { max-width: 1240px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; flex: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; background: var(--yellow); color: var(--black); border-radius: 8px; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: .01em; text-transform: uppercase; }
.brand-name b { color: var(--yellow); font-weight: 800; }
.search { position: relative; flex: 1; max-width: 520px; margin-left: auto; }
.search input {
  width: 100%; height: 42px; padding: 0 14px 0 42px; border: 2px solid #3f3f46; border-radius: 999px;
  background: #18181b; color: #fff; outline: none; transition: border-color .15s, background .15s;
}
.search input::placeholder { color: #a1a1aa; }
.search input:focus { border-color: var(--yellow); background: #000; }
.search-icon { position: absolute; left: 15px; top: 12px; color: #a1a1aa; pointer-events: none; }
.top-button {
  flex: none; height: 42px; padding: 0 18px; border: 2px solid #3f3f46; border-radius: 999px; background: transparent; color: #fff;
  font-weight: 700; cursor: pointer; transition: border-color .15s, color .15s;
}
.top-button:hover, .top-button:focus-visible { border-color: var(--yellow); color: var(--yellow); outline: none; }

.editbar { background: var(--yellow); color: var(--black); }
.editbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: 14px; }
.editbar-actions { display: flex; align-items: center; gap: 14px; }
.done-button { height: 36px; padding: 0 20px; border: 0; border-radius: 999px; background: var(--black); color: #fff; font-weight: 700; cursor: pointer; }
.editbar .link-button { color: var(--black); }

/* ---- Page ---- */
.main { max-width: 1240px; margin: 0 auto; padding: 36px 24px 64px; }
.hero { margin-bottom: 36px; text-align: center; }
.greeting { margin: 0 0 4px; color: var(--zinc-500); font-size: 14px; font-weight: 600; letter-spacing: .02em; }
.hero h1 { margin: 0; font-size: 34px; line-height: 1.15; font-weight: 800; letter-spacing: -.01em; }
.subtitle { margin: 6px 0 0; color: var(--zinc-600); font-size: 16px; }
.hero.editable h1, .hero.editable .subtitle { cursor: pointer; text-decoration: underline dashed var(--zinc-400) 1px; text-underline-offset: 6px; }

.groups { display: grid; gap: 34px; }
.group-head { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 16px; min-height: 32px; }
.group-head h2 { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--zinc-600); display: flex; align-items: center; gap: 10px; }
.group-head h2::before { content: ''; width: 4px; height: 16px; background: var(--yellow); border-radius: 2px; }
.group-name { width: min(320px, 100%); height: 34px; padding: 0 10px; border: 2px solid var(--zinc-300); border-radius: 8px; background: var(--tile); font-weight: 700; outline: none; }
.group-name:focus { border-color: var(--yellow); }
.group-tools { display: flex; gap: 4px; }

.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; }
.tiles > .tile, .tiles > .add-tile { width: 180px; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 12px;
  min-height: 164px; padding: 28px 14px 18px; border-radius: var(--radius); background: var(--tile); color: var(--ink);
  text-decoration: none; text-align: center; box-shadow: var(--shadow); border: 1px solid var(--zinc-200);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; outline: none;
}
.tile::after { content: ''; position: absolute; left: 18px; right: 18px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--yellow); transform: scaleX(0); transition: transform .18s ease; }
a.tile:hover, a.tile:focus-visible { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: var(--zinc-300); }
a.tile:hover::after, a.tile:focus-visible::after { transform: scaleX(1); }
a.tile:focus-visible { border-color: var(--yellow); }
.tile-icon { width: 64px; height: 64px; flex: none; display: grid; place-items: center; }
.tile-icon img { width: 64px; height: 64px; object-fit: contain; border-radius: 14px; }
.letter { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; font-weight: 800; letter-spacing: .02em; color: #fff; }
.letter.light { color: var(--black); }
.tile-title { font-size: 15px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tile mark { background: var(--yellow-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

/* Editing */
.editing .tile { cursor: grab; }
.editing .tile:hover { border-color: var(--zinc-300); }
.tile.dragging { opacity: .35; }
.tile.drop-before { box-shadow: -4px 0 0 var(--yellow), var(--shadow); }
.tiles.drop-end { outline: 2px dashed var(--yellow); outline-offset: 6px; border-radius: var(--radius); }
.tile-tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.icon-button {
  width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 1px solid var(--zinc-200); border-radius: 8px;
  background: var(--tile); color: var(--zinc-600); cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.icon-button:hover, .icon-button:focus-visible { background: var(--yellow); border-color: var(--yellow); color: var(--black); outline: none; }
.icon-button.danger:hover, .icon-button.danger:focus-visible { background: var(--red); border-color: var(--red); color: #fff; }
.add-tile {
  min-height: 164px; border: 2px dashed var(--zinc-300); border-radius: var(--radius); background: transparent; color: var(--zinc-500);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-weight: 700; transition: border-color .15s, color .15s, background .15s;
}
.add-tile:hover, .add-tile:focus-visible { border-color: var(--yellow); color: var(--ink); background: var(--yellow-soft); outline: none; }
.add-group { justify-self: center; }
.empty-group { color: var(--zinc-500); font-size: 14px; margin: 12px 0 0; text-align: center; }
.no-results { padding: 40px 0; text-align: center; color: var(--zinc-500); }

/* Buttons */
.primary-button, .plain-button, .danger-button {
  height: 40px; padding: 0 18px; border-radius: 999px; font-weight: 700; cursor: pointer; border: 2px solid transparent; transition: background .15s, border-color .15s;
}
.primary-button { background: var(--yellow); color: var(--black); }
.primary-button:hover { background: var(--yellow-hover); }
.plain-button { background: transparent; border-color: var(--zinc-300); color: var(--ink); }
.plain-button:hover { border-color: var(--ink); }
.danger-button { background: transparent; border-color: transparent; color: var(--red); padding: 0 8px; }
.danger-button:hover { text-decoration: underline; }
.link-button { padding: 0; border: 0; background: none; color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; }

/* Dialogs */
.dialog { width: min(520px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px; background: var(--tile); color: var(--ink); box-shadow: 0 24px 60px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(9, 9, 11, .55); backdrop-filter: blur(2px); }
.dialog form { padding: 24px; display: grid; gap: 14px; }
.dialog h2 { margin: 0; font-size: 20px; font-weight: 800; }
.small-dialog { width: min(420px, calc(100vw - 32px)); }
.preview-wrap { display: grid; place-items: center; padding: 18px; background: var(--zinc-100); border-radius: 12px; }
.preview-wrap .tile { width: 160px; pointer-events: none; }
.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; font-size: 13px; font-weight: 700; color: var(--zinc-600); }
.field legend { padding: 0; margin-bottom: 6px; }
.optional { font-weight: 400; color: var(--zinc-500); }
.field input:not([type="radio"]):not([type="file"]) {
  height: 42px; padding: 0 12px; border: 2px solid var(--zinc-300); border-radius: 10px; background: var(--tile); color: var(--ink); font-weight: 400; font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--yellow); }
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: inline-block; padding: 7px 14px; border: 2px solid var(--zinc-300); border-radius: 999px; font-weight: 700; color: var(--ink); }
.segmented input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--tile); }
.segmented input:focus-visible + span { border-color: var(--yellow); }
.icon-option { margin-top: 10px; font-weight: 400; color: var(--ink); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.swatch[aria-checked="true"] { border-color: var(--tile); box-shadow: 0 0 0 2px var(--ink); }
.dialog-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.spacer { flex: 1; }
.error { margin: 0; padding: 10px 12px; border-radius: 10px; background: #fef2f2; color: #991b1b; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; padding: 10px 18px; border-radius: 999px;
  background: var(--black); color: #fff; font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast.bad { background: var(--red); }

@media (max-width: 720px) {
  .top-inner { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .brand-name { font-size: 16px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .top-button { margin-left: auto; height: 36px; padding: 0 14px; }
  .main { padding: 24px 16px 48px; }
  .hero h1 { font-size: 26px; }
  .tiles { gap: 10px; }
  .tiles > .tile, .tiles > .add-tile { width: calc(50% - 5px); }
  .tile { min-height: 132px; padding: 18px 8px 14px; gap: 10px; }
  .tile-icon, .tile-icon img, .letter { width: 52px; height: 52px; }
  .add-tile { min-height: 132px; }
  .editbar-inner { padding: 10px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

