*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #3c3c3c;
  --bg-hover: rgba(255, 255, 255, 0.08);
  --bg-active: rgba(255, 255, 255, 0.14);
  --text: #e8e8e8;
  --text-muted: #aaa;
  --icon-label: #e2e2e2;
  --radius-item: 12px;

  /* Surfaces layered above the page */
  --chip-bg: #505050;
  --fab-bg: #505050;
  --panel-bg: #454545;
  --panel-border: rgba(255, 255, 255, 0.08);
  --overlay: rgba(0, 0, 0, 0.55);
  --badge-bg: #e8e8e8;
  --badge-fg: #1f1f1f;
  --fab-hover-bg: #5c5c5c;
  --radius-panel: 16px;
  --shadow-panel: 0 18px 50px rgba(0, 0, 0, 0.45);
  --shadow-fab: 0 4px 14px rgba(0, 0, 0, 0.4);
}

html {
  --cursor-default: url("../img/cursors/arrow-cursor.svg"), auto;
  --cursor-pointer: url("../img/cursors/pointer-cursor.svg"), auto;
  cursor: var(--cursor-default);
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: "Outfit", "Segoe UI", sans-serif;
  overflow-x: hidden;
  min-height: 100dvh;
}

a {
  cursor: var(--cursor-pointer);
  text-decoration: none;
}
button {
  font: inherit;
  cursor: var(--cursor-pointer);
}

/* ── Page shell ───────────────────────────────── */
.page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px 96px;
  /* the fab is revealed by a manual double tap/click timer (see app.js),
     not the native dblclick event — this keeps a real double tap from
     being swallowed by the browser's own double-tap-to-zoom gesture while
     still allowing pinch zoom */
  touch-action: manipulation;
}

/* sections stack in a single column: title gutter + 7 shortcuts in view */
.stage {
  width: 100%;
  max-width: 736px;
}

/* ── Category sections ────────────────────────── */
/* one row per category: the section scrolls sideways when it has more
   shortcuts than fit, and its title stays pinned on the left */
.group {
  --gutter: 96px; /* title column, including the gap before the first icon */
  display: flex;
  align-items: flex-start;
  padding: 14px 0;
  overflow-x: auto;
  scroll-padding-left: var(--gutter); /* keyboard focus / snapping clear the title */
  scrollbar-width: none;
}

.group::-webkit-scrollbar {
  display: none;
}

/* right-edge fade, pinned to the visible end of the row while there's more
   to scroll to (app.js sets .more) */
.group::after {
  content: "";
  position: sticky;
  right: 0;
  flex: 0 0 28px;
  margin-left: -28px;
  align-self: stretch;
  background: linear-gradient(to left, var(--bg), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.group.more::after {
  opacity: 1;
}

/* hairline between categories */
.group + .group {
  border-top: 1px solid var(--panel-border);
}

/* pinned title: fills the row's height with the page colour so icons scroll
   out of sight beneath it; its content is centred in the gutter and level
   with the middle of the shortcuts (icon + name ~90px tall, title ~38px) */
.group > .groupTitle {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: 0 0 var(--gutter);
  align-self: stretch;
  justify-content: flex-start;
  margin: 0;
  padding: 26px 16px 0 0;
  background: var(--bg);
}

/* once icons have scrolled under the title, they fade out into it */
.group > .groupTitle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  width: 28px;
  background: linear-gradient(to right, var(--bg), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.group.scrolled > .groupTitle::after {
  opacity: 1;
}

.group > .grid {
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

/* quiet category name with its icon above (front page and popup) */
.groupTitle {
  display: flex;
  flex-direction: column;
  align-items: center; /* icon centred over the name */
  width: fit-content;
  gap: 4px;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
  user-select: none;
}

/* on the front page it opens that category in the popup, and is also the
   drag handle for its section (hold-to-drag on touch, like the shortcuts) */
.stage .groupTitle {
  cursor: var(--cursor-pointer);
  touch-action: none;
  -webkit-touch-callout: none;
  border-radius: 4px;
}

.stage .groupTitle:hover {
  color: var(--text);
}

.stage .groupTitle:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.group.dragging {
  opacity: 0.35;
}

/* ── Empty state ──────────────────────────────── */
.empty {
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
}

.emptyPlus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--chip-bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
}

/* ── Shortcuts grid ───────────────────────────── */
.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Cell wraps an item; it's the unit that gets dragged and reordered */
.cell {
  position: relative;
  /* Touch drives the reorder gesture instead of scrolling the page, and the
     iOS long-press callout / text selection is suppressed so the hold can
     start a drag cleanly. */
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

.cell.dragging {
  opacity: 0.35;
}

/* ── Individual shortcut ──────────────────────── */
.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 88px;
  padding: 10px 4px;
  border-radius: var(--radius-item);
  transition: background 0.15s ease;
  animation: fadeUp 0.3s ease both;
}

.item:hover {
  background: var(--bg-hover);
}

.item:focus-visible,
.libItem:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: -2px;
}

.item:active {
  background: var(--bg-active);
}

.iconWrap {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.label {
  font-size: 13px;
  color: var(--icon-label);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}

/* ── Floating add button ──────────────────────── */
.fab {
  position: fixed;
  right: 28px;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--fab-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-fab);
  transition:
    background 0.15s ease,
    transform 0.2s ease,
    opacity 0.15s ease;
  z-index: 20;
}

.fabHidden {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.fab:hover {
  background: var(--fab-hover-bg);
}

.fab:active {
  transform: scale(0.94);
}

.fabOpen {
  transform: rotate(45deg);
}

.fabOpen:active {
  transform: rotate(45deg) scale(0.94);
}

/* ── Popup panel (native <dialog>) ────────────── */
.panel::backdrop {
  background: var(--overlay);
  animation: fadeIn 0.15s ease both;
}

.panel {
  width: calc(100% - 48px);
  max-width: 640px;
  max-height: 80dvh;
  margin: auto;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
  animation: popIn 0.18s ease both;
}

.panelHead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px 0;
}

.panelTitle {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.panelClose {
  width: 44px;
  height: 44px;
  margin: -8px -12px -8px 0;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.panelClose:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.selectAllBtn {
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.selectAllBtn:hover {
  background: var(--bg-hover);
}

/* ── Popup body ───────────────────────────────── */
.panelBody {
  padding: 12px 12px 20px;
  overflow-y: auto;
}

.libGroup + .libGroup {
  margin-top: 16px;
}

.libGroup .groupTitle {
  padding: 0 8px;
}

.libraryGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 2px;
}

.libItem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 4px 12px;
  border-radius: var(--radius-item);
  border: none;
  background: transparent;
  transition: background 0.15s ease;
}

.libItem:hover {
  background: var(--bg-hover);
}

.libItem:active {
  background: var(--bg-active);
}

/* tick badge: shown only on shortcuts already added to the front */
.stateBadge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--badge-bg);
  color: var(--badge-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ── Animations ───────────────────────────────── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Mobile ───────────────────────────────────── */
@media (max-width: 480px) {
  .page {
    padding: 32px 16px 96px;
  }

  /* narrower gutter so a 390px phone still shows 4 shortcuts
     (58 + 4×72 + 3×4 = 358) */
  .group {
    --gutter: 58px;
    scroll-snap-type: x proximity;
  }

  .group > .groupTitle {
    padding: 20px 6px 0 0; /* phone shortcuts are ~79px tall */
  }

  .item,
  .libItem {
    width: 76px;
    padding: 8px 2px;
    gap: 4px;
  }

  .item {
    width: 72px;
    flex-shrink: 0;
  }

  .cell {
    scroll-snap-align: start;
    touch-action: pan-x pan-y; /* let the row scroll; app.js blocks it mid-drag */
  }

  .iconWrap {
    width: 44px;
    height: 44px;
  }

  .label {
    font-size: 12px;
  }

  .fab {
    right: 20px;
    bottom: 20px;
  }

  .panel {
    max-height: 86dvh;
  }
}

/* ── Reduced motion ───────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .item,
  .panel,
  .panel::backdrop,
  .fab {
    animation: none !important;
    transition: none !important;
  }
}
