/* ============================================================
   TERMINAL WIDGET — Floating terminal for Terry's portfolio
   All classes prefixed .tw-* to avoid conflicts with host site.
   This file is the single source of truth for widget styling.
   The JS file (terminal.js) creates the DOM; this file styles it.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500&display=swap');

/* ── Visually-hidden utility ── */
.tw-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   TRIGGER ICON — 52px circle, bottom-right
   ============================================================ */

.tw-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #1c2333;
  border: 1px solid rgba(72, 213, 151, 0.2);
  color: #48d597;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: box-shadow 0.2s ease, transform 0.2s ease, opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  padding: 0;
  opacity: 1;
}

.tw-trigger:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 16px rgba(72, 213, 151, 0.15);
  transform: scale(1.08);
}

.tw-trigger:focus-visible {
  outline: 2px solid #48d597;
  outline-offset: 3px;
}

.tw-trigger.tw-open {
  transform: scale(0.92);
  opacity: 0.6;
}

.tw-trigger.tw-hidden {
  opacity: 0;
  pointer-events: none;
}

.tw-trigger svg {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

/* ============================================================
   TEASER BUBBLE — first-visit nudge
   ============================================================ */

.tw-teaser {
  position: fixed;
  bottom: 86px;
  right: 24px;
  z-index: 9999;
  background: rgba(28, 35, 51, 0.96);
  border: 1px solid rgba(72, 213, 151, 0.2);
  border-radius: 8px 8px 0 8px;
  padding: 10px 16px;
  font-family: 'Geist Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 13px;
  color: #48d597;
  max-width: 240px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.tw-teaser.tw-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   PANEL — Main terminal window
   ============================================================ */

.tw-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 10001;
  width: 420px;
  max-width: calc(100vw - 32px);
  height: 480px;
  max-height: calc(100vh - 120px);
  background: rgba(22, 27, 43, 0.98);
  border: 1px solid rgba(72, 213, 151, 0.12);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: 'Geist Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 13px;
  color: #d4d4d4;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 30px rgba(72, 213, 151, 0.04);
  cursor: default !important;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.tw-panel.tw-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.tw-panel.tw-shake {
  animation: tw-shake-anim 0.3s ease;
}

@keyframes tw-shake-anim {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* ── CRT scanline overlay ── */
.tw-panel.tw-crt .tw-output::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.08) 0px,
    rgba(0, 0, 0, 0.08) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 1;
}

.tw-panel.tw-crt .tw-output {
  text-shadow: 0 0 6px rgba(72, 213, 151, 0.15);
}

.tw-panel.tw-crt .tw-input {
  text-shadow: 0 0 6px rgba(72, 213, 151, 0.15);
}

/* CRT turn-on effect — used on first panel open */
@keyframes tw-crt-on {
  0% {
    transform: scaleY(0.005) scaleX(0.3);
    filter: brightness(30);
    opacity: 1;
  }
  30% {
    transform: scaleY(0.005) scaleX(1);
    filter: brightness(10);
  }
  60% {
    transform: scaleY(1) scaleX(1);
    filter: brightness(2);
  }
  100% {
    transform: scaleY(1) scaleX(1);
    filter: brightness(1);
  }
}

.tw-crt-on {
  animation: tw-crt-on 0.4s ease-out forwards;
}

/* Boot sequence status indicators */
.tw-boot-ok {
  color: #27c93f;
  font-weight: 500;
}

.tw-boot-fail {
  color: #ff5f56;
  font-weight: 500;
}

/* ============================================================
   TITLE BAR
   ============================================================ */

.tw-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(17, 21, 33, 0.6);
  flex-shrink: 0;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

.tw-title-text {
  font-size: 12px;
  opacity: 0.6;
}

.tw-title-btns {
  display: flex;
  gap: 8px;
}

.tw-title-btn {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: #8b949e;
  cursor: pointer !important;
  font-size: 11px;
  line-height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease;
}

.tw-title-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tw-title-btn:focus-visible {
  outline: 2px solid #00ff41;
  outline-offset: 2px;
}

.tw-btn-close:hover {
  border-color: rgba(255, 95, 86, 0.5);
  background: rgba(255, 95, 86, 0.15);
  color: #ff5f56;
}

/* ============================================================
   DRAG HANDLE (mobile bottom sheet)
   ============================================================ */

.tw-drag-handle {
  display: flex;
  justify-content: center;
  padding: 6px 0 2px;
  flex-shrink: 0;
}

.tw-drag-handle span {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
}

/* ============================================================
   OUTPUT AREA
   ============================================================ */

.tw-output {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(72, 213, 151, 0.15) transparent;
}

.tw-output::-webkit-scrollbar {
  width: 5px;
}

.tw-output::-webkit-scrollbar-track {
  background: transparent;
}

.tw-output::-webkit-scrollbar-thumb {
  background: rgba(72, 213, 151, 0.15);
  border-radius: 3px;
}

.tw-output::-webkit-scrollbar-thumb:hover {
  background: rgba(72, 213, 151, 0.3);
}

/* ── Output Lines ── */

.tw-line {
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 2px;
  line-height: 1.55;
}

.tw-line-cmd {
  color: #8b949e;
}

.tw-line-sys {
  color: #d4d4d4;
}

.tw-line-err {
  color: #f85149;
}

.tw-line-accent {
  color: #48d597;
}

.tw-line-banner {
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: -0.3px;
}

.tw-timestamp {
  color: #444;
  font-size: 11px;
  margin-right: 6px;
  user-select: none;
  opacity: 0.6;
}

.tw-line a {
  color: #48d597;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer !important;
}

.tw-line a:hover {
  color: #6ee7b7;
}

.tw-line a:focus-visible {
  outline: 1px solid #48d597;
  outline-offset: 2px;
}

/* ============================================================
   QUICK CHIPS (command shortcuts)
   ============================================================ */

.tw-chips {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  flex-shrink: 0;
  flex-wrap: wrap;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.tw-chip {
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid rgba(72, 213, 151, 0.2);
  background: rgba(72, 213, 151, 0.06);
  color: #48d597;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer !important;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.tw-chip:hover {
  background: rgba(72, 213, 151, 0.12);
}

.tw-chip:focus-visible {
  outline: 2px solid #48d597;
  outline-offset: 1px;
}

/* ============================================================
   INPUT ROW
   ============================================================ */

.tw-input-row {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(17, 21, 33, 0.4);
  flex-shrink: 0;
}

.tw-prompt {
  color: #48d597;
  margin-right: 2px;
  flex-shrink: 0;
}

.tw-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #e0e0e0;
  font-family: inherit;
  font-size: 13px;
  caret-color: transparent;
  cursor: text !important;
  padding: 0;
  min-width: 0;
}

.tw-input::placeholder {
  color: rgba(255, 255, 255, 0.15);
}

.tw-cursor {
  color: #48d597;
  animation: tw-blink 1s step-end infinite;
  margin-left: -1px;
}

@keyframes tw-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.tw-autocomplete {
  color: #333;
  pointer-events: none;
  position: absolute;
  left: 0;
  top: 0;
}

/* ============================================================
   GLITCH EFFECT (easter eggs)
   ============================================================ */

@keyframes tw-glitch {
  0%, 100% { text-shadow: none; }
  25% { text-shadow: -2px 0 #ff0000, 2px 0 #00ffff; }
  50% { text-shadow: 2px 0 #ff0000, -2px 0 #00ffff; }
  75% { text-shadow: -1px 0 #ff0000, 1px 0 #00ffff; }
}

.tw-glitch {
  animation: tw-glitch 0.2s linear;
}

/* ============================================================
   MATRIX RAIN CANVAS
   ============================================================ */

.tw-matrix-canvas {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
}

/* ============================================================
   MOBILE — max-width: 768px
   ============================================================ */

@media (max-width: 768px) {
  .tw-trigger {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }

  .tw-trigger svg {
    width: 20px;
    height: 20px;
  }

  .tw-teaser {
    bottom: 74px;
    right: 16px;
    font-size: 12px;
  }

  .tw-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease, opacity 0.3s ease;
  }

  .tw-panel.tw-open {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── Small mobile ── */
@media (max-width: 480px) {
  .tw-output {
    font-size: 12px;
    padding: 10px 12px;
  }

  .tw-input,
  .tw-prompt {
    font-size: 12px;
  }

  .tw-chip {
    font-size: 10px;
    padding: 3px 8px;
  }
}

/* ============================================================
   SAFE AREA (iPhone notch / home indicator)
   ============================================================ */

@supports (bottom: env(safe-area-inset-bottom)) {
  .tw-trigger {
    bottom: max(24px, calc(env(safe-area-inset-bottom) + 8px));
  }

  @media (max-width: 768px) {
    .tw-trigger {
      bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
    }

    .tw-input-row {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* ============================================================
   PRINT — hide widget entirely
   ============================================================ */

@media print {
  .tw-trigger,
  .tw-panel,
  .tw-teaser {
    display: none !important;
  }
}

/* ============================================================
   REDUCED MOTION — respect user preference
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .tw-cursor {
    animation: none;
    opacity: 1;
  }

  .tw-panel {
    transition: opacity 0.1s ease !important;
    transform: none !important;
  }

  .tw-panel:not(.tw-open) {
    opacity: 0;
  }

  .tw-panel.tw-crt .tw-output::before {
    display: none;
  }

  .tw-panel.tw-crt .tw-output,
  .tw-panel.tw-crt .tw-input {
    text-shadow: none;
  }

  .tw-shake {
    animation: none;
  }

  .tw-glitch {
    animation: none;
  }

  .tw-crt-on {
    animation: none;
  }
}
