/* Klikstek — design tokens, light and dark */
:root {
  --petrol: #164E52;
  --mint: #50C9AD;
  --bg: #F3F7F6;
  --surface: #FFFFFF;
  --surface-2: #EAF1EF;
  --surface-3: #DFEAE7;
  --ink: #12292B;
  --muted: #56706F;
  --line: #D9E4E2;
  --line-strong: #B4C8C5;
  --primary: #164E52;
  --primary-hover: #0F3B3E;
  --on-primary: #FFFFFF;
  --accent-soft: #DDF4EE;
  --focus: #1E8F78;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --toast-bg: #12292B;
  --toast-ink: #F3F7F6;
  --toast-action: #7FE0C8;
  --shadow-1: 0 1px 2px rgba(18, 41, 43, .06), 0 1px 1px rgba(18, 41, 43, .03);
  --shadow-2: 0 10px 24px -12px rgba(18, 41, 43, .28), 0 2px 6px rgba(18, 41, 43, .06);
  --shadow-3: 0 24px 60px -20px rgba(18, 41, 43, .35), 0 4px 14px rgba(18, 41, 43, .08);
  --backdrop: rgba(14, 29, 31, .42);

  --radius-tile: 18px;
  --radius-ctl: 12px;
  --radius-panel: 22px;
  --tile: 116px;
  --gap: 14px;
  --page: 1120px;
  --font: "Figtree", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1D1F;
    --surface: #15292C;
    --surface-2: #1A3235;
    --surface-3: #22403F;
    --ink: #E3EFED;
    --muted: #93AEAB;
    --line: #25403F;
    --line-strong: #3A5E5D;
    --primary: #50C9AD;
    --primary-hover: #6FDCC2;
    --on-primary: #08201F;
    --accent-soft: #173F3A;
    --focus: #6FDCC2;
    --danger: #FF8A80;
    --danger-soft: #3A1F1E;
    --toast-bg: #E3EFED;
    --toast-ink: #0E1D1F;
    --toast-action: #116B5A;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-2: 0 12px 28px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
    --shadow-3: 0 28px 70px -20px rgba(0, 0, 0, .7), 0 4px 14px rgba(0, 0, 0, .35);
    --backdrop: rgba(3, 10, 11, .62);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0E1D1F;
  --surface: #15292C;
  --surface-2: #1A3235;
  --surface-3: #22403F;
  --ink: #E3EFED;
  --muted: #93AEAB;
  --line: #25403F;
  --line-strong: #3A5E5D;
  --primary: #50C9AD;
  --primary-hover: #6FDCC2;
  --on-primary: #08201F;
  --accent-soft: #173F3A;
  --focus: #6FDCC2;
  --danger: #FF8A80;
  --danger-soft: #3A1F1E;
  --toast-bg: #E3EFED;
  --toast-ink: #0E1D1F;
  --toast-action: #116B5A;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 12px 28px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-3: 0 28px 70px -20px rgba(0, 0, 0, .7), 0 4px 14px rgba(0, 0, 0, .35);
  --backdrop: rgba(3, 10, 11, .62);
  color-scheme: dark;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-weight: 420;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 680; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
kbd {
  font: 600 .8125rem/1 var(--font);
  padding: 3px 7px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface);
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: 16px; top: -100px; z-index: 100; background: var(--surface); padding: 8px 14px; border-radius: var(--radius-ctl); }
.skip:focus { top: 12px; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Logo (inline svg) */
.logo { display: block; height: 30px; width: auto; }
.logo .p { fill: var(--petrol); }
.logo .m { fill: var(--mint); }
.logo .w { fill: var(--petrol); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo .p, :root:not([data-theme="light"]) .logo .w { fill: var(--ink); }
}
:root[data-theme="dark"] .logo .p, :root[data-theme="dark"] .logo .w { fill: var(--ink); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-ctl);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: .9375rem; text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
.btn-danger { color: var(--danger); border-color: var(--line-strong); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-danger-solid:hover { filter: brightness(1.08); background: var(--danger); color: var(--surface); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-small { min-height: 34px; padding: 0 12px; font-size: .875rem; border-radius: 10px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-ctl);
  background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn .icon { width: 18px; height: 18px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label, .field-label { font-weight: 600; font-size: .9375rem; }
.hint { color: var(--muted); font-size: .875rem; margin: 0; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-ctl);
  background: var(--surface); color: var(--ink);
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: transparent; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: .9375rem; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--primary); flex: none; }
.radio-row { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-chip { position: relative; }
.radio-chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.radio-chip span {
  display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 10px; font-weight: 550; font-size: .875rem;
}
.radio-chip input:checked + span { border-color: var(--primary); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.radio-chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.alert { padding: 12px 14px; border-radius: var(--radius-ctl); margin-bottom: 16px; font-size: .9375rem; background: var(--surface-2); border: 1px solid var(--line); }
.alert-error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alert-success { background: var(--accent-soft); border-color: transparent; }
.validation-errors ul { margin: 0; padding-left: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions.end { justify-content: flex-end; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .875rem; margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* App header */
.app { max-width: var(--page); margin: 0 auto; padding: 0 24px 64px; }
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 0 8px; }
.app-header .brand { display: inline-flex; border-radius: 8px; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.save-status { font-size: .8125rem; color: var(--muted); min-width: 0; }
.save-status.error { color: var(--danger); font-weight: 600; }

/* Search: the one big element on the start page */
.search-wrap { position: relative; max-width: 700px; margin: 28px auto 36px; }
.search {
  width: 100%; height: 62px; padding: 0 64px 0 58px;
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface); color: var(--ink);
  font-size: 1.25rem; font-weight: 450;
  box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .15s;
}
.search::-webkit-search-cancel-button { display: none; }
.search::placeholder { color: var(--muted); }
.search:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--mint) 40%, transparent), var(--shadow-2); }
.search-icon { position: absolute; left: 20px; top: 50%; width: 22px; height: 22px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-aside { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; }
.search-aside kbd { margin-right: 8px; }

/* Grid of tiles */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  grid-auto-rows: var(--tile);
  grid-auto-flow: dense;
  gap: var(--gap);
}
.tile {
  position: relative;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-tile);
  box-shadow: var(--shadow-1);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
  -webkit-touch-callout: none;
}
.tile.size-2x1 { grid-column: span 2; }
.tile.size-1x2 { grid-row: span 2; }
.tile.size-2x2 { grid-column: span 2; grid-row: span 2; }
.tile.size-3x1 { grid-column: span 3; }
.tile:hover { border-color: var(--line-strong); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.tile-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 100%; padding: 14px 12px;
  border: 0; border-radius: inherit; background: none;
  color: var(--ink); text-decoration: none; text-align: center; cursor: pointer;
  -webkit-user-drag: none; user-select: none;
}
.tile-link:hover { color: var(--ink); }
.tile-link:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.tile-icon {
  position: relative; display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 10px; overflow: hidden;
}
.tile-icon img { width: 100%; height: 100%; object-fit: contain; }
.initials { width: 100%; height: 100%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .9375rem; letter-spacing: .01em; }
.tile-text { display: grid; gap: 2px; min-width: 0; max-width: 100%; }
.tile-title {
  font-size: .875rem; font-weight: 580; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.tile-domain { display: none; font-size: .8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:is(.size-2x1, .size-3x1) .tile-link { flex-direction: row; justify-content: flex-start; text-align: left; padding: 0 44px 0 18px; gap: 14px; }
.tile:is(.size-2x1, .size-3x1) .tile-icon { width: 42px; height: 42px; }
.tile.size-1x2 .tile-icon { width: 54px; height: 54px; border-radius: 14px; }
.tile.size-2x2 .tile-icon { width: 72px; height: 72px; border-radius: 18px; }
.tile.size-2x2 .initials { font-size: 1.5rem; }
.tile.size-1x2 .initials { font-size: 1.125rem; }
.tile.size-2x2 .tile-title { font-size: 1.0625rem; }
.tile:is(.size-2x1, .size-3x1, .size-1x2, .size-2x2) .tile-domain { display: block; }
.tile-more {
  position: absolute; top: 6px; right: 6px;
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  cursor: pointer; opacity: 0; transition: opacity .12s, background-color .12s;
}
.tile-more .icon { width: 18px; height: 18px; }
.tile:hover .tile-more, .tile:focus-within .tile-more, .tile-more[aria-expanded="true"] { opacity: 1; }
.tile-more:hover { background: var(--surface-2); color: var(--ink); }
@media (hover: none) { .tile-more { opacity: .75; } }

/* Tabs */
.tabbar { display: flex; align-items: center; gap: 6px; margin: -14px 0 18px; overflow-x: auto; scrollbar-width: thin; padding: 2px; }
.tabs { display: flex; gap: 4px; }
.tab-item { display: flex; align-items: center; border: 1px solid transparent; border-radius: 12px; }
.tab-item.active { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-1); }
.tab {
  height: 38px; padding: 0 14px; border: 0; border-radius: 11px; background: none;
  color: var(--muted); font: inherit; font-weight: 600; font-size: .9375rem; white-space: nowrap; cursor: pointer;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab-item.active .tab { color: var(--ink); padding-right: 4px; }
.tab-item.active .tab:hover { background: none; }
.tab:focus-visible, .tab-more:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.tab.drop-target { background: var(--accent-soft); color: var(--ink); box-shadow: inset 0 0 0 2px var(--primary); }
.tab-more {
  width: 28px; height: 28px; margin-right: 5px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
}
.tab-more .icon { width: 17px; height: 17px; }
.tab-more:hover { background: var(--surface-2); color: var(--ink); }
.tab-add { flex: none; }
.tab-empty { margin-top: 24px; }

/* Group tiles */
.tile.group { background: var(--surface-2); }
.group-preview {
  display: grid; grid-template-columns: repeat(2, 20px); grid-auto-rows: 20px; gap: 5px;
  padding: 7px; border-radius: 12px; background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}
.group-preview .mini { width: 20px; height: 20px; border-radius: 6px; overflow: hidden; display: grid; place-items: center; background: var(--surface-3); }
.group-preview .mini img { width: 100%; height: 100%; object-fit: contain; }
.group-preview .mini .initials { font-size: .5625rem; }
.tile.group.size-2x1 .group-preview { grid-template-columns: repeat(2, 20px); }
.tile.group.size-3x1 .group-preview { grid-template-columns: repeat(4, 20px); }
.tile.group.size-1x2 .group-preview { grid-template-columns: repeat(2, 26px); grid-auto-rows: 26px; }
.tile.group.size-1x2 .mini { width: 26px; height: 26px; }
.tile.group.size-2x2 .group-preview { grid-template-columns: repeat(3, 34px); grid-auto-rows: 34px; gap: 8px; padding: 10px; border-radius: 16px; }
.tile.group.size-2x2 .mini { width: 34px; height: 34px; border-radius: 9px; }
.tile.group.size-2x2 .mini .initials { font-size: .8125rem; }
.group-count { font-size: .8125rem; color: var(--muted); }

/* Dragging */
.grid.dragging .tile { transition: none; }
.grid.dragging .tile:hover { transform: none; }
.sortable-ghost { opacity: .35; border-style: dashed; box-shadow: none; }
.sortable-fallback, .sortable-drag { box-shadow: var(--shadow-3) !important; opacity: .96 !important; transition: none !important; cursor: grabbing; }
.tile.group-target {
  border-color: var(--mint); background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--mint), var(--shadow-2);
  transform: scale(1.04);
}
.tile.group-target::after {
  content: attr(data-drop-label);
  position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%);
  padding: 2px 10px; border-radius: 999px; white-space: nowrap;
  background: var(--primary); color: var(--on-primary); font-size: .75rem; font-weight: 650;
  pointer-events: none;
}
.tile.highlight { animation: highlight 1.6s ease-out 1; }
@keyframes highlight {
  0%, 30% { box-shadow: 0 0 0 4px var(--mint), var(--shadow-2); }
  100% { box-shadow: var(--shadow-1); }
}

/* Search results */
.results-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 14px; color: var(--muted); font-size: .9375rem; }
.tile.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary), var(--shadow-2); }
.tile-group-name {
  position: absolute; left: 10px; top: 8px; max-width: calc(100% - 20px);
  font-size: .6875rem; font-weight: 600; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Empty states */
.empty { max-width: 520px; margin: 40px auto; text-align: center; }
.empty .empty-art { width: 84px; height: 84px; margin: 0 auto 20px; }
.empty h2 { font-size: 1.375rem; margin-bottom: 8px; }
.empty p { color: var(--muted); }
.empty .actions { justify-content: center; margin-top: 20px; }

/* Dialogs */
dialog.panel {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius-panel);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3);
  overflow: auto;
}
dialog.panel.wide { width: min(820px, calc(100vw - 32px)); }
dialog.panel::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
dialog.panel[open] { animation: panel-in .18s ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px 0; }
.panel-head h2 { min-width: 0; overflow-wrap: anywhere; }
.panel-body { padding: 18px 24px 8px; }
.panel-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 12px 24px 22px; }
.panel-foot .spacer { flex: 1; }
@media (max-width: 600px) {
  dialog.panel, dialog.panel.wide {
    width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0;
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
  }
  dialog.panel[open] { animation: sheet-in .2s ease-out; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}

/* Link form preview */
.preview {
  display: flex; align-items: center; gap: 14px; padding: 14px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface-2); margin-bottom: 16px;
}
.preview .tile-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--surface); }
.preview-text { min-width: 0; display: grid; gap: 2px; }
.preview-title { font-weight: 650; overflow-wrap: anywhere; }
.preview-url { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.icon-choices { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin-top: 10px; max-height: 236px; overflow: auto; padding: 2px; }
.icon-pick {
  aspect-ratio: 1; display: grid; place-items: center; padding: 8px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface-2); cursor: pointer;
}
.icon-pick img { width: 100%; height: 100%; object-fit: contain; }
.icon-pick:hover { border-color: var(--primary); }
.icon-pick[aria-pressed="true"] { border-color: var(--primary); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.icon-pick:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.status-line { display: flex; align-items: center; gap: 10px; min-height: 24px; color: var(--muted); font-size: .9375rem; margin-bottom: 12px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--primary); animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.duplicate { border: 1px solid var(--line-strong); background: var(--surface-2); border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; font-size: .9375rem; }
.duplicate strong { font-weight: 650; }
.duplicate .actions { margin-top: 10px; }

/* Group panel grid (smaller tiles) */
.group-grid { --tile: 104px; }
.group-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }

/* Menus */
.menu {
  position: fixed; z-index: 50; min-width: 220px; margin: 0; padding: 6px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3);
  inset: auto;
}
.menu[popover]:not(:popover-open) { display: none; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 38px; padding: 0 10px; border: 0; border-radius: 9px;
  background: none; color: inherit; font-size: .9375rem; text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); color: inherit; outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.menu-item.danger { color: var(--danger); }
.menu-item[aria-checked="true"]::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-left: auto; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; border: 0; }
.menu-label { padding: 6px 10px 2px; font-size: .8125rem; color: var(--muted); font-weight: 600; }
.menu-sizes { display: flex; gap: 6px; padding: 4px 6px 6px; }
.size-btn {
  flex: 1; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); cursor: pointer; color: var(--ink);
}
.size-btn[aria-checked="true"] { border-color: var(--primary); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.size-btn svg { width: 22px; height: 22px; }
.size-btn rect { fill: currentColor; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: grid; gap: 10px; width: min(560px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 14px; padding: 12px 12px 12px 18px;
  border-radius: 14px; background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: var(--shadow-3); pointer-events: auto; font-size: .9375rem;
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
.toast-msg { flex: 1; }
.toast button { flex: none; border: 0; background: transparent; color: var(--toast-action); font-weight: 700; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.toast.error button { color: #fff; }
.toast button:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Auth and content pages */
.auth { min-height: 100vh; display: grid; place-items: start center; padding: 56px 16px 40px; }
.auth-card { width: min(440px, 100%); }
.auth-card .brand { display: inline-flex; margin: 0 auto 28px; }
.auth-card .logo { height: 40px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head h1 { margin-bottom: 6px; }
.auth-head p { color: var(--muted); margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-panel); padding: 28px; box-shadow: var(--shadow-1); }
.auth-foot { text-align: center; margin-top: 20px; color: var(--muted); font-size: .9375rem; }
.auth-foot p { margin: 0 0 6px; }

.page { max-width: 760px; margin: 0 auto; padding: 0 24px 72px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 0 8px; }
.page-title { margin: 28px 0 8px; font-size: 2rem; }
.lead { color: var(--muted); font-size: 1.0625rem; max-width: 62ch; }
.section { margin-top: 36px; }
.section > h2 { margin-bottom: 6px; }
.section > .hint { margin-bottom: 14px; }
.section .card { padding: 22px; }
.stack > * + * { margin-top: 14px; }
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; padding-top: 0; }
.list-row:last-child { padding-bottom: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; overflow-wrap: anywhere; }
.list-meta { color: var(--muted); font-size: .875rem; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-size: .75rem; font-weight: 650; vertical-align: 2px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 24px; padding: 18px 22px; margin: 0 0 16px; list-style: none; border-radius: 14px; background: var(--surface-2); font: 600 1.0625rem/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .04em; }
.prose h2 { margin: 32px 0 8px; }
.prose h3 { margin: 22px 0 6px; }
.prose p, .prose li { max-width: 68ch; }
.prose ol, .prose ul { padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.prose code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

/* Landing */
.landing { max-width: var(--page); margin: 0 auto; padding: 0 24px 56px; }
.landing-hero { display: grid; grid-template-columns: 1.05fr 1fr; gap: 56px; align-items: center; padding: 64px 0 40px; }
.landing-hero h1 { font-size: clamp(2.25rem, 5vw, 3.5rem); line-height: 1.05; letter-spacing: -0.025em; font-weight: 720; margin-bottom: 18px; color: var(--petrol); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .landing-hero h1 { color: var(--ink); } }
:root[data-theme="dark"] .landing-hero h1 { color: var(--ink); }
.landing-hero .lead { margin-bottom: 26px; }
.landing-art { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.landing-art span { aspect-ratio: 1; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.landing-art span.wide { grid-column: span 2; aspect-ratio: auto; }
.landing-art span.big { grid-column: span 2; grid-row: span 2; aspect-ratio: auto; background: var(--petrol); border-color: var(--petrol); }
.landing-art span.mint { background: var(--mint); border-color: var(--mint); transform: translateY(-8px); }
.landing-points { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; padding: 24px 0; border-top: 1px solid var(--line); }
.landing-points h2 { font-size: 1.0625rem; margin-bottom: 6px; }
.landing-points p { color: var(--muted); font-size: .9375rem; margin: 0; }
.site-foot { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; padding: 28px 16px 36px; color: var(--muted); font-size: .875rem; }
.site-foot a { color: var(--muted); }

/* Cleanup table */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 18px 0; }
.toolbar .field { margin: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: .9375rem; }
table.data th, table.data td { padding: 10px 14px; text-align: left; border-top: 1px solid var(--line); vertical-align: middle; }
table.data thead th { border-top: 0; font-size: .8125rem; color: var(--muted); font-weight: 650; background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.is-selected td { background: var(--accent-soft); }
.cell-link { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.cell-link .tile-icon { width: 24px; height: 24px; border-radius: 6px; }
.cell-link .initials { font-size: .625rem; }
.cell-title { font-weight: 600; overflow-wrap: anywhere; }
.cell-sub { color: var(--muted); font-size: .8125rem; overflow-wrap: anywhere; }
.sticky-bar { position: sticky; bottom: 16px; display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-top: 16px; padding: 12px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); }

/* Import preview */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0; }
.stat { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.stat b { display: block; font-size: 1.375rem; font-weight: 700; }
.stat span { color: var(--muted); font-size: .875rem; }
details.invalid summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
details.invalid ul { max-height: 220px; overflow: auto; padding-left: 18px; font-size: .875rem; color: var(--muted); }

/* Responsive */
@media (max-width: 760px) {
  :root { --tile: 96px; --gap: 10px; }
  .app, .page, .landing { padding-left: 16px; padding-right: 16px; }
  .app-header { padding-top: 14px; }
  .logo { height: 26px; }
  .search-wrap { margin: 16px auto 22px; }
  .search { height: 54px; font-size: 1.0625rem; padding-left: 50px; border-radius: 16px; }
  .search-icon { left: 17px; }
  .search-aside kbd { display: none; }
  .btn-add-label { display: none; }
  .tile-link { padding: 10px 8px; gap: 8px; }
  .tile-icon { width: 34px; height: 34px; }
  .tile-title { font-size: .8125rem; }
  .tile:is(.size-2x1, .size-3x1) .tile-link { padding: 0 38px 0 12px; gap: 10px; }
  .tile.size-2x2 .tile-icon { width: 60px; height: 60px; }
  .landing-hero { grid-template-columns: 1fr; gap: 32px; padding-top: 36px; }
  .landing-points { grid-template-columns: 1fr; }
  .codes { grid-template-columns: 1fr; }
  .card { padding: 22px 18px; }
  .page-title { font-size: 1.625rem; }
}
/* Phones: exactly three square columns, so rows match the column width. */
@media (max-width: 520px) {
  .grid { --tile: calc((100vw - 32px - 2 * var(--gap)) / 3); }
  /* The group panel is a full-width sheet here; three columns keep a 3 × 1 tile from overflowing. */
  .group-grid { --tile: calc((100vw - 48px - 2 * var(--gap)) / 3); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .tile:hover, .tile.group-target { transform: none !important; }
}

@media (forced-colors: active) {
  .tile, .btn, .input, .search { border: 1px solid CanvasText; }
  .tile.group-target { outline: 3px solid Highlight; }
}

.fieldset-plain { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.fieldset-plain legend { padding: 0; margin-bottom: 6px; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.empty-foot { margin-top: 18px; }
.btn-block + .hint { margin-top: 10px; }
.section-gap { margin-top: 14px; }
.card-title { font-size: 1.0625rem; margin-bottom: 14px; }
.actions .input { flex: 1 1 220px; width: auto; }
.page.page-wide { max-width: 980px; }

/* Touch: our own pressed and focus styles replace the default blue tap flash. */
a, button, .tile-link { -webkit-tap-highlight-color: transparent; }
