/* ── reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── base ── */
html, body {
  background: #000;
  color: #00ff00;
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px;
  height: 100%;
  overflow: hidden;
  cursor: default;
  -webkit-text-size-adjust: 100%;
}

/* ── terminal container ── */
#terminal {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 1.2rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  overflow: hidden;
}

/* ── screens ── */
.screen {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.screen.active {
  display: flex;
}

/* ── entry screen ── */
#screen-entry {
  justify-content: center;
  align-items: flex-start;
}

.entry-wrap {
  line-height: 2.2;
}

.blink-line {
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  font-weight: bold;
  letter-spacing: 0.1em;
  animation: textpulse 2.4s step-end infinite;
}

.entry-sub {
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  opacity: 0.7;
  margin-top: 0.4rem;
}

.entry-hint {
  margin-top: 1.6rem;
  font-size: clamp(0.8rem, 3vw, 0.95rem);
  animation: blink 1.1s step-end infinite;
}

/* ── connecting / searching screens ── */
#screen-connecting,
#screen-searching {
  justify-content: flex-start;
  gap: 0;
}

#connect-lines,
#search-lines {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.term-line {
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: clamp(0.82rem, 3.2vw, 0.95rem);
}

.term-line.dim {
  opacity: 0.5;
}

.term-line.bright {
  font-weight: bold;
}

.term-line.system {
  color: #00cc00;
  opacity: 0.8;
}

.term-line.error {
  color: #ff4444;
}

/* ── search stats ── */
#search-stats {
  margin-top: 1rem;
  opacity: 0.45;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

/* ── chat screen ── */
#screen-chat {
  display: none;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

#screen-chat.active {
  display: flex;
}

#chat-header {
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #003300;
  margin-bottom: 0.5rem;
  opacity: 0.8;
  flex-shrink: 0;
  font-size: clamp(0.8rem, 3vw, 0.95rem);
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-right: 0.3rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#chat-log::-webkit-scrollbar {
  width: 3px;
}
#chat-log::-webkit-scrollbar-thumb {
  background: #003300;
}

.chat-msg {
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: clamp(0.85rem, 3.4vw, 1rem);
}

.chat-msg.them {
  color: #00ff00;
  opacity: 0.85;
}

.chat-msg.you {
  color: #00ff00;
}

.chat-msg.sys {
  color: #00aa00;
  opacity: 0.7;
  font-style: italic;
}

.chat-msg.event {
  color: #008800;
  opacity: 0.6;
}

.chat-msg.special {
  color: #00ffaa;
  font-weight: bold;
}

/* ── buttons ── */
#chat-buttons {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.7rem;
  flex-shrink: 0;
}

#chat-buttons button {
  flex: 1;
  background: #000;
  color: #00ff00;
  border: 1px solid #00ff00;
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.72rem, 2.8vw, 0.85rem);
  padding: 0.7rem 0.3rem;
  cursor: pointer;
  border-radius: 0;
  letter-spacing: 0.03em;
  min-height: 2.8rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#chat-buttons button:hover {
  background: #003300;
}

#chat-buttons button:active {
  background: #005500;
}

/* ── install prompt ── */
#install-prompt {
  display: none;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0;
  border-top: 1px solid #003300;
  flex-shrink: 0;
}

#install-prompt.visible {
  display: flex;
}

#install-label {
  color: #00ff00;
  font-size: clamp(0.8rem, 3.2vw, 0.9rem);
  opacity: 0.8;
}

#install-actions {
  display: flex;
  gap: 0.5rem;
}

#install-actions button {
  flex: 1;
  background: #000;
  color: #00ff00;
  border: 1px solid #00ff00;
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.72rem, 2.8vw, 0.82rem);
  padding: 0.6rem 0.3rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#install-actions button:active {
  background: #002200;
}

/* ── save prompt ── */
#save-prompt {
  display: none;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0;
  border-top: 1px solid #003300;
  flex-shrink: 0;
}

#save-prompt.visible {
  display: flex;
}

#save-label {
  color: #00ffaa;
  font-size: clamp(0.8rem, 3.2vw, 0.9rem);
  font-weight: bold;
}

#save-actions {
  display: flex;
  gap: 0.5rem;
}

#save-actions button {
  flex: 1;
  background: #000;
  color: #00ffaa;
  border: 1px solid #00ffaa;
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.72rem, 2.8vw, 0.82rem);
  padding: 0.6rem 0.3rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#save-actions button:active {
  background: #003322;
}

/* ── commands hint ── */
#chat-commands {
  display: none; /* hidden on mobile — buttons cover it */
}

@media (min-width: 600px) {
  #chat-commands {
    display: block;
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px solid #003300;
    opacity: 0.35;
    font-size: 0.78rem;
    flex-shrink: 0;
  }
}

/* ── input row ── */
#chat-input-row {
  display: flex;
  align-items: center;
  margin-top: 0.5rem;
  flex-shrink: 0;
  border-top: 1px solid #002200;
  padding-top: 0.6rem;
  padding-bottom: 0.3rem;
  min-height: 2.6rem;
}

#prompt-char {
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #00ff00;
  font-family: inherit;
  font-size: 17px; /* prevent iOS zoom, slightly larger */
  caret-color: #00ff00;
  min-width: 0;
  line-height: 1.5;
  -webkit-appearance: none;
}

/* ── cursors ── */
.cursor-blink,
.cursor-inline {
  animation: blink 1s step-end infinite;
  font-weight: bold;
}

/* ── animations ── */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

@keyframes textpulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── scanline overlay ── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.07) 2px,
    rgba(0,0,0,0.07) 4px
  );
  pointer-events: none;
  z-index: 999;
}

/* ── selection color ── */
::selection {
  background: #00ff00;
  color: #000;
}

/* ── desktop: more breathing room ── */
@media (min-width: 600px) {
  #terminal {
    padding: 2rem;
    max-width: 720px;
    margin: 0 auto;
  }

  .chat-msg,
  .term-line {
    font-size: 0.95rem;
  }

  #chat-buttons button {
    font-size: 0.82rem;
    padding: 0.55rem 0.8rem;
    min-height: 2.4rem;
  }

  #chat-input {
    font-size: 0.95rem;
  }
}
