/* The guides palette: a natural white (just off #FFFFFF) with warm grays and the
   app's own blue for links. Contrast (WCAG): text on the background 16.4:1,
   muted text 6.9:1, accent 6.6:1; on a white surface 16.8 / 7.1 / 6.8; white on
   the accent 6.8; all above the 4.5:1 AA minimum. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/inter-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;

  --background: #fcfcfb; /* the page: natural white */
  --surface: #ffffff; /* cards and panels raised off the page */
  --text: #1f1d1a; /* body text, headings */
  --muted: #5c5850; /* secondary text, captions */
  --border: #e7e3db; /* dividers and outlines */
  --chip: #f0ede6; /* resting chips and quiet buttons */
  --accent: #1051cf; /* links and buttons (the app's blue) */
  --accent-on: #ffffff; /* text on the accent */
  --accent-soft: #e8eefa; /* a light wash of the accent: highlights, hovers */
  --danger: #a32d2d; /* errors and delete */

  /* The tile a card shows when its guide has no picture. */
  --tile-bg: #f1efe8;
  --tile-ink: #444441;

  --radius: 12px;
  --page-pad: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

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

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

[hidden] {
  display: none !important;
}

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

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px var(--page-pad);
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

.brand span {
  color: var(--accent);
}

.search {
  position: relative;
  flex: 1;
  max-width: 640px;
  margin: 0 auto;
}

.search input {
  width: 100%;
  height: 40px;
  padding: 0 16px 0 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

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

.search svg {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

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

/* Buttons */
.button {
  height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--chip);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  background: var(--border);
}

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

.button--primary:hover {
  background: #0d44ad;
}

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

.button--danger:hover {
  background: #fbeaea;
}

.button[disabled] {
  opacity: 0.6;
  cursor: default;
}

/* The grid of guides */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px var(--page-pad) 64px;
}

.section-title {
  margin: 24px 0 12px;
  font-size: 18px;
  font-weight: 600;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
}

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

.sort {
  flex: none;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 24px 16px;
  margin-top: 12px;
  padding: 0;
  list-style: none;
}

.card {
  position: relative;
}

.card-link {
  display: block;
  border-radius: var(--radius);
}

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--tile-bg);
  color: var(--tile-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.card-link:hover .thumb img {
  transform: scale(1.03);
}

.thumb-initials {
  font-size: 40px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--text);
  color: var(--background);
  font-size: 12px;
  font-weight: 500;
}

.badge--draft {
  right: auto;
  left: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.card-title {
  margin: 10px 0 2px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.card-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.card-edit:hover {
  background: var(--accent-soft);
}

.skeleton .thumb {
  background: var(--chip);
}

.skeleton .line {
  height: 14px;
  margin-top: 10px;
  border-radius: 4px;
  background: var(--chip);
}

.skeleton .line--short {
  width: 55%;
}

@media (prefers-reduced-motion: no-preference) {
  .skeleton .thumb,
  .skeleton .line {
    animation: pulse 1.4s ease-in-out infinite;
  }
}

@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}

.message {
  max-width: 440px;
  margin: 72px auto;
  text-align: center;
  color: var(--muted);
}

.message h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: var(--text);
}

.footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--page-pad) 32px;
  font-size: 13px;
  color: var(--muted);
}

.footer button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* A single guide */
.article {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px var(--page-pad) 80px;
}

.back {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}

.back:hover {
  text-decoration: underline;
}

.article h1 {
  margin: 0 0 6px;
  font-size: 32px;
  line-height: 1.2;
}

.article .meta {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 15px;
}

.article .cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: 24px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--chip);
}

.prose h2,
.prose h3,
.prose h4 {
  margin: 1.6em 0 0.4em;
  line-height: 1.3;
}

.prose h2 {
  font-size: 24px;
}

.prose h3 {
  font-size: 20px;
}

.prose h4 {
  font-size: 17px;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose pre {
  margin: 0 0 1em;
}

.prose ul,
.prose ol {
  padding-left: 1.4em;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1em 0;
  border-radius: 8px;
}

.prose blockquote {
  padding: 8px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}

.prose code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--chip);
  font-size: 0.92em;
}

.prose pre {
  padding: 12px 16px;
  overflow-x: auto;
  border-radius: 8px;
  background: var(--chip);
}

.prose pre code {
  padding: 0;
  background: none;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

/* The editor (admins) */
dialog.editor {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}

dialog.editor::backdrop {
  background: rgba(31, 29, 26, 0.45);
}

.editor form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
}

.editor h2 {
  margin: 0;
  font-size: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label,
.field .label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
}

.field textarea {
  min-height: 200px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
}

.row {
  display: flex;
  gap: 12px;
}

.row .field {
  flex: 1;
}

.key-input {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--muted);
  font-size: 15px;
}

.key-input:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field .key-input input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--text);
}

.field .key-input input[type="text"]:disabled {
  color: var(--muted);
}

.thumb-picker {
  display: flex;
  align-items: center;
  gap: 12px;
}

.thumb-picker .preview {
  width: 160px;
  flex: none;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  background: var(--chip);
  object-fit: cover;
}

.hint {
  font-size: 13px;
  color: var(--muted);
}

.error {
  min-height: 1.2em;
  margin: 0;
  font-size: 14px;
  color: var(--danger);
}

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

.actions .spacer {
  flex: 1;
}

/* The buttons stay in view at the bottom of a tall editor. */
.actions--pinned {
  position: sticky;
  bottom: -24px;
  margin: 0 -24px -24px;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

@media (max-width: 640px) {
  :root {
    --page-pad: 16px;
  }

  .topbar {
    flex-wrap: wrap;
  }

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

  .article h1 {
    font-size: 26px;
  }

  .row {
    flex-direction: column;
  }
}
