/* ==========================================================================
   hardluau — design tokens
   Palette: instrument-panel dark, not the generic near-black+neon default.
   Base charcoal with a warm diagnostic amber (primary) and a cool cyan
   (secondary, links/interactive). Difficulty runs its own green→red scale
   so a row's severity reads before you even reach the label.
   ========================================================================== */
:root {
  --bg: #14161b;
  --bg-raised: #1a1d24;
  --bg-inset: #101216;
  --line: #2b2f38;
  --line-soft: #22252c;
  --text: #dfe3ea;
  --text-dim: #8b93a3;
  --text-faint: #5c6373;

  --amber: #e2a63d;
  --amber-dim: #8a6a33;
  --cyan: #5fc9c0;
  --cyan-dim: #3a6a66;

  --diff-trivial: #6fbf6f;
  --diff-easy: #6fc2bf;
  --diff-medium: #dcb24f;
  --diff-hard: #d98f4e;
  --diff-pathological: #d9655f;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 4px;
  --radius-sm: 3px;
}

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

* { box-sizing: border-box; }

/* The hidden attribute must always win over layout display rules
   (e.g. .viewer-backdrop's display:flex), otherwise toggling .hidden
   does nothing and hidden overlays still intercept pointer events. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--amber);
  color: #14161b;
  padding: 8px 14px;
  z-index: 500;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

a { color: var(--cyan); }

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------- */
/* Top bar                                                                 */
/* ---------------------------------------------------------------------- */

.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}

.brand-mark {
  font-family: var(--font-mono);
  color: var(--amber);
  font-size: 15px;
}

.brand-name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 460px;
}

#search {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 34px 8px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-ui);
}

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

.search-hint {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text-faint);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.repo-link {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
  flex-shrink: 0;
}
.repo-link:hover { color: var(--cyan); }

.stats-bar {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px 12px;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.stats-bar .stat-value { color: var(--text); }

/* ---------------------------------------------------------------------- */
/* Layout                                                                  */
/* ---------------------------------------------------------------------- */

.layout {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 28px;
  padding: 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 96px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.filter-group h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  margin: 0 0 10px;
  text-transform: none;
}

.chip-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: left;
}

.chip:hover {
  background: var(--bg-raised);
  color: var(--text);
}

.chip[aria-pressed="true"] {
  background: var(--bg-inset);
  border-color: var(--line);
  color: var(--text);
}

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

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.chip-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

.reset-btn {
  align-self: flex-start;
  background: none;
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.reset-btn:hover { color: var(--text); border-color: var(--text-faint); }

.sidebar-note {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.6;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
  margin: 0;
}
.sidebar-note code {
  font-family: var(--font-mono);
  color: var(--text-dim);
}

/* ---------------------------------------------------------------------- */
/* Entry list                                                              */
/* ---------------------------------------------------------------------- */

.main { min-width: 0; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

#sort-select {
  background: var(--bg-inset);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 12.5px;
}

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.entry-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-raised);
  cursor: pointer;
}

.entry-row:last-child { border-bottom: none; }

.entry-row:hover,
.entry-row.is-active {
  background: var(--bg-inset);
}

.entry-row.is-keyboard-focus {
  box-shadow: inset 2px 0 0 var(--amber);
}

.entry-diff-mark {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-top: 6px;
  flex-shrink: 0;
}

.entry-main { min-width: 0; flex: 1; }

.entry-file {
  display: block;
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--text);
  word-break: break-word;
}

.entry-file mark,
.entry-desc mark {
  background: var(--amber-dim);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

.entry-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.entry-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-inset);
  border: 1px solid var(--line-soft);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.entry-category-badge {
  flex-shrink: 0;
  font-size: 11.5px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  padding-top: 2px;
  white-space: nowrap;
}

.empty-state, .error-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}

.empty-state button, .error-state button {
  margin-top: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}

.error-state { border-color: var(--diff-hard); color: var(--text); }

/* ---------------------------------------------------------------------- */
/* Viewer                                                                  */
/* ---------------------------------------------------------------------- */

.viewer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 11, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  z-index: 100;
}

.viewer {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: min(900px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}

.viewer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px 0;
}

.viewer-heading h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.viewer-path {
  margin: 3px 0 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
}

.viewer-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.btn:hover { border-color: var(--text-faint); }

.btn-icon { padding: 6px 9px; }

.viewer-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 18px 0;
  flex-wrap: wrap;
}

.meta-pill {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.viewer-description {
  padding: 10px 18px 0;
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.viewer-body {
  flex: 1;
  overflow: auto;
  margin: 14px 18px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  position: relative;
}

.code-pane {
  margin: 0;
  padding: 14px 0;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  counter-reset: line;
  tab-size: 2;
}

.code-pane code {
  display: block;
}

.code-line {
  display: block;
  padding: 0 16px 0 0;
  position: relative;
}

.code-line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 42px;
  margin-right: 14px;
  padding-right: 8px;
  text-align: right;
  color: var(--text-faint);
  user-select: none;
  position: sticky;
  left: 0;
  background: var(--bg-inset);
}

.viewer-loading, .viewer-error {
  padding: 30px 18px;
  color: var(--text-dim);
  font-size: 13px;
}
.viewer-error { color: var(--diff-hard); }

.viewer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px 16px;
}

.viewer-footer-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

/* Token colors */
.tok-comment { color: var(--text-faint); font-style: italic; }
.tok-string { color: #9fca7a; }
.tok-interp-brace { color: var(--amber); }
.tok-interp { color: var(--text); }
.tok-number { color: #c9a5e0; }
.tok-keyword { color: #e2a63d; }
.tok-luau-keyword { color: var(--cyan); }
.tok-attribute { color: var(--cyan); }
.tok-fn { color: #7fb7e8; }
.tok-self { color: #d98f4e; font-style: italic; }
.tok-op { color: var(--text-dim); }
.tok-ident { color: var(--text); }

/* ---------------------------------------------------------------------- */
/* Responsive                                                              */
/* ---------------------------------------------------------------------- */

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 18px;
  }
  .sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
  }
  .filter-group { flex: 1 1 200px; }
  .search-wrap { max-width: none; }
  .topbar-inner { flex-wrap: wrap; }
  .repo-link { display: none; }
  .viewer-backdrop { padding: 0; }
  .viewer { max-height: 100vh; height: 100%; border-radius: 0; }
}

@media (max-width: 520px) {
  .entry-row { flex-wrap: wrap; }
  .entry-category-badge { order: -1; }
}
