:root {
  --bg: #141414;
  --bg-dark: #161616;
  --terminal: #141414;
  --terminal-deep: #101010;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --border: rgba(255, 255, 255, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background-color: var(--terminal);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family:
    "SFMono-Regular",
    Menlo,
    Monaco,
    Consolas,
    "Liberation Mono",
    monospace;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-dark) 100%);
  user-select: text;
  -webkit-user-select: text;
}

.terminal {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: calc(24px + var(--safe-top)) calc(20px + var(--safe-right))
    calc(32px + var(--safe-bottom)) calc(20px + var(--safe-left));
  background: var(--terminal);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(255, 255, 255, 0.24) transparent;
}

.hidden {
  display: none;
}

.terminal__output {
  flex: 1 0 auto;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
}

.terminal__ascii {
  margin: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: pre;
  word-break: normal;
  line-height: 1;
  font: inherit;
  color: var(--muted);
  scrollbar-color: rgba(255, 255, 255, 0.24) transparent;
}

.line {
  min-height: 1.45rem;
  line-height: 1.45;
}

.line--spacer {
  min-height: 1rem;
}

.line--spacer-tight {
  min-height: 0.4rem;
}

.line--compact {
  min-height: 1.15rem;
  line-height: 1.2;
}

.prompt,
.accent {
  color: var(--text);
}

.terminal__link {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.terminal__link:visited {
  color: var(--text);
}

.muted {
  color: var(--muted);
}

.terminal__input-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-top: 0;
}

.prompt {
  flex: 0 0 auto;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.terminal__input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
  outline: none;
  caret-color: var(--text);
}

.pager,
.session-closed {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--terminal-deep);
  color: var(--text);
}

.pager {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right))
    calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
  overflow: hidden;
  overscroll-behavior: none;
}

.pager.hidden,
.session-closed.hidden {
  display: none;
}

.pager__content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.5;
  padding-top: 2px;
  padding-bottom: 24px;
  scroll-padding-top: 12px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  user-select: text;
  -webkit-user-select: text;
  touch-action: pan-y;
}

.pager__status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  position: sticky;
  bottom: 0;
  background: var(--terminal-deep);
}

.pager__status-text {
  min-width: 0;
}

.pager__desktop-hint {
  display: inline;
}

.pager__actions {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.pager__button {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  padding: 0.45rem 0.8rem;
  min-width: 4.5rem;
  min-height: 2.75rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  font: inherit;
  cursor: pointer;
  transform: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pager__button:active,
.pager__button:focus:active {
  transform: none;
  background: rgba(255, 255, 255, 0.04);
}

.session-closed {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right))
    calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
}

.session-closed__box {
  max-width: 34rem;
  width: 100%;
  padding: 24px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.session-closed__box p {
  margin: 0 0 10px;
  line-height: 1.5;
}

.terminal__input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .terminal {
    padding: calc(16px + var(--safe-top)) calc(14px + var(--safe-right))
      calc(20px + var(--safe-bottom)) calc(14px + var(--safe-left));
  }

  .terminal__input-row {
    position: sticky;
    bottom: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    padding-top: 14px;
    background: linear-gradient(180deg, rgba(20, 20, 20, 0) 0%, var(--terminal) 24%);
  }

  .prompt {
    flex: 1 1 auto;
    font-size: 0.92rem;
    line-height: 1.35;
  }

  .terminal__input {
    width: 100%;
    min-height: 2.25rem;
    padding: 0.25rem 0;
  }

  .terminal__ascii {
    font-size: 5px;
    line-height: 0.9;
    overflow: hidden;
  }

  .line {
    min-height: 1.35rem;
    line-height: 1.35;
  }

  .line--compact {
    min-height: 1.25rem;
    line-height: 1.25;
  }

  .pager {
    gap: 12px;
    padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right))
      calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left));
  }

  .pager__status {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    font-size: 0.9rem;
    line-height: 1.4;
    padding-top: 10px;
  }

  .pager__actions {
    display: flex;
    width: 100%;
  }

  .pager__desktop-hint {
    display: none;
  }

  .pager__button {
    flex: 1 1 0;
    min-height: 3rem;
    padding: 0.7rem 1rem;
  }

  .session-closed {
    padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right))
      calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left));
  }

  .session-closed__box {
    padding: 18px;
  }
}
