/* ========================================
   CSS Custom Properties - Theme System
   ======================================== */

/* Terminal Theme (default) */
[data-theme="terminal"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-card-hover: #22272e;
  --bg-input: #0d1117;
  --bg-badge: #1f6feb22;
  --bg-category: #21262d;
  --bg-category-active: #1f6feb;
  --bg-kbd: #30363d;
  --bg-toast: #3fb950;

  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --text-link: #58a6ff;
  --text-heading: #e6edf3;
  --text-badge: #58a6ff;
  --text-category-active: #ffffff;
  --text-kbd: #7ee787;
  --text-toast: #0d1117;
  --text-on-accent: #ffffff;

  --border-primary: #30363d;
  --border-card: #30363d;
  --border-input: #30363d;
  --border-input-focus: #1f6feb;

  --accent: #1f6feb;
  --accent-secondary: #3fb950;
  --accent-glow: #1f6feb33;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.5);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --font-body: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', Menlo, Consolas, monospace;
  --font-heading: var(--font-body);

  --transition: 0.2s ease;
}

/* Minimal Theme */
[data-theme="minimal"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f9fa;
  --bg-input: #ffffff;
  --bg-badge: #eff6ff;
  --bg-category: #f1f3f5;
  --bg-category-active: #111827;
  --bg-kbd: #f1f3f5;
  --bg-toast: #111827;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --text-link: #2563eb;
  --text-heading: #111827;
  --text-badge: #2563eb;
  --text-category-active: #ffffff;
  --text-kbd: #111827;
  --text-toast: #ffffff;
  --text-on-accent: #ffffff;

  --border-primary: #e5e7eb;
  --border-card: #e5e7eb;
  --border-input: #d1d5db;
  --border-input-focus: #2563eb;

  --accent: #2563eb;
  --accent-secondary: #059669;
  --accent-glow: #2563eb15;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --font-body: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-heading: var(--font-body);

  --transition: 0.15s ease;
}

/* OpenCode Theme */
[data-theme="opencode"] {
  --bg-primary: #09090b;
  --bg-secondary: #18181b;
  --bg-card: #18181b;
  --bg-card-hover: #27272a;
  --bg-input: #09090b;
  --bg-badge: #7c3aed22;
  --bg-category: #27272a;
  --bg-category-active: linear-gradient(135deg, #7c3aed, #2563eb);
  --bg-kbd: #3f3f46;
  --bg-toast: #7c3aed;

  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-link: #a78bfa;
  --text-heading: #fafafa;
  --text-badge: #a78bfa;
  --text-category-active: #ffffff;
  --text-kbd: #c4b5fd;
  --text-toast: #ffffff;
  --text-on-accent: #ffffff;

  --border-primary: #27272a;
  --border-card: #27272a;
  --border-input: #3f3f46;
  --border-input-focus: #7c3aed;

  --accent: #7c3aed;
  --accent-secondary: #06b6d4;
  --accent-glow: #7c3aed33;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-card-hover: 0 4px 16px rgba(124,58,237,0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --font-body: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-heading: var(--font-body);

  --transition: 0.2s ease;
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a {
  color: var(--text-link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code {
  font-family: 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--bg-kbd);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--text-kbd);
}

/* ========================================
   Header
   ======================================== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  padding: 1rem 1.5rem;
  transition: background var(--transition);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.02em;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-badge);
  background: var(--bg-badge);
  padding: 0.2em 0.6em;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}

.tip-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Theme Switcher */
.theme-switcher {
  display: flex;
  gap: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 3px;
}

.theme-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8rem;
  transition: all var(--transition);
  white-space: nowrap;
}

.theme-btn:hover {
  color: var(--text-primary);
  background: var(--bg-category);
}

.theme-btn.active {
  background: var(--accent);
  color: var(--text-on-accent);
}

.theme-icon {
  font-weight: 700;
  font-size: 0.85rem;
}

/* Search */
.search-bar {
  width: 100%;
}

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

.search-icon {
  position: absolute;
  left: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.65rem 2.5rem 0.65rem 2.5rem;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--border-input-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-clear {
  position: absolute;
  right: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  transition: all var(--transition);
}

.search-clear:hover {
  background: var(--bg-category);
  color: var(--text-primary);
}

/* ========================================
   Category Bar
   ======================================== */
.category-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  overflow-x: auto;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-primary);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-primary) transparent;
}

.category-bar::-webkit-scrollbar {
  height: 4px;
}

.category-bar::-webkit-scrollbar-track {
  background: transparent;
}

.category-bar::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: 4px;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-full);
  background: var(--bg-category);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  user-select: none;
}

.category-pill:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.category-pill.active {
  background: var(--bg-category-active);
  color: var(--text-category-active);
  border-color: transparent;
}

.category-pill .cat-count {
  font-size: 0.7rem;
  opacity: 0.7;
}

/* ========================================
   Tips Grid
   ======================================== */
.tips-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
}

/* ========================================
   Tip Card
   ======================================== */
.tip-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.tip-card:hover {
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--accent);
}

.tip-card.expanded {
  grid-column: 1 / -1;
}

.tip-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.tip-text {
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.5;
  flex: 1;
}

.tip-card-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.tip-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.tip-action-btn:hover {
  background: var(--bg-category);
  color: var(--text-primary);
}

.tip-action-btn.expand-btn {
  transition: transform var(--transition), background var(--transition), color var(--transition);
}

.tip-card.expanded .expand-btn {
  transform: rotate(180deg);
}

.tip-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.tip-category-tag {
  font-size: 0.7rem;
  color: var(--text-secondary);
  background: var(--bg-category);
  padding: 0.15em 0.5em;
  border-radius: var(--radius-full);
}

/* Keyboard shortcut badges */
.kbd {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  font-family: 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-kbd);
  background: var(--bg-kbd);
  padding: 0.15em 0.45em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  line-height: 1.4;
  white-space: nowrap;
}

.kbd-separator {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin: 0 0.1rem;
}

/* Expanded description */
.tip-description {
  display: none;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-primary);
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-secondary);
  animation: fadeIn 0.25s ease;
}

.tip-card.expanded .tip-description {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
}

.empty-icon {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.empty-text {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 1.5rem;
}

.empty-reset {
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}

.empty-reset:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

/* ========================================
   Footer
   ======================================== */
.footer {
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-primary);
}

/* ========================================
   Toast
   ======================================== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--bg-toast);
  color: var(--text-toast);
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========================================
   Utility
   ======================================== */
.hidden {
  display: none !important;
}

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

/* Highlight matching text in search */
mark {
  background: var(--accent-glow);
  color: var(--text-primary);
  padding: 0.05em 0.15em;
  border-radius: 2px;
}

[data-theme="minimal"] mark {
  background: #fef08a;
  color: #111827;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 860px) {
  .tips-container {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 0.75rem;
  }

  .tip-card.expanded {
    grid-column: 1;
  }

  .header {
    padding: 0.75rem 1rem;
  }

  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .theme-switcher {
    width: 100%;
  }

  .theme-btn {
    flex: 1;
    justify-content: center;
  }

  .category-bar {
    padding: 0.5rem 1rem;
  }

  .theme-label {
    display: inline;
  }
}

@media (max-width: 480px) {
  .header-title {
    font-size: 1.2rem;
  }

  .search-input {
    font-size: 0.85rem;
  }

  .tip-text {
    font-size: 0.85rem;
  }

  .tip-description {
    font-size: 0.82rem;
  }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
  * {
    color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    background: white !important;
    color: #111 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  }

  .header {
    position: static;
    background: white !important;
    border-bottom: 2px solid #111 !important;
    padding-bottom: 0.5rem;
  }

  .header-controls,
  .search-bar,
  .category-bar,
  .tip-action-btn,
  .toast,
  .footer {
    display: none !important;
  }

  .tips-container {
    display: block !important;
    padding: 0 !important;
    max-width: none !important;
  }

  .tip-card {
    background: white !important;
    border: 1px solid #ccc !important;
    border-radius: 4px !important;
    margin-bottom: 0.75rem;
    page-break-inside: avoid;
    box-shadow: none !important;
  }

  .tip-card.expanded {
    grid-column: unset;
  }

  .tip-description {
    display: block !important;
    color: #333 !important;
    border-top: 1px solid #ddd !important;
  }

  .tip-text {
    color: #111 !important;
    font-weight: 600;
  }

  .kbd {
    background: #f3f3f3 !important;
    color: #111 !important;
    border-color: #999 !important;
  }

  .tip-category-tag {
    background: #eee !important;
    color: #333 !important;
  }

  .version-badge {
    background: #eee !important;
    color: #333 !important;
  }

  mark {
    background: transparent !important;
  }
}

/* ========================================
   Accessibility
   ======================================== */

/* Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 300;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--text-on-accent);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0.5rem;
}

/* Focus outlines — visible in all themes */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tip-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: var(--shadow-card-hover);
}

.theme-btn:focus-visible,
.category-pill:focus-visible,
.tip-action-btn:focus-visible,
.search-input:focus-visible,
.empty-reset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
