:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --raised: #fafafa;
  --text: #18181b;
  --muted: #71717a;
  --border: #e4e4e7;
  --field: #d4d4d8;
  --accent: #2563eb;
  --accent-text: #1d4ed8;
  --on-accent: #ffffff;
  --danger: #b91c1c;
  --open: #2563eb;
  --planned: #b45309;
  --done: #15803d;
  --dismissed: #71717a;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 1px 3px rgb(0 0 0 / 0.06);
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #09090b;
    --surface: #18181b;
    --raised: #1f1f23;
    --text: #fafafa;
    --muted: #a1a1aa;
    --border: #27272a;
    --field: #3f3f46;
    --accent: #3b82f6;
    --accent-text: #60a5fa;
    --danger: #f87171;
    --open: #60a5fa;
    --planned: #fbbf24;
    --done: #4ade80;
    --dismissed: #a1a1aa;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

/* An element's own display rule would otherwise beat the attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

code,
pre {
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

button,
select,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--field);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 13px;
}

button:hover {
  background: var(--raised);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
.flag:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

button.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

button.danger {
  color: var(--danger);
}

button.icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  font-weight: 400;
}

select,
input[type='search'],
input[type='password'],
textarea {
  border: 1px solid var(--field);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 0;
}

textarea {
  width: 100%;
  resize: vertical;
}

/* The key gate */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.gate-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 8px;
}

.gate-card h1 {
  font-size: 18px;
  margin-bottom: 8px;
}

.gate-card label {
  font-size: 13px;
  color: var(--muted);
}

.gate-card button {
  margin-top: 8px;
}

.gate-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* The bar */

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px 0;
}

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

.bar-row h1 {
  font-size: 20px;
  flex: 1;
}

.bar-actions {
  display: flex;
  gap: 4px;
}

.filters {
  justify-content: space-between;
  margin-top: 8px;
}

.filter-fields {
  display: flex;
  gap: 8px;
  padding-bottom: 8px;
  flex-wrap: wrap;
}

.filter-fields input {
  width: 200px;
}

.filter-fields select {
  max-width: 260px;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.tabs button {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  padding: 8px 10px 10px;
  color: var(--muted);
  white-space: nowrap;
}

.tabs button[aria-selected='true'] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tabs .count {
  margin-left: 6px;
  font-weight: 500;
  color: var(--muted);
}

/* The list */

.list {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 24px 64px;
}

.group {
  margin-top: 24px;
}

.group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.group-head h2 {
  font-size: 15px;
}

.group-head code {
  color: var(--muted);
}

.group-head a {
  margin-left: auto;
  color: var(--accent-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.group-head a:hover {
  text-decoration: underline;
}

.flags {
  display: grid;
  gap: 8px;
}

.flag {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
  cursor: pointer;
  text-align: left;
}

.flag:hover {
  border-color: var(--field);
}

.thumb {
  width: 240px;
  height: 150px;
  border-radius: 6px;
  background-color: var(--raised);
  background-repeat: no-repeat;
  border: 1px solid var(--border);
}

.flag-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 4px 2px 0;
}

.flag-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}

.flag-top .num {
  font-weight: 700;
  color: var(--text);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-open {
  color: var(--open);
}

.status-planned {
  color: var(--planned);
}

.status-done {
  color: var(--done);
}

.status-dismissed {
  color: var(--dismissed);
}

.flag-top .when {
  margin-left: auto;
}

.note {
  margin: 0;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.where {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.decision {
  margin: 0;
  font-size: 13px;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
  white-space: pre-wrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 64px 16px;
}

.empty h2 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 4px;
}

/* One flag, close up */

.focus {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
}

.focus[open] {
  display: grid;
  grid-template-columns: 1fr 380px;
}

.focus::backdrop {
  background: rgb(0 0 0 / 0.4);
}

.focus-shot {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}

.focus-shot img {
  max-width: 100%;
  max-height: calc(100vh - 32px);
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
}

.noshot {
  color: var(--muted);
}

.focus-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* The panel scrolls; nothing in it should shrink to make room instead. */
.focus-panel > * {
  flex-shrink: 0;
}

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

.focus-head h2 {
  font-size: 18px;
  flex: 1;
}

.focus-nav {
  display: flex;
  gap: 4px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--field);
  border-radius: 6px;
  overflow: hidden;
  margin: 4px 0 8px;
}

.segmented button {
  border: 0;
  border-radius: 0;
  padding: 7px 4px;
  border-right: 1px solid var(--field);
  color: var(--muted);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button[aria-checked='true'] {
  background: var(--accent);
  color: var(--on-accent);
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 4px;
}

.saved {
  margin: 0;
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
}

.details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 4px 0;
  font-size: 13px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.details a {
  color: var(--accent-text);
}

.markup summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.markup pre {
  margin: 8px 0 0;
  padding: 8px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 240px;
  overflow-y: auto;
}

.focus-foot {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.keys {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #18181b;
  color: #fafafa;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 10;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.2);
}

@media (max-width: 760px) {
  .bar {
    padding: 12px 16px 0;
  }

  .list {
    padding: 12px 16px 48px;
  }

  .flag {
    grid-template-columns: 1fr;
  }

  .thumb {
    width: 100%;
  }

  .filter-fields input,
  .filter-fields select {
    width: 100%;
    max-width: none;
  }

  .filter-fields {
    width: 100%;
  }

  .focus[open] {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
  }

  .focus-shot img {
    max-height: 50vh;
  }

  .focus-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}
