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

:root {
  --bg: #111111;
  --surface: #1c1c1e;
  --surface2: #2c2c2e;
  --code-bg: #252527;
  --border: #3a3a3c;
  --text: #f2f2f7;
  --muted: #8e8e93;
  /* docs=blue default; JS swaps to amber for examples */
  --accent:       #3b82f6;
  --accent-tint:  rgba(59, 130, 246, 0.15);
  --accent-dim:   rgba(59, 130, 246, 0.20);
  --mark-bg:      rgba(59, 130, 246, 0.20);
  --mark-color:   #93c5fd;

  --cat-bash:    #ff9f0a;
  --cat-python:  #0a84ff;
  --cat-linux:   #bf5af2;
  --cat-git:     #ff453a;
  --cat-docker:  #2496ed;
  --cat-ansible: #e84040;
  --cat-kubectl: #326ce5;

  --header-h: 108px;
  --cats-h: 53px;    /* cats padding(20) + chip(32) + border(1) */

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  max-width: 100vw;
}

/* ── Background glow ── */

#bg-glow {
  position: fixed;
  top: -25vh;
  left: 50%;
  transform: translateX(-50%);
  width: 160vw;
  height: 65vh;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(70px);
  opacity: 0.22;
  background-color: #ffffff;
  transition: background-color 0.65s ease;
}

#app {
  position: relative;
  z-index: 1;
}

/* ── Header ── */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(17, 17, 17, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 8px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Mode toggle ── */

.mode-toggle {
  display: flex;
  background: var(--surface2);
  border-radius: 8px;
  padding: 2px;
}

.mode-tab {
  flex: 1;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.mode-tab[data-mode="cheat"].active {
  background: rgba(249, 115, 22, 0.18);
  color: #f97316;
  font-weight: 700;
  box-shadow: 0 1px 5px rgba(249, 115, 22, 0.28);
}

.mode-tab[data-mode="docs"].active {
  background: rgba(255, 255, 255, 0.13);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 1px 5px rgba(255, 255, 255, 0.12);
}

.mode-tab[data-mode="examples"].active {
  background: rgba(48, 209, 88, 0.18);
  color: #30d158;
  font-weight: 700;
  box-shadow: 0 1px 5px rgba(48, 209, 88, 0.28);
}

.mode-tab[data-mode="notation"].active {
  background: rgba(124, 58, 237, 0.18);
  color: #7c3aed;
  font-weight: 700;
  box-shadow: 0 1px 5px rgba(124, 58, 237, 0.28);
}

.mode-tab:active {
  opacity: 0.75;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--muted);
  pointer-events: none;
  flex-shrink: 0;
}

#search {
  width: 100%;
  height: 42px;
  padding: 0 16px 0 38px;
  background: var(--surface2);
  border: 1.5px solid transparent;
  border-radius: 11px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

#search::placeholder {
  color: var(--muted);
}

#search:focus {
  border-color: var(--accent);
}

#search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%238e8e93'%3E%3Ccircle cx='10' cy='10' r='9'/%3E%3Cpath stroke='%23111' stroke-width='2' stroke-linecap='round' d='M7 7l6 6M13 7l-6 6'/%3E%3C/svg%3E") center/contain no-repeat;
  cursor: pointer;
  opacity: 1;
  margin-right: 2px;
}

/* ── Categories ── */

.cats {
  position: sticky;
  top: calc(var(--header-h) + 1px);
  z-index: 90;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  background: rgba(17, 17, 17, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  max-width: 100vw;
  width: 100%;
}

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

.cat {
  flex-shrink: 0;
  height: 32px;
  padding: 0 14px;
  border: 1.5px solid var(--cat-border, var(--border));
  border-radius: 20px;
  background: var(--cat-bg, transparent);
  color: var(--cat-color, var(--muted));
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.55;
}

.cat:active {
  opacity: 0.35;
  transform: scale(0.96);
}

.cat.active {
  background: var(--cat-color, var(--accent));
  border-color: var(--cat-color, var(--accent));
  color: #000;
  font-weight: 700;
  opacity: 1;
}

/* Per-category chip colours */
.cat[data-cat="all"] {
  --cat-color:  #3b82f6;
  --cat-bg:     rgba(59,  130, 246, 0.08);
  --cat-border: rgba(59,  130, 246, 0.45);
}
.cat[data-cat="bash"] {
  --cat-color:  #ff9f0a;
  --cat-bg:     rgba(255, 159, 10,  0.08);
  --cat-border: rgba(255, 159, 10,  0.45);
}
.cat[data-cat="python"] {
  --cat-color:  #0a84ff;
  --cat-bg:     rgba(10,  132, 255, 0.08);
  --cat-border: rgba(10,  132, 255, 0.45);
}
.cat[data-cat="linux"] {
  --cat-color:  #bf5af2;
  --cat-bg:     rgba(191, 90,  242, 0.08);
  --cat-border: rgba(191, 90,  242, 0.45);
}
.cat[data-cat="git"] {
  --cat-color:  #ff453a;
  --cat-bg:     rgba(255, 69,  58,  0.08);
  --cat-border: rgba(255, 69,  58,  0.45);
}
.cat[data-cat="docker"] {
  --cat-color:  #2496ed;
  --cat-bg:     rgba(36,  150, 237, 0.08);
  --cat-border: rgba(36,  150, 237, 0.45);
}
.cat[data-cat="ansible"] {
  --cat-color:  #e84040;
  --cat-bg:     rgba(232, 64,  64,  0.08);
  --cat-border: rgba(232, 64,  64,  0.45);
}
.cat[data-cat="kubectl"] {
  --cat-color:  #326ce5;
  --cat-bg:     rgba(50,  108, 229, 0.08);
  --cat-border: rgba(50,  108, 229, 0.45);
}

/* ── Subcategories ── */

.subcats {
  position: sticky;
  top: calc(var(--header-h) + 1px + var(--cats-h));
  z-index: 80;
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  background: rgba(28, 28, 30, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  max-width: 100vw;
  width: 100%;
}

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

.subcat {
  flex-shrink: 0;
  height: 26px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.subcat:active {
  opacity: 0.7;
  transform: scale(0.96);
}

.subcat.active {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── Count ── */

.count {
  padding: 10px 16px 4px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.3px;
}

/* ── Grid ── */

#grid {
  padding: 8px 12px 32px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  min-width: 0;
  overflow-x: hidden;
}

@media (min-width: 640px) {
  #grid {
    grid-template-columns: repeat(2, 1fr);
    padding: 12px 16px 40px;
    gap: 12px;
  }
}

@media (min-width: 1024px) {
  #grid {
    grid-template-columns: repeat(3, 1fr);
    padding: 16px 24px 48px;
    gap: 14px;
  }
}

/* ── Card ── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s;
  list-style: none;
  min-width: 0;
  cursor: pointer;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.card:active {
  border-color: var(--accent);
}

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 5px;
  margin-top: 2px;
}

.tag-bash    { background: rgba(255, 159, 10, 0.18); color: var(--cat-bash); }
.tag-python  { background: rgba(10, 132, 255, 0.18); color: var(--cat-python); }
.tag-linux   { background: rgba(191, 90, 242, 0.18); color: var(--cat-linux); }
.tag-git     { background: rgba(255, 69, 58,  0.18); color: var(--cat-git); }
.tag-docker  { background: rgba(36, 150, 237, 0.18); color: var(--cat-docker); }
.tag-ansible { background: rgba(232, 64,  64,  0.18); color: var(--cat-ansible); }
.tag-kubectl { background: rgba(50, 108, 229, 0.18); color: var(--cat-kubectl); }

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.card-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Code block ── */

.code-block {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}

.code-block pre {
  padding: 10px 44px 10px 12px;
}

.code-block code {
  font-family: "SF Mono", "Fira Code", ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.65;
  color: #e5e5ea;
  display: block;
  /* wrap long lines on all screen sizes so nothing hides off-screen */
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* on wider screens keep long commands on one line if they fit */
@media (min-width: 640px) {
  .code-block code {
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
  }
  .code-block pre {
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  .code-block pre::-webkit-scrollbar { height: 4px; }
  .code-block pre::-webkit-scrollbar-track { background: transparent; }
  .code-block pre::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 36px;
  height: 28px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.copy-btn:active,
.copy-btn:hover {
  background: var(--border);
  color: var(--text);
}

.copy-btn.copied {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Highlight ── */

mark {
  background: var(--mark-bg);
  color: var(--mark-color);
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Empty state ── */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 64px 24px;
  color: var(--muted);
  text-align: center;
}

.empty svg {
  opacity: 0.4;
  margin-bottom: 4px;
}

.empty p {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
}

.empty small {
  font-size: 14px;
}

/* ── Detail / fullscreen card view ── */

.detail {
  padding: 20px 16px 100px;
  animation: detailIn 0.18s ease;
}

@keyframes detailIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.detail-inner {
  max-width: 760px;
  margin: 0 auto;
}

.detail-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.detail-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.detail-desc {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 16px;
}

.detail .code-block code {
  font-size: 13.5px;
  line-height: 1.75;
}

.detail-close {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  height: 40px;
  padding: 0 22px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  z-index: 500;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.detail-close:hover {
  background: var(--border);
  border-color: var(--muted);
}

/* ── Syntax highlight tokens (Catppuccin Mocha palette) ── */

.hl-cmt { color: #6c7086; }
.hl-str { color: #a6e3a1; }
.hl-kw  { color: #cba6f7; }
.hl-var { color: #fab387; }
.hl-blt { color: #89dceb; }
.hl-num { color: #f9e2af; }
.hl-dec { color: #f38ba8; }

.hidden {
  display: none !important;
}
