/* ═══════════════════════════════════════════════════════════════
   TERMINAL.CSS — Interactive CLI terminal styles
   ═══════════════════════════════════════════════════════════════ */

/* ── OVERLAY ──────────────────────────────────────────────────── */
#terminal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#terminal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

/* ── TERMINAL BOX ─────────────────────────────────────────────── */
#terminal-box {
  width: 100%;
  max-width: 760px;
  height: min(580px, 80vh);
  background: #0D1117;
  border-radius: 12px;
  border: 1px solid #30363d;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 80px rgba(0, 0, 0, 0.7),
    0 0 60px rgba(0, 200, 100, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.96) translateY(12px);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  position: relative; /* needed for cursor positioning */
}
#terminal-overlay.open #terminal-box {
  transform: scale(1) translateY(0);
}

/* ── TITLE BAR ────────────────────────────────────────────────── */
#terminal-titlebar {
  display: flex;
  align-items: center;
  height: 40px;
  min-height: 40px;
  background: #161B22;
  border-bottom: 1px solid #30363d;
  padding: 0 14px;
  flex-shrink: 0;
  user-select: none;
}

.t-traffic-lights {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 14px;
}

.t-tl {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: filter 0.15s, transform 0.12s;
  position: relative;
  flex-shrink: 0;
}
.t-tl:hover { filter: brightness(1.2); transform: scale(1.1); }
.t-tl[disabled] { cursor: default; opacity: 0.35; }
.t-tl[disabled]:hover { filter: none; transform: none; }

.t-tl-close { background: #FF5F57; }
.t-tl-min   { background: #FFBD2E; }
.t-tl-max   { background: #28C941; }

/* ✕ / — symbols on hover */
.t-tl-close::after,
.t-tl-min::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s;
  font-size: 7px;
  line-height: 8px;
  color: rgba(0,0,0,0.6);
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}
.t-traffic-lights:hover .t-tl-close::after { opacity: 1; content: '✕'; }
.t-traffic-lights:hover .t-tl-min::after   { opacity: 1; content: '—'; }

.t-title {
  flex: 1;
  text-align: center;
  font-size: 0.78rem;
  color: #8B949E;
  letter-spacing: 0.02em;
}

.t-hint {
  font-size: 0.68rem;
  color: #484F58;
  letter-spacing: 0.04em;
}

/* ── BODY + SCROLLBAR ─────────────────────────────────────────── */
#terminal-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem 0;
  scroll-behavior: smooth;
  min-height: 0; /* critical for flex child scrolling */
}
#terminal-body::-webkit-scrollbar { width: 5px; }
#terminal-body::-webkit-scrollbar-track { background: transparent; }
#terminal-body::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 999px;
}
#terminal-body::-webkit-scrollbar-thumb:hover { background: #484F58; }

/* ── OUTPUT ───────────────────────────────────────────────────── */
#terminal-output {
  flex: 1;
  padding-bottom: 0.5rem;
}

.t-line {
  font-size: 0.825rem;
  line-height: 1.65;
  color: #C9D1D9;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.35em;
}

/* ── INPUT ROW (sticky at bottom) ────────────────────────────── */
#terminal-input-row {
  display: flex;
  align-items: center;
  padding: 2px 0 10px;
  position: relative;
  flex-shrink: 0;
}

#terminal-prompt-live {
  font-size: 0.825rem;
  color: #C9D1D9;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.65;
  pointer-events: none;
}

#terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #C9D1D9;
  font-family: inherit;
  font-size: 0.825rem;
  /* Hide the native caret — we use our custom blinking cursor span */
  caret-color: transparent;
  line-height: 1.65;
  padding: 0;
  margin: 0;
  min-width: 0;
  position: relative;
  z-index: 1;
}
#terminal-input::selection { background: rgba(88, 166, 255, 0.25); }

/* ── CUSTOM CURSOR ────────────────────────────────────────────── */
#terminal-cursor {
  display: inline-block;
  width: 0.5em;
  height: 1.1em;
  background: #58A6FF;
  vertical-align: text-bottom;
  position: absolute;
  /* left is set dynamically by syncCursor() in JS */
  left: 0;
  animation: t-blink 1s step-end infinite;
  border-radius: 1px;
  pointer-events: none;
}
@keyframes t-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── COLOUR TOKENS ────────────────────────────────────────────── */
.t-green   { color: #3FB950; }
.t-yellow  { color: #D29922; }
.t-cyan    { color: #58A6FF; }
.t-red     { color: #F85149; }
.t-magenta { color: #BC8CFF; }
.t-bold    { font-weight: 700; }
.t-dim     { color: #484F58; }

/* Prompt segment colours */
.t-user   { color: #3FB950; font-weight: 600; }
.t-at     { color: #484F58; }
.t-host   { color: #58A6FF; font-weight: 600; }
.t-colon  { color: #484F58; }
.t-tilde  { color: #D29922; }
.t-dollar { color: #C9D1D9; margin-left: 4px; margin-right: 2px; }

/* ── FOOTER HINT BUTTON ───────────────────────────────────────── */
#terminal-hint {
  margin-top: 1rem;
  text-align: center;
}

#terminal-hint button {
  background: transparent;
  border: 1px solid #30363d;
  color: #484F58;
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  padding: 5px 14px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#terminal-hint button:hover {
  color: #3FB950;
  border-color: #3FB950;
  background: rgba(63, 185, 80, 0.06);
}

.t-hint-prompt { color: #3FB950; font-weight: 700; }

/* ── MOBILE ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #terminal-box {
    height: min(90vh, 520px);
    border-radius: 10px;
  }
  .t-line,
  #terminal-input,
  #terminal-prompt-live {
    font-size: 0.75rem;
  }
  .t-hint { display: none; }
  #terminal-hint { display: none; }
}