:root {
  color-scheme: dark;
  color: #d3f7de;
  background: #020704;
  font: 16px / 1.55 ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --green: #67ff97;
  --muted: #8ab79a;
  --line: #255036;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  margin: 0;
  padding: clamp(0.75rem, 3vw, 2rem);
  background: radial-gradient(ellipse at 50% 40%, #0b2412 0%, #041008 52%, #010402 100%);
}

.rain {
  position: fixed;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  opacity: .43;
  pointer-events: none;
}

.terminal {
  position: relative;
  min-inline-size: 0;
  inline-size: min(100%, 56rem);
  block-size: min(43rem, calc(100dvh - clamp(1.5rem, 6vw, 4rem)));
  min-block-size: 20rem;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #061008;
  border: 1px solid #347447;
  box-shadow: 0 22px 100px #000b, 0 0 65px #28eb5825, inset 0 0 18px #65ff8e0b;
}

.terminal-head {
  min-inline-size: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: clamp(.85rem, 3vw, 1.65rem);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(98deg, #10271a, #08150c 72%);
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 4.1vw, 2.2rem);
  font-weight: 720;
  line-height: 1.15;
  letter-spacing: -.06em;
  color: #ecfff1;
}

h1 span {
  color: var(--green);
  text-shadow: 0 0 14px #34ff6388;
}

button, textarea { font: inherit; }

button {
  min-block-size: 2.75rem;
  padding: .5rem .85rem;
  border: 1px solid #3a7b50;
  border-radius: 0;
  background: #0e2114;
  color: var(--green);
  font-size: .875rem;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
}

button:enabled:hover { background: #1b3d26; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, textarea:focus-visible, .history:focus-visible, #notice:focus-visible { outline: 2px solid #acfcc1; outline-offset: -2px; }

.history {
  overflow-y: auto;
  scrollbar-color: #3b8051 #08120b;
  overscroll-behavior: contain;
  min-block-size: 0;
  padding: clamp(1rem, 3vw, 1.75rem);
  background: repeating-linear-gradient(0deg, #4fb74d07 0 1px, transparent 1px 5px);
}

#messages { display: grid; gap: .65rem; }
#messages:empty { display: none; }

.turn { display: grid; gap: .65rem; min-inline-size: 0; }

.message {
  max-inline-size: 72ch;
  min-inline-size: 0;
  padding: .7rem .95rem .8rem;
  border-inline-start: 2px solid #386849;
  background: #0c180f;
}

.message.user {
  justify-self: end;
  inline-size: fit-content;
  max-inline-size: min(100%, 72ch);
  border-inline-start: 0;
  border-inline-end: 2px solid #5ae582;
  background: #11291a;
}

.message strong { color: #a7e8ba; font-size: .875rem; }
.message p { margin: .2rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.pending { opacity: .75; }

.idle {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: var(--green);
}
.idle[hidden], .status[hidden] { display: none; }
.idle span {
  display: inline-block;
  inline-size: .58rem;
  block-size: 1rem;
  background: var(--green);
  box-shadow: 0 0 13px #67ff9780;
  animation: blink 1.25s steps(1, end) infinite;
}

.composer {
  min-inline-size: 0;
  padding: .85rem clamp(.85rem, 3vw, 1.65rem);
  border-top: 1px solid var(--line);
  background: #0a170e;
}

.compose-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .65rem;
}

.compose-row label { color: var(--green); }

textarea {
  min-inline-size: 0;
  inline-size: 100%;
  min-block-size: 3.2rem;
  max-block-size: 8rem;
  resize: vertical;
  padding: .55rem .7rem;
  border: 1px solid #31573a;
  border-radius: 0;
  background: #050c07;
  color: #f0fff2;
}

textarea::placeholder { color: #97b6a0; opacity: 1; }

button.send {
  border-color: var(--green);
  background: var(--green);
  color: #041308;
  min-inline-size: 5.5rem;
}
button.send:enabled:hover { background: #aaffc3; }
button.send:focus-visible { outline-color: #0a2e17; }

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  margin-top: .55rem;
  color: var(--muted);
  font-size: .78rem;
}
.composer-meta p { margin: 0; max-block-size: 5rem; overflow-y: auto; overflow-wrap: anywhere; white-space: pre-wrap; }
.composer-meta p:empty { display: none; }
.composer-meta output { margin-inline-start: auto; white-space: nowrap; }
.status { margin: 0 0 .45rem; color: #e1f7e6; font-size: .875rem; }

.terminal-offline { block-size: auto; min-block-size: 0; grid-template-rows: auto auto; }
.offline-message { margin: 0; padding: 2rem; color: var(--green); }

@keyframes blink { 0%, 62% { opacity: 1; } 63%, 100% { opacity: .18; } }

@media (max-width: 35rem) {
  .terminal { block-size: calc(100dvh - 1.5rem); }
  .compose-row { gap: .35rem; }
  .compose-row label { display: none; }
  .compose-row { grid-template-columns: minmax(0, 1fr) auto; }
  button.send { min-inline-size: 4rem; }
}

@media (prefers-reduced-motion: reduce) { .idle span { animation: none; } }
