/*
 * Layout-only stylesheet: spacing, sizing, typography scale and responsive behaviour.
 * Deliberately sets no colours or backgrounds (see issue #16); borders use currentColor.
 * Breakpoints: <= 40rem phones, 40-64rem tablets, > 64rem desktops.
 */

/* ---- base ------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  line-height: 1.6;
  overflow-wrap: break-word;
}

body > header,
body > main,
body > footer {
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2.5rem);
}

body > main {
  flex: 1 0 auto;
  padding-block: 1.5rem 3rem;
}

body > footer {
  padding-block: 1.5rem;
  border-top: 1px solid;
}

/* ---- typography ------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
  margin-block: 1.5em 0.5em;
  text-wrap: balance;
}

h1 { font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.5rem); }
h2 { font-size: clamp(1.5rem, 1.25rem + 1vw, 2rem); }
h3 { font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem); }
h4 { font-size: 1.125rem; }

h1 a {
  text-decoration: none;
}

p, ul, ol, dl, table, pre, blockquote, figure {
  margin-block: 0 1rem;
}

small {
  font-size: 0.875em;
}

time {
  white-space: nowrap;
}

/* ---- site header & navigation ----------------------------------------- */

body > header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
  padding-block: 1rem;
  border-bottom: 1px solid;
}

body > header h1 {
  margin: 0;
  flex: 1 1 auto;
}

body > header > p {
  flex-basis: 100%;
  margin: 0;
  order: 1;
}

body > header nav {
  flex: 0 1 auto;
  order: 2;
  margin-left: auto;
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
}

nav li,
nav form {
  margin: 0;
}

nav button {
  padding: 0.25rem 0.5rem;
}

/* Admin sub-navigation sits on its own row above the panel. */
main > nav {
  margin-block: 0 1.5rem;
  padding-block: 0.5rem;
  border-bottom: 1px solid;
}

/* ---- flash messages ---------------------------------------------------- */

.flashes {
  list-style: none;
  padding: 0;
  margin-block: 0 1.5rem;
}

.flash {
  padding: 0.75rem 1rem;
  border: 1px solid;
  margin-block: 0 0.5rem;
}

/* ---- content: posts, markdown, comments -------------------------------- */

#post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#post-list > li {
  padding-block: 1.25rem;
  border-bottom: 1px solid;
}

#post-list article h3 {
  margin-block: 0 0.25rem;
}

#post-list article p {
  margin-block: 0 0.5rem;
}

#load-more {
  padding-block: 1.5rem;
  text-align: center;
  border-bottom: 0;
}

article > header p {
  margin-block: 0 1.5rem;
}

.post-body {
  max-width: 70ch;
}

.post-body img,
.post-body video,
.post-body iframe {
  max-width: 100%;
  height: auto;
}

.post-body h2,
.post-body h3 {
  margin-top: 2em;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 1rem;
  border: 1px solid;
  line-height: 1.45;
  -webkit-overflow-scrolling: touch;
}

code, kbd, samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

pre code {
  font-size: inherit;
}

blockquote {
  margin-inline: 0;
  padding-inline-start: 1rem;
  border-inline-start: 3px solid;
}

hr {
  border: 0;
  border-top: 1px solid;
  margin-block: 2rem;
}

#comments {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid;
  max-width: 70ch;
}

.comment-list {
  list-style: none;
  padding: 0;
}

.comment-list > li {
  padding-block: 1rem;
  border-bottom: 1px solid;
}

.comment-list article p {
  margin-block: 0 0.5rem;
}

/* ---- forms --------------------------------------------------------------- */

form p {
  margin-block: 0 1rem;
}

label {
  display: block;
  margin-block-end: 0.25rem;
}

label small {
  display: block;
}

/* Checkbox labels keep the control inline with their text. */
label:has(input[type="checkbox"]) {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
select,
textarea {
  display: block;
  width: 100%;
  max-width: 40rem;
  padding: 0.5rem 0.75rem;
  font: inherit;
  border: 1px solid;
}

textarea {
  max-width: none;
  min-height: 6rem;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.95em;
  line-height: 1.5;
}

button,
input[type="submit"] {
  font: inherit;
  padding: 0.5rem 1rem;
  border: 1px solid;
  cursor: pointer;
  touch-action: manipulation;
}

/* Comfortable touch targets on coarse pointers (phones, tablets). */
@media (pointer: coarse) {
  button,
  input[type="submit"],
  nav a {
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
  }
}

/* ---- tables (admin lists) ------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}

th, td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid;
}

thead th {
  border-bottom-width: 2px;
  white-space: nowrap;
}

td form {
  display: inline-block;
  margin: 0;
}

td form button {
  padding: 0.25rem 0.5rem;
}

td > a + form,
td > form + form,
td > form + a {
  margin-inline-start: 0.5rem;
}

/* Tables scroll sideways on narrow screens instead of squashing columns. */
@media (max-width: 64rem) {
  table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th, td {
    white-space: nowrap;
  }

  td:nth-child(2),
  td:nth-child(3) {
    white-space: normal;
    min-width: 12rem;
  }
}

/* ---- definition lists (dashboard, account) ------------------------------ */

dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1.5rem;
  max-width: 40rem;
}

dt {
  font-weight: 600;
}

dd {
  margin: 0;
}

/* ---- post editor: form and live preview side by side on wide screens ---- */

.editor-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

.editor-layout textarea[name="content"] {
  min-height: 24rem;
}

.editor-layout .editor-preview {
  min-width: 0;
}

.editor-layout .editor-preview #preview {
  padding: 1rem;
  border: 1px dashed;
  min-height: 10rem;
}

@media (min-width: 64rem) {
  .editor-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }

  .editor-layout .editor-preview {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
}

/* ---- small screens ------------------------------------------------------- */

@media (max-width: 40rem) {
  body > header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  body > header nav {
    margin-left: 0;
  }

  nav ul {
    gap: 0.25rem 0.75rem;
  }

  dl {
    grid-template-columns: 1fr;
    gap: 0;
  }

  dt {
    margin-top: 0.5rem;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
  select {
    max-width: none;
  }

  button,
  input[type="submit"] {
    width: 100%;
  }

  nav button,
  td form button,
  #load-more button {
    width: auto;
  }
}

/* ---- HTMX request indicator ---------------------------------------------- */
/* HTMX's own injected <style> is disabled (CSP has no 'unsafe-inline'), so the
   standard indicator classes are defined here instead. */

.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

.htmx-request #load-more button {
  opacity: 0.5;
  pointer-events: none;
}

/* ---- print ------------------------------------------------------------------ */

@media print {
  body > header nav,
  body > footer,
  #comments form,
  main > nav {
    display: none;
  }

  body > main {
    max-width: none;
    padding: 0;
  }
}
