/* Self-hosted Inter (not Google Fonts' CDN) so type doesn't depend on a
   request to fonts.googleapis.com, which ad-blockers/privacy extensions
   often block by default. See public/fonts/LICENSE-Inter-OFL.txt. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/inter-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/inter-latin-700-normal.woff2") format("woff2");
}

:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --color-bg: #ffffff;
  --color-bg-wash: rgba(38, 110, 115, 0.06);
  --color-fg: #171717;
  --color-fg-muted: #525252;
  --color-border: #e5e5e5;
  --color-card-bg: #ffffff;
  --color-input-bg: #ffffff;

  --color-accent: #266e73;
  --color-accent-hover: #1d5458;
  --color-accent-fg: #ffffff;
  --color-accent-soft: #e7f2f2;
  --color-accent-soft-border: #b9dada;

  --color-danger: #b91c1c;
  --color-danger-bg: #fef2f2;

  --radius-card: 0.625rem;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 20px -14px rgba(15, 23, 42, 0.12);
  --shadow-focus: 0 0 0 3px rgba(38, 110, 115, 0.25);
}

html.dark {
  --color-bg: #0a0a0a;
  --color-bg-wash: rgba(48, 158, 166, 0.12);
  --color-fg: #f5f5f5;
  --color-fg-muted: #a3a3a3;
  --color-border: #262626;
  --color-card-bg: #141414;
  --color-input-bg: #0a0a0a;

  --color-accent: #309ea6;
  --color-accent-hover: #4eb4bc;
  --color-accent-fg: #ffffff;
  --color-accent-soft: rgba(48, 158, 166, 0.12);
  --color-accent-soft-border: rgba(48, 158, 166, 0.35);

  --color-danger: #f87171;
  --color-danger-bg: #2a1414;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -16px rgba(0, 0, 0, 0.45);
  --shadow-focus: 0 0 0 3px rgba(48, 158, 166, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  background-color: var(--color-bg);
  color: var(--color-fg);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--color-fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image: radial-gradient(1200px 560px at 50% -12%, var(--color-bg-wash), transparent 60%);
  background-color: var(--color-bg);
  background-repeat: no-repeat;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-fg);
  text-decoration: none;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle,
.admin-link,
.expand-editor {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  padding: 0.375rem 0.625rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.25;
  cursor: pointer;
  color: var(--color-fg);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.theme-toggle:hover,
.admin-link:hover,
.expand-editor:hover {
  border-color: var(--color-accent-soft-border);
  background-color: var(--color-accent-soft);
}

.expand-editor {
  justify-content: center;
  padding: 0.375rem;
  color: var(--color-fg-muted);
}

.expand-editor svg {
  display: block;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1.25rem;
  width: 100%;
}

.card {
  width: 100%;
  max-width: 720px;
  background-color: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
}

.card + .card {
  margin-top: 1.5rem;
}

.card-wide {
  max-width: 960px;
}

/* Expanded editor: break the card out of its frame and let it consume the whole
   main area — flush to the edges, no max-width, no card chrome. The class lives
   on <body> (see editor.js) so it can zero out main's padding too. */
body.editor-expanded main {
  padding: 0;
}

body.editor-expanded .card-wide {
  max-width: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.admin-header h1 {
  margin: 0 0 0.25rem;
}

.admin-header .subtitle {
  margin: 0;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.5rem 0 1rem;
}

.admin-search {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}

.admin-search input[type="search"] {
  width: auto;
  min-width: 220px;
}

.admin-bulk-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.admin-table-wrap {
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  overflow: hidden;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.admin-table th,
.admin-table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.admin-table tbody tr:last-child td {
  border-bottom: none;
}

.admin-table tbody tr:hover {
  background-color: var(--color-bg-wash);
}

.admin-table thead {
  background-color: var(--color-bg-wash);
}

.admin-table th {
  color: var(--color-fg-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-table td.actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn-sm {
  padding: 0.3125rem 0.625rem;
  font-size: 0.8125rem;
}

.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
}

.pagination-controls {
  display: flex;
  gap: 0.5rem;
}

.btn-secondary[aria-disabled="true"],
.btn-danger[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem;
}

.subtitle {
  color: var(--color-fg-muted);
  margin: 0 0 1.5rem;
  font-size: 0.9375rem;
}

.hint {
  color: var(--color-fg-muted);
  font-size: 0.875rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-fg-muted);
}

textarea,
input[type="text"],
input[type="search"] {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: var(--color-fg);
  background-color: var(--color-input-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea:focus,
input[type="text"]:focus,
input[type="search"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}

textarea {
  font-family: var(--font-mono);
  resize: vertical;
  min-height: 16rem;
}

button,
.btn-primary,
.btn-secondary,
.btn-danger {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.25;
  cursor: pointer;
  border-radius: 0.375rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

button:active,
.btn-primary:active,
.btn-secondary:active,
.btn-danger:active {
  transform: translateY(1px);
}

button:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-danger:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

button:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-primary {
  background-color: var(--color-accent);
  color: var(--color-accent-fg);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-accent-hover);
}

.btn-secondary {
  background-color: transparent;
  color: var(--color-fg);
  border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--color-accent-soft-border);
  background-color: var(--color-accent-soft);
}

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

.btn-danger:hover:not(:disabled) {
  border-color: var(--color-danger);
  background-color: var(--color-danger-bg);
}

.actions {
  display: flex;
  gap: 0.75rem;
}

.error {
  color: var(--color-danger);
  background-color: var(--color-danger-bg);
  border-radius: 0.375rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  margin: 0;
}

/* Editor (create/edit) */

/* Heading row: the h1 on the left, the expand button aligned to its far right. */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.editor-header h1 {
  margin: 0;
}

.editor-title {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.view-link {
  font-size: 0.875rem;
  color: var(--color-accent);
  text-decoration: none;
}

.view-link:hover {
  text-decoration: underline;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.editor-tabs {
  display: flex;
  gap: 0.25rem;
}

.editor-tab {
  background: none;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-fg-muted);
  cursor: pointer;
}

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

/* The global `button { display: inline-flex }` rule (author origin) beats the
   UA `[hidden] { display: none }`, so a plain `hidden` attribute won't hide a
   tab button. Re-assert it with enough specificity to win. */
.editor-tab[hidden] {
  display: none;
}

.editor-tab.active {
  background-color: var(--color-accent-soft);
  border-color: var(--color-accent-soft-border);
  color: var(--color-accent);
}

.expand-editor.active {
  background-color: var(--color-accent-soft);
  border-color: var(--color-accent-soft-border);
  color: var(--color-accent);
}

.editor-panes {
  display: block;
}

.editor-panes[data-split="true"] {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

.editor-pane textarea {
  min-height: 20rem;
}

.editor-pane .page {
  max-width: none;
  min-height: 20rem;
  box-shadow: none;
}

.cheatsheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.cheatsheet-table th,
.cheatsheet-table td {
  border: 1px solid var(--color-border);
  padding: 0.5em 0.75em;
  text-align: left;
  vertical-align: top;
}

.cheatsheet-table code {
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background-color: var(--color-bg-wash);
  border-radius: 0.25rem;
  padding: 0.1em 0.35em;
}

.metadata-panel {
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 0.875rem 1rem;
}

.metadata-panel summary {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-fg-muted);
}

.metadata-panel[open] summary {
  margin-bottom: 1rem;
}

.metadata-fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.field,
.metadata-fields > div {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

/* The author display:flex above beats the UA `[hidden] { display: none }`,
   so editor.js hiding the slug field on the How tab needs this to take. */
.field[hidden] {
  display: none;
}

.field-inline {
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
}

.field-inline label {
  flex-shrink: 0;
}

.field-inline input {
  flex: 1 1 auto;
  min-width: 0;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  color: var(--color-fg);
}

@media (max-width: 767px) {
  .expand-editor {
    display: none;
  }

  .editor-panes[data-split="true"] {
    display: block;
  }
}

.site-footer {
  text-align: center;
  padding: 1.5rem 1.25rem;
  color: var(--color-fg-muted);
  font-size: 0.8125rem;
}

.site-footer a {
  color: var(--color-accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* Page view */

.page-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  max-width: 720px;
  margin-top: 1.75rem;
  font-size: 0.875rem;
  color: var(--color-fg-muted);
}

.page {
  width: 100%;
  max-width: 720px;
  background-color: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: 2rem 2.25rem;
  box-shadow: var(--shadow-card);
  line-height: 1.65;
  word-wrap: break-word;
}

.page h1,
.page h2,
.page h3,
.page h4,
.page h5,
.page h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 1.5em 0 0.5em;
}

.page h1:first-child,
.page h2:first-child,
.page h3:first-child {
  margin-top: 0;
}

.page h1 {
  font-size: 1.75rem;
}
.page h2 {
  font-size: 1.375rem;
}
.page h3 {
  font-size: 1.125rem;
}

.page p {
  margin: 0 0 1em;
}

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

.page code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: var(--color-bg-wash);
  border-radius: 0.25rem;
  padding: 0.15em 0.4em;
}

.page pre {
  background-color: var(--color-input-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 1rem;
  overflow-x: auto;
}

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

.page blockquote {
  margin: 0 0 1em;
  padding: 0.25em 1em;
  border-left: 3px solid var(--color-accent-soft-border);
  color: var(--color-fg-muted);
}

.page ul,
.page ol {
  margin: 0 0 1em;
  padding-left: 1.5em;
}

.page img {
  max-width: 100%;
  border-radius: 0.375rem;
}

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

.page table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1em;
  font-size: 0.9375em;
}

.page th,
.page td {
  border: 1px solid var(--color-border);
  padding: 0.5em 0.75em;
  text-align: left;
}

/* Public slug view: the rendered content stands on its own — keep the 720px
   measure and typography from .page, but drop the card chrome and padding. */
.page-bare {
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}

/* Phones ------------------------------------------------------------------
   A 360px viewport can't afford three nested gutters (main + card + inner
   panel), so on small screens `main` owns the only page margin and the card
   goes full-bleed: no border, shadow, radius, or padding of its own. What's
   left is the content, aligned with the header and footer. */
@media (max-width: 640px) {
  .site-header {
    padding: 0.5rem 1rem;
  }

  .header-actions {
    gap: 0.375rem;
  }

  .theme-toggle,
  .admin-link {
    font-size: 0.875rem;
    padding: 0.5rem 0.625rem;
  }

  .editor-tab {
    padding: 0.5rem 0.75rem;
  }

  main {
    padding: 1.25rem 1rem 2rem;
  }

  .card,
  .page {
    background: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }

  .card + .card {
    margin-top: 1.25rem;
  }

  .site-footer {
    padding: 1.25rem 1rem;
  }

  .subtitle {
    margin-bottom: 1rem;
  }

  form {
    gap: 1rem;
  }

  /* 16px is the threshold below which iOS Safari zooms the viewport on focus. */
  textarea,
  input[type="text"],
  input[type="search"] {
    font-size: 1rem;
  }

  /* Roomier tap targets than the desktop 15px/8px buttons. */
  button,
  .btn-primary,
  .btn-secondary,
  .btn-danger {
    padding: 0.5625rem 0.875rem;
  }

  .btn-sm {
    padding: 0.375rem 0.625rem;
  }

  .metadata-fields {
    grid-template-columns: 1fr;
  }

  .metadata-panel {
    padding: 0.75rem 0.875rem;
  }

  /* Side-by-side leaves the input too narrow to read its own placeholder. */
  .field-inline {
    flex-direction: column;
    align-items: stretch;
    gap: 0.375rem;
  }

  .page-meta {
    margin-top: 1.25rem;
  }

  /* A rendered table is the one thing that can't be reflowed to fit — let it
     scroll inside its own box instead of widening the page. */
  .page table {
    display: block;
    overflow-x: auto;
  }

  /* The cheatsheet's two columns do fit; it's the unbreakable code samples
     that push it wide. */
  .cheatsheet-table code {
    word-break: break-word;
  }

  /* Bigger than the ~13px default so row selection is tappable. */
  input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
  }

  .admin-header {
    flex-wrap: wrap;
  }

  .admin-toolbar {
    margin: 1.25rem 0 0.875rem;
  }

  .admin-search {
    flex-wrap: wrap;
  }

  /* Let the field shrink so it keeps the Search button company; the 220px
     desktop minimum forces the button onto its own line. */
  .admin-search input[type="search"] {
    flex: 1 1 8rem;
    min-width: 0;
  }

  /* Nothing selected means nothing to delete — reclaim the row rather than
     parking a permanently disabled button above the list. */
  .admin-bulk-actions:has(button:disabled) {
    display: none;
  }

  /* One block per page instead of six columns fighting over 320px:
       [x] slug
           owner · date · N views
           [Edit] [Delete] */
  .admin-table,
  .admin-table thead,
  .admin-table tbody,
  .admin-table tr,
  .admin-table th,
  .admin-table td {
    display: block;
  }

  .admin-table th,
  .admin-table td {
    border: none;
    padding: 0;
  }

  .admin-table thead tr {
    padding: 0.5rem 0.875rem;
    border-bottom: 1px solid var(--color-border);
  }

  /* Column headings have nothing to label once the row is a block, but the
     select-all checkbox still needs to be reachable, so it keeps a visible
     row of its own with a generated label (the input carries the aria-label). */
  .admin-table th {
    display: none;
  }

  .admin-table th.col-select {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .admin-table th.col-select::after {
    content: "Select all";
  }

  /* The checkbox sits in the padding gutter so every line of the row — slug,
     meta, actions — shares one left edge and wrapped text doesn't slide back
     underneath it. */
  .admin-table tbody tr {
    position: relative;
    padding: 0.75rem 0.875rem 0.75rem 2.5rem;
    border-bottom: 1px solid var(--color-border);
  }

  .admin-table tbody tr:last-child {
    border-bottom: none;
  }

  .admin-table td.col-select {
    position: absolute;
    top: 0.8125rem;
    left: 0.875rem;
  }

  .admin-table td.col-slug {
    font-weight: 500;
    word-break: break-word;
  }

  /* Inline so the three read as one line. Dates and view counts get nowrap so
     a break lands between them, not inside "12 views"; an email can be long
     enough to need breaking, so it keeps normal wrapping. */
  .admin-table td.col-owner,
  .admin-table td.col-created,
  .admin-table td.col-views {
    display: inline;
    font-size: 0.8125rem;
    color: var(--color-fg-muted);
  }

  .admin-table td.col-owner {
    overflow-wrap: anywhere;
  }

  .admin-table td.col-created,
  .admin-table td.col-views {
    white-space: nowrap;
  }

  .admin-table td.col-owner::after,
  .admin-table td.col-created::after {
    content: "·";
    margin: 0 0.375rem;
  }

  .admin-table td.col-views::after {
    content: " views";
  }

  .admin-table td.actions {
    justify-content: flex-start;
    margin-top: 0.5rem;
  }

  .admin-pagination {
    margin-top: 0.875rem;
  }
}
