/* palette.css — ⌘K spotlight + "?" shortcuts sticker sheet (#palette-layer, z 240). */
#palette-layer { display: none; }
#palette-layer.is-open {
  display: flex; justify-content: center; align-items: flex-start;
  position: fixed; inset: 0; z-index: 240; /* full-screen layer band (200-260): above the bottom nav and tour */
  padding: max(9vh, 56px) 16px 24px;
  overscroll-behavior: contain;
  overflow-y: auto;
}
.pal-scrim {
  position: fixed; inset: 0;
  background-color: color-mix(in srgb, var(--paper) 62%, transparent);
  background-image: radial-gradient(circle at 1.5px 1.5px, var(--dot) 1.5px, transparent 1.8px);
  background-size: 26px 26px;
  backdrop-filter: blur(3px) saturate(0.8);
  animation: pal-fade 0.18s ease-out both;
}
@keyframes pal-fade { from { opacity: 0; } }

/* ===== spotlight ===== */
.pal {
  position: relative; width: min(680px, 100%);
  background: var(--card); color: var(--ink);
  border: var(--bw) solid var(--line); border-radius: var(--r-md);
  box-shadow: 8px 8px 0 var(--ink);
  animation: pal-in 0.28s var(--ease-spring) both;
  display: flex; flex-direction: column; max-height: min(620px, calc(100vh - 18vh));
}

@keyframes pal-in { from { transform: translateY(-14px) rotate(-0.6deg) scale(0.98); opacity: 0; } }
.pal-tape {
  position: absolute; top: -13px; left: 50%; width: 110px; height: 24px; transform: translateX(-50%) rotate(-2deg);
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.35) 0 6px, transparent 6px 12px), var(--acid);
  border: 1.5px solid rgba(14,14,16,.35); opacity: 0.92; z-index: 2;
}
.pal-head {
  display: flex; align-items: center; gap: 12px; padding: 18px 16px 14px 18px;
  border-bottom: var(--bw) solid var(--line);
}
.pal-glyph {
  flex: none; font-family: var(--f-mono); font-size: 12px; font-weight: 700;
  padding: 4px 7px; background: var(--ink); color: var(--paper); border-radius: 4px; transform: rotate(-4deg);
}
.pal-input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none;
  font-family: var(--f-mono); font-size: 20px; font-weight: 500; letter-spacing: -0.01em;
  caret-color: var(--hot);
}
.pal-input::placeholder { color: var(--ink-3); }
.pal-esc {
  flex: none; font-family: var(--f-mono); font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em;
  padding: 4px 7px; border: 1.5px solid var(--line); border-radius: 4px; background: var(--paper-2);
}
.pal-esc:hover { background: var(--acid); color: #0e0e10; }

.pal-results { overflow-y: auto; padding: 6px 8px 10px; overscroll-behavior: contain; }
.pal-group + .pal-group { margin-top: 4px; }
.pal-group-label {
  position: sticky; top: 0; z-index: 1;
  font-family: var(--f-mono); font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; color: var(--ink-3);
  padding: 10px 10px 6px; background: var(--card);
}
.pal-group-label::before { content: "■ "; color: var(--ink); }
.pal-row {
  display: block; border-radius: 8px; padding: 8px 10px; cursor: pointer;
  border: 1.5px solid transparent;
}
.pal-row.is-active {
  background: var(--acid); color: #0e0e10; border-color: #0e0e10; box-shadow: 3px 3px 0 #0e0e10;
  transform: rotate(-0.3deg);
}
.pal-row.is-active .pal-sub, .pal-row.is-active .pal-by { color: #2a2a30; }
.pal-row-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pal-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pal-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-sub { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-meta { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; font-family: var(--f-mono); font-size: 10.5px; }
.pal-by { color: var(--ink-3); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-count { font-weight: 700; padding: 1px 6px; border-radius: 3px; background: var(--ink); color: var(--paper); white-space: nowrap; }
.pal-count.is-zero { background: var(--hot); color: #0e0e10; }
.pal-row.is-active .pal-count { background: #0e0e10; color: var(--acid); }
.pal-chip {
  flex: none; width: 92px; text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-family: var(--f-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  padding: 3px 5px; border: 1.5px solid #0e0e10; border-radius: 3px; background: var(--c); color: #0e0e10;
}
.pal-swatch, .pal-icon {
  flex: none; width: 30px; height: 30px; display: grid; place-items: center; font-size: 15px;
  border: 1.5px solid #0e0e10; border-radius: 6px; background: var(--c, var(--paper-2)); color: #0e0e10;
  transform: rotate(-4deg);
}
.pal-icon { font-family: var(--f-mono); font-weight: 700; background: var(--paper-2); color: var(--ink); border-color: var(--line); }
.pal-row.is-active .pal-icon { background: #0e0e10; color: var(--acid); border-color: #0e0e10; }
.pal-kbd { opacity: 1; font-size: 10.5px; }
.pal mark { background: var(--hot); color: #0e0e10; border-radius: 2px; padding: 0 1px; box-shadow: 0 0 0 1px #0e0e10; }
.pal-row.is-active mark { background: #0e0e10; color: var(--acid); box-shadow: none; }

.pal-empty { padding: 26px 16px 22px; text-align: center; font-family: var(--f-mono); font-size: 12.5px; color: var(--ink-2); }
.pal-empty-big { font-family: var(--f-display); font-style: italic; font-size: 34px; color: var(--ink); margin: 0 0 6px; overflow-wrap: anywhere; }
.pal-empty .btn { margin-top: 10px; }

.pal-foot {
  display: flex; align-items: center; gap: 16px; padding: 9px 16px;
  border-top: 1.5px dashed var(--line);
  font-family: var(--f-mono); font-size: 11px; color: var(--ink-3);
}
.pal-foot kbd { opacity: 0.9; color: var(--ink); margin-right: 2px; }
.pal-foot-link {
  margin-left: auto; border: 0; background: none; padding: 2px 4px;
  font-family: var(--f-mono); font-size: 11px; font-weight: 600; color: var(--ink); text-decoration: underline; text-underline-offset: 3px;
}
.pal-foot-link:hover { background: var(--acid); color: #0e0e10; }

/* ===== shortcuts sticker sheet ===== */
.sc {
  position: relative; width: min(820px, 100%);
  padding: 22px 24px 20px;
  background: var(--paper); color: var(--ink);
  background-image: radial-gradient(circle at 1.5px 1.5px, var(--dot) 1.5px, transparent 1.8px);
  background-size: 22px 22px;
  border: var(--bw) solid var(--line); border-radius: var(--r-md);
  box-shadow: 8px 8px 0 var(--ink);
  animation: pal-in 0.32s var(--ease-spring) both;
}

.sc-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.sc-kicker { width: 100%; order: -1; font-family: var(--f-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; color: var(--ink-3); }
.sc-title { margin: 0; flex: 1; font-family: var(--f-display); font-style: italic; font-weight: 400; font-size: clamp(48px, 8vw, 72px); line-height: 0.85; letter-spacing: -0.03em; }
.sc-title em { color: var(--hot); font-style: normal; }
.sc-head .pal-x { margin-top: 4px; }
.sc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 22px; }
.sc-sticker {
  background: var(--bg); color: #0e0e10;
  border: 1.5px solid #0e0e10; box-shadow: var(--shadow-postit);
  padding: 14px 16px 12px; transform: rotate(var(--rot));
  transition: transform 0.2s var(--ease-spring);
}
.sc-sticker:hover { transform: rotate(0) scale(1.015); }
.sc-group { margin: 0 0 8px; font-family: var(--f-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; }
.sc-group::before { content: ""; display: inline-block; width: 9px; height: 9px; background: #0e0e10; margin-right: 7px; }
.sc-sticker ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.sc-sticker li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.sc-keys { flex: none; min-width: 108px; display: inline-flex; align-items: center; gap: 3px; }
.sc-kbd {
  opacity: 1; font-size: 11px; font-weight: 700; color: #0e0e10; background: #fffdf7;
  border: 1.5px solid #0e0e10; box-shadow: 1.5px 1.5px 0 #0e0e10; padding: 1px 6px; border-radius: 4px;
}
.sc-plus { font-style: normal; font-family: var(--f-mono); font-size: 10px; opacity: 0.6; }
.sc-label { line-height: 1.25; }
.sc-foot { margin-top: 22px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sc-note { margin: 0 auto 0 0; font-family: var(--f-marker); font-size: 17px; transform: rotate(-1.5deg); }

@media (max-width: 700px) {
  #palette-layer.is-open { padding: 56px 10px 16px; }
  .pal { max-height: calc(100vh - 80px); }
  .pal-input { font-size: 16px; }
  .pal-chip { width: 66px; font-size: 9.5px; padding: 3px 3px; }
  .pal-by { display: none; }
  .pal-foot span { display: none; }
  .sc { padding: 18px 14px 16px; }
  .sc-grid { grid-template-columns: 1fr; gap: 14px; }
  .sc-foot .btn { flex: 1 1 auto; justify-content: center; }
  .sc-note { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .pal, .sc, .pal-scrim { animation: none; }
}

/* ----- polish: exit, shared close ×, contrast, touch ----- */
#palette-layer.is-closing { pointer-events: none; }
#palette-layer.is-closing .pal-scrim { animation: pal-fade 0.17s ease-in reverse both; }
#palette-layer.is-closing :is(.pal, .sc) { animation: pal-out 0.17s var(--ease-out) both; }
@keyframes pal-out { to { transform: translateY(-10px) scale(0.98); opacity: 0; } }

/* same round × as every other overlay */
.pal-x {
  flex: none; width: 38px; height: 38px; display: grid; place-items: center;
  font-size: 24px; line-height: 1; color: var(--ink);
  background: var(--card); border: var(--bw) solid var(--line); border-radius: 50%;
  transition: transform 0.25s var(--ease-spring), background 0.2s;
}
.pal-x:hover { background: var(--hot); color: #0e0e10; transform: rotate(90deg); }
.pal-x:active { transform: rotate(90deg) scale(0.9); }
.pal-esc:active { transform: translate(1px, 1px); }

:root #palette-layer { --ink-3: #5f5f67; }

@media (pointer: coarse) {
  .pal-esc { min-height: 36px; padding: 4px 10px; }
  .pal-x { width: 42px; height: 42px; }
  .pal-row { padding-block: 10px; }
  .pal-foot-link { min-height: 40px; }
  .sc-foot .btn { height: 42px; }
}

/* =====================================================================
   Responsive pass
   ===================================================================== */
.pal-esc-x { display: none; }
.pal { max-height: min(620px, calc(100dvh - 18vh)); }
.pal-foot-touch { flex: 1; min-width: 0; }
@media (hover: none), (pointer: coarse), (max-width: 700px) {
  /* a real close button instead of the ESC keycap */
  .pal-esc {
    width: 44px; height: 44px; min-height: 44px; padding: 0; display: grid; place-items: center;
    font-family: var(--f-sans); font-size: 26px; font-weight: 400; letter-spacing: 0; line-height: 1;
    background: var(--card); border: var(--bw) solid var(--line); border-radius: 50%;
  }
  .pal-esc-k { display: none; }
  .pal-esc-x { display: block; }
  .pal-row { min-height: 52px; display: flex; align-items: center; }
  .pal-row-main { width: 100%; }
  .pal-foot-link { min-height: 44px; padding: 4px 8px; }
  .sc-grid.is-touch .sc-keys { min-width: 96px; flex-wrap: wrap; }
  .sc-grid.is-touch .sc-kbd { white-space: nowrap; }
  .sc-sticker:hover { transform: rotate(var(--rot)); }
}
/* phones: a full-screen sheet, input pinned to the top */
@media (max-width: 700px) {
  #palette-layer.is-open.is-palette { padding: 0; align-items: stretch; overflow: hidden; }
  #palette-layer.is-palette .pal {
    width: 100%; height: 100vh; height: 100dvh; max-height: none;
    border: 0; border-radius: 0; box-shadow: none;
    animation-name: pal-sheet-in;
  }
  #palette-layer.is-palette .pal-tape { display: none; }
  #palette-layer.is-palette .pal-head {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
    gap: 10px; background: var(--card);
  }
  .pal-glyph { font-size: 16px; padding: 3px 7px; }
  .pal-input { font-size: 16px; height: 44px; }
  #palette-layer.is-palette .pal-results { flex: 1; padding: 4px 6px 12px; }
  .pal-group-label { padding: 12px 10px 6px; }
  .pal-title { font-size: 15px; }
  .pal-sub { font-size: 13px; }
  .pal-chip { width: 58px; }
  .pal-row.is-active { transform: none; box-shadow: 2px 2px 0 #0e0e10; }
  #palette-layer.is-palette .pal-foot { padding: 6px 14px max(6px, env(safe-area-inset-bottom)); }
  .pal-foot span.pal-foot-touch { display: inline; }
  .pal-empty .btn { max-width: 100%; white-space: normal; height: auto; min-height: 48px; padding: 8px 14px; }
  #palette-layer.is-closing.is-palette .pal { animation: pal-sheet-out 0.17s var(--ease-out) both; }
  /* gestures / shortcuts sheet: full width, scrolls inside the layer */
  #palette-layer.is-open.is-shortcuts { padding: max(14px, env(safe-area-inset-top)) 10px max(16px, env(safe-area-inset-bottom)); }
  .sc-title { font-size: 46px; }
  /* the close button stays put while the sheet scrolls */
  #palette-layer.is-shortcuts .sc-head .pal-x {
    position: fixed; z-index: 3; top: max(22px, calc(env(safe-area-inset-top) + 8px)); right: max(20px, calc(env(safe-area-inset-right) + 10px));
    width: 44px; height: 44px; box-shadow: 2px 2px 0 var(--line);
  }
  .sc-sticker li { font-size: 14px; }
  .sc-foot .btn { min-height: 48px; }
}
@keyframes pal-sheet-in { from { transform: translateY(24px); opacity: 0; } }
@keyframes pal-sheet-out { to { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #palette-layer.is-palette .pal, #palette-layer.is-closing .pal, #palette-layer.is-closing .sc { animation: none !important; }
}
/* entrance animations: don't keep filling after they end (a lingering transform would
   make the sheet a containing block and break the fixed × above) */
.pal, .sc { animation-fill-mode: backwards; }
