/* The textarea demo's page. */

/* the colours, light and dark (as the system has it); the browser draws its controls to match */
:root { color-scheme: light dark; --page: #fff; --fg: #1f2328; --strong: #000; --muted: #6e7781; --line: #999; --bar-line: #e4e4e0; --pressed: #e6e6e3; --toast: #1f2328; --toast-fg: #fff; }
@media (prefers-color-scheme: dark) {
  :root { --page: #0d1117; --fg: #e6edf3; --strong: #fff; --muted: #8b949e; --line: #3d444d; --bar-line: #30363d; --pressed: #262c36; --toast: #e6edf3; --toast-fg: #1f2328; }
  textarea { background: var(--page); color: var(--fg); }
  a { color: #4493f8; }
}
/* --inset: from the column's edge to the textarea's text (its border and padding) */
:root { --pad: 16px; --inset: 9px; }
/* the page's background set (on html too), not left to the browser, and the bar's the same, so
   dark-mode readers darken them alike */
html { background: var(--page); }
/* a grid: the header's row ("ourus   Preview · CM6"), the panes, the status; the column
   is as wide as the textarea, so it stays centred as it's resized */
body { margin: 0 auto; width: fit-content; padding: var(--pad); display: grid; grid-template: auto minmax(0, 1fr) auto / auto minmax(0, 1fr) auto auto; column-gap: 8px; align-items: baseline; font: 14px/1.45 system-ui, sans-serif; color: var(--fg); }
/* split: the panes fill the window, half each */
body.split { width: auto; height: 100dvh; box-sizing: border-box; }
header { display: contents; color: var(--muted); font-size: 13px; }
header b { grid-area: 1 / 1; padding-left: var(--inset); color: var(--strong); font-size: 16px; }
/* the name links to the source, but in the name's colour, not a link's */
header b a { color: inherit; text-decoration: none; }
label { grid-area: 1 / 3; }
label input { margin: 0 4px 0 0; vertical-align: middle; }
.links { grid-area: 1 / 4; padding-right: var(--inset); }
/* at the bottom, never widening the column */
#status { grid-area: 3 / 1 / 4 / -1; box-sizing: border-box; width: 0; min-width: 100%; padding-inline: var(--inset); min-height: 1.45em; margin-top: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
main { grid-area: 2 / 1 / 3 / -1; align-self: stretch; margin-top: 12px; display: grid; gap: var(--pad); }
.split main { grid-template: minmax(0, 1fr) / 1fr 1fr; }
textarea, #preview { box-sizing: border-box; height: 60vh; padding: 8px; border: 1px solid var(--line); }
textarea { width: min(760px, calc(100vw - 2 * var(--pad))); max-width: calc(100vw - 2 * var(--pad)); font: 14px/1.6 ui-monospace, 'SF Mono', Menlo, monospace; tab-size: 4; }
/* over the size a resize left on the textarea */
.split textarea, .split #preview { width: 100% !important; height: 100% !important; max-width: none; resize: none; }
#preview { overflow: auto; padding: 0 16px; }
#preview > :first-child { margin-top: 0.4em; }
/* touch screens: a bar of buttons for the keys they lack, at the bottom (above the keyboard);
   text big enough that iOS doesn't zoom in */
#keys { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1; justify-content: center; gap: 2px; padding: 4px 8px; background: var(--page); border-top: 1px solid var(--bar-line); }
#keys button { flex: 0 1 52px; height: 38px; display: flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--fg); touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#keys button.pressed { background: var(--pressed); }
@media (pointer: coarse) {
  #keys { display: flex; }
  /* the textarea fills the screen, down to the bar (and the keyboard, where it shrinks the page) */
  body { height: 100dvh; box-sizing: border-box; padding-bottom: calc(48px + var(--pad)); }
  main { grid-template-rows: minmax(0, 1fr); }
  textarea { height: 100%; resize: none; font-size: 16px; }
}
/* narrow: the status a notification at the top, for a few seconds; the panes one above the other,
   the preview first; less room around everything */
@media (max-width: 700px) {
  :root { --pad: 8px; --inset: 4px; } /* the textarea edge to edge, its text 12px in */
  body, body.split { width: auto; }
  #status { position: fixed; top: 8px; left: 50%; z-index: 2; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); min-width: 0; min-height: 0; margin: 0; padding: 6px 12px; border-radius: 8px; background: var(--toast); color: var(--toast-fg); box-shadow: 0 2px 8px rgb(0 0 0 / 0.2); pointer-events: none; opacity: 0; transition: opacity 0.3s; }
  #status.shown { opacity: 1; }
  main { margin-top: 6px; }
  .split main { grid-template: minmax(0, 1fr) minmax(0, 1fr) / 1fr; }
  .split #preview { order: -1; }
  /* the panes edge to edge, no frame: lines between them, and above and below */
  main { margin-inline: calc(-1 * var(--pad)); gap: 0; border-bottom: 1px solid var(--line); }
  textarea, #preview { border-width: 1px 0 0; outline: none; }
  textarea { width: 100%; max-width: none; padding: 10px 12px; }
  #preview { padding: 0 12px; }
}
@media (max-width: 700px) and (pointer: coarse) {
  body { padding-bottom: 47px; } /* down to the bar, whose line is the one below */
  main { border-bottom: 0; }
}
