:root {
  --background: #F7F2E8;
  --foreground: #18181B;
  --muted: #59524A;
  --surface: #FFFFFF;
  --surface-secondary: #EAE6DD;
  --surface-hover: #EAEAEA;
  --border: #DCD3C3;
  --separator: #DCD3C3;
  --field-background: #FFFFFF;
  --field-background-hover: #F9F9F9;
  --field-border: #DCD3C3;
  --field-border-hover: #C5BDB0;
  --field-border-focus: #AAA398;
  --field-foreground: #18181B;
  --field-placeholder: #59524A;
  --accent: #C8553D;
  --accent-foreground: #FCFCFC;
  --accent-hover: #D26E59;
  --accent-soft: rgba(200, 85, 61, 0.15);
  --accent-soft-foreground: #C8553D;
  --accent-soft-hover: rgba(200, 85, 61, 0.2);
  --focus: #C8553D;
  --danger: #E60026;
  --shadow-field: 0 2px 4px 0 rgba(0, 0, 0, 0.04), 0 1px 2px 0 rgba(0, 0, 0, 0.06), 0 0 1px 0 rgba(0, 0, 0, 0.06);

  --radius: 4px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --text-xs: 12px;
  --text-xs-lh: 16px;
  --text-sm: 14px;
  --text-sm-lh: 20px;
  --text-base: 16px;
  --text-base-lh: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #121214;
    --foreground: #FCFCFC;
    --muted: #A0A0A0;
    --surface: #1D1D20;
    --surface-secondary: #232323;
    --surface-hover: #2C2C2F;
    --border: #2C2C32;
    --separator: #2C2C32;
    --field-background: #181818;
    --field-background-hover: #1C1C1C;
    --field-border: #292929;
    --field-border-hover: #3B3B3B;
    --field-border-focus: #535353;
    --field-foreground: #FCFCFC;
    --field-placeholder: #A0A0A0;
    --shadow-field: 0 0 0 0 transparent inset;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  color: var(--foreground);
  background: var(--background);
  height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header {
  padding: 16px 16px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  font-weight: 600;
  letter-spacing: -0.005em;
}

#search {
  width: 100%;
  padding: 8px 12px;
  background: var(--field-background);
  color: var(--field-foreground);
  border: 1px solid var(--field-border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  outline: none;
  box-shadow: var(--shadow-field);
  transition: background 0.15s, border-color 0.15s;
}

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

#search:hover {
  background: var(--field-background-hover);
  border-color: var(--field-border-hover);
}

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

nav#tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px;
  border-bottom: 1px solid var(--separator);
  overflow-x: auto;
  scrollbar-width: thin;
  flex-shrink: 0;
}

.tab {
  appearance: none;
  background: transparent;
  border: none;
  padding: 8px 8px 10px;
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab small {
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  color: var(--muted);
  font-weight: 400;
  margin-left: 2px;
}

.tab:hover { color: var(--foreground); }

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

.tab.active small { color: var(--accent-soft-foreground); }

main {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

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

.icon-tile {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}

.icon-tile:hover {
  background: var(--accent-soft);
  color: var(--accent-soft-foreground);
}

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

.icon-tile:active { background: var(--accent-soft-hover); }

.icon-tile img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  pointer-events: none;
}

.icon-tile span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.icon-tile.inserting {
  opacity: 0.4;
  pointer-events: none;
}

.status {
  color: var(--muted);
  text-align: center;
  padding: 16px;
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  margin: 0;
}

.status.error { color: var(--danger); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }
