.resident-terminal {
  position:absolute;
  z-index:5;
  inset:2% clamp(4%,8vw,10%) 1%;
  display:grid;
  grid-template-rows:auto 1fr auto;
  overflow:hidden;
  pointer-events:auto;
  clip-path:polygon(7% 0,93% 0,100% 100%,0 100%);
  border-block:1px solid rgba(var(--resident-core-rgb),.5);
  background:
    radial-gradient(ellipse at 50% 42%,rgba(var(--resident-core-rgb),.12),transparent 48%),
    linear-gradient(90deg,rgba(0,6,13,.68),rgba(1,11,20,.96) 10% 90%,rgba(0,6,13,.68));
  box-shadow:inset 0 0 5rem rgba(var(--resident-core-rgb),.09),0 0 2.6rem rgba(1,21,34,.24);
  color:#bffcff;
  font:500 clamp(.65rem,.82vw,.78rem)/1.55 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;
  letter-spacing:.055em;
  transform:none;
}

.resident-terminal::before {
  position:absolute;
  z-index:-1;
  inset:0;
  content:"";
  pointer-events:none;
  opacity:.24;
  background:repeating-linear-gradient(0deg,transparent 0 3px,rgba(var(--resident-core-rgb),.11) 4px);
}

.resident-terminal__header {
  display:grid;
  grid-template-columns:1fr auto auto;
  align-items:center;
  gap:.65rem;
  min-height:2.35rem;
  padding:.55rem clamp(1rem,4vw,3.5rem);
  border-bottom:1px solid rgba(var(--resident-core-rgb),.28);
  color:rgba(211,253,255,.65);
}
.resident-terminal__header strong { color:var(--resident-core-accent); font-size:.62rem; text-shadow:0 0 .65rem rgba(var(--resident-core-rgb),.68); }
.resident-terminal__header button,.resident-terminal__command button {
  min-height:1.8rem;
  border:1px solid rgba(var(--resident-core-rgb),.42);
  background:rgba(2,15,23,.88);
  color:#c7fbff;
  font:inherit;
  letter-spacing:.08em;
}
.resident-terminal__header button:hover,.resident-terminal__header button:focus-visible,.resident-terminal__command button:hover,.resident-terminal__command button:focus-visible { border-color:var(--resident-core-accent); box-shadow:0 0 .65rem rgba(var(--resident-core-rgb),.25); outline:none; }
.resident-terminal__header button[hidden] { display:none; }

.resident-terminal__history {
  min-height:0;
  overflow:auto;
  padding:clamp(1rem,3vh,2rem) clamp(1rem,6vw,5.5rem);
  scrollbar-color:rgba(var(--resident-core-rgb),.42) transparent;
  scrollbar-width:thin;
}
.resident-terminal__line { display:grid; grid-template-columns:max-content 1fr; gap:.55rem; margin:0 0 .55rem; overflow-wrap:anywhere; }
.resident-terminal__line b { color:var(--resident-core-accent); font-weight:600; }
.resident-terminal__line span { color:rgba(222,253,255,.88); white-space:pre-wrap; }
.resident-terminal__line--system { opacity:.62; font-size:.92em; }
.resident-terminal__line--system[data-kind="error"],.resident-terminal[data-state="error"] .resident-terminal__header strong { color:#ff8e9e; }
.resident-terminal__line--system[data-kind="offline"] { color:#9cb4bd; }
.resident-terminal__line--user span { color:#d9ffbc; }

.resident-terminal__command {
  display:grid;
  grid-template-columns:auto minmax(4rem,1fr) auto auto auto;
  align-items:center;
  gap:.4rem;
  padding:.7rem clamp(1rem,4vw,3.5rem);
  border-top:1px solid rgba(var(--resident-core-rgb),.3);
  background:rgba(0,8,14,.84);
}
.resident-terminal__command label { color:#bfff83; white-space:nowrap; }
.resident-terminal__command input {
  width:100%;
  min-width:0;
  border:0;
  border-bottom:1px solid rgba(var(--resident-core-rgb),.28);
  border-radius:0;
  outline:0;
  background:transparent;
  color:#e5ffff;
  font:inherit;
  caret-color:#bfff83;
}
.resident-terminal__command input::placeholder { color:rgba(196,238,242,.35); }
.resident-terminal__command button { padding:.25rem .52rem; }
.resident-terminal__command button:disabled { opacity:.3; cursor:not-allowed; }
.resident-terminal__cursor { width:.38rem; height:.85rem; background:#bfff83; box-shadow:0 0 .55rem rgba(191,255,131,.7); animation:resident-terminal-cursor .85s steps(1,end) infinite; }
.resident-terminal[data-state="connecting"] { opacity:.78; }
.resident-terminal[data-state="thinking"] { border-color:rgba(198,154,255,.72); }
.resident-terminal[data-state="speaking"] { border-color:rgba(128,216,255,.75); }

@keyframes resident-terminal-cursor { 50% { opacity:0; } }

@media (max-width:760px) {
  .resident-terminal {
    inset:1% 1% 0;
    width:auto;
    height:auto;
    font-size:.62rem;
    transform:none;
    clip-path:polygon(3% 0,97% 0,100% 100%,0 100%);
  }
  .resident-terminal__header { grid-template-columns:1fr auto auto; gap:.35rem; min-height:2rem; padding:.3rem .4rem; }
  .resident-terminal__command { grid-template-columns:auto minmax(3rem,1fr) auto auto; gap:.3rem; padding:.4rem; }
  .resident-terminal__cursor { display:none; }
  .resident-terminal__command button { min-height:2rem; padding:.2rem .4rem; }
  .resident-terminal__history { padding:.8rem .65rem 1rem; }
}

@media (max-width:390px) {
  .resident-terminal__header > span { max-width:8rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .resident-terminal__command { grid-template-columns:auto 1fr auto; }
  .resident-terminal__command [data-resident-terminal-interrupt] { grid-column:2 / -1; }
}

@media (prefers-reduced-motion:reduce) {
  .resident-terminal__cursor { animation:none; opacity:1; }
  .resident-terminal { transition:none; }
}
