:root {
  --bg: #010201;
  --bg-soft: rgba(0, 10, 0, 0.94);
  --panel: rgba(0, 2, 0, 0.98);
  --line: rgba(83, 255, 116, 0.24);
  --line-soft: rgba(83, 255, 116, 0.12);
  --text: #7dff8f;
  --muted: #3f9d51;
  --accent: #b7ffbe;
  --label: #72f987;
  --danger: #ff9292;
  --inverse-bg: rgba(131, 255, 150, 0.18);
  --inverse-text: #baffc2;
}

html,
body {
  height: 100%;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: #010201;
  color: var(--text);
  font-family: "Courier New", "Lucida Console", "Monaco", monospace;
  overflow: hidden;
  text-shadow: 0 0 3px rgba(90, 255, 110, 0.26), 0 0 10px rgba(90, 255, 110, 0.04);
}

.landing-shell {
  overflow-y: auto;
  overflow-x: hidden;
}

.landing-shell .terminal-app {
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  grid-template-rows: auto auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: rgba(110, 255, 128, 0.018);
  opacity: 0.08;
  animation: crt-flicker 2.4s step-end infinite;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow:
    inset 0 0 120px rgba(0, 0, 0, 0.84),
    inset 0 0 28px rgba(110, 255, 128, 0.04);
}

@keyframes crt-flicker {
  0% { opacity: 0.18; }
  12% { opacity: 0.2; }
  18% { opacity: 0.24; }
  31% { opacity: 0.17; }
  42% { opacity: 0.22; }
  57% { opacity: 0.19; }
  71% { opacity: 0.23; }
  84% { opacity: 0.18; }
  100% { opacity: 0.21; }
}

a {
  color: inherit;
}

.d-none {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.terminal-app {
  height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0;
  padding:
    max(0rem, env(safe-area-inset-top))
    max(0rem, env(safe-area-inset-right))
    max(0rem, env(safe-area-inset-bottom))
    max(0rem, env(safe-area-inset-left));
}

.app-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 2rem;
  padding: 0.45rem 1rem 0.5rem;
  background: #021005;
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 -1px 0 rgba(131, 255, 150, 0.06);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.74rem;
  text-shadow: inherit;
}

.app-meta {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.app-meta > * + * {
  position: relative;
  padding-left: 0.85rem;
}

.app-meta > * + *::before {
  content: "|";
  position: absolute;
  left: 0;
  top: 0;
  color: rgba(125, 255, 143, 0.42);
}

.app-meta-right {
  justify-content: flex-end;
}

.app-title {
  color: var(--inverse-text);
  flex: 0 0 auto;
  font-weight: 700;
  padding: 0.08rem 0.34rem;
  background: rgba(131, 255, 150, 0.14);
  box-shadow: inset 0 0 0 1px rgba(131, 255, 150, 0.14);
  text-shadow: 0 0 5px rgba(131, 255, 150, 0.16);
}

.app-mode {
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell {
  min-height: 0;
  height: 100%;
  display: grid;
  background: #000200;
}

.landing-stack {
  display: grid;
  gap: 1rem;
}

.seo-layout,
.faq-layout {
  content-visibility: auto;
  contain-intrinsic-size: 44rem;
}

.landing-layout {
  grid-template-columns: minmax(0, 1fr) minmax(25rem, 0.92fr);
}

.chat-layout {
  grid-template-columns: 21rem minmax(0, 1fr);
}

.panel {
  min-height: 0;
  padding: 0.9rem 1rem;
}

.panel + .panel {
  border-left: 1px solid var(--line);
}

.info-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.screen-title {
  margin: 0 0 1rem;
  max-width: 24ch;
  color: var(--text);
  font-size: clamp(1.2rem, 2.2vw, 1.9rem);
  line-height: 1.35;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-shadow: 0 0 6px rgba(125, 255, 143, 0.12);
}

.screen-copy,
.section-copy,
.fact-value,
.text-secondary,
.field-copy,
#composer-note,
.message-time,
.message-separator,
.message-image-meta,
.attachment-status {
  color: var(--muted) !important;
}

.screen-copy {
  max-width: 60ch;
  margin: 0 0 1.6rem;
  line-height: 1.55;
}

.hero-kicker {
  margin: 0 0 0.7rem;
  color: var(--label);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
}

.fact-list {
  display: grid;
  gap: 0.45rem;
}

.fact-row {
  display: grid;
  grid-template-columns: 10.5rem minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  padding: 0.18rem 0;
  border-bottom: 1px dotted rgba(76, 195, 92, 0.18);
}

.fact-label,
.field-prefix,
.terminal-label {
  color: var(--label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.73rem;
}

.action-panel {
  display: flex;
  flex-direction: column;
}

.seo-layout,
.faq-layout {
  height: auto;
}

.seo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: 0;
}

.seo-card,
.faq-panel {
  padding: 1rem;
}

.seo-card {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line-soft);
}

.seo-card:nth-child(2n) {
  border-right: 0;
}

.seo-card:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.seo-copy,
.faq-answer {
  margin: 0 0 0.9rem;
  color: var(--muted);
  line-height: 1.55;
}

.seo-copy:last-child,
.faq-answer:last-child {
  margin-bottom: 0;
}

.seo-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  display: grid;
  gap: 0.45rem;
  line-height: 1.5;
}

.faq-panel {
  display: grid;
  gap: 0.9rem;
}

.faq-list {
  display: grid;
  gap: 0.8rem;
}

.faq-item {
  padding-bottom: 0.8rem;
  border-bottom: 1px dotted rgba(76, 195, 92, 0.18);
}

.faq-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.faq-question {
  margin: 0 0 0.35rem;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.action-section {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px dashed var(--line-soft);
}

.action-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.section-title {
  margin: 0 0 0.5rem;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.section-title::before {
  content: "[";
  color: var(--accent);
}

.section-title::after {
  content: "]";
  color: var(--accent);
}

.section-copy {
  margin: 0 0 1rem;
  line-height: 1.45;
}

.tui-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.terminal-label {
  display: block;
}

.input-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
  padding: 0.15rem 0 0.35rem;
  border-bottom: 1px solid var(--line);
}

.field-prefix {
  padding-top: 0.15rem;
  white-space: nowrap;
  min-width: 4.6rem;
  color: var(--accent);
  background: rgba(131, 255, 150, 0.08);
  padding-inline: 0.32rem;
  box-shadow: inset 0 0 0 1px rgba(131, 255, 150, 0.08);
  text-shadow: 0 0 4px rgba(131, 255, 150, 0.14);
}

.field-line {
  display: grid;
  grid-template-columns: 5.2rem minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
  padding: 0.12rem 0;
}

.field-copy {
  margin-top: 0.55rem;
}

.form-control,
.form-control:focus,
.form-control:focus-visible,
.form-control:active {
  width: 100%;
  padding: 0.04rem 0 0.28rem;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent !important;
  background-color: transparent !important;
  color: var(--text) !important;
  box-shadow: none !important;
  caret-color: var(--accent);
}

.form-control:focus,
.form-control:focus-visible {
  text-shadow: 0 0 5px rgba(131, 255, 150, 0.12);
}

.form-control:-webkit-autofill,
.form-control:-webkit-autofill:hover,
.form-control:-webkit-autofill:focus,
.form-control:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px transparent inset;
  transition: background-color 9999s ease-out 0s;
}

.form-control::placeholder {
  color: rgba(78, 169, 93, 0.72);
}

textarea.form-control {
  min-height: 4.8rem;
  resize: none;
  line-height: 1.55;
}

.btn {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
}

.terminal-action,
.back-link {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  min-height: 1.7rem;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.73rem;
}

.terminal-action::before,
.back-link::before {
  content: "[";
  color: var(--accent);
  margin-right: 0.35rem;
}

.terminal-action::after,
.back-link::after {
  content: "]";
  color: var(--accent);
  margin-left: 0.35rem;
}

.terminal-action:hover,
.terminal-action:focus,
.back-link:hover,
.back-link:focus {
  color: var(--accent);
  text-shadow: 0 0 6px rgba(131, 255, 150, 0.18);
  text-decoration: none;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.panel-block {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px dashed var(--line-soft);
}

.panel-block:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.back-link {
  text-decoration: none;
}

.connection-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
}

.connection-dot span {
  width: 0.72rem;
  height: 0.72rem;
  background: rgba(2, 21, 4, 0.42);
}

.connection-dot[data-state="online"] span,
.connection-dot[data-state="syncing"] span,
.connection-dot[data-state="sending"] span {
  background: var(--inverse-text);
}

.connection-dot[data-state="offline"] span {
  background: var(--danger);
}

.relay-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.alert {
  margin: 0 0 0.8rem;
  padding: 0.45rem 0.6rem;
  border: 1px dashed rgba(255, 116, 116, 0.42);
  border-radius: 0;
  background: rgba(32, 4, 4, 0.94);
  color: #ffc0c0;
}

.messages-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.2rem 0.5rem 0 0;
  overscroll-behavior: contain;
}

.empty-state {
  padding-top: 0.3rem;
  color: var(--muted);
  line-height: 1.7;
}

.message-row {
  margin-bottom: 0.9rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px dotted rgba(76, 195, 92, 0.16);
}

.message-line {
  display: grid;
  grid-template-columns: 5.3rem 2.7rem minmax(8rem, auto) auto minmax(0, 1fr);
  gap: 0.55rem;
  align-items: start;
}

.message-time,
.message-route,
.message-separator {
  white-space: nowrap;
}

.message-route {
  color: var(--label);
}

.message-row.mine .message-route {
  color: var(--accent);
}

.message-row.system {
  border-bottom-color: rgba(76, 195, 92, 0.08);
}

.message-row.system .message-line {
  grid-template-columns: 5.3rem 2.7rem minmax(0, 1fr);
}

.message-row.system .message-route {
  color: var(--muted);
}

.message-row.system .message-body {
  color: var(--label);
}

.message-alias {
  color: var(--text);
  white-space: nowrap;
  text-transform: uppercase;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-media {
  margin: 0.45rem 0 0 9.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.message-image-link {
  display: inline-block;
  max-width: min(36rem, 100%);
  padding: 0.2rem;
  background: rgba(0, 10, 0, 0.86);
  box-shadow:
    inset 0 0 0 1px rgba(76, 195, 92, 0.2),
    0 0 10px rgba(76, 195, 92, 0.04);
}

.message-image {
  display: block;
  max-width: 100%;
  max-height: 24rem;
  height: auto;
}

.message-image-meta,
.attachment-status {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.composer-card {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  padding-bottom: max(0.15rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.composer-input {
  min-height: 5.5rem;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.7rem;
}

.action-cluster {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.attachment-status {
  margin-top: 0.75rem;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: rgba(2, 4, 2, 0.82);
}

::-webkit-scrollbar-thumb {
  background: rgba(86, 255, 105, 0.2);
}

@media (max-width: 1100px) {
  .landing-layout,
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .seo-grid {
    grid-template-columns: 1fr;
  }

  .seo-card {
    border-right: 0;
  }

  .seo-card:nth-last-child(-n + 2) {
    border-bottom: 1px solid var(--line-soft);
  }

  .seo-card:last-child {
    border-bottom: 0;
  }

  .panel + .panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .chat-shell .terminal-app {
    height: 100vh;
    min-height: 100dvh;
    height: 100dvh;
  }

  .chat-shell .chat-layout {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .chat-shell .side-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem 1rem;
    align-content: start;
  }

  .chat-shell .back-link,
  .chat-shell .panel-block:first-of-type {
    grid-column: 1 / -1;
  }

  .chat-shell .relay-panel {
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    animation: none;
  }
}

@media (max-width: 720px) {
  .terminal-app {
    gap: 0;
  }

  .panel {
    padding: 0.72rem 0.8rem;
  }

  .app-bar,
  .app-meta,
  .app-meta-right,
  .composer-actions,
  .action-cluster {
    flex-wrap: wrap;
  }

  .app-bar {
    gap: 0.35rem 0.75rem;
    padding: 0.38rem 0.75rem 0.42rem;
    font-size: 0.68rem;
  }

  .app-meta {
    gap: 0.45rem 0.75rem;
  }

  .app-meta > * + * {
    padding-left: 0.55rem;
  }

  .app-meta-right {
    justify-content: flex-start;
  }

  .landing-shell .app-shell {
    height: auto;
  }

  .landing-stack {
    gap: 0.75rem;
  }

  .chat-shell .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 0.8rem;
    padding-bottom: 0.55rem;
  }

  .chat-shell .panel-block {
    gap: 0.45rem;
    padding-bottom: 0.55rem;
  }

  .chat-shell .back-link,
  .chat-shell .panel-block:first-of-type {
    grid-column: 1 / -1;
  }

  .chat-shell .panel-block:first-of-type {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem 0.8rem;
    align-content: start;
  }

  .chat-shell .panel-block:first-of-type .field-copy {
    grid-column: 1 / -1;
    margin-top: 0;
  }

  .chat-shell .panel-block:first-of-type .terminal-action {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-shell .relay-panel {
    padding-top: 0.55rem;
  }

  .fact-row,
  .field-line,
  .input-row,
  .message-line {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .screen-title {
    max-width: none;
    font-size: 1.3rem;
  }

  .screen-copy,
  .section-copy {
    line-height: 1.55;
  }

  .field-line,
  .input-row {
    gap: 0.35rem;
  }

  .fact-list {
    gap: 0.3rem;
  }

  .fact-row {
    padding: 0.14rem 0;
  }

  .section-copy,
  .screen-copy {
    margin-bottom: 0.8rem;
  }

  .seo-card,
  .faq-panel {
    padding: 0.8rem;
  }

  .hero-kicker {
    margin-bottom: 0.55rem;
  }

  .message-row {
    margin-bottom: 0.7rem;
    padding-bottom: 0.4rem;
  }

  .message-line {
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-areas:
      "time route alias"
      ". body body";
    gap: 0.2rem 0.55rem;
  }

  .message-time {
    grid-area: time;
  }

  .message-route {
    grid-area: route;
  }

  .message-alias {
    grid-area: alias;
    overflow-wrap: anywhere;
  }

  .message-body {
    grid-area: body;
    padding-top: 0.1rem;
  }

  .message-separator {
    display: none;
  }

  .message-media {
    margin-left: 0;
    max-width: 100%;
  }

  .message-row.system .message-line {
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-areas:
      "time route body";
  }

  .composer-card {
    margin-top: 0.55rem;
    padding-top: 0.55rem;
    padding-bottom: calc(0.45rem + env(safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    background: #000200;
    z-index: 1;
  }

  .composer-input {
    min-height: 4.25rem;
  }

  .composer-actions {
    align-items: stretch;
    gap: 0.5rem;
  }

  .action-cluster {
    width: 100%;
    justify-content: space-between;
    gap: 0.65rem;
  }

  .terminal-action,
  .back-link {
    min-height: 2rem;
  }

  .field-prefix {
    min-width: 3.8rem;
    padding-inline: 0.24rem;
    font-size: 0.68rem;
  }

  .messages-list {
    min-height: 7rem;
    padding-top: 0;
  }

  .empty-state {
    padding-top: 0;
  }

  #composer-note {
    font-size: 0.68rem;
  }

  #room-id-label,
  #room-status-copy,
  #history-floor-copy,
  #room-header-label,
  #composer-note {
    overflow-wrap: anywhere;
  }
}
