/*
 * Terminal UI: tmux-style status line, Norton Commander-style key bar of
 * links, theme picker menu, shortcuts help dialog.
 * Behaviour lives in assets/js/terminal-ui.js.
 */

/* Leave room for the fixed footer. terminal-ui.js keeps this in step with
 * the footer's real height (the key bar wraps to two rows on phones). */
body {
  padding-bottom: var(--statusbar-height, 5em);
}

/* Buttons inside the terminal chrome look like text */
.statusbar button,
.theme-menu button,
.help button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0 0.4em;
  cursor: pointer;
  text-shadow: inherit;
}

.statusbar button:hover,
.statusbar button:focus-visible,
.statusbar button[aria-expanded="true"],
.help button:hover,
.help button:focus-visible {
  background: var(--punct-color);
  color: var(--bg-color);
  text-shadow: none;
  outline: none;
}

/* ===== STATUS LINE ===== */
.statusbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9996; /* under the scanlines so they run across it too */
  font-family: var(--term-font, 'IBM VGA', monospace);
  font-size: 16px;
  line-height: 1.5;
  white-space: nowrap;
  color: var(--punct-color);
  background: var(--bg-color);
  border-top: 1px solid var(--punct-color);
}

.statusbar__line {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.2em 0.6em;
  overflow: hidden; /* one row, always: see ONE-ROW FIT below */
}

.statusbar__line > * {
  flex: none;
}

/* ===== LINKS: Norton Commander key-bar style, inside the status line.
 * The key sits on the screen colour, the logo and label on an inverse
 * block. Narrower screens drop the labels, then the keys (see below). ===== */
.keybar {
  display: flex;
  align-items: center;
  gap: 1ch;
  flex: none;
}

.keybar a {
  display: flex !important;
  align-items: center;
  gap: 0.5ch;
  color: inherit;
  text-decoration: none;
  text-shadow: inherit;
}

.keybar kbd {
  font: inherit;
  color: var(--keyval-color);
}

.keybar a > span {
  display: flex;
  align-items: center;
  gap: 0.6ch;
  padding: 0 0.5ch;
  background: var(--punct-color);
  color: var(--bg-color);
  text-shadow: none;
}


/* Pixel-art logo, filled in the label's colour. 18px = exactly 2px per
 * logo pixel (logos are 9 rows), so every pixel comes out the same size. */
.keybar__icon {
  flex: none;
  height: 18px;
  width: auto;
  fill: currentColor;
  shape-rendering: crispEdges;
}

.keybar a:hover > span,
.keybar a:focus-visible > span {
  background: var(--hover-color);
}

.keybar a:focus-visible {
  outline: none;
}

.keybar a:focus-visible kbd {
  background: var(--keyval-color);
  color: var(--bg-color);
}

/* no link-hover shimmer from custom-styles.css inside the chrome */
.keybar a:hover::after {
  content: none;
}

.statusbar__host {
  padding: 0 0.5em;
  background: var(--punct-color);
  color: var(--bg-color);
  text-shadow: none;
}

.statusbar__msg {
  flex: 1 1 0 !important;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--keyval-color);
}

.statusbar__theme-name {
  color: var(--keyval-color);
}

.statusbar button:hover .statusbar__theme-name,
.statusbar button:focus-visible .statusbar__theme-name,
.statusbar button[aria-expanded="true"] .statusbar__theme-name {
  color: inherit;
}

/* ===== THEME MENU (DOS-style pop-up above the status line) ===== */
.theme-menu {
  position: absolute;
  right: 0.6em;
  bottom: calc(100% + 0.6em);
  min-width: 18em;
  max-width: calc(100vw - 1.2em);
  padding: 0.9em 0 0.5em;
  background: var(--bg-color);
  border: 4px double var(--punct-color);
  box-shadow: 0.5em 0.5em 0 rgba(0, 0, 0, 0.45);
}

.theme-menu[hidden] {
  display: none;
}

.theme-menu__title,
.help__title {
  position: absolute;
  top: -0.85em;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0 0.5em;
  font-size: inherit;
  font-weight: normal;
  background: var(--bg-color);
  color: var(--punct-color);
  white-space: nowrap;
}

.theme-menu__option {
  display: grid !important;
  grid-template-columns: 1.5ch 2ch 7ch auto;
  gap: 0 0.6ch;
  width: 100%;
  padding: 0 1em !important;
  text-align: left;
}

.theme-menu__option:hover,
.theme-menu__option:focus-visible {
  background: var(--punct-color) !important;
  color: var(--bg-color) !important;
  text-shadow: none !important;
  outline: none;
}

.theme-menu__key {
  color: var(--keyval-color);
}

.theme-menu__desc {
  opacity: 0.75;
}

.theme-menu__option:hover .theme-menu__key,
.theme-menu__option:focus-visible .theme-menu__key {
  color: inherit;
}

.theme-menu__hint {
  margin: 0.4em 1em 0;
  opacity: 0.7;
}

/* ===== HELP DIALOG ===== */
.help {
  position: fixed;
  max-width: min(34em, calc(100vw - 2em));
  max-height: calc(100vh - 4em);
  overflow: visible;
  padding: 1.4em 1.6em 1em;
  font-family: var(--term-font, 'IBM VGA', monospace);
  font-size: 16px;
  line-height: 1.5;
  color: var(--punct-color);
  background: var(--bg-color);
  border: 4px double var(--punct-color);
  box-shadow: 0.6em 0.6em 0 rgba(0, 0, 0, 0.45);
  text-shadow: var(--text-glow, none);
}

.help::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.help__list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.15em 1.5em;
  margin: 0;
  max-height: calc(100vh - 10em);
  overflow-y: auto;
}

.help__list dt {
  color: var(--keyval-color);
}

.help__list dd {
  margin: 0;
}

.help__list kbd {
  font: inherit;
}

.help__section {
  grid-column: 1 / -1;
  margin-top: 0.6em;
  opacity: 0.7;
}

.help__footer {
  margin: 1em 0 0;
  text-align: center;
  opacity: 0.7;
}

/* ===== SCREEN EFFECTS OFF (s) ===== */
.no-crt .crt-scanlines,
.no-crt .crt-scanline,
.no-crt .crt-flicker,
.no-crt .crt-texture {
  display: none;
}

/* ===== SMALL SCREENS ===== */
@media (max-width: 480px) {
  .statusbar {
    font-size: 14px;
  }

  .theme-menu__option {
    grid-template-columns: 1.5ch 2ch auto;
  }

  .theme-menu__desc {
    display: none;
  }
}

/* ===== ONE-ROW FIT =====
 * The status line never wraps. terminal-ui.js measures it (widths depend on
 * the theme's font) and sets data-fit to the first level that fits:
 *   0  everything
 *   1  links drop their labels (logo + key)
 *   2  links drop their keys, help and theme drop their words, no message
 *   3  the j47.in tag goes too
 * The media query is the no-JS fallback for phones. */
.statusbar[data-fit="1"] .keybar__label,
.statusbar[data-fit="2"] .keybar__label,
.statusbar[data-fit="3"] .keybar__label {
  /* visually hidden, still read out by screen readers */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.statusbar[data-fit="2"] :is(.keybar kbd, .statusbar__help-label, .statusbar__theme-label, .statusbar__theme-auto, .statusbar__msg),
.statusbar[data-fit="3"] :is(.keybar kbd, .statusbar__help-label, .statusbar__theme-label, .statusbar__theme-auto, .statusbar__msg, .statusbar__host) {
  display: none;
}

.statusbar:is([data-fit="2"], [data-fit="3"]) .statusbar__line {
  gap: 0.4em;
}

.statusbar:is([data-fit="2"], [data-fit="3"]) .keybar {
  gap: 0.5ch;
  /* with no message, push help and theme to the right */
  margin-right: auto;
}

.statusbar:is([data-fit="2"], [data-fit="3"]) button {
  padding: 0 0.3em;
}

@media (max-width: 480px) {
  .statusbar:not([data-fit]) :is(.keybar kbd, .keybar__label) {
    display: none;
  }
}

@media print {
  .statusbar,
  .help {
    display: none;
  }
}
