:root {
  --bg-canvas: #FAFAFA;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #EFF6FF;
  --bg-subtle: #F3F4F6;
  --border-color: #E5E7EB;
  --border-strong: #D1D5DB;
  --text-primary: #111827;
  --text-secondary: #4B5563;
  --text-muted: #6B7280;
  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --accent-tint: rgba(59, 130, 246, 0.1);
  --success: #10B981;
  --success-tint: rgba(16, 185, 129, 0.16);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-pill: 9999px;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-glyph-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols", "Noto Sans Symbols 2", "Apple Color Emoji", sans-serif;
  --font-glyph-serif: Georgia, "Times New Roman", "Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols", serif;
  --font-glyph-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Segoe UI Symbol", "Noto Sans Symbols", monospace;
}

[data-theme="dark"] {
  --bg-canvas: #0F172A;
  --bg-surface: #1E293B;
  --bg-surface-hover: #1E3A5F;
  --bg-subtle: #0B1220;
  --border-color: #334155;
  --border-strong: #475569;
  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-muted: #94A3B8;
  --accent: #3B82F6;
  --accent-hover: #60A5FA;
  --accent-tint: rgba(59, 130, 246, 0.18);
  --success: #34D399;
  --success-tint: rgba(52, 211, 153, 0.2);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.35);
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 1000;
  padding: 8px 14px;
  background: var(--accent);
  color: #FFFFFF;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  left: 12px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--text-primary);
  color: var(--bg-surface);
  font-size: 17px;
  line-height: 1;
}

/* Search */
.search-wrap {
  position: relative;
  flex: 1 1 260px;
  max-width: 440px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 54px 0 34px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

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

/* Hide browser native search cancel icon */
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-kbd {
  position: absolute;
  right: 10px;
  padding: 1px 6px;
  font-family: var(--font-glyph-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.search-clear[hidden] {
  display: none;
}

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

/* Controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.control-select,
.control-btn,
.icon-btn {
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.control-select {
  padding: 0 10px;
}

.control-select:hover,
.control-btn:hover,
.icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.control-select:focus-visible,
.control-btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
}

.collect-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background-color 0.15s ease;
}

.control-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent);
}

.control-btn[aria-pressed="true"] .collect-dot {
  background: var(--accent);
}

.icon-btn {
  width: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-sun {
  display: none;
}

.icon-moon {
  display: block;
}

[data-theme="dark"] .icon-sun {
  display: block;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

/* Category Navigation */
.category-bar {
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.category-pills {
  max-width: 1360px;
  margin: 0 auto;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-pills::-webkit-scrollbar {
  display: none;
}

.pill {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 13px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.pill:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: var(--bg-subtle);
}

.pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pill.is-active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--bg-surface);
}

/* Inspector Bar */
.inspector-bar {
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
}

.inspector-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
}

.inspector-preview {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-family: var(--font-glyph-sans);
  flex-shrink: 0;
}

.inspector-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.inspector-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.inspector-codes {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.code-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  font-family: var(--font-glyph-mono);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.inspector-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Main Grid */
.main-content {
  flex: 1;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
}

.character-grid.font-sans .char-glyph {
  font-family: var(--font-glyph-sans);
}

.character-grid.font-serif .char-glyph {
  font-family: var(--font-glyph-serif);
}

.character-grid.font-mono .char-glyph {
  font-family: var(--font-glyph-mono);
}

.char-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 64px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-sm);
  transition:
    transform 0.12s ease,
    border-color 0.12s ease,
    background-color 0.12s ease,
    box-shadow 0.12s ease;
}

.char-tile:hover {
  border-color: var(--accent);
  background: var(--bg-surface-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.char-tile:active {
  transform: scale(0.95);
}

.char-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.char-glyph {
  font-size: 30px;
  line-height: 1;
  pointer-events: none;
}

.char-tile.is-copied {
  border-color: var(--success);
  background: var(--success-tint);
  animation: tile-pop 0.35s ease;
}

.char-tile.is-copied::after {
  content: "Copied";
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--success);
  color: #FFFFFF;
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  pointer-events: none;
}

@keyframes tile-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-secondary);
}

.empty-state[hidden] {
  display: none;
}

.empty-glyph {
  margin: 0 0 8px;
  font-size: 42px;
  color: var(--text-muted);
}

.empty-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-sub {
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--text-muted);
}

.reset-btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.reset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Collect Staging Bar */
.collect-bar {
  position: sticky;
  bottom: 14px;
  z-index: 35;
  margin: 0 auto 12px;
  width: calc(100% - 40px);
  max-width: 960px;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px 14px;
}

.collect-bar[hidden] {
  display: none;
}

.collect-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.collect-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.collect-output {
  flex: 1 1 200px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-glyph-sans);
  font-size: 16px;
}

.collect-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.collect-btn {
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.collect-btn:hover {
  background: var(--bg-subtle);
}

.collect-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.collect-btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Footer */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.footer-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.recent-section[hidden] {
  display: none;
}

.recent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.recent-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.recent-clear {
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
}

.recent-clear:hover {
  color: var(--text-primary);
}

.recent-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.recent-item {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-glyph-sans);
  font-size: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.recent-item:hover {
  border-color: var(--accent);
  background: var(--bg-surface-hover);
}

.recent-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.footer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}

.footer-hint,
.footer-copy {
  margin: 0;
}

.footer-hint kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-canvas);
  font-family: var(--font-glyph-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  z-index: 60;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: var(--bg-surface);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

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

@media (max-width: 640px) {
  .header-inner {
    padding: 10px 14px;
    gap: 10px;
  }

  .search-wrap {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
  }

  .category-pills,
  .inspector-inner,
  .main-content,
  .footer-inner {
    padding-left: 14px;
    padding-right: 14px;
  }

  .inspector-count {
    display: none;
  }

  .collect-bar {
    width: calc(100% - 28px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
