/* ===== CSS Reset & Variables ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-hover: #f0f1f3;
  --bg-active: #e8e9eb;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --border: #e5e5ea;
  --border-light: #f2f2f7;
  --accent: #007aff;
  --accent-light: #e8f2ff;
  --accent-hover: #0066d6;
  --success: #34c759;
  --warning: #ff9500;
  --danger: #ff3b30;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
  --sidebar-width: 220px;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 24px;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -0.3px;
}

.logo-icon {
  font-size: 26px;
}

/* ===== Mode Tabs ===== */
.mode-tabs {
  display: flex;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.mode-tab {
  padding: 8px 20px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  transition: all var(--transition);
  white-space: nowrap;
}

.mode-tab:hover {
  color: var(--text-primary);
}

.mode-tab.active {
  background: var(--bg);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ===== Search ===== */
.search-wrapper {
  flex: 1;
  min-width: 200px;
  max-width: 400px;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  outline: none;
  transition: all var(--transition);
}

.search-input:focus {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 14px;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: none;
  background: var(--text-tertiary);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.search-clear.visible {
  display: flex;
}

/* ===== Header Actions ===== */
.header-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.action-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.action-btn.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.action-btn .badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

/* ===== Layout ===== */
.app-layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 70px);
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  position: sticky;
  top: 70px;
  height: calc(100vh - 70px);
  overflow-y: auto;
  padding: 16px 0 16px 16px;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  padding: 8px 12px;
  margin-top: 8px;
}

.sidebar-title:first-child {
  margin-top: 0;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  user-select: none;
}

.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}

.sidebar-item .icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-item .count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  padding: 24px;
  min-width: 0;
}

/* ===== Collected Bar ===== */
.collected-bar {
  display: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 20px;
  align-items: center;
  gap: 12px;
}

.collected-bar.visible {
  display: flex;
}

.collected-bar-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.collected-symbols {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 20px;
  min-height: 32px;
  align-items: center;
}

.collected-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.collected-actions button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
  color: var(--text-secondary);
}

.collected-actions button:hover {
  background: var(--bg-hover);
}

.collected-actions button.copy-all {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.collected-actions button.copy-all:hover {
  background: var(--accent-hover);
}

/* ===== Section ===== */
.section {
  margin-bottom: 36px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .icon {
  font-size: 20px;
}

.section-count {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ===== Symbol Grid ===== */
.symbol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 4px;
}

.symbol-grid.emoji-grid {
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
}

.symbol-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  font-size: 22px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  border: 1px solid transparent;
}

.symbol-item:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  transform: scale(1.15);
  z-index: 2;
  box-shadow: var(--shadow-md);
}

.symbol-item:active {
  transform: scale(0.95);
}



/* ===== Subsection ===== */
.subsection {
  margin-bottom: 20px;
}

.subsection-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  padding-left: 4px;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state-text {
  font-size: 16px;
}

.empty-state-hint {
  font-size: 13px;
  margin-top: 6px;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text-primary);
  color: white;
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 18px;
  font-family: var(--font);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.5s forwards;
  white-space: nowrap;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
}

/* ===== Back to Top ===== */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: var(--shadow-md);
  transition: all var(--transition);
  opacity: 0;
  pointer-events: none;
  z-index: 99;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  background: var(--bg);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* ===== Mobile Sidebar Toggle ===== */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: var(--shadow-md);
  z-index: 99;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 200;
}

/* ===== Search Results Info ===== */
.search-info {
  display: none;
  padding: 12px 16px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--accent);
  align-items: center;
  gap: 8px;
}

.search-info.visible {
  display: flex;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .header-inner {
    padding: 0;
  }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    height: 100vh;
    width: 250px;
    background: var(--bg);
    z-index: 300;
    padding: 80px 12px 24px 12px;
    transition: left 0.3s ease;
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: var(--shadow-lg);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .sidebar-toggle {
    display: flex;
  }

  .main-content {
    padding: 16px;
  }

  .symbol-grid {
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  }

  .search-wrapper {
    max-width: 100%;
    order: 10;
    min-width: 100%;
  }

  .header-actions {
    margin-left: auto;
  }
}

@media (max-width: 600px) {
  .header {
    padding: 10px 12px;
  }

  .logo {
    font-size: 16px;
  }

  .mode-tab {
    padding: 6px 14px;
    font-size: 13px;
  }

  .action-btn span:not(.badge) {
    display: none;
  }

  .collected-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .section-title {
    font-size: 16px;
  }
}

/* ===== Selection Highlight ===== */
::selection {
  background: var(--accent-light);
  color: var(--accent);
}

/* ===== Loading Skeleton ===== */
.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-hover) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}