/* GWiki base styles.
 *
 * Layout, spacing, readable widths and phone-friendly sizing, plus a colour
 * palette worked out from a few inputs. Themes (/theme/<name>.css, loaded
 * after this file) set the inputs on :root and everything else follows,
 * in light and dark. A theme may also override any derived value, but
 * must do so on :root: derived values are worked out where they are
 * declared (:root), so an input set on another element isn't seen.
 *
 * Needs browsers from 2024 on (color-mix(), light-dark()); older ones fall
 * back to their default colours.
 *
 * Mobile: everything is fluid; one breakpoint (40em) tightens spacing and
 * enlarges tap targets. Nothing should make the page scroll sideways: wide
 * tables and code scroll inside their own box, media shrinks to fit, long
 * words and paths wrap.
 */

:root {
  /* ---- Inputs: what a theme sets ---------------------------------- */
  color-scheme: light dark;   /* follow the device; a theme may force light or dark */
  --accent:     #0b5cad;
  --bg-light:   #ffffff;
  --bg-dark:    #16181b;
  --text-light: #1a1a1a;
  --text-dark:  #e6e6e6;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg-image: none;

  /* ---- Derived: worked out from the inputs ------------------------- */
  --bg:          light-dark(var(--bg-light), var(--bg-dark));
  --text:        light-dark(var(--text-light), var(--text-dark));
  --muted:       color-mix(in oklch, var(--text) 60%, var(--bg));
  --link:        light-dark(var(--accent), color-mix(in oklch, var(--accent) 45%, white));
  --surface:     color-mix(in oklch, var(--accent) 7%, color-mix(in oklch, var(--text) 4%, var(--bg)));
  --border:      color-mix(in oklch, var(--accent) 15%, color-mix(in oklch, var(--text) 18%, var(--bg)));
  --header-bg:   light-dark(color-mix(in oklch, var(--accent) 85%, black),
                            color-mix(in oklch, var(--accent) 55%, black));
  --header-text: #ffffff;
  --button-bg:   var(--surface);
  --page-bg:     color-mix(in oklch, var(--bg) 70%, transparent); /* readable over --bg-image */
  --missing:     light-dark(#b3261e, #ff8a80);
  --notice-bg:   light-dark(#fff8e1, #3a3218);
  --notice-bd:   light-dark(#e2c46a, #7a6524);
  --error-bg:    light-dark(#fdecea, #3d1f1d);
  --error-bd:    light-dark(#e3a19c, #8a3b35);
  --note:        light-dark(#0969da, #4493f8);
  --tip:         light-dark(#1a7f37, #3fb950);
  --important:   light-dark(#8250df, #ab7df8);
  --warning:     light-dark(#9a6700, #d29922);
  --caution:     light-dark(#cf222e, #f85149);

  /* ---- Layout ------------------------------------------------------ */
  --content-width: 50em;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-image);
  /* Best fit: the whole image, scaled to the window's width or height
     (whichever fits), centred; the rest shows --bg. */
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

/* ---- Page frame ---------------------------------------------------- */

.site-header .bar,
.site-footer,
main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding-left: 1.25em;
  padding-right: 1.25em;
}

.site-header {
  background: var(--header-bg);
  color: var(--header-text);
}

.site-header .bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5em 1em;
  padding-top: 0.6em;
  padding-bottom: 0.6em;
}

.site-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-weight: 600;
  font-size: 1.15em;
  text-decoration: none;
  color: var(--header-text);
}

.site-header form { margin: 0 0 0 auto; }

.site-header button {
  background: transparent;
  color: var(--header-text);
  border-color: color-mix(in oklch, var(--header-text) 50%, transparent);
}

main {
  padding-top: 1.25em;
  padding-bottom: 3em;
  background: var(--page-bg);
}

.site-footer {
  padding-top: 1em;
  padding-bottom: 2em;
  border-top: 1px solid var(--border);
  background: var(--page-bg);
}

/* Smaller text on the form, not the footer, so the footer's em-based
   width and padding still line up with main. */
.theme-picker {
  font-size: 0.9em;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5em 0.75em;
}

/* ---- Text ---------------------------------------------------------- */

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

a.missing {
  color: var(--missing);
  text-decoration-style: dashed;
}

h1, h2, h3, h4, h5, h6 { line-height: 1.25; margin: 1.5em 0 0.5em; }
h1 { font-size: 1.9em; }
h2 { font-size: 1.45em; }
h3 { font-size: 1.2em; }

main > :first-child,
.page > :first-child { margin-top: 0; }

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

.page { overflow-wrap: break-word; }

blockquote {
  margin-left: 0;
  padding: 0.1em 1em;
  border-left: 4px solid var(--border);
  color: var(--muted);
}

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

/* ---- Media --------------------------------------------------------- */

img, video {
  max-width: 100%;
  height: auto;
}

video { display: block; background: #000; }

/* ---- Code and tables (scroll inside, never the page) --------------- */

code, pre { font-family: var(--mono); }

code { font-size: 0.9em; }

:not(pre) > code {
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background: var(--surface);
  overflow-wrap: anywhere;
}

pre {
  overflow-x: auto;
  padding: 0.75em 1em;
  border-radius: 4px;
  background: var(--surface);
  line-height: 1.45;
}

table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

th, td {
  padding: 0.4em 0.7em;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th { background: var(--surface); }

/* ---- GitHub alerts ------------------------------------------------- */

.markdown-alert {
  margin: 0 0 1em;
  padding: 0.5em 1em;
  border-left: 4px solid var(--note);
  background: var(--surface);
}

.markdown-alert > :last-child { margin-bottom: 0; }

.markdown-alert-title { font-weight: 600; margin-bottom: 0.25em; }

.markdown-alert-note      { border-color: var(--note); }
.markdown-alert-tip       { border-color: var(--tip); }
.markdown-alert-important { border-color: var(--important); }
.markdown-alert-warning   { border-color: var(--warning); }
.markdown-alert-caution   { border-color: var(--caution); }

/* ---- Navigation ---------------------------------------------------- */

.breadcrumbs {
  margin-bottom: 1.25em;
  font-size: 0.9em;
  color: var(--muted);
  overflow-wrap: anywhere;
}

p.edit { margin: 1.5em 0 0; }

.page-nav {
  margin-top: 1.5em;
  padding-top: 1em;
  border-top: 1px solid var(--border);
}

.page-nav .parent { margin-bottom: 0.75em; }

.page-nav h2 { font-size: 1.1em; margin: 1em 0 0.4em; }

.sub-pages,
.tree {
  list-style: none;
  padding-left: 0;
}

.sub-pages li,
.tree li { padding: 0.2em 0; }

.tree .tree {
  margin: 0.2em 0 0.2em 0.4em;
  padding-left: 1.1em;
  border-left: 1px solid var(--border);
}

.file {
  font-size: 0.8em;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.unreachable { margin-top: 2.5em; }

/* ---- Messages ------------------------------------------------------ */

.notice,
.error {
  padding: 0.75em 1em;
  border: 1px solid;
  border-radius: 4px;
}

.notice { background: var(--notice-bg); border-color: var(--notice-bd); }
.error  { background: var(--error-bg);  border-color: var(--error-bd); }

.hint { font-size: 0.9em; color: var(--muted); }

/* ---- Forms --------------------------------------------------------- */

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

button {
  min-height: 44px;
  padding: 0.4em 1.2em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--button-bg);
  cursor: pointer;
}

button:hover { border-color: var(--accent); }

select {
  display: block;
  margin-top: 0.25em;
  min-height: 44px;
  padding: 0.4em 0.6em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

input:not([type]),
input[type="text"],
input[type="password"],
input[type="search"] {
  width: 100%;
  max-width: 24em;
  min-height: 44px;
  padding: 0.4em 0.6em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

label input { display: block; margin-top: 0.25em; }

textarea {
  display: block;
  width: 100%;
  min-height: 60vh;
  padding: 0.6em 0.75em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  font-family: var(--mono); /* after the form-control `font: inherit` */
  font-size: 0.9em;
  line-height: 1.5;
  resize: vertical;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75em 1.25em;
  margin-top: 0.75em;
}

/* New page / sub-page box: field and button side by side, wrapping. */
.new-page {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5em 0.75em;
  margin: 1.5em 0 0;
}

.new-page label { flex: 1 1 14em; max-width: 24em; }

h1 + .new-page { margin: 0 0 1.5em; }

/* ---- Files section ------------------------------------------------- */

.files {
  margin-top: 1.5em;
  padding-top: 1em;
  border-top: 1px solid var(--border);
}

.files h2 { font-size: 1.1em; margin: 0 0 0.5em; }

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

.file-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5em 0.75em;
  padding: 0.5em 0;
  border-bottom: 1px solid var(--border);
}

.file-list .thumb {
  width: 3.5em;
  height: 3.5em;
  object-fit: cover;
  border-radius: 3px;
}

.file-list .file-info { flex: 1 1 12em; min-width: 0; overflow-wrap: anywhere; }

.file-list form { margin: 0; }

/* Upload/download rows. In the HTML, "Save as" comes before the file so
   it is sent first (the server reads fields before the file); flex order
   puts the file or URL first on screen. */
.add-file {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5em 0.75em;
  margin: 1em 0 0;
}

.add-file .source  { order: 1; flex: 2 1 16em; }
.add-file .save-as { order: 2; flex: 1 1 10em; }
.add-file button   { order: 3; }

.add-file input { max-width: none; }

input[type="url"] {
  width: 100%;
  min-height: 44px;
  padding: 0.4em 0.6em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

input[type="file"] { display: block; margin-top: 0.25em; max-width: 100%; }

/* ---- Phones -------------------------------------------------------- */

@media (max-width: 40em) {
  .site-header .bar,
  .site-footer,
  main {
    padding-left: 1em;
    padding-right: 1em;
  }

  h1 { font-size: 1.6em; }
  h2 { font-size: 1.3em; }

  input:not([type]),
  input[type="text"],
  input[type="password"],
  input[type="search"] { max-width: none; }

  /* Bigger, easier taps on lists of links. */
  .sub-pages li,
  .tree li { padding: 0.45em 0; }

  .page-nav .parent a,
  p.edit a,
  .actions a {
    display: inline-block;
    padding: 0.5em 0;
  }

  .tree .tree { padding-left: 0.75em; }

  textarea { min-height: 50vh; }
}
