:root {
  color-scheme: dark;
  --shell-font-size: 0.875rem;
  --shell-line-height: 1.5rem;
  --shell-padding-x: var(--space-6);
  --shell-padding-y: var(--space-5);
  --shell-bar-height: var(--control-height-lg);
  --shell-target: var(--target-min-pointer);
  --shell-action-row-height: var(--shell-line-height);
  --shell-label-width: 18ch;
  --shell-icon-size: var(--icon-sm);
  --shell-logo-size: var(--icon-md);
  --shell-portrait-size: 12rem;
}

/* 1rem au tactile : sous 16px, iOS zoome sur le champ à la prise de focus. */
@media (max-width: 47.4375rem), (pointer: coarse) {
  :root {
    --shell-font-size: 1rem;
    --shell-padding-x: var(--space-4);
    --shell-padding-y: var(--space-4);
    --shell-bar-height: var(--target-min-touch);
    --shell-target: var(--target-min-touch);
    --shell-action-row-height: var(--target-min-touch);
    --shell-label-width: 14ch;
    --shell-icon-size: var(--icon-md);
    --shell-logo-size: var(--icon-lg);
  }
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--terminal-surface);
}

.terminal {
  --icon-size: var(--shell-icon-size);

  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--terminal-surface);
  color: var(--terminal-text);
  font: 400 var(--shell-font-size) / var(--shell-line-height) var(--font-mono);
}

.plain-button {
  min-width: var(--shell-target);
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

:focus-visible {
  outline: var(--focus-ring-width) solid var(--terminal-accent);
  outline-offset: var(--focus-ring-offset);
}

/* Les boutons des barres touchent le bord de leur conteneur : un anneau extérieur y serait rogné. */
.tab-bar :focus-visible,
.status-bar :focus-visible {
  outline-offset: calc(-1 * var(--focus-ring-width));
}

/* La marge négative annule le remplissage : le texte garde sa place, l'anneau intérieur ne le touche plus. */
.tab__select,
.status-bar__help {
  margin-inline: calc(-1 * var(--space-1));
  padding-inline: var(--space-1);
}

.tone-dim {
  color: var(--terminal-dim);
}

.tone-accent {
  color: var(--terminal-accent);
}

.tone-danger {
  color: var(--terminal-danger);
}

.prompt-symbol {
  flex: none;
  color: var(--terminal-dim);
}

.prompt-symbol__directory {
  color: var(--palette-green);
}

.tab-bar {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
  min-height: var(--shell-bar-height);
  padding: 0 var(--shell-padding-x);
  overflow-x: auto;
  box-shadow: inset 0 -1px 0 0 var(--terminal-border);
}

.tab-list {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.tab {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
}

.tab--active {
  box-shadow: inset 0 -1px 0 0 var(--terminal-text);
}

.tab__select {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--terminal-dim);
}

.tab__title {
  max-width: 24ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab__image {
  flex: none;
  width: var(--shell-icon-size);
  height: var(--shell-icon-size);
  object-fit: contain;
}

.tab--active .tab__select {
  color: var(--terminal-text);
}

.tab__close,
.tab-bar__add {
  flex: none;
  color: var(--terminal-dim);
  text-align: center;
}

.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--shell-padding-y) var(--shell-padding-x) 0;
  overflow-y: auto;
}

.log {
  display: flex;
  flex-direction: column;
}

.entry {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--shell-line-height);
  scroll-margin-top: var(--space-4);
}

.entry__command {
  overflow-wrap: anywhere;
}

.line {
  display: flex;
  gap: 1ch;
  min-height: var(--shell-line-height);
  overflow-wrap: anywhere;
}

.line--action {
  align-items: center;
  min-height: var(--shell-action-row-height);
}

.line__label {
  flex: none;
  width: var(--shell-label-width);
  color: var(--terminal-dim);
}

.line__content {
  min-width: 0;
}

.command-link {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 1ch;
  color: var(--terminal-accent);
}

.command-link .icon {
  color: var(--hue, var(--terminal-dim));
}

.command-link__image {
  flex: none;
  width: var(--shell-icon-size);
  height: var(--shell-icon-size);
  object-fit: contain;
}

.command-link__text {
  min-width: 0;
}

.figure {
  display: flex;
  flex-wrap: wrap;
  gap: var(--shell-line-height) 3ch;
}

.figure__image {
  flex: none;
  width: var(--shell-portrait-size);
  height: var(--shell-portrait-size);
  object-fit: cover;
}

.figure__lines {
  flex: 1;
  min-width: min(100%, 32ch);
}

.line__anchor {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 1ch;
}

.chips {
  align-self: stretch;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0 2ch;
}

.chip {
  position: relative;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 1ch;
  min-height: var(--shell-action-row-height);
}

.chip--action {
  justify-content: center;
  min-width: var(--shell-target);
  color: var(--hue, var(--terminal-accent));
}

.chip--logo {
  text-decoration: none;
}

.chip--logo .icon {
  width: var(--shell-logo-size);
  height: var(--shell-logo-size);
}

/* Avec une souris, le logo suffit et son nom apparaît dans une bulle au survol ou au focus.
   Sans survol possible (tactile), le nom reste écrit à côté du logo. */
@media (hover: hover) {
  .chip--logo .chip__name {
    position: absolute;
    bottom: 100%;
    left: 50%;
    z-index: 1;
    padding: 0 1ch;
    background: var(--terminal-text);
    color: var(--terminal-surface);
    white-space: nowrap;
    transform: translateX(-50%);
    clip-path: inset(50%);
  }

  .chip--logo:hover .chip__name,
  .chip--logo:focus .chip__name {
    clip-path: none;
  }

  .chip--logo[data-tooltip-dismissed] .chip__name {
    clip-path: inset(50%);
  }
}

.swatches {
  gap: 0;
  margin-top: var(--space-2);
}

.swatch {
  width: 3ch;
  height: var(--shell-line-height);
  background: currentColor;
}

/* Vidéo inverse, comme grep : le mot trouvé reste lisible et ne tient pas qu'à une teinte. */
.highlight {
  background: var(--terminal-accent);
  color: var(--terminal-surface);
}

/* Graphe à la manière de « git log --graph » : une colonne par branche, un point par élément.
   Les traits sont dessinés en CSS pour rester continus quand une ligne passe sur plusieurs rangées. */
.graph-row {
  --graph-center: calc(var(--shell-line-height) / 2);

  display: flex;
  gap: 1ch;
}

.graph-row--action {
  --graph-center: calc(var(--shell-action-row-height) / 2);
}

.graph {
  flex: none;
  align-self: stretch;
  display: flex;
}

.graph__lane {
  position: relative;
  width: 2ch;
}

.graph__lane--line::before,
.graph__lane--from-above::before,
.graph__lane--to-below::after {
  content: "";
  position: absolute;
  left: calc(50% - 0.5px);
  width: 1px;
  background: currentColor;
}

.graph__lane--line::before {
  top: 0;
  bottom: 0;
}

.graph__lane--from-above::before {
  top: 0;
  height: var(--graph-center);
}

.graph__lane--to-below::after {
  top: var(--graph-center);
  bottom: 0;
}

.graph__lane--node {
  background: radial-gradient(
    circle at 50% var(--graph-center),
    currentColor 0.25rem,
    transparent calc(0.25rem + 1px)
  );
}

.graph-row__date {
  flex: none;
  width: 5ch;
  display: flex;
  align-items: center;
  height: calc(var(--graph-center) * 2);
  color: var(--terminal-dim);
}

.graph-row__lines {
  flex: 1;
  min-width: 0;
}

/* Sur un écran étroit, le texte d'une ligne du graphe passe sous son libellé au lieu de s'y écraser. */
@media (max-width: 47.4375rem), (pointer: coarse) {
  .graph-row .line {
    flex-wrap: wrap;
  }

  .graph-row .line__content {
    flex: 1 1 100%;
  }

  .graph-row .command-link {
    min-height: var(--shell-action-row-height);
  }
}

.legend {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--shell-line-height);
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 1ch;
  min-height: var(--shell-line-height);
}

.legend__dot {
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--radius-full);
  background: currentColor;
}

.copy-button {
  color: var(--terminal-accent);
}

.picture {
  align-self: flex-start;
  max-width: min(100%, 48rem);
  height: auto;
  margin-top: var(--shell-line-height);
}

a {
  color: var(--terminal-accent);
  text-underline-offset: 0.3em;
}

.prompt {
  flex: 1;
  display: flex;
  min-height: var(--shell-target);
  margin: 0;
}

.prompt__label {
  flex: 1;
  display: flex;
  flex-direction: column;
  cursor: text;
}

/* Un long chemin dans l'invite ne doit pas écraser la saisie : sur un écran étroit,
   le champ passe à la ligne suivante. */
.prompt__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1ch;
}

.prompt__row:focus-within {
  box-shadow: inset 0 -1px 0 0 var(--terminal-accent);
}

/* Le champ n'a pas d'anneau : le trait sous la ligne de commande est son indicateur de focus. */
.prompt__input {
  flex: 1 1 14ch;
  min-width: 14ch;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--terminal-text);
  font: inherit;
  caret-color: var(--terminal-accent);
}

.prompt__hint {
  flex: none;
  color: var(--terminal-dim);
}

/* La proposition se valide avec la touche Tab, absente des claviers tactiles. */
@media (max-width: 47.4375rem), (pointer: coarse) {
  .prompt__hint {
    display: none;
  }
}

.status-bar {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
  min-height: var(--shell-bar-height);
  padding: 0 var(--shell-padding-x);
  color: var(--terminal-dim);
}

.status-bar__help {
  flex: none;
  color: var(--terminal-accent);
}

.status-bar__hint {
  align-self: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.language-switch {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
}

.language-button {
  text-align: center;
  text-underline-offset: 0.3em;
}

.language-button[aria-pressed="true"] {
  color: var(--terminal-text);
  text-decoration: underline;
}

.no-script {
  max-width: 72ch;
  margin: 0;
  padding: var(--space-4) var(--space-6);
  color: var(--terminal-text);
  font: 400 1rem / 1.5rem var(--font-mono);
}

/* En couleurs forcées, les ombres ne sont plus dessinées : les états qu'elles portent passent en bordures. */
@media (forced-colors: active) {
  .tab-bar {
    border-bottom: 1px solid CanvasText;
  }

  .tab--active {
    border-bottom: 2px solid Highlight;
  }

  .prompt__row:focus-within {
    border-bottom: 1px solid Highlight;
  }
}
