/* WAnsiDraw. DOS look with the VGA font. Mobile first: base rules for narrow
   screens, wider layouts via min-width. All sizes in whole pixels and font
   sizes in multiples of 16 px so the pixel font stays sharp. */

@font-face {
  font-family: 'WAnsiVGA';
  src: url('../fonts/wansidraw-vga.woff2') format('woff2');
  font-display: block;
}

:root {
  --c0: #000000; --c1: #0000aa; --c2: #00aa00; --c3: #00aaaa;
  --c4: #aa0000; --c5: #aa00aa; --c6: #aa5500; --c7: #aaaaaa;
  --c8: #555555; --c9: #5555ff; --c10: #55ff55; --c11: #55ffff;
  --c12: #ff5555; --c13: #ff55ff; --c14: #ffff55; --c15: #ffffff;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--c0);
  color: var(--c7);
  font-family: 'WAnsiVGA', 'Courier New', monospace;
  font-size: 16px;
  line-height: 16px;
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: optimizeSpeed;
}

button, input, textarea, select {
  font: inherit;
  line-height: 16px;
  letter-spacing: 0;
}

a { color: var(--c14); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--c14); outline-offset: 0; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Color classes for text and swatches */
.fg0 { color: var(--c0); } .fg1 { color: var(--c1); } .fg2 { color: var(--c2); } .fg3 { color: var(--c3); }
.fg4 { color: var(--c4); } .fg5 { color: var(--c5); } .fg6 { color: var(--c6); } .fg7 { color: var(--c7); }
.fg8 { color: var(--c8); } .fg9 { color: var(--c9); } .fg10 { color: var(--c10); } .fg11 { color: var(--c11); }
.fg12 { color: var(--c12); } .fg13 { color: var(--c13); } .fg14 { color: var(--c14); } .fg15 { color: var(--c15); }
.bg0 { background: var(--c0); } .bg1 { background: var(--c1); } .bg2 { background: var(--c2); } .bg3 { background: var(--c3); }
.bg4 { background: var(--c4); } .bg5 { background: var(--c5); } .bg6 { background: var(--c6); } .bg7 { background: var(--c7); }
.bg8 { background: var(--c8); } .bg9 { background: var(--c9); } .bg10 { background: var(--c10); } .bg11 { background: var(--c11); }
.bg12 { background: var(--c12); } .bg13 { background: var(--c13); } .bg14 { background: var(--c14); } .bg15 { background: var(--c15); }
.c0 { background: var(--c0); } .c1 { background: var(--c1); } .c2 { background: var(--c2); } .c3 { background: var(--c3); }
.c4 { background: var(--c4); } .c5 { background: var(--c5); } .c6 { background: var(--c6); } .c7 { background: var(--c7); }
.c8 { background: var(--c8); } .c9 { background: var(--c9); } .c10 { background: var(--c10); } .c11 { background: var(--c11); }
.c12 { background: var(--c12); } .c13 { background: var(--c13); } .c14 { background: var(--c14); } .c15 { background: var(--c15); }

/* Scrollbars in DOS style: shaded track, solid thumb */
.scroller, .viewer-stage, .modem-screen, .keys-scroll, .sidebar, .dlg {
  scrollbar-color: var(--c3) var(--c1);
}
::-webkit-scrollbar { width: 16px; height: 16px; }
::-webkit-scrollbar-track {
  background-color: var(--c1);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' shape-rendering='crispEdges'%3E%3Crect width='2' height='2' fill='%2300aaaa'/%3E%3Crect x='2' y='2' width='2' height='2' fill='%2300aaaa'/%3E%3C/svg%3E");
}
::-webkit-scrollbar-thumb { background: var(--c3); }
::-webkit-scrollbar-corner { background: var(--c1); }
::-webkit-scrollbar-button { display: none; }

/* ------------------------------------------------------------ app frame */

.app { position: relative; }

/* Reserve the full screen before the script builds the editor, so the
   text below does not show up at the top for a moment while loading. */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--c0);
}

.app.mode-editor {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--c0);
}

/* Menu bar */
.menubar {
  position: relative;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  background: var(--c1);
  color: var(--c15);
  flex: none;
}
.menu-list { display: flex; flex-wrap: wrap; margin: 0; padding: 0; list-style: none; }
.menu-li { margin: 0; padding: 0; }
.menu-top {
  background: transparent;
  color: var(--c15);
  border: 0;
  padding: 4px 8px;
  cursor: default;
}
.menu-top:focus, .menu-top.open { background: var(--c3); color: var(--c0); outline: none; }
.menu-top:focus .hk, .menu-top.open .hk { color: var(--c15); }
.hk { color: var(--c14); }
.menu-lang {
  margin-left: auto;
  padding: 4px 8px;
  color: var(--c15);
  text-decoration: none;
}
.menu-lang:hover { color: var(--c14); }

.menu-drop {
  position: absolute;
  top: 24px;
  left: 0;
  min-width: 288px;
  max-width: calc(100vw - 16px);
  padding: 4px 0;
  background: var(--c1);
  border: 6px double var(--c15);
  box-shadow: 8px 8px 0 var(--c0);
}
.menu-item {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  column-gap: 8px;
  width: 100%;
  padding: 0 16px 0 8px;
  background: transparent;
  color: var(--c15);
  border: 0;
  text-align: left;
  cursor: default;
  white-space: nowrap;
}
.menu-item:focus { background: var(--c3); color: var(--c0); outline: none; }
.menu-item:focus .hk { color: var(--c15); }
.menu-item:disabled { color: var(--c8); }
.menu-item:disabled .hk { color: var(--c8); }
.menu-key { color: var(--c7); }
.menu-item:focus .menu-key { color: var(--c0); }
.menu-sep { height: 0; margin: 4px 0; border-top: 2px solid var(--c15); }

/* Work area: side panel and canvas */
.workarea {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sidebar {
  flex: none;
  max-height: 192px;
  overflow: auto;
  background: var(--c1);
  color: var(--c15);
  padding: 0 0 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}
.side-section { padding: 0 8px; min-width: 208px; }
.side-title {
  margin: 8px 0 4px;
  padding: 0 8px;
  font-size: 16px;
  font-weight: normal;
  line-height: 16px;
  background: var(--c3);
  color: var(--c0);
}
.tool-list { display: flex; flex-wrap: wrap; }
.tool-btn {
  background: transparent;
  color: var(--c15);
  border: 0;
  padding: 4px 8px;
  text-align: left;
  cursor: default;
}
.tool-btn:hover { color: var(--c14); }
.tool-btn.active { background: var(--c15); color: var(--c1); }

.char-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  background: transparent;
  color: var(--c15);
  border: 0;
  padding: 4px 8px;
  cursor: default;
}
.char-big {
  display: inline-block;
  font-size: 32px;
  line-height: 32px;
  min-width: 18px;
  text-align: center;
}
.char-code { color: var(--c7); }

.palette {
  display: grid;
  grid-template-columns: repeat(8, 24px);
  grid-auto-rows: 24px;
  gap: 0;
  margin: 4px 8px 0;
}
.swatch {
  border: 0;
  padding: 0;
  margin: 0;
  width: 24px;
  height: 24px;
  cursor: default;
  color: var(--c15);
}
.swatch.light { color: var(--c0); }
.swatch.sel { outline: 2px solid var(--c15); outline-offset: -2px; }
.swatch.light.sel { outline-color: var(--c0); }
.swatch-mark { display: block; text-align: center; }
.palette-help { margin: 8px 8px 0; color: var(--c7); }
.color-preview { display: inline-block; margin: 8px 8px 0; padding: 0; }

.check, .radio {
  position: relative;
  display: flex;
  gap: 8px;
  padding: 4px 8px;
  cursor: default;
}
.check-input, .radio-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.check-box::before { content: '[ ]'; }
.check-input:checked + .check-box::before { content: '[X]'; }
.radio-box::before { content: '( )'; }
.radio-input:checked + .radio-box::before { content: '(\2022)'; }
.check-input:focus-visible + .check-box,
.radio-input:focus-visible + .radio-box { background: var(--c3); color: var(--c0); }
.radios { border: 0; margin: 0 0 8px; padding: 0; min-width: 0; }
.radios legend { padding: 0; margin: 0 0 4px; }

.stage {
  position: relative;
  flex: 1;
  min-height: 256px;
  background: var(--c0);
}
.scroller {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  outline: none;
}
.scroller:focus-visible { box-shadow: inset 0 0 0 2px var(--c3); }
.sizer { display: inline-block; padding: 16px; vertical-align: top; }
.doc-canvas {
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  cursor: crosshair;
}
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* F key bar and status line */
.fkeybar {
  display: flex;
  flex-wrap: wrap;
  flex: none;
  background: var(--c0);
  color: var(--c15);
}
.fkeys { display: flex; flex-wrap: wrap; }
.fkey {
  display: flex;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--c15);
  cursor: default;
}
.fkey-name { padding: 4px 4px 4px 8px; }
.fkey-char { padding: 4px 8px; background: var(--c3); color: var(--c0); min-width: 25px; text-align: center; }
.fkey:hover .fkey-char { background: var(--c11); }
.set-box { display: flex; align-items: center; margin-left: auto; }
.set-btn { background: transparent; border: 0; color: var(--c15); padding: 4px 8px; cursor: default; }
.set-btn:hover { color: var(--c14); }
.set-label { padding: 4px 0; }

.statusbar {
  display: flex;
  flex-wrap: wrap;
  flex: none;
  background: var(--c3);
  color: var(--c0);
}
.st { padding: 4px 8px; border-right: 2px solid var(--c1); white-space: nowrap; }
.st-swatch { padding: 0 4px; }
.st-msg { border-right: 0; flex: 1; color: var(--c1); }

/* ------------------------------------------------------------ dialogs */

.dlg-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.dlg {
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 16px;
  background: var(--c7);
  color: var(--c0);
  box-shadow: 16px 16px 0 var(--c0);
}
.dlg-frame {
  position: relative;
  border: 6px double var(--c15);
  padding: 24px 16px 16px;
}
.dlg-title {
  position: absolute;
  top: -11px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 16px;
  line-height: 16px;
  font-weight: normal;
  pointer-events: none;
}
.dlg-title span { background: var(--c7); color: var(--c0); padding: 0 8px; }
.dlg-body p { margin: 0 0 16px; line-height: 16px; }
.dlg-body a { color: var(--c1); }
.dlg-note { color: var(--c8); }
.dlg-error { color: var(--c4); min-height: 16px; }
.dlg-error:empty { display: none; }
.dlg-buttons { display: flex; flex-wrap: wrap; gap: 16px 24px; justify-content: center; margin-top: 16px; padding-bottom: 8px; }
.dlg-cols { display: flex; flex-wrap: wrap; gap: 16px 32px; }
.dlg .check, .dlg .radio { padding: 2px 0; }

.btn {
  background: var(--c2);
  color: var(--c0);
  border: 0;
  padding: 4px 16px;
  box-shadow: 8px 8px 0 var(--c0);
  cursor: default;
}
.btn-primary { color: var(--c15); }
.btn:focus { background: var(--c10); color: var(--c0); outline: none; }
.btn:active { transform: translate(8px, 8px); box-shadow: none; }

.field { margin: 0 0 16px; }
.field label { display: block; margin: 0 0 4px; }
.input {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 0;
  border-radius: 0;
  padding: 4px 8px;
  background: var(--c1);
  color: var(--c15);
  caret-color: var(--c14);
}
.input:focus { outline: 2px solid var(--c14); outline-offset: 0; }
.textarea { resize: vertical; min-height: 72px; }

.char-table {
  display: block;
  max-width: 100%;
  margin: 0 auto 8px;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  cursor: default;
}
.char-table:focus { outline: 2px solid var(--c14); }
.char-info { text-align: center; }

.keys-scroll { max-height: 50vh; overflow: auto; }
.keys { border-collapse: collapse; }
.keys th, .keys td { padding: 2px 16px 2px 0; text-align: left; vertical-align: top; font-weight: normal; }
.keys th { color: var(--c1); white-space: nowrap; }
.about-name { color: var(--c1); }

.modem-screen {
  max-height: 400px;
  max-width: 100%;
  overflow: auto;
  background: var(--c0);
  margin: 0 0 8px;
  cursor: pointer;
}
.modem-canvas {
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
.modem-controls .radios { display: flex; flex-wrap: wrap; gap: 0 16px; }
.modem-controls legend { width: 100%; }

/* ------------------------------------------------------------ start screen */

body.splash-open { overflow: hidden; }
.splash {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px;
  background: var(--c0);
  cursor: pointer;
}
.splash-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
.splash-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px 24px;
}
.splash-hint { color: var(--c7); animation: splash-blink 1s steps(1) infinite; }
@keyframes splash-blink { 50% { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  .splash-hint { animation: none; }
}

/* ------------------------------------------------------------ viewer */

.app.mode-viewer { background: var(--c0); }
.viewer-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 4px 16px;
  background: var(--c1);
  color: var(--c15);
}
.viewer-title { margin: 0; font-size: 16px; font-weight: normal; }
.viewer-nav { display: flex; gap: 16px; margin-left: auto; }
.viewer-nav a { color: var(--c15); }
.viewer-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px; padding: 16px; }
.viewer-zoom { color: var(--c15); min-width: 32px; text-align: center; }
.viewer-stage {
  overflow: auto;
  max-height: 70vh;
  padding: 16px;
  outline: none;
}
.viewer-info { margin: 0; padding: 8px 16px 16px; }

/* DOS windows on the pages */
.dos-window {
  position: relative;
  margin: 32px 16px;
  padding: 24px 16px 16px;
  border: 6px double var(--c15);
  background: var(--c7);
  color: var(--c0);
  box-shadow: 16px 16px 0 var(--c8);
}
.dos-window-title {
  position: absolute;
  top: -11px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 16px;
  line-height: 16px;
  font-weight: normal;
}
.dos-window-title span { padding: 0 8px; background: var(--c7); color: var(--c0); }
.dos-window p { margin: 0 0 16px; line-height: 24px; }
.dos-window p:last-child { margin-bottom: 0; }
.dos-window a { color: var(--c1); }

/* ------------------------------------------------------------ text pages */

.info {
  padding: 16px 0 32px;
  max-width: 928px;
  margin: 0 auto;
}
.info-head { padding: 16px; }
.info-head h1, .doc-page h1 {
  margin: 0 0 16px;
  font-size: 32px;
  line-height: 32px;
  font-weight: normal;
  color: var(--c15);
}
.info-head p { margin: 0; line-height: 24px; color: var(--c7); }
.blue { background: var(--c1); color: var(--c15); border-color: var(--c11); }
.blue .dos-window-title span { background: var(--c1); color: var(--c14); }
.blue a { color: var(--c14); }
.dos-window ul, .dos-window ol { margin: 0 0 16px; padding: 0 0 0 32px; line-height: 24px; }
.dos-window li { margin: 0; }
.dos-window h3 { margin: 24px 0 8px; font-size: 16px; line-height: 16px; font-weight: normal; color: var(--c14); }
.dos-window code, .dos-window kbd { font-family: inherit; color: var(--c11); }
/* Tables on the text pages: stacked on narrow screens, two columns from 600 px */
.dos-window table { display: block; border-collapse: collapse; margin: 0 0 16px; }
.dos-window tbody, .dos-window tr, .dos-window th, .dos-window td { display: block; }
.dos-window th, .dos-window td { text-align: left; vertical-align: top; padding: 0; font-weight: normal; line-height: 24px; }
.dos-window tr { margin: 0 0 8px; }
.dos-window th { color: var(--c11); }

.doc-page { max-width: 928px; margin: 0 auto; padding: 0 0 32px; }
.doc-top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 4px 16px;
  background: var(--c1);
  color: var(--c15);
}
.doc-top a { color: var(--c15); }
.doc-top .doc-top-right { margin-left: auto; display: flex; gap: 16px; }
.doc-intro { padding: 32px 16px 0; }
.doc-intro p { line-height: 24px; margin: 0; }
.toc { columns: 1; }
.toc a { display: inline-block; padding: 0 4px; margin: 0 -4px; }
.toc a:hover { color: var(--c15); }
.toc a.current { background: var(--c3); color: var(--c0); text-decoration: none; }
.doc-sections .dos-window { scroll-margin-top: 32px; }

.site-footer {
  background: var(--c3);
  color: var(--c0);
  padding: 8px 16px;
}
.site-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.site-footer a { color: var(--c0); }
.legal-links { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-top: 8px; }

/* ------------------------------------------------------------ wider screens */

@media (min-width: 600px) {
  .dos-window table { display: table; }
  .dos-window tbody { display: table-row-group; }
  .dos-window tr { display: table-row; margin: 0; }
  .dos-window th, .dos-window td { display: table-cell; padding: 4px 16px 4px 0; }
  .dos-window th { white-space: nowrap; }
  .dlg { width: 512px; }
  .dlg.dlg-wide { width: 736px; }
  .toc { columns: 2; }
}

@media (min-width: 1100px) {
  .doc-page { max-width: 1248px; }
  .doc-layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    align-items: start;
  }
  .toc-box {
    position: sticky;
    top: 32px;
    margin-right: 0;
  }
  .toc-box .toc {
    columns: 1;
    max-height: calc(100vh - 136px);
    overflow-y: auto;
  }
}

@media (min-width: 900px) {
  .workarea { flex-direction: row; }
  .sidebar {
    display: block;
    width: 240px;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 2px solid var(--c0);
  }
  .side-section { min-width: 0; }
  .tool-list { display: block; }
  .tool-btn { display: block; width: 100%; }
  .dos-window { margin: 32px 16px; }
}
