/* ============================================================
   disetti.it - MS-DOS / Turbo Vision skin
   Hand-written CSS. EGA 16-color palette.
   ============================================================ */

@font-face {
  font-family: "WebPlusIBMVGA";
  src: url("../fonts/WebPlusIBMVGA8x16.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  /* EGA 16-color palette */
  --ega-black:   #000000;
  --ega-blue:    #0000A8;
  --ega-green:   #00A800;
  --ega-cyan:    #54FCFC;
  --ega-red:     #A80000;
  --ega-gray:    #A8A8A8;
  --ega-white:   #FFFFFF;
  --ega-yellow:  #FCFC54;
  --ega-ltgreen: #54FC54;
  --ega-ltblue:  #5454FC;
  --ega-dgray:   #545454;

  --font-dos: "WebPlusIBMVGA", ui-monospace, Consolas, "DejaVu Sans Mono", monospace;

  /* one character cell; scales with viewport, never fixed px */
  --cell: clamp(0.75rem, 2.4vw, 1rem);
  --line: 1.5;

  --shadow: 8px 8px 0 rgba(0, 0, 0, .5);
}

/* Full-coverage fallback for scripts CP437 would miss.
   WebPlus already covers Cyrillic + Romanian, so this only ever
   engages if the woff2 fails to load; same metrics keep the grid intact. */
:lang(ru),
:lang(ro) {
  --font-dos: "WebPlusIBMVGA", ui-monospace, Consolas, "DejaVu Sans Mono", "Noto Sans Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;          /* hard guarantee: never any horizontal scroll */
}

body {
  font-family: var(--font-dos);
  font-size: var(--cell);
  line-height: var(--line);
  color: var(--ega-white);
  background: var(--ega-black);
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
  text-rendering: optimizeSpeed;
  overflow: hidden;          /* the app owns the viewport; no page scroll */
}

/* When JS is off we still want the document readable & scrollable */
body.no-js { overflow-x: hidden; overflow-y: auto; }

a { color: var(--ega-ltgreen); }
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible,
input:focus-visible {
  outline: 2px solid var(--ega-yellow);
  outline-offset: -2px;
}

/* ---------- App shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* ---------- Menu bar ---------- */
.menubar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--ega-gray);
  color: var(--ega-black);
  padding: 0 0.5ch;
  flex: 0 0 auto;
  user-select: none;
  overflow: hidden;
}
.menubar__item {
  font: inherit;
  background: transparent;
  color: var(--ega-black);
  border: 0;
  padding: 0.15em 1ch;
  cursor: pointer;
  white-space: nowrap;
}
.menubar__item:hover,
.menubar__item[aria-expanded="true"] {
  background: var(--ega-black);
  color: var(--ega-white);
}
.menubar__item .hot { color: var(--ega-red); }
.menubar__item:hover .hot,
.menubar__item[aria-expanded="true"] .hot { color: var(--ega-yellow); }
.menubar__clock {
  margin-left: auto;
  padding: 0.15em 1ch;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- Dropdown menus ---------- */
.dropdown {
  position: absolute;
  z-index: 60;
  min-width: 22ch;
  background: var(--ega-gray);
  color: var(--ega-black);
  border: 1px solid var(--ega-black);
  box-shadow: var(--shadow);
  padding: 0.25em 0;
}
.dropdown[hidden] { display: none; }
.dropdown__item {
  display: flex;
  justify-content: space-between;
  gap: 2ch;
  width: 100%;
  font: inherit;
  text-align: left;
  background: transparent;
  color: var(--ega-black);
  border: 0;
  padding: 0.1em 1.5ch;
  cursor: pointer;
}
.dropdown__item:hover,
.dropdown__item:focus {
  background: var(--ega-black);
  color: var(--ega-white);
}
.dropdown__item[aria-checked="true"]::before { content: "\2022 "; }
.dropdown__sep {
  height: 1px;
  margin: 0.25em 0.75ch;
  background: var(--ega-dgray);
}

/* ---------- Desktop ---------- */
.desktop {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background-color: var(--ega-blue);
  /* 2x2 stipple = classic Turbo Vision "▒" desktop */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='2' height='2'><rect width='1' height='1' x='0' y='0' fill='%233737c0'/><rect width='1' height='1' x='1' y='1' fill='%233737c0'/></svg>");
  background-size: 2px 2px;
  image-rendering: pixelated;
  padding: clamp(0.5ch, 2vw, 2ch);
}

/* ---------- Norton-Commander two-panel ---------- */
.commander {
  display: flex;
  gap: clamp(0.5ch, 2vw, 2ch);
  height: 100%;
  min-height: 0;
}
.panel {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 0.2em solid var(--ega-cyan);      /* double line drawn via outline trick below */
  background: var(--ega-blue);
  box-shadow: var(--shadow);
  min-height: 0;
}
/* double-line border look */
.panel { outline: 1px solid var(--ega-cyan); outline-offset: 2px; }
.panel__title {
  flex: 0 0 auto;
  text-align: center;
  color: var(--ega-yellow);
  background: var(--ega-blue);
  padding: 0 1ch;
  margin-top: -0.2em;
}
.panel__list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  list-style: none;
  margin: 0;
  padding: 0.25em 0;
}
.panel__row {
  display: flex;
  align-items: baseline;
  gap: 1ch;
  width: 100%;
  font: inherit;
  text-align: left;
  background: transparent;
  color: var(--ega-white);
  border: 0;
  padding: 0 1ch;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel__row .icon { color: var(--ega-cyan); }
.panel__row .folder { color: var(--ega-yellow); }
.panel__row .urlname { color: var(--ega-ltgreen); }
.panel__row:hover { background: var(--ega-dgray); }
.panel__row[aria-selected="true"],
.panel__row.selected {
  background: var(--ega-cyan);
  color: var(--ega-black);
}
.panel__row[aria-selected="true"] .icon,
.panel__row[aria-selected="true"] .folder,
.panel__row[aria-selected="true"] .urlname { color: var(--ega-black); }

/* ---------- Windows ---------- */
.window {
  position: absolute;
  min-width: min(90vw, 40ch);
  max-width: min(96vw, 80ch);
  background: var(--ega-blue);
  border: 0.2em solid var(--ega-cyan);
  outline: 1px solid var(--ega-cyan);
  outline-offset: 2px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: 85%;
  z-index: 20;
}
.window.active { z-index: 40; }
.window__bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1ch;
  padding: 0 1ch;
  background: var(--ega-cyan);
  color: var(--ega-black);
  cursor: move;
  user-select: none;
}
.window__title {
  flex: 1 1 auto;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.window__close {
  font: inherit;
  background: var(--ega-blue);
  color: var(--ega-white);
  border: 1px solid var(--ega-black);
  padding: 0 1ch;
  cursor: pointer;
  line-height: 1.2;
}
.window__close:hover { background: var(--ega-red); }
.window__body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 0.5em 1.5ch;
  color: var(--ega-white);
}
.window__body h1,
.window__body h2 {
  font-size: inherit;
  color: var(--ega-yellow);
  margin: 0 0 0.5em;
  font-weight: normal;
}
.window__body p { margin: 0 0 0.5em; }
.window__body a { word-break: break-all; }

/* ---------- COMMAND.COM prompt window ----------
   Authentic DOS command line: monochrome white text on black.
   No coloured tokens - a real COMMAND.COM printed everything in one colour. */
.window--prompt { width: min(94vw, 72ch); }
.window--prompt .window__body {
  background: var(--ega-black);
  color: var(--ega-white);
  cursor: text;
}
.term {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  color: var(--ega-white);
}
.term .cwd,
.term .err,
.term .head { color: var(--ega-white); }
.term__inputline {
  display: flex;
  align-items: baseline;
  gap: 0;
}
.term__prompt { color: var(--ega-white); white-space: pre; }
.term__input {
  flex: 0 1 auto;
  width: 0;
  max-width: 100%;
  font: inherit;
  color: var(--ega-white);
  background: transparent;
  border: 0;
  padding: 0;
  outline: none;
  caret-color: transparent;   /* the block cursor below is the cursor */
}
/* Blinking block cursor, DOS-style, shown when the input is focused. */
.term__cursor {
  display: inline-block;
  width: 1ch;
  height: 1em;
  background: var(--ega-white);
  vertical-align: text-bottom;
  animation: dos-blink 1s steps(1) infinite;
}
.term__input:focus ~ .term__cursor { display: inline-block; }
.term__input:not(:focus) ~ .term__cursor { display: none; }
@keyframes dos-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .term__cursor { animation: none; }
}

/* ---------- Status bar ---------- */
.statusbar {
  display: flex;
  align-items: stretch;
  gap: 1ch;
  flex: 0 0 auto;
  background: var(--ega-gray);
  color: var(--ega-black);
  padding: 0 1ch;
  user-select: none;
  overflow-x: auto;
}
.statusbar__key {
  font: inherit;
  background: transparent;
  color: var(--ega-black);
  border: 0;
  padding: 0.15em 0.75ch;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.5ch;
}
.statusbar__key .fkey {
  background: var(--ega-black);
  color: var(--ega-white);
  padding: 0 0.5ch;
}
.statusbar__key:hover { background: var(--ega-black); color: var(--ega-white); }
.statusbar__key:hover .fkey { background: var(--ega-white); color: var(--ega-black); }
.statusbar__hint {
  margin-left: auto;
  padding: 0.15em 0.75ch;
  color: var(--ega-red);
  white-space: nowrap;
}
.statusbar__hint[hidden] { display: none; }
.statusbar__hint a { color: var(--ega-black); text-decoration: underline; }
.statusbar__hint a:hover { color: var(--ega-red); }

/* ---------- Boot sequence ---------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--ega-black);
  color: var(--ega-gray);
  padding: clamp(1ch, 4vw, 4ch);
  overflow: hidden;
}
.boot[hidden] { display: none; }
.boot pre {
  margin: 0;
  white-space: pre-wrap;
  color: var(--ega-gray);
}
.boot .skip {
  position: absolute;
  bottom: clamp(1ch, 4vw, 4ch);
  left: clamp(1ch, 4vw, 4ch);
  color: var(--ega-dgray);
}

/* ---------- No-JS semantic fallback ---------- */
.docs {
  padding: clamp(1ch, 4vw, 3ch);
  max-width: 80ch;
  margin: 0 auto;
}
body.no-js .desktop,
body.no-js .statusbar { display: none; }
.docs article { margin: 0 0 2em; }
.docs h1, .docs h2 { color: var(--ega-yellow); font-weight: normal; }
.docs p, .docs a, .docs li { overflow-wrap: anywhere; word-break: break-word; }
/* When JS runs, the articles are the data source, kept out of the visual flow */
.js .docs { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ============================================================
   Responsive: phones & narrow screens (< 720px)
   ============================================================ */
@media (max-width: 720px) {
  .commander { flex-direction: column; }           /* panels stack */
  .panel { min-height: 8em; }

  /* windows go full-screen */
  .window {
    position: fixed;
    inset: 0;
    max-width: none;
    max-height: none;
    min-width: 0;
    width: auto;
    border-width: 0.15em;
  }
  .window__bar { cursor: default; }                 /* drag disabled */
  .window--prompt { width: auto; }

  /* status bar becomes a row of >=44px touch targets */
  .statusbar {
    padding: 0;
    gap: 0;
  }
  .statusbar__key {
    flex: 1 1 0;
    min-height: 44px;
    justify-content: center;
    border-right: 1px solid var(--ega-dgray);
  }
  .statusbar__hint { display: none !important; }
}

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