/* davidcarroll.org: one-bit desktop. Ink and paper only; every grey is a dither. */

@font-face {
  font-family: "Tiny5";
  src: url("../fonts/tiny5.woff2") format("woff2");
  /* One weight; claim the whole range so headings never get a synthetic bold. */
  font-weight: 100 900;
  font-display: swap;
}
/* Tiny5's figures and @ are pinched at UI sizes; Jersey 10 supplies them at matching widths. */
@font-face {
  font-family: "Tiny5";
  src: url("../fonts/jersey10-figures.woff2") format("woff2");
  font-weight: 100 900;
  unicode-range: U+0030-0039, U+0040;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-next.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-next-italic.woff2") format("woff2");
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}

:root {
  --ink: #000;
  --paper: #fff;
  --pixel: "Tiny5", "Chicago", "Geneva", monospace;
  --text: "Atkinson Hyperlegible Next", "Geneva", "Verdana", sans-serif;
  --menubar: 2.25rem;
  /* The shadow box sits 6px down-right of its owner; clip it to the L that shows. */
  --shadow-clip: polygon(calc(100% - 6px) 0, 100% 0, 100% 100%, 0 100%, 0 calc(100% - 6px), calc(100% - 6px) calc(100% - 6px));
  --frame: 2px;
  --gutter: 1rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --ink: #f4f4f4; --paper: #000; color-scheme: dark; }
}
:root[data-theme="dark"] { --ink: #f4f4f4; --paper: #000; color-scheme: dark; }

/* Dithers. Each tile is drawn from ink and paper so it inverts with the theme. */
:root {
  /* one ink pixel in a 2x2 cell */
  --dither-25: conic-gradient(from 270deg at 1px 1px, var(--ink) 25%, var(--paper) 0) 0 0 / 2px 2px;
  /* checkerboard */
  --dither-50: conic-gradient(var(--ink) 25%, var(--paper) 0 50%, var(--ink) 0 75%, var(--paper) 0) 0 0 / 2px 2px;
  /* one ink pixel in a 4x4 cell, staggered */
  --dither-12: conic-gradient(from 270deg at 1px 1px, var(--ink) 25%, transparent 0) 0 0 / 4px 4px,
               conic-gradient(from 270deg at 1px 1px, var(--ink) 25%, transparent 0) 2px 2px / 4px 4px,
               var(--paper);
}

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

html {
  background: var(--paper);
  color: var(--ink);
  scrollbar-color: var(--ink) var(--paper);
  -webkit-text-size-adjust: 100%;
  font-variant-ligatures: none;
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--dither-25);
  color: var(--ink);
  font: 400 1.0625rem/1.55 var(--text);
  font-kerning: normal;
}
::selection { background: var(--ink); color: var(--paper); }

/* Classic scrollbar: dithered track, paper thumb in an ink frame. */
::-webkit-scrollbar { width: 16px; height: 16px; }
::-webkit-scrollbar-track { background: var(--dither-50); border-left: var(--frame) solid var(--ink); }
::-webkit-scrollbar-thumb { background: var(--paper); border: var(--frame) solid var(--ink); }
::-webkit-scrollbar-corner { background: var(--paper); }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { background: var(--ink); color: var(--paper); text-decoration: none; }
:focus-visible { outline: 2px dashed var(--ink); outline-offset: 2px; }
a:focus-visible { background: var(--ink); color: var(--paper); text-decoration: none; }

.icon { width: 32px; height: 32px; flex: none; color: var(--ink); image-rendering: pixelated; }
.icon--sm { width: 16px; height: 16px; }

.skip { position: absolute; left: -999px; top: 0; z-index: 100; padding: .4rem .7rem; background: var(--ink); color: var(--paper); font-family: var(--pixel); }
.skip:focus { left: .5rem; top: .25rem; }

/* ---------- Menu bar ---------- */
.menubar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: stretch;
  height: var(--menubar);
  padding: 0 .5rem;
  background: var(--paper);
  border-bottom: var(--frame) solid var(--ink);
  font: 500 1rem/1 var(--pixel);
  white-space: nowrap;
}
.menubar > a, .menubar > .menu > summary, .menubar .mark {
  display: flex; align-items: center; gap: .45rem;
  padding: 0 .75rem;
  text-decoration: none;
}
.menubar .mark { padding-left: .35rem; }
.menubar .mark .icon { width: 16px; height: 16px; }
.menubar .app { font-weight: 700; }
.menubar .spacer { flex: 1; }
.menubar .clock { display: flex; align-items: center; padding: 0 .5rem; font-variant-numeric: tabular-nums; }
.menubar > a:hover, .menubar > a:focus-visible,
.menu > summary:hover, .menu[open] > summary { background: var(--ink); color: var(--paper); outline: none; }

.menu { position: relative; display: flex; }
.menu > summary { cursor: default; list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > ul {
  position: absolute; top: calc(100% + var(--frame)); left: 0;
  min-width: 22rem; margin: 0; padding: .25rem 0;
  list-style: none;
  background: var(--paper);
  border: var(--frame) solid var(--ink);
  font: 400 1rem/1 var(--pixel);
  white-space: normal;
}
.menu > ul::after { content: ""; position: absolute; inset: 6px -8px -8px 6px; background: var(--dither-50); clip-path: var(--shadow-clip); pointer-events: none; }
.menu > ul a { display: block; padding: .5rem 1rem; text-decoration: none; line-height: 1.3; }

/* ---------- Windows ---------- */
.window {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--paper);
  border: var(--frame) solid var(--ink);
}
/* Dithered drop shadow, offset down and right. */
.window::after {
  content: ""; position: absolute;
  inset: 6px -8px -8px 6px;
  background: var(--dither-50);
  clip-path: var(--shadow-clip);
  pointer-events: none;
}
.titlebar {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 2rem;
  padding: 0 2.75rem;
  background: var(--paper);
  color: var(--ink);
  border-bottom: var(--frame) solid var(--ink);
  font: 500 1.0625rem/1 var(--pixel);
  user-select: none;
}
/* Active window: 1px ink stripes, with the title and close box knocked out on paper. */
.titlebar::before {
  content: ""; position: absolute; inset: 6px 5px;
  background: repeating-linear-gradient(var(--ink) 0 1px, transparent 1px 3px);
  visibility: hidden;
}
.window.is-active > .titlebar::before, .window--doc > .titlebar::before { visibility: visible; }
.titlebar > .title { position: relative; padding: 0 .6rem; background: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.closebox {
  position: absolute; right: .55rem; top: 50%;
  width: 1.15rem; height: 1.15rem; margin-top: -.575rem; padding: 0;
  display: grid; place-items: center;
  background: var(--paper); color: var(--ink);
  border: var(--frame) solid var(--ink);
  outline-offset: 1px;
  cursor: pointer;
}
.closebox svg { width: 10px; height: 10px; }
.closebox { box-shadow: 0 0 0 3px var(--paper); }
.closebox:hover, .closebox:active { background: var(--ink); color: var(--paper); }
.window:not(.is-active) > .titlebar .closebox { visibility: hidden; }
.window--doc > .titlebar .closebox { visibility: visible; }

.infobar, .statusbar {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: .4rem .85rem;
  font: 400 .9375rem/1.3 var(--pixel);
}
.infobar { border-bottom: 1px solid var(--ink); }
.statusbar { margin-top: auto; border-top: var(--frame) solid var(--ink); }
.statusbar > * + * { padding-left: 1rem; border-left: 1px solid var(--ink); }
.statusbar .grow { margin-left: auto; }
/* Resize grip, drawn as three diagonal steps. */
.statusbar::after {
  content: ""; align-self: flex-end; flex: none;
  width: 12px; height: 12px; margin: 0 -.45rem -.15rem 0;
  background:
    linear-gradient(135deg, transparent 45%, var(--ink) 45% 55%, transparent 55%) 0 0 / 4px 4px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.75rem; padding: .35rem 1.35rem;
  background: var(--paper); color: var(--ink);
  border: var(--frame) solid var(--ink); border-radius: 7px;
  font: 500 1.125rem/1 var(--pixel);
  text-decoration: none;
  cursor: pointer;
}
/* Default button: the heavy outer ring. */
.btn--default { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); margin: 6px; }
.btn:hover, .btn:focus-visible { background: var(--ink); color: var(--paper); outline: none; }
.btn:focus-visible { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.btn--default:focus-visible { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); outline: 2px dashed var(--ink); outline-offset: 9px; }
.btn:active { background: var(--dither-50); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Dragging and zooming draw dotted outlines, never the window itself. */
.zoomrect { position: fixed; z-index: 1000; border: 2px dotted var(--ink); pointer-events: none; }
.zoomrect--drag { outline: 2px dotted var(--paper); outline-offset: -4px; }
.titlebar > .title { margin: 0; font: inherit; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 1099px) {
  .menubar { overflow-x: auto; scrollbar-width: none; }
  .menubar .clock { display: none; }
}
@media (max-width: 30rem) {
  .menubar > a, .menubar > .menu > summary { padding: 0 .55rem; }
}
