/* biome-ignore-all lint/complexity/noImportantStyles: the shell must win the
   cascade against arbitrary organism CSS — !important on #shell-root rules is
   the security mechanism, not a code smell (see the survivability block below). */

/* The instrument: the immutable shell riding above the mutable document.
   Everything here is namespaced under #shell-root / [data-flash] so the
   organism's styles never collide with it. */

#shell-root {
  --shell-bg: oklch(21% 0.02 260);
  --shell-edge: oklch(32% 0.025 260);
  --shell-text: oklch(88% 0.01 140);
  --shell-dim: oklch(68% 0.02 200);
  --phosphor: oklch(78% 0.19 152);
  --phosphor-dim: oklch(78% 0.19 152 / 0.15);
  --alarm: oklch(70% 0.17 32);
  --amber: oklch(80% 0.14 85);
  position: fixed;
  inset: auto 0 0 0;
  z-index: 2147483647;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 clamp(0.5rem, 3vw, 2rem) clamp(0.75rem, 2.5vh, 1.5rem);
  pointer-events: none;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

#shell-root .shell-log {
  pointer-events: none;
  max-width: 46rem;
  width: 100%;
  margin: 0 0 0.5rem;
  padding: 0 1rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--shell-dim);
  text-shadow: 0 1px 2px oklch(0% 0 0 / 0.4);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
#shell-root .shell-log .entry {
  background: oklch(21% 0.02 260 / 0.96);
  backdrop-filter: blur(6px);
  border-radius: 6px;
  padding: 0.2rem 0.75rem;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  animation: shell-entry 300ms ease both;
}
#shell-root .shell-log .entry[data-kind="note"] {
  color: var(--phosphor);
  font-style: italic;
}
#shell-root .shell-log .entry[data-kind="op"] {
  color: var(--shell-dim);
}
#shell-root .shell-log .entry[data-kind="error"] {
  color: var(--alarm);
}
#shell-root .shell-log .entry[data-kind="system"] {
  color: var(--amber);
}
@keyframes shell-entry {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#shell-root .shell-bar {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 46rem;
  padding: 0.7rem 1rem;
  background: var(--shell-bg);
  border: 1px solid var(--shell-edge);
  border-radius: 10px;
  box-shadow:
    0 24px 48px -12px oklch(0% 0 0 / 0.45),
    0 4px 12px oklch(0% 0 0 / 0.3),
    inset 0 1px 0 oklch(100% 0 0 / 0.06);
}

#shell-root .shell-led {
  flex: none;
  position: relative;
  width: 9px;
  height: 9px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--phosphor);
  box-shadow: 0 0 8px 1px var(--phosphor-dim);
  cursor: default;
  transition:
    background 300ms ease,
    box-shadow 300ms ease;
}
#shell-root .shell-led::after {
  content: "";
  position: absolute;
  inset: -16px;
}
#shell-root .shell-led[data-state="busy"] {
  animation: shell-led-pulse 0.9s ease-in-out infinite;
  box-shadow: 0 0 12px 3px oklch(78% 0.19 152 / 0.5);
  cursor: pointer;
}
#shell-root .shell-led[data-state="busy"]:hover {
  background: var(--alarm);
  box-shadow: 0 0 10px 2px oklch(70% 0.17 32 / 0.5);
}
#shell-root .shell-led[data-state="error"] {
  background: var(--alarm);
  box-shadow: 0 0 10px 2px oklch(70% 0.17 32 / 0.5);
}
@keyframes shell-led-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.8);
  }
}

#shell-root .shell-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--shell-text);
  font:
    500 0.875rem / 1.4 "IBM Plex Mono",
    ui-monospace,
    monospace;
  caret-color: var(--phosphor);
}
#shell-root .shell-input::placeholder {
  color: oklch(55% 0.015 220);
}
#shell-root .shell-input:disabled {
  opacity: 0.45;
}

#shell-root .shell-settings {
  flex: none;
  position: relative;
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  font:
    500 0.9rem / 1 "IBM Plex Mono",
    ui-monospace,
    monospace;
  color: var(--shell-dim);
  background: transparent;
  border: 1px solid var(--shell-edge);
  border-radius: 7px;
  cursor: pointer;
  transition:
    color 200ms ease,
    border-color 200ms ease;
}
#shell-root .shell-settings::after {
  content: "";
  position: absolute;
  inset: -8px;
}
#shell-root .shell-settings:hover {
  color: var(--phosphor);
  border-color: var(--phosphor);
}
#shell-root .shell-settings[data-state="attention"] {
  color: var(--amber);
  border-color: var(--amber);
  animation: shell-led-pulse 1.4s ease-in-out infinite;
}

#shell-root .shell-modal {
  pointer-events: auto;
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: oklch(10% 0.01 260 / 0.6);
  backdrop-filter: blur(4px);
}
#shell-root .shell-modal[hidden] {
  display: none;
}
#shell-root .shell-modal-card {
  width: min(26rem, calc(100vw - 2rem));
  padding: 1.5rem 1.5rem 1.25rem;
  background: var(--shell-bg);
  border: 1px solid var(--shell-edge);
  border-radius: 12px;
  box-shadow:
    0 32px 64px -16px oklch(0% 0 0 / 0.6),
    inset 0 1px 0 oklch(100% 0 0 / 0.06);
  animation: shell-entry 200ms ease both;
}
#shell-root .shell-modal-card h2 {
  margin: 0 0 1.25rem;
  font:
    500 0.75rem / 1 "IBM Plex Mono",
    ui-monospace,
    monospace;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--phosphor);
}
#shell-root .shell-modal-card label {
  display: block;
  margin-bottom: 1.1rem;
}
#shell-root .shell-modal-card .field-name {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--shell-text);
  margin-bottom: 0.4rem;
}
#shell-root .shell-modal-card .field-name em {
  font-style: normal;
  color: var(--amber);
  margin-left: 0.4rem;
}
#shell-root .shell-modal-card input {
  width: 100%;
  background: oklch(16% 0.015 260);
  border: 1px solid var(--shell-edge);
  border-radius: 7px;
  padding: 0.55rem 0.7rem;
  color: var(--shell-text);
  font:
    400 0.8125rem / 1.4 "IBM Plex Mono",
    ui-monospace,
    monospace;
  outline: none;
  transition: border-color 150ms ease;
}
#shell-root .shell-modal-card input:focus {
  border-color: var(--phosphor);
}
#shell-root .shell-modal-card .field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--shell-dim);
}
#shell-root .shell-modal-card .modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}
#shell-root .shell-modal-card .modal-actions button {
  font:
    500 0.75rem / 1 "IBM Plex Mono",
    ui-monospace,
    monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition:
    color 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}
#shell-root .shell-modal-card .modal-save {
  color: oklch(15% 0.02 152);
  background: var(--phosphor);
  border: 1px solid var(--phosphor);
}
#shell-root .shell-modal-card .modal-save:hover {
  background: oklch(84% 0.19 152);
}
#shell-root .shell-modal-card .modal-close {
  color: var(--shell-dim);
  background: transparent;
  border: 1px solid var(--shell-edge);
}
#shell-root .shell-modal-card .modal-close:hover {
  color: var(--shell-text);
  border-color: var(--shell-dim);
}
#shell-root .shell-modal-card .modal-home {
  margin-bottom: 1.1rem;
}
#shell-root .shell-modal-card .home-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
#shell-root .shell-modal-card .home-status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--amber);
}
#shell-root .shell-modal-card .modal-bind {
  flex: none;
  font:
    500 0.75rem / 1 "IBM Plex Mono",
    ui-monospace,
    monospace;
  letter-spacing: 0.1em;
  color: var(--shell-dim);
  background: transparent;
  border: 1px solid var(--shell-edge);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  transition:
    color 150ms ease,
    border-color 150ms ease;
}
#shell-root .shell-modal-card .modal-bind:hover {
  color: var(--phosphor);
  border-color: var(--phosphor);
}

#shell-root .shell-gen {
  flex: none;
  font:
    500 0.75rem / 1 "IBM Plex Mono",
    ui-monospace,
    monospace;
  letter-spacing: 0.12em;
  color: var(--shell-dim);
  background: transparent;
  border: 1px solid var(--shell-edge);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  transition:
    color 200ms ease,
    border-color 200ms ease;
}
#shell-root .shell-gen:hover,
#shell-root .shell-gen[aria-expanded="true"] {
  color: var(--phosphor);
  border-color: var(--phosphor);
}

#shell-root .shell-history {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  right: 0;
  min-width: 15rem;
  max-width: min(28rem, calc(100vw - 2rem));
  max-height: 40vh;
  overflow-y: auto;
  padding: 0.4rem;
  background: var(--shell-bg);
  border: 1px solid var(--shell-edge);
  border-radius: 10px;
  box-shadow:
    0 18px 40px -10px oklch(0% 0 0 / 0.5),
    inset 0 1px 0 oklch(100% 0 0 / 0.06);
  animation: shell-entry 200ms ease both;
}
#shell-root .shell-history .history-entry {
  display: block;
  width: 100%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font:
    400 0.75rem / 1.4 "IBM Plex Mono",
    ui-monospace,
    monospace;
  letter-spacing: 0.08em;
  color: var(--shell-dim);
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  transition:
    color 150ms ease,
    background 150ms ease;
}
#shell-root .shell-history button.history-entry:hover {
  color: var(--phosphor);
  background: var(--phosphor-dim);
}
#shell-root .shell-history .history-entry.is-current {
  color: var(--amber);
  cursor: default;
}
#shell-root .shell-history a.history-link {
  text-decoration: none;
  color: var(--phosphor);
  border-top: 1px solid var(--shell-edge);
  border-radius: 0 0 6px 6px;
  margin-top: 0.25rem;
  padding-top: 0.55rem;
}
#shell-root .shell-history a.history-link:hover {
  background: var(--phosphor-dim);
}
#shell-root .shell-history .history-empty {
  font:
    italic 400 0.75rem / 1.4 "IBM Plex Mono",
    ui-monospace,
    monospace;
  color: var(--shell-dim);
  padding: 0.45rem 0.75rem;
  opacity: 0.7;
}

/* Keyboard focus speaks phosphor, not browser-default blue. */
#shell-root :is(button, input):focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 2px;
}
#shell-root .shell-modal-card input:focus {
  border-color: var(--phosphor);
  box-shadow: 0 0 0 3px var(--phosphor-dim);
}

/* Mutation flash — freshly grafted tissue glows, then settles. */
[data-flash] {
  animation: substrate-flash 1.4s ease-out both;
}
@keyframes substrate-flash {
  0% {
    outline: 2px solid oklch(70% 0.18 152 / 0.9);
    outline-offset: 3px;
    background-color: oklch(70% 0.18 152 / 0.12);
  }
  100% {
    outline: 2px solid transparent;
    outline-offset: 6px;
    background-color: transparent;
  }
}
@media (prefers-reduced-motion: reduce) {
  [data-flash] {
    animation: none;
  }
  #shell-root .shell-led[data-state="busy"] {
    animation: none;
    opacity: 0.7;
  }
}

/* Shell survivability. A mutation stylesheet may use broad selectors the
   protocol's substring guard can't catch (e.g. `* { display: none !important }`),
   but it can never name #shell-root or [data-shell] (those strings are rejected),
   so it can't reach ID specificity on the shell. These ID-level !important rules
   therefore always win, keeping the command bar reachable no matter what the
   organism does to the page. */
#shell-root {
  position: fixed !important;
  inset: auto 0 0 0 !important;
  z-index: 2147483647 !important;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: none !important;
  transform: none !important;
  filter: none !important;
}
#shell-root .shell-bar,
#shell-root .shell-input,
#shell-root .shell-led,
#shell-root .shell-settings,
#shell-root .shell-gen {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}
#shell-root .shell-bar {
  display: flex !important;
}
