/* ============================================================
   KALISTAMP HUT — the home-screen grid

   The category standard, played straight: a wall of saturated icon tiles
   with a name under each, Launchpad's grid and Raycast's palette. The wall
   is for launching and nothing else; managing it is a mode you enter (Edit),
   which keeps the layout: on the grid each tile gets a delete badge and is
   dragged by itself, the home-screen idiom; in List view the row ends hold
   delete and a drag handle. Choosing a tool edits it.

   MOTION BUDGET
     Launching is the 100+/day action, so it is not animated: a tile dims
     under the finger (press feedback) and the page navigates. The one
     authored moment is entering Edit, where the badges pop onto the tiles
     and shrink away again on Done, so the mode change is legible. Dialogs get a short
     150-240ms entrance; the palette opens instantly because it is keyboard-
     driven and repeated many times a day. Reduced motion keeps opacity and
     colour (the meaning) and drops the movement.

   COLOUR
     Apple-standard neutrals with one blue for actions and selection, and six
     saturated accents that only ever colour an icon tile. Every value is hex
     and every pair is checked: text >= 4.5:1 on the surface it sits on,
     control boundaries, focus ring and tile glyphs >= 3:1, in both themes.
     No oklch, color-mix, backdrop-filter or container queries -- these pages
     get opened on older phones, where a half-supported colour function
     degrades to something unreadable rather than something plain.

   THEME
     Two states, light and dark, chosen explicitly and never inferred from
     the OS. <html> always carries data-theme, so the theme is a fact in the
     markup and the page renders correctly with JavaScript blocked.
   ============================================================ */

/* ── tokens ─────────────────────────────────────────────── */

:root {
  --bg:            #f5f5f7;   /* the page */
  --surface:       #ffffff;   /* sheets, menus, lists, palette */
  --surface-2:     #ebebf0;   /* hover, pressed, raised wells */
  --field:         #f0f0f4;   /* inputs and segmented tracks */

  --fg:            #1d1d1f;
  --fg-muted:      #56565f;   /* >= 4.5:1 on every surface above */
  --fg-subtle:     #66666f;   /* >= 4.5:1 on every surface above */

  --border:        #dcdce2;   /* decorative separation */
  --border-strong: #8a8a94;   /* control boundaries, >= 3:1 */
  --separator:     #e3e3e8;

  --primary:       #0061d1;   /* fills: Save, Sign in, selection */
  --on-primary:    #ffffff;
  --link:          #0061d1;   /* blue text: Edit, Cancel, Add */
  --primary-soft:  #e3eefc;
  --ring:          #0061d1;
  --selection:     #cfe1fb;

  --sel-sub:       #dce9fb;   /* secondary text on a selected palette row */
  --toast-action:  #5aa1ff;   /* action text on the inverted (ink) toast: the dark theme's link blue */

  --danger:        #c42b1c;
  --danger-soft:   #fde8e6;
  --badge-red:     #d1352a;   /* delete badge disc: white minus 4.9:1, both themes */
  --ok:            #1a7f37;

  --avatar:        #6b6b76;
  --mark-bg:       #1d1d1f;   /* the Hut mark: ink, never the action blue */
  --mark-fg:       #ffffff;
  --switch-off:    #8a8a94;
  --seg-on:        #ffffff;   /* the selected segment: raised, lighter than the track */
  --scrim:         rgba(18, 18, 22, .42);
  --shadow-pop:    0 10px 24px -6px rgba(0, 0, 0, .22), 0 2px 6px rgba(0, 0, 0, .08);
  --shadow-tile:   0 1px 2px rgba(0, 0, 0, .14);

  /* radius scale; icon tiles use the 22.5% superellipse ratio instead */
  --r-xs: 6px;  --r-sm: 8px;  --r-md: 10px;  --r-lg: 12px;  --r-xl: 14px;
  --r-pill: 999px;

  /* spacing */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px; --s8: 48px;

  --tap: 44px;
  --gutter: 16px;
  --tile-size: 60px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text",
          "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Easing: ease-out for entrances and feedback. Never ease-in on UI. */
  --ease-out:   cubic-bezier(.23, 1, .32, 1);
  --ease-hover: cubic-bezier(.25, .46, .45, .94);
  --t-hover: 120ms;
  --t-press: 90ms;
  --t-enter: 200ms;

  color-scheme: light;
}

/* Dark. Selected by data-theme on <html>; never by prefers-color-scheme. */
:root[data-theme="dark"] {
  --bg:            #121214;
  --surface:       #1c1c1f;
  --surface-2:     #2a2a2f;
  --field:         #26262b;

  --fg:            #f5f5f7;
  --fg-muted:      #aeaeb8;
  --fg-subtle:     #9a9aa5;

  --border:        #323238;
  --border-strong: #71717c;
  --separator:     #2c2c31;

  --primary:       #1a66d6;
  --on-primary:    #ffffff;
  --link:          #5aa1ff;
  --primary-soft:  #15284a;
  --ring:          #5aa1ff;
  --selection:     #1d3f73;

  --sel-sub:       #eef4ff;
  --toast-action:  #0061d1;   /* action text on the inverted (light) toast: the light theme's link blue */

  --danger:        #ff6b5e;
  --danger-soft:   #3a1916;
  --badge-red:     #d1352a;
  --ok:            #4cc27a;

  --avatar:        #6b6b76;
  --mark-bg:       #4a4a52;
  --mark-fg:       #ffffff;
  --switch-off:    #71717c;
  --seg-on:        #3a3a40;
  --scrim:         rgba(0, 0, 0, .56);
  --shadow-pop:    0 12px 24px -6px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .4);
  --shadow-tile:   0 1px 2px rgba(0, 0, 0, .5);

  color-scheme: dark;
}

/* Accents. Each card sets one class; nothing ever writes a colour into a
   style attribute, so the accent column stays a CHECK-constrained enum and an
   unknown value falls back to ember. Saturated like app icons, the same in
   both themes, glyph >= 3:1 on its tile. */
.accent-ember  { --accent-bg: #e2560f; --accent-fg: #ffffff; }
.accent-citrus { --accent-bg: #f3b80c; --accent-fg: #3a2a00; }
.accent-mint   { --accent-bg: #178f52; --accent-fg: #ffffff; }
.accent-lagoon { --accent-bg: #2a6de0; --accent-fg: #ffffff; }
.accent-orchid { --accent-bg: #8a4bd6; --accent-fg: #ffffff; }
.accent-slate  { --accent-bg: #5b6676; --accent-fg: #ffffff; }

/* ── base ───────────────────────────────────────────────── */

* { box-sizing: border-box; }

/* .btn and friends set display, which would otherwise beat the attribute. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  scrollbar-color: var(--border-strong) transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 400 0.9375rem/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  caret-color: var(--primary);
}

::selection { background: var(--selection); color: var(--fg); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: var(--r-pill);
  background-clip: padding-box;
}
::-webkit-scrollbar-track { background: transparent; }

a { color: var(--link); text-underline-offset: .2em; }

/* No one-word last lines in running text. */
p { text-wrap: pretty; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

svg { flex: none; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* One ring token for everything, never a card's accent; the element keeps
   its own corner radius. */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--fg-muted);
  font: 600 0.6875rem/1 var(--font);
  white-space: nowrap;
}

/* ── buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--fg);
  font-size: 0.9375rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-hover) var(--ease-hover),
              border-color var(--t-hover) var(--ease-hover);
}
.btn svg { width: 18px; height: 18px; }
.btn:active { background: var(--surface-2); }

.btn-primary {
  border-color: transparent;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}
.btn-primary:active { background: var(--primary); filter: brightness(.9); }

.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger-solid {
  border-color: transparent;
  background: var(--danger);
  color: #ffffff;
  font-weight: 600;
}
:root[data-theme="dark"] .btn-danger-solid { background: #c42b1c; }

.btn-block { width: 100%; }
.btn-lg { min-height: 48px; border-radius: var(--r-lg); font-size: 1rem; }

/* Text buttons: the iOS navigation-bar idiom (Cancel, Save, Edit, Done). */
.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--link);
  font-size: 1rem;
  font-weight: 500;
  white-space: nowrap;
}
.btn-text-strong { font-weight: 600; }
.btn-text:active { opacity: .6; }

@media (hover: hover) and (pointer: fine) {
  .btn { min-height: 36px; padding: 0 var(--s3); font-size: 0.875rem; }
  .btn-lg { min-height: 44px; font-size: 0.9375rem; }
  .btn:hover { background: var(--surface-2); }
  .btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
  .btn-danger-solid:hover { background: var(--danger); filter: brightness(1.06); }
  :root[data-theme="dark"] .btn-danger-solid:hover { background: #c42b1c; }
  .btn-text { min-height: 36px; font-size: 0.9375rem; }
  .btn-text:hover { background: var(--primary-soft); }
}

/* ── app icon (brand mark) ──────────────────────────────── */

.app-icon {
  display: grid;
  place-items: center;
  flex: none;
  background: var(--mark-bg);
  color: var(--mark-fg);
  box-shadow: var(--shadow-tile);
}
.app-icon svg { width: 58%; height: 58%; }

/* ── top bar ────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 56px;
  padding: max(6px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 6px max(var(--gutter), env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin: 0;
  font-size: 1.1875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-mark { width: 30px; height: 30px; border-radius: var(--r-sm); }
.brand-text { overflow: hidden; text-overflow: ellipsis; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s1);
  margin-left: auto;
}

/* Add: a blue plus in the bar on a phone, a quiet labelled button on a desk.
   It is a monthly action and must never outshout the tools. */
.btn-add {
  min-width: var(--tap);
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--link);
}
.btn-add svg { width: 24px; height: 24px; }
.btn-add .add-label { display: none; }

/* ── search trigger ─────────────────────────────────────── */

/* Phone: the home-screen Search pill, fixed above the bottom edge where the
   thumb rests. */
.search-trigger {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 15;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-width: 148px;
  height: 48px;
  padding: 0 var(--s6);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--fg);
  font-size: 1rem;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
}
.search-trigger svg { width: 18px; height: 18px; color: var(--fg-muted); }
.search-trigger kbd { display: none; }
.search-trigger:active { background: var(--surface-2); }

/* ── account menu ───────────────────────────────────────── */

.account { position: relative; }

.avatar {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
}
.avatar-face {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--avatar);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 600;
}
.avatar[aria-expanded="true"] .avatar-face { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--border-strong); }

.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  width: min(300px, calc(100vw - 2 * var(--gutter)));
  padding: var(--s1) 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
}

.menu-who {
  margin: 0;
  padding: var(--s3) var(--s4) var(--s3);
  font-size: 0.8125rem;
  color: var(--fg-muted);
}
.menu-who b {
  display: block;
  overflow: hidden;
  color: var(--fg);
  font-size: 0.9375rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-section {
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--separator);
}
.menu-label {
  display: block;
  margin-bottom: var(--s2);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--fg-muted);
}
.menu-hint { margin: var(--s2) 0 0; font-size: 0.8125rem; color: var(--fg-subtle); }

.menu-actions { padding: var(--s1) 0; }
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 0.9375rem;
  text-align: left;
}
.menu-item svg { width: 18px; height: 18px; color: var(--fg-muted); }
.menu-item:active { background: var(--surface-2); }
.menu-item:focus-visible { outline-offset: -2px; }
.menu-value { margin-left: auto; color: var(--fg-muted); }
.switch-visual {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  margin-left: auto;
  border-radius: var(--r-pill);
  background: var(--switch-off);
  transition: background var(--t-hover) var(--ease-out);
}
.switch-visual::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform 160ms var(--ease-out);
}
[aria-checked="true"] > .switch-visual { background: var(--primary); }
[aria-checked="true"] > .switch-visual::before { transform: translateX(16px); }
.menu-item-danger, .menu-item-danger svg { color: var(--danger); }

@media (hover: hover) and (pointer: fine) {
  .menu-item:hover { background: var(--surface-2); }
}

/* Segmented control: layout, order, and the editor's icon tabs. The pressed
   segment is a raised chip with a control-strength edge, so the state is
   never carried by a fill difference alone. */
.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--r-md);
  background: var(--field);
}
.segmented button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--t-hover) var(--ease-hover), color var(--t-hover) var(--ease-hover);
}
.segmented svg { width: 16px; height: 16px; }
.segmented button[aria-pressed="true"],
.segmented button[aria-selected="true"] {
  background: var(--seg-on);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border-strong), 0 1px 2px rgba(0, 0, 0, .1);
}
@media (hover: hover) and (pointer: fine) {
  .segmented button { min-height: 32px; }
  .segmented button:hover { color: var(--fg); }
}
@media (pointer: coarse) {
  .segmented button { min-height: var(--tap); }
}

/* ── layout ─────────────────────────────────────────────── */

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--s4) max(var(--gutter), env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--s2);
  min-height: var(--tap);
  margin-bottom: var(--s3);
}
.spacer { flex: 1; }

/* A quiet caption, not a headline: the tiles are the page. */
.wall-title {
  white-space: nowrap;
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* The order chip: only in Most used, so the reshuffling wall says why. */
.order-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 var(--s2);
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--link);
  font-size: 0.875rem;
  font-weight: 500;
}
/* The visible pill sits inside the 44px target. */
.order-chip { background-clip: content-box; flex: none; white-space: nowrap; }
.order-chip > span { margin-right: 2px; }
.order-chip svg { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .order-chip { min-height: 32px; }
  .order-chip:hover { background: var(--primary-soft); }
}

/* A text button inside a sentence. */
.btn-inline {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: .2em;
}

.btn-edit { margin-right: calc(-1 * var(--s2)); font-weight: 500; }
.toolbar-status { display: flex; flex: none; align-items: center; gap: var(--s1); }
.bar-view { flex: none; }
/* Held in place (not removed) during Edit, so entering Edit moves no tile. */
#app.is-editing .bar-view { visibility: hidden; }
#app.is-empty .bar-view { display: none; }
/* Narrow screens: the menu carries Layout, and status that carries words
   (a failure, Most used) gets its own row under the count. The toolbar
   never overflows, whatever combination of states is showing. */
@media (max-width: 599px) {
  .bar-view { display: none; }
  #app.status-row .toolbar-status { order: 10; flex-basis: 100%; }
  /* On its own row the chip's words line up with the count above; the
     target stays 44px tall and as wide as its words. */
  #app.status-row .order-chip { padding: 0; }
}
.bar-view button { flex: none; width: 40px; padding: 0; }
@media (pointer: coarse) { .bar-view button { width: var(--tap); } }

.is-editing .btn-edit { font-weight: 600; }

/* The sync state says nothing while all is well: "Synced" is visually
   hidden. Saving, offline and errors show; a failure also gets a toast,
   which is the announcement, and tapping the failed pill retries. The pill is not a live
   region, so routine saves do not chatter. */
/* The pill is a button (a target sized for the pointer) with a small face
   drawn inside it, so a 44px touch target never becomes a 44px oval. */
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-subtle);
  font: inherit;
  cursor: pointer;
}
.pill-face {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.pill-face::before {
  content: "";
  flex: none;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
/* Routine states are quiet grey; only success (briefly) and failure carry colour. */
.pill-load,
.pill-sync   { color: var(--fg-subtle); }
.pill-saved  { color: var(--ok); }
.pill-error  { color: var(--danger); }
.pill-error .pill-face { height: 28px; border-color: var(--danger); font-weight: 600; }
.pill:disabled { cursor: default; opacity: 1; }
@media (pointer: coarse) { .pill-error { min-height: var(--tap); } }
/* All is well: the pill steps aside entirely (it is a button only while it
   has a failure to explain). */
.pill-synced { display: none; }
/* On a phone, routine work is a dot, so it never crowds the Edit caption;
   the words stay for assistive tech. */
@media (max-width: 479px) {
  .pill-sync .pill-face,
  .pill-load .pill-face { gap: 0; padding: 0 8px; font-size: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .pill-sync .pill-face::before { animation: pulse 1.1s var(--ease-hover) infinite; }
}
@keyframes pulse { 50% { opacity: .3; } }

.edit-caption { display: none; font-size: 0.875rem; font-weight: 600; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#app.is-editing .wall-title { display: none; }
#app.is-editing .edit-caption { display: block; }
.cap-list, .cap-frecency { display: none; }
#app.view-list .cap-grid { display: none; }
#app.view-list .cap-list { display: inline; }
#app.order-frecency .cap-grid,
#app.order-frecency .cap-list { display: none; }
#app.order-frecency .cap-frecency { display: inline; }
/* A failure needs the row more than the caption does. */
#app.has-sync-error .edit-caption { display: none; }
.wall-foot {
  margin: var(--s6) 0 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--fg-subtle);
}
#app.is-editing .wall-foot,
#app.is-empty .wall-foot { display: none; }

.edit-hint {
  margin: var(--s5) 0 0;
  font-size: 0.875rem;
  color: var(--fg-muted);
}
.edit-hint svg { width: 14px; height: 14px; vertical-align: -2px; }
.hint-frecency, .hint-keys { display: none; }
@media (hover: hover) and (pointer: fine) { #app:not(.order-frecency) .hint-keys { display: inline; } }
@media (hover: none) and (pointer: coarse) { .hint-keys { display: none; } }
.hint-touch { display: none; }
@media (pointer: coarse) { .hint-touch { display: inline; } .hint-fine { display: none; } }
#app.order-frecency .hint-manual,
#app.order-frecency .hint-keys { display: none; }
#app.order-frecency .hint-frecency { display: inline; }

/* ── the wall: icon grid ────────────────────────────────── */

/* Rows are a fixed height (tile + one label line + padding), so the wall
   keeps an even rhythm at a home-screen pitch; the rare second line of a
   long name runs into the row gap, which is sized to hold it. */
.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: calc(var(--tile-size) + 40px);
  gap: var(--s3) var(--s2);
}

/* The slot is the grid item and the drag unit, so the edit controls can be
   siblings of the anchor rather than children of it -- a button inside an
   <a> is invalid, and its click would bubble up and navigate away. */
.card-slot { position: relative; min-width: 0; }

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 2px 0;
  border-radius: var(--r-lg);
  color: var(--fg);
  text-decoration: none;
  -webkit-touch-callout: default;
}
.card[aria-disabled="true"] { opacity: .55; }
/* A long-press belongs to Hut (it enters Edit), not to the browser's link
   preview or a text selection. */
.card { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
/* Scroll and pinch-zoom still work from a tile; declaring them up front lets
   a long-press go straight on into a drag (the browser decides a gesture's
   touch-action when the finger lands, before Edit exists). */
.grid:not(.view-list) .card { touch-action: pan-y pinch-zoom; }

.card-icon {
  --tile: var(--tile-size);
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tile);
  height: var(--tile);
  border-radius: calc(var(--tile) * .225);
  background: var(--accent-bg, var(--surface-2));
  color: var(--accent-fg, var(--fg));
  font-size: calc(var(--tile) * .5);
  line-height: 1;
  overflow: hidden; /* a stored word instead of an emoji stays inside the tile */
  box-shadow: var(--shadow-tile);
  transition: transform var(--t-press) var(--ease-out), filter var(--t-press) var(--ease-out);
}
.card-icon svg { display: block; width: 50%; height: 50%; }

/* Press feedback, not a launch animation: the tile dims under the finger and
   the page is already navigating. */
.card:active .card-icon { transform: scale(.94); filter: brightness(.88); }

.card-body { display: block; width: 100%; min-width: 0; text-align: center; }

/* Up to two lines before an ellipsis, so "Photo inbox" reads whole on a
   360px phone. A single word wider than the column hyphenates (or, without
   a hyphenation dictionary, breaks) onto the second line rather than being
   clipped. Rows are a fixed height (see .grid), so the rhythm stays even. */
.card-name {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
  -webkit-hyphens: auto;
  hyphens: auto;
  overflow-wrap: break-word;
  min-height: 1.3em;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* The grid is icon + name only. Description and host live in List view and
   in search, where there is room to read them. */
.card-desc, .card-host { display: none; }

/* On the grid, keyboard focus rings the icon (a page-colour gap, then the
   ring) and bolds the name, as Launchpad does; the box around icon + label
   is never drawn. List rows keep their full-row ring. */
.grid:not(.view-list) .card:focus-visible { outline: none; }
.grid:not(.view-list) .card:focus-visible .card-icon { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring); }
.grid:not(.view-list) .card:focus-visible .card-name { font-weight: 600; }

@media (hover: hover) and (pointer: fine) {
  .grid:not(.view-list) .card:hover .card-icon { filter: brightness(1.07); }
  .grid:not(.view-list) .card:hover .card-name { color: var(--fg); text-decoration: underline; text-underline-offset: .2em; text-decoration-thickness: 1px; }
}

/* ── list view ──────────────────────────────────────────── */

/* Raycast / iOS grouped list: one surface, inset hairlines, icon, name,
   description, host. */
.grid.view-list {
  display: block;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.view-list .card-slot + .card-slot::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 64px;
  height: 1px;
  background: var(--separator);
}

.view-list .card {
  flex-direction: row;
  gap: var(--s3);
  min-height: 60px;
  padding: var(--s2) var(--s4);
  border-radius: 0;
}
.view-list .card:focus-visible { outline-offset: -3px; border-radius: var(--r-md); }

.view-list .card-icon { --tile: 36px; }
.view-list .card-body { flex: 1; text-align: left; }
.view-list .card-name { display: block; min-height: 0; font-size: 0.9375rem; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }

.view-list .card-desc {
  display: block;
  overflow: hidden;
  font-size: 0.8125rem;
  color: var(--fg-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.view-list .card-host {
  display: block;
  flex: none;
  max-width: 38%;
  overflow: hidden;
  font-size: 0.8125rem;
  color: var(--fg-subtle);
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) {
  .view-list .card:hover { background: var(--surface-2); }
}

/* ── edit mode ──────────────────────────────────────────── */

/* Edit keeps the layout the owner was looking at. On the icon grid each tile
   wears one badge, delete, on its top-left corner, and the tile itself is
   what you drag (the home-screen idiom); choosing it edits it. In List view
   delete and a drag handle sit at the two ends of the row. Badges are 44px
   targets drawn smaller. */

/* Hidden at rest. Scoped to the slot so the later .icon-btn display rule
   can never bring the badges back outside Edit. */
.card-slot > .card-delete,
.card-slot > .drag-handle { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--fg-muted);
}

.is-editing .card-slot > .card-delete,
.is-editing .card-slot > .drag-handle { display: grid; }

.card-delete { color: var(--badge-red); }
.card-delete svg { width: 26px; height: 26px; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg); }

/* touch-action: none is what makes the pointer-drag work on a phone: without
   it the browser claims the gesture for scrolling and the drag never starts.
   Only the List view's handle claims it there, so the list still scrolls. */
.drag-handle { cursor: grab; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg {
  width: 28px;
  height: 28px;
  padding: 5px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--fg-muted);
  box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-tile);
}

/* Grid: one badge, delete, on the tile's corner. The tile itself is what
   you drag (script.js arms a drag after an 8px move; a still press is a tap
   that opens the editor), so it claims the gesture from scrolling. */
.grid.is-editing:not(.view-list) .card-delete {
  position: absolute;
  z-index: 2;
  top: calc(6px - 18px);
  left: calc(50% - var(--tile-size) / 2 - 18px);
}
.grid.is-editing:not(.view-list) .card-slot > .drag-handle { display: none; }
.grid.is-editing:not(.view-list):not(.order-frecency) .card { touch-action: pan-y; cursor: grab; }
.grid.is-editing:not(.view-list) .card-delete:focus-visible { outline-offset: -4px; border-radius: 50%; }

/* List: controls at the ends of the row. */
.view-list.is-editing .card-slot {
  display: grid;
  grid-template-columns: var(--tap) minmax(0, 1fr) var(--tap);
  align-items: center;
  padding: 0 var(--s1);
}
.view-list.is-editing .card { padding-left: var(--s1); padding-right: var(--s1); }
.view-list.is-editing .card-host { display: none; }
.view-list .card-delete svg { box-shadow: none; }
.view-list.is-editing .card-slot + .card-slot::before { left: 100px; }
.view-list.is-editing .card-delete:focus-visible,
.view-list.is-editing .drag-handle:focus-visible { outline-offset: -4px; }

.card-slot.dragging { z-index: 3; }
.card-slot.dragging .card-icon { box-shadow: 0 0 0 3px var(--ring), var(--shadow-pop); transform: scale(1.06); }
.view-list .card-slot.dragging { background: var(--surface-2); }

/* Reorder is manual-order only; in Most used the wall sorts itself and a
   drag handle would promise something it cannot keep. */
.order-frecency .card-slot > .drag-handle,
.is-editing.order-frecency .card-slot > .drag-handle { display: none; }
.view-list.is-editing.order-frecency .card-slot { grid-template-columns: var(--tap) minmax(0, 1fr); }

/* The one authored motion moment: entering Edit pops the badges onto the
   tiles from the corner they sit on; Done shrinks them away. The classes
   last one beat (script.js), so a re-render while editing never replays it. */
@media (prefers-reduced-motion: no-preference) {
  .edit-enter .card-delete svg { animation: badge-in 240ms var(--ease-out) both; transform-origin: center; }
  .edit-enter .drag-handle svg { animation: badge-in 240ms var(--ease-out) 40ms both; transform-origin: center; }
  .edit-enter:not(.view-list) .card-icon { animation: tile-settle 300ms var(--ease-out) both; }
  .edit-leave .card-delete svg,
  .edit-leave .drag-handle svg { animation: badge-out 160ms var(--ease-hover) both; }
  .edit-enter.view-list .card-slot { animation: row-settle 240ms var(--ease-out) both; }
}
@media (prefers-reduced-motion: reduce) {
  .edit-enter .card-delete svg,
  .edit-enter .drag-handle svg { animation: fade-in 180ms linear both; }
  .edit-leave .card-delete svg,
  .edit-leave .drag-handle svg { animation: fade-out 140ms linear both; }
}
@keyframes badge-in  { from { opacity: 0; transform: scale(.4); } }
@keyframes tile-settle { 40% { transform: scale(.94); } }
@keyframes badge-out { to   { opacity: 0; transform: scale(.4); } }
@keyframes row-settle { from { transform: translateX(-12px); } }
@keyframes fade-in   { from { opacity: 0; } }
@keyframes fade-out  { to   { opacity: 0; } }

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover svg { filter: brightness(1.08); }
  .drag-handle:hover svg { color: var(--fg); }
}

/* ── empty state ────────────────────────────────────────── */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 34rem;
  margin: var(--s7) auto 0;
  text-align: center;
}
.empty h2 { margin: 0 0 var(--s2); font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }
.empty p { margin: 0 0 var(--s5); color: var(--fg-muted); }

.ghost-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r-lg);
  background: transparent;
  color: var(--link);
  font-size: 0.875rem;
  font-weight: 500;
}
.ghost-icon {
  display: grid;
  place-items: center;
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px dashed var(--border-strong);
  border-radius: calc(var(--tile-size) * .225);
}
.ghost-icon svg { width: 26px; height: 26px; }
@media (hover: hover) and (pointer: fine) {
  .ghost-tile:hover .ghost-icon { border-color: var(--link); background: var(--primary-soft); }
}

/* ── dialogs: shared ────────────────────────────────────── */

dialog {
  padding: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: var(--scrim); }

/* ── tool editor sheet ──────────────────────────────────── */

.sheet {
  width: min(520px, calc(100vw - 2 * var(--gutter)));
  max-width: none;
  max-height: min(86vh, 760px);
  border-radius: var(--r-xl);
  overflow: hidden;
}
.sheet form {
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 760px);
}

.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 56px;
  padding: 0 var(--s2);
  border-bottom: 1px solid var(--separator);
}
.sheet-head h2 { margin: 0; font-size: 1.1875rem; font-weight: 600; text-align: center; }
#toolCancel { justify-self: start; }
#toolSave { justify-self: end; }

.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s4) var(--s4) max(var(--s6), env(safe-area-inset-bottom));
}

/* Live preview of the tile being built: the choices below change it. */
.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  margin: var(--s1) 0 var(--s5);
}
.preview .card-icon { --tile: 64px; }
.preview-name {
  max-width: 100%;
  overflow: hidden;
  font-size: 0.875rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  display: block;
  min-width: 0;
  margin: 0 0 var(--s4);
  padding: 0;
  border: 0;
}
.field > span,
.field > legend {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--fg-muted);
}
.field em { font-style: normal; font-weight: 400; color: var(--fg-subtle); }

.field input[type="text"],
.field input[type="url"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--field);
  font-size: 1rem; /* 16px stops iOS Safari zooming the page on focus */
}
.field input::placeholder,
#paletteInput::placeholder,
#gateEmail::placeholder,
#gatePassword::placeholder { color: var(--fg-subtle); opacity: 1; }

.field input:focus-visible { outline-offset: 0; border-color: var(--ring); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field input[aria-invalid="true"]:focus-visible { outline-color: var(--danger); }

.hint { display: block; margin-top: 6px; font-size: 0.8125rem; color: var(--fg-subtle); }

.error {
  margin: 0 0 var(--s4);
  padding: var(--s3);
  border: 1px solid var(--danger);
  border-radius: var(--r-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 500;
}
.error:empty { display: none; }
/* Stays in view while focus moves to a field further down the sheet. */
.sheet-body .error { position: sticky; top: calc(-1 * var(--s4)); z-index: 2; box-shadow: 0 6px 12px -8px rgba(0, 0, 0, .3); }

.icon-tabs { margin-bottom: var(--s3); }

.emoji-input {
  text-align: center;
  font-size: 1.25rem !important;
}
.emoji-input::placeholder { font-size: 1rem; }

.picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tap), 1fr));
  gap: 6px;
  margin-top: var(--s3);
}
.pick {
  display: grid;
  place-items: center;
  height: var(--tap);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--field);
  color: var(--fg);
  font-size: 1.25rem;
  line-height: 1;
}
.pick svg { width: 22px; height: 22px; }
.pick[aria-pressed="true"] {
  border-color: var(--ring);
  box-shadow: inset 0 0 0 1px var(--ring);
  background: var(--primary-soft);
}
@media (hover: hover) and (pointer: fine) {
  .pick:hover { border-color: var(--border-strong); }
}

/* Swatches preview exactly what the tile will show. Selection is a ring in
   the foreground colour plus a check, never colour alone. */
.accents { display: flex; flex-wrap: wrap; gap: var(--s2); }
.swatch {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
}
.swatch::before {
  content: "";
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  background: var(--accent-bg);
}
.swatch[aria-pressed="true"]::before { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--fg); }
.swatch[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 15px;
  left: 18px;
  width: 7px;
  height: 12px;
  border: solid var(--accent-fg);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

#toolDelete { margin-top: var(--s3); }

/* Position: the no-drag way to reorder. */
.position-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.position-label { flex: 1; min-width: 4.5em; font-variant-numeric: tabular-nums; color: var(--fg); }

/* Discard question: inline at the top of the sheet, never a second modal. */
.discard {
  margin: 0 0 var(--s4);
  padding: var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--field);
}
.discard p { margin: 0 0 var(--s3); font-weight: 600; }
.discard-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }

/* ── confirm alert ──────────────────────────────────────── */

.alert {
  width: min(320px, calc(100vw - 2 * var(--s7)));
  max-width: none;
  padding: var(--s5) var(--s4) var(--s4);
  border-radius: var(--r-xl);
  text-align: center;
}
/* Dialog titles share the brand step (1.1875rem), a clear 1.25x over body. */
.alert h2 { margin: 0 0 6px; font-size: 1.1875rem; font-weight: 600; }
.alert p { margin: 0 0 var(--s5); font-size: 0.9375rem; color: var(--fg-muted); }
.alert-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.alert-actions .btn { min-height: var(--tap); }

/* Shortcuts and gestures: Touch and Keyboard groups, whichever the device
   uses leads. Two left-aligned columns, the action on the left. */
.help {
  width: min(460px, calc(100vw - 2 * var(--gutter)));
  max-height: min(88vh, 760px);
  overflow-y: auto;
  text-align: left;
}
.help { padding-top: 0; }
.help-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  min-height: 56px;
  margin: 0 calc(-1 * var(--s4)) var(--s2);
  padding: 0 var(--s2) 0 var(--s4);
  border-bottom: 1px solid var(--separator);
  background: var(--surface);
}
.help h2 { margin: 0; text-align: left; }
@media (hover: none) and (pointer: coarse) { .help-keys { display: none; } }
.help-groups { display: flex; flex-direction: column; gap: var(--s4); margin-bottom: var(--s5); }
.help-group h3 { margin: 0 0 var(--s1); font-size: 0.8125rem; font-weight: 600; color: var(--fg-muted); }
.help-keys { order: 2; }
@media (hover: hover) and (pointer: fine) { .help-keys { order: -1; } }
.keys { margin: 0; }
.keys > div {
  display: grid;
  grid-template-columns: minmax(9rem, 44%) 1fr;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) 0;
  border-top: 1px solid var(--separator);
}
.keys > div:first-child { border-top: 0; }
.keys dt { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--fg-muted); font-size: 0.875rem; }
.keys dd { margin: 0; font-size: 0.9375rem; text-wrap: pretty; }
.help-sync { order: 3; }
@media (max-width: 479px) {
  .keys > div { grid-template-columns: 1fr; gap: 2px; }
}

/* ── dialog motion ──────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  .sheet[open], .alert[open] { animation: pop-in var(--t-enter) var(--ease-out); }
  .menu:not([hidden]) { animation: menu-in 150ms var(--ease-out); transform-origin: top right; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet[open], .alert[open], .menu:not([hidden]) { animation: fade-in 150ms linear; }
}
/* Never from scale(0): a panel that grows out of nothing reads as a glitch. */
@keyframes pop-in  { from { opacity: 0; transform: scale(.97); } }
@keyframes menu-in { from { opacity: 0; transform: scale(.96); } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }

/* ── command palette ────────────────────────────────────── */

/* Raycast: a large search row, grouped results, a key-hint footer. Selection
   is the macOS accent highlight with white text, driven by aria-selected so
   the highlight and the screen-reader state can never disagree. */
.palette {
  width: min(640px, calc(100vw - 2 * var(--gutter)));
  max-width: none;
  max-height: min(72vh, 560px);
  margin: 14vh auto auto;
  border-radius: var(--r-xl);
  overflow: hidden;
}
.palette[open] { display: flex; flex-direction: column; }

.palette-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 56px;
  padding: 0 var(--s2) 0 var(--s4);
  border-bottom: 1px solid var(--separator);
}
.palette-head > svg { width: 20px; height: 20px; color: var(--fg-muted); }

#paletteInput {
  flex: 1;
  min-width: 0;
  height: 56px;
  border: 0;
  background: transparent;
  font-size: 1.0625rem;
}
#paletteInput:focus { outline: none; }

.palette-close { display: none; }

.palette-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.palette-group {
  padding: 10px 10px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--fg-subtle);
}

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--tap);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  scroll-margin: 6px;
}
.palette-item[aria-selected="true"] { background: var(--primary); color: var(--on-primary); }
.palette-item[aria-selected="true"] .palette-sub { color: var(--sel-sub); }
.palette-item[aria-selected="true"] .palette-action-icon { background: rgba(255, 255, 255, .18); color: #ffffff; }

.palette-item .card-icon { --tile: 28px; box-shadow: none; }
/* A lagoon tile on the blue selection would vanish without an edge. */
.palette-item[aria-selected="true"] .card-icon { box-shadow: 0 0 0 1.5px #ffffff; }

.palette-text {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  flex: 1;
  min-width: 0;
}
.palette-name { flex: none; max-width: 60%; overflow: hidden; font-size: 0.9375rem; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.palette-sub {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 0.8125rem;
  color: var(--fg-subtle);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-action-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--fg-muted);
}
.palette-action-icon svg { width: 16px; height: 16px; }

.palette-empty { padding: var(--s6) var(--s4); text-align: center; color: var(--fg-muted); }

.palette-foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4);
  padding: var(--s2) var(--s4);
  border-top: 1px solid var(--separator);
  font-size: 0.75rem;
  color: var(--fg-muted);
}
.palette-foot span { display: inline-flex; align-items: center; gap: 4px; }
.palette-foot-end { margin-left: auto; }

/* On touch the first row is a gentle suggestion, not a solid slab. */
@media (hover: none) and (pointer: coarse) {
  .palette-item[aria-selected="true"] { background: var(--primary-soft); color: var(--fg); }
  .palette-item[aria-selected="true"] .palette-sub { color: var(--fg-muted); }
  .palette-item[aria-selected="true"] .palette-action-icon { background: var(--surface-2); color: var(--fg-muted); }
  .palette-item[aria-selected="true"] .card-icon { box-shadow: none; }
}

/* Touch has no arrow keys: the hints go, a Cancel button comes. */
@media (hover: none) and (pointer: coarse) {
  .palette-foot { display: none; }
  .palette-close { display: inline-flex; }
}

/* ── toast ──────────────────────────────────────────────── */

/* The live region stays in the DOM and only its text changes. */
.toast {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: max-content;
  max-width: min(440px, calc(100vw - 2 * var(--gutter)));
  margin: 0 auto;
  padding: 10px var(--s2) 10px var(--s4);
  border-radius: var(--r-lg);
  background: var(--fg);
  color: var(--bg);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--t-enter) var(--ease-out), visibility 0s linear var(--t-enter);
}
.toast-action {
  flex: none;
  min-height: 36px;
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--toast-action);
  font-weight: 700;
}
.toast-action:focus-visible { outline-color: var(--bg); }
@media (pointer: coarse) { .toast-action { min-height: var(--tap); } }
#toastText { flex: 1; min-width: 0; padding-right: var(--s2); }
.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--t-enter) var(--ease-out), visibility 0s;
}

/* ── sign-in gate ───────────────────────────────────────── */

/* The first screen, and the only one until Supabase returns a user. It is
   seen once per session, which is the frequency band where a little motion
   reads as craft instead of lag. */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s6);
  padding: max(var(--s5), env(safe-area-inset-top)) var(--s5) max(var(--s5), env(safe-area-inset-bottom));
  background: var(--bg);
  overflow-y: auto;
}
.gate.is-gone { display: none; }
/* Until the session check answers, the gate is a blank page in the theme's
   colour: a signed-in visit never flashes the sign-in form. */
.gate.is-checking > * { visibility: hidden; }

.gate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(340px, 100%);
  text-align: center;
}
@media (prefers-reduced-motion: no-preference) {
  .gate-card { animation: gate-rise 420ms var(--ease-out) both; }
}
@keyframes gate-rise { from { opacity: 0; transform: translateY(12px); } }

/* The same lockup as the top bar's brand, at sign-in scale. */
.gate-brand { display: flex; align-items: center; gap: var(--s3); }
.gate-mark { width: 44px; height: 44px; border-radius: 10px; }

.gate-card h1 { margin: 0; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.gate-sub { margin: var(--s1) 0 var(--s6); color: var(--fg-muted); }

#gateForm { width: 100%; }

/* Email over password in one stacked field, the platform sign-in idiom. */
.field-stack { display: flex; flex-direction: column; }
#gateEmail,
#gatePassword {
  position: relative;
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s4);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 1rem; /* 16px stops iOS Safari zooming the page on focus */
}
#gateEmail { border-radius: var(--r-lg) var(--r-lg) 0 0; }
#gatePassword { margin-top: -1px; border-radius: 0 0 var(--r-lg) var(--r-lg); }
/* An inset ring, so the focused half of the stacked pair never overhangs. */
#gateEmail:focus-visible,
#gatePassword:focus-visible { z-index: 1; outline-offset: -2px; border-color: var(--ring); }
#gateEmail[aria-invalid="true"],
#gatePassword[aria-invalid="true"] { z-index: 1; border-color: var(--danger); }
#gateEmail[aria-invalid="true"]:focus-visible,
#gatePassword[aria-invalid="true"]:focus-visible { outline-color: var(--danger); }

/* One sign-in covers every *.kalistamp.lol app; unchecked, it lasts until
   the browser quits. See site-auth.js. */
.gate-remember {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  width: 100%;
  min-height: 52px;
  margin: var(--s1) 0 var(--s3);
  color: var(--fg);
  cursor: pointer;
}

/* A checkbox drawn as the platform switch; it stays a checkbox to assistive
   tech. Off is a control-strength track, on is the primary. */
.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: var(--r-pill);
  background: var(--switch-off);
  cursor: pointer;
  transition: background var(--t-hover) var(--ease-out);
}
.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform 160ms var(--ease-out);
}
.switch:checked { background: var(--primary); }
.switch:checked::before { transform: translateX(18px); }
.switch:disabled { opacity: .5; }

#gateGithub { margin-top: var(--s2); }

/* Holds its own line height so the column does not jump when a message lands. */
.gate-msg {
  min-height: 1.45em;
  margin: var(--s1) 0 var(--s3);
  font-size: 0.875rem;
  color: var(--danger);
}
.gate-msg.is-busy { color: var(--fg-muted); }
.gate-msg:empty { min-height: 0; margin: 0; }

.gate-foot {
  max-width: 300px;
  margin: 0;
  font-size: 0.8125rem;
  color: var(--fg-subtle);
  text-align: center;
}

/* A refused password: feedback, not decoration. */
@media (prefers-reduced-motion: no-preference) {
  .gate-card.is-wrong { animation: gate-shake 380ms var(--ease-hover); }
}
@keyframes gate-shake {
  10%, 90% { transform: translateX(-3px); }
  30%, 70% { transform: translateX(5px); }
  50%      { transform: translateX(-5px); }
}

/* ── reduced motion ─────────────────────────────────────── */

/* Gentler, not absent: movement goes, the opacity and colour that tell you
   something happened stay. */
@media (prefers-reduced-motion: reduce) {
  .card:active .card-icon { transform: none; }
  .switch::before { transition: none; }
  * { scroll-behavior: auto !important; }
}

/* ── phone: bottom sheets ───────────────────────────────── */

@media (max-width: 699px) {
  .sheet {
    width: 100%;
    max-height: 94vh;
    max-height: 94dvh;
    margin: auto 0 0;
    border-bottom: 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  .sheet form { max-height: 94vh; max-height: 94dvh; }
  .sheet-head { touch-action: none; }
  .sheet-head::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 36px;
    height: 5px;
    margin-left: -18px;
    border-radius: var(--r-pill);
    background: var(--border-strong);
  }
  .sheet-head { position: relative; }
  @media (prefers-reduced-motion: no-preference) {
    .sheet[open] { animation: sheet-up 240ms var(--ease-out); }
  }

  .palette {
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .palette-head { padding-top: env(safe-area-inset-top); }
  .palette-close { display: inline-flex; }
  .palette-text { flex-direction: column; align-items: flex-start; gap: 0; }

  .help {
    width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    margin: auto 0 0;
    border-bottom: 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding-bottom: max(var(--s5), env(safe-area-inset-bottom));
  }
  .palette-name { max-width: 100%; }
  .palette-sub { width: 100%; }
  .palette-item { padding-top: var(--s2); padding-bottom: var(--s2); }
}

@media (max-width: 479px) {
  .view-list .card-host { display: none; }
}

@media (max-width: 359px) {
  :root { --tile-size: 54px; --gutter: 12px; }
  .brand-mark { width: 28px; height: 28px; }
}

/* ── tablet and desk ────────────────────────────────────── */

@media (min-width: 480px) {
  :root { --tile-size: 64px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

@media (min-width: 700px) {
  :root { --tile-size: 72px; --gutter: 24px; }

  .topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    padding-left: max(var(--gutter), calc((100% - 1080px) / 2 + var(--gutter)));
    padding-right: max(var(--gutter), calc((100% - 1080px) / 2 + var(--gutter)));
  }
  .topbar-actions { justify-self: end; gap: var(--s2); }

  /* Launchpad's search field, centred in the bar. */
  .search-trigger {
    position: static;
    transform: none;
    justify-content: flex-start;
    width: min(360px, 36vw);
    min-width: 0;
    height: 36px;
    padding: 0 6px 0 var(--s3);
    border-radius: var(--r-md);
    background: var(--field);
    color: var(--fg-subtle);
    font-size: 0.9375rem;
    font-weight: 400;
    box-shadow: none;
  }
  .search-trigger .search-label { flex: 1; text-align: left; }
  .search-trigger kbd { display: inline-flex; }
  .search-trigger .search-slash { margin-left: -4px; }

  .btn-add {
    padding: 0 var(--s3);
    border-color: var(--border-strong);
    background: var(--surface);
    color: var(--fg);
  }
  .btn-add svg { width: 18px; height: 18px; color: var(--link); }
  .btn-add .add-label { display: inline; }

  .wrap { padding-top: var(--s6); padding-bottom: var(--s8); }

  .grid {
    grid-template-columns: repeat(auto-fit, 120px);
    justify-content: center;
    gap: var(--s5) var(--s3);
  }
  .card-name { font-size: 0.875rem; }

  #app:not(.view-list) .toolbar { padding-left: var(--wall-left, 0); padding-right: var(--wall-right, 0); }

  /* List view reads as one column; the toolbar and hint sit on it too. */
  .grid.view-list,
  #app.view-list .toolbar,
  #app.view-list .edit-hint { max-width: 760px; margin-left: auto; margin-right: auto; }

  .toast { bottom: var(--s6); }
}

@media (min-width: 700px) and (hover: hover) and (pointer: fine) {
  .search-trigger:hover { border-color: var(--fg-subtle); }
  .btn-add:hover { background: var(--surface-2); }
}
