:root {
  --glyph-size: 28px;
  --card-size: 130px;
}

body { overflow-x: hidden; }

nav {
  background: var(--surface-raised);
  position: sticky;
  top: 0;
  z-index: 10;
}

.toolbar {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
  position: sticky;
  top: var(--nav-height, 57px);
  z-index: 9;
}

.toolbar-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar-hint {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 6px;
}

#search {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
#search:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

#set-filter, #sort-order {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  cursor: pointer;
}
#set-filter:focus, #sort-order:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

#count {
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}

#grid {
  position: relative;
  overflow-y: auto;
  padding: 12px 16px;
}

#container { position: relative; }

.card {
  position: absolute;
  width: var(--card-size);
  height: var(--card-size);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
  padding: 4px;
  user-select: none;
}

.card:hover,
.card:focus-visible {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--glow);
}
.card:focus { outline: none; }

.card.collected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.card .collect-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  display: none;
}

.card.collected .collect-badge { display: block; }

.card .glyph {
  font-family: 'LowGravitasSymbols', monospace;
  font-size: var(--glyph-size);
  line-height: 1;
  margin-bottom: 4px;
}

.card .name {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}

.card .set {
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}

.card .cp {
  font-size: 10px;
  color: var(--accent);
  font-family: monospace;
}

/* --- Detail modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, var(--backdrop-alpha));
  z-index: 50;
  opacity: 0;
  transition: opacity 150ms ease-out;
}
.modal-backdrop.visible { opacity: 1; }

.modal-dialog {
  position: fixed;
  z-index: 51;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0, var(--shadow-alpha));
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: 90vh;
  overflow-y: auto;
  top: 20%;
  left: 50%;
  transform: translateX(-50%) scale(0.95);
  opacity: 0;
  transition: opacity 150ms ease-out, transform 150ms ease-out;
  padding: 24px;
}
.modal-dialog.visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text);
  background: var(--bg);
}

.modal-specimen-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-top: 8px;
}

.modal-nav {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.modal-nav:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.modal-nav:disabled {
  opacity: 0.25;
  pointer-events: none;
}

.glyph-specimen {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-family: 'LowGravitasSymbols', monospace;
  font-size: 72px;
  line-height: 1;
  flex-shrink: 0;
}

.modal-info {
  text-align: center;
  margin-bottom: 20px;
}

.modal-info .glyph-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  word-break: break-word;
}

.modal-info .glyph-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.modal-info .glyph-meta .cp-val {
  color: var(--accent);
  font-family: monospace;
}

.modal-info .glyph-class {
  font-size: 12px;
  color: var(--text-dim);
  font-family: monospace;
  word-break: break-all;
}

.modal-actions {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.modal-actions button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  gap: 12px;
  min-height: 44px;
  transition: background 0.15s;
}
.modal-actions button:last-child { border-bottom: none; }
.modal-actions button:hover { background: var(--bg); }
.modal-actions button:focus { outline: none; }
.modal-actions button:focus-visible,
.modal-actions button.focus-force {
  background: var(--bg);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.modal-actions button .label {
  color: var(--text-dim);
  font-size: 12px;
  flex-shrink: 0;
}
.modal-actions button .label.mono { font-family: monospace; }
.modal-actions button .label.symbol { font-family: 'LowGravitasSymbols', monospace; font-size: 16px; }
.modal-actions button .copied {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

/* Consistent focus-visible for all modal interactive elements */
.modal-close:focus-visible,
.modal-nav:focus-visible,
.modal-footer button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.modal-footer {
  display: flex;
  gap: 8px;
}

.modal-footer button {
  flex: 1;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
  min-height: 44px;
}
.modal-footer button:hover { border-color: var(--accent); }
.modal-footer button.primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}
.modal-footer button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

@media (max-width: 520px) {
  .modal-dialog {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 12px 12px 0 0;
    transform: translateY(20px) scale(1);
    max-height: 80vh;
  }
  .modal-dialog.visible {
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal-backdrop,
  .modal-dialog,
  .toast,
  .card {
    transition: none;
  }
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--accent);
  color: var(--text-on-accent);
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  pointer-events: none;
  z-index: 100;
}

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

#selection-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 24px;
  display: none;
  box-shadow: 0 -4px 16px rgba(0,0,0,var(--shadow-alpha));
}

#selection-panel.visible {
  display: flex;
  align-items: center;
  gap: 12px;
}

#selection-panel .sel-icons {
  flex: 1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  font-family: 'LowGravitasSymbols', monospace;
  font-size: 20px;
  padding: 2px 0;
}

#selection-panel .sel-icon {
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s;
  flex-shrink: 0;
}

#selection-panel .sel-icon:hover { background: var(--border); }

#selection-panel .sel-count {
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}

#selection-panel button {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s;
}

#selection-panel button:hover { border-color: var(--accent); }

#selection-panel button.primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

#selection-panel button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-dim);
  font-size: 14px;
}

footer {
  position: sticky;
  bottom: 0;
  background: var(--surface-raised);
  z-index: 8;
}
