/* ════════════════════════════════════════════════════════════
   wojtek.gift — Retro CRT Terminal Styles
   ════════════════════════════════════════════════════════════ */

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

:root {
  /* Dark theme (default) */
  --bg: #0a0a0a;
  --monitor-bg: #1a1a1a;
  --screen-bg: #0d1117;
  --text: #33ff33;
  --text-dim: #1a8c1a;
  --text-glow: rgba(51, 255, 51, 0.4);
  --border: #333;
  --input-bg: #0a0e14;
  --titlebar-bg: #222;

  /* Model colors — dark */
  --gemini-color: #4fc3f7;
  --claude-color: #ff9800;
  --chatgpt-color: #66bb6a;
  --user-color: #aaa;

  /* Party theme overrides (applied via .phase-party) */
  --font-main: 'VT323', monospace;
  --font-title: 'Press Start 2P', cursive;
}

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: background 1s ease;
  /* Prevent pull-to-refresh on mobile */
  overscroll-behavior: none;
  /* Smooth scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

/* ── Party Theme ──────────────────────────────────────────── */
.phase-party {
  --bg: #fdf6e3;
  --monitor-bg: #eee8d5;
  --screen-bg: #fefbf0;
  --text: #2c2c2c;
  --text-dim: #666;
  --text-glow: transparent;
  --border: #ccc;
  --input-bg: #fff;
  --titlebar-bg: #d4a0ff;

  --gemini-color: #1565c0;
  --claude-color: #e65100;
  --chatgpt-color: #2e7d32;
  --user-color: #555;
}

/* ── Monitor Frame ────────────────────────────────────────── */
.monitor {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 95vw;
  max-width: 800px;
}

.monitor-frame {
  background: var(--monitor-bg);
  border: 3px solid var(--border);
  border-radius: 16px 16px 4px 4px;
  overflow: hidden;
  width: 100%;
  box-shadow:
    0 0 30px rgba(0, 0, 0, 0.5),
    inset 0 0 60px rgba(0, 0, 0, 0.3);
  transition: background 1s ease, border-color 1s ease, box-shadow 1s ease;
}

.phase-party .monitor-frame {
  box-shadow:
    0 0 30px rgba(200, 150, 255, 0.3),
    0 4px 20px rgba(0, 0, 0, 0.1);
  border-color: #b388ff;
}

.monitor-stand {
  width: 60px;
  height: 30px;
  background: var(--border);
  border-radius: 0 0 4px 4px;
  transition: background 0.8s;
}

.monitor-base {
  width: 140px;
  height: 8px;
  background: var(--border);
  border-radius: 0 0 8px 8px;
  transition: background 0.8s;
}

/* ── Title Bar ────────────────────────────────────────────── */
.titlebar {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--titlebar-bg);
  border-bottom: 2px solid var(--border);
  font-family: var(--font-title);
  font-size: 8px;
  gap: 12px;
  transition: background 0.8s, border-color 0.8s;
}

.titlebar-buttons {
  display: flex;
  gap: 6px;
}

.titlebar-buttons span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: block;
}

.btn-close { background: #ff5f56; }
.btn-min { background: #ffbd2e; }
.btn-max { background: #27c93f; }

.titlebar-text {
  flex: 1;
  letter-spacing: 1px;
  color: var(--text);
  transition: color 0.8s;
}

.phase-party .titlebar-text {
  color: #fff;
}

.titlebar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  transition: color 0.8s;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff5f56;
  transition: background 0.3s;
}

.status-dot.connected {
  background: #27c93f;
  box-shadow: 0 0 6px rgba(39, 201, 63, 0.6);
}

/* ── Screen Area ──────────────────────────────────────────── */
.screen {
  position: relative;
  background: var(--screen-bg);
  min-height: 420px;
  max-height: 65vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 1s ease;
}

/* CRT Scanlines */
.scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(0, 0, 0, 0.15) 4px
  );
  pointer-events: none;
  z-index: 10;
  opacity: 1;
  transition: opacity 1s;
}

.phase-party .scanlines {
  opacity: 0.05;
}

/* Static noise overlay */
.screen-noise {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 11;
  opacity: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.5'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.screen-noise.active {
  opacity: 0.8;
  animation: noiseFlicker 0.1s steps(5) infinite;
}

@keyframes noiseFlicker {
  0%, 100% { opacity: 0.8; }
  25% { opacity: 0.3; }
  50% { opacity: 0.6; }
  75% { opacity: 0.9; }
}

/* CRT glow on dark theme */
.phase-dark .screen {
  box-shadow: inset 0 0 80px rgba(51, 255, 51, 0.05);
}

/* Screen flicker (dark theme) */
.phase-dark .screen::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 9;
  animation: flicker 4s ease-in-out infinite;
}

@keyframes flicker {
  0%, 97%, 100% { opacity: 0; }
  98% { opacity: 0.02; background: var(--text); }
}

/* ── Boot Sequence ────────────────────────────────────────── */
.boot-sequence {
  padding: 20px;
  font-size: 18px;
  line-height: 2;
  z-index: 5;
}

.boot-line {
  opacity: 0;
  animation: bootFadeIn 0.3s forwards;
}

.boot-line:nth-child(1) { animation-delay: 0.3s; }
.boot-line:nth-child(2) { animation-delay: 0.8s; }
.boot-line:nth-child(3) { animation-delay: 1.3s; }
.boot-line:nth-child(4) { animation-delay: 1.8s; }
.boot-line:nth-child(5) { animation-delay: 2.3s; }

.boot-ready {
  color: #ffbd2e;
  text-shadow: 0 0 8px rgba(255, 189, 46, 0.5);
}

.phase-party .boot-ready {
  color: #e65100;
  text-shadow: none;
}

@keyframes bootFadeIn {
  to { opacity: 1; }
}

.boot-sequence.hidden {
  display: none;
}

/* ── Chat Area ────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
  scroll-behavior: smooth;
  /* Better iOS scrolling */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chat-area.visible {
  display: flex;
}

/* Scrollbar */
.chat-area::-webkit-scrollbar {
  width: 6px;
}
.chat-area::-webkit-scrollbar-track {
  background: transparent;
}
.chat-area::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
}

/* ── Chat Messages ────────────────────────────────────────── */
.chat-message {
  padding: 12px 0;
  font-size: 20px;
  line-height: 1.4;
  word-wrap: break-word;
  animation: msgAppear 0.2s ease-out;
  border-bottom: 1px dashed var(--text-dim);
}

.chat-message:last-child {
  border-bottom: none;
}

@keyframes msgAppear {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message .msg-label {
  font-family: var(--font-title);
  font-size: 9px;
  letter-spacing: 1px;
  margin-bottom: 0;
  display: inline;
}

.chat-message .msg-label::after {
  content: ' ›';
  opacity: 0.5;
}

.chat-message .msg-content {
  display: inline;
  padding-left: 0;
}

/* Model-specific colors */
.msg-gemini .msg-label { color: var(--gemini-color); }
.msg-gemini .msg-content { color: var(--gemini-color); }
.phase-dark .msg-gemini .msg-content { text-shadow: 0 0 6px rgba(79, 195, 247, 0.3); }

.msg-claude .msg-label { color: var(--claude-color); }
.msg-claude .msg-content { color: var(--claude-color); }
.phase-dark .msg-claude .msg-content { text-shadow: 0 0 6px rgba(255, 152, 0, 0.3); }

.msg-chatgpt .msg-label { color: var(--chatgpt-color); }
.msg-chatgpt .msg-content { color: var(--chatgpt-color); }
.phase-dark .msg-chatgpt .msg-content { text-shadow: 0 0 6px rgba(102, 187, 106, 0.3); }

.msg-user .msg-label { color: var(--user-color); }
.msg-user .msg-content { color: var(--text); }

/* Party theme glow removal */
.phase-party .msg-content { text-shadow: none !important; }

/* ── Markdown Elements (Retro Terminal Style) ─────────────── */

/* Bold: enhanced glow instead of font-weight (VT323 has no bold) */
.msg-content strong {
  font-weight: normal;
  color: inherit;
}
.phase-dark .msg-content strong {
  text-shadow:
    0 0 8px currentColor,
    0 0 16px currentColor;
}
.phase-party .msg-content strong {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

/* Italic: dimmed color instead of font-style (VT323 has no italic) */
.msg-content em {
  font-style: normal;
  color: var(--text-dim);
}
.phase-party .msg-content em {
  color: #888;
}

/* Inline code: terminal input style */
.msg-content code {
  font-family: var(--font-main);
  font-size: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid currentColor;
  padding: 0 6px;
  border-radius: 2px;
}
.phase-dark .msg-content code {
  text-shadow: 0 0 4px var(--text);
}

/* Code blocks: nested terminal */
.msg-content pre {
  background: transparent;
  border: 1px solid var(--text-dim);
  padding: 10px 14px;
  margin: 8px 0;
  overflow-x: auto;
  border-radius: 0;
}
.msg-content pre code {
  font-size: 16px;
  border: none;
  padding: 0;
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}
.phase-dark .msg-content pre {
  box-shadow: inset 0 0 20px rgba(51, 255, 51, 0.03);
}

/* Lists: terminal listing with custom bullets */
.msg-content ul,
.msg-content ol {
  list-style: none;
  padding-left: 0;
  margin: 6px 0;
}
.msg-content li {
  padding-left: 18px;
  position: relative;
  margin: 3px 0;
}
.msg-content ul li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--text-dim);
}
.msg-content ol {
  counter-reset: terminal-counter;
}
.msg-content ol li {
  counter-increment: terminal-counter;
}
.msg-content ol li::before {
  content: counter(terminal-counter) '.';
  position: absolute;
  left: 0;
  color: var(--text-dim);
  font-size: 0.9em;
}

/* Links: dashed underline, no color change */
.msg-content a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
  transition: text-shadow 0.2s;
}
.phase-dark .msg-content a:hover {
  text-shadow: 0 0 8px currentColor;
}
.phase-party .msg-content a:hover {
  border-bottom-style: solid;
}

/* Paragraphs: no margin for tight chat layout */
.msg-content p {
  margin: 0;
}
.msg-content p + p {
  margin-top: 6px;
}

/* Headings: treat as bold text, no size change */
.msg-content h1,
.msg-content h2,
.msg-content h3,
.msg-content h4 {
  font-size: inherit;
  font-weight: normal;
  margin: 8px 0 4px 0;
}
.phase-dark .msg-content h1,
.phase-dark .msg-content h2,
.phase-dark .msg-content h3,
.phase-dark .msg-content h4 {
  text-shadow:
    0 0 8px currentColor,
    0 0 16px currentColor;
}
.phase-party .msg-content h1,
.phase-party .msg-content h2,
.phase-party .msg-content h3,
.phase-party .msg-content h4 {
  text-decoration: underline;
}

/* ── Verification Bar ─────────────────────────────────────── */
.verification-bar {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  font-family: var(--font-title);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  z-index: 5;
  transition: all 0.5s;
}

.verify-item {
  transition: color 0.3s;
}

.verify-item.verified {
  color: #27c93f;
}

.phase-party .verification-bar {
  display: none;
}

/* ── Typing Indicator ─────────────────────────────────────── */
.typing-indicator {
  padding: 4px 16px 8px;
  font-size: 16px;
  color: var(--text-dim);
  z-index: 5;
  display: none;
  align-items: center;
  gap: 6px;
}

.typing-indicator.visible {
  display: flex;
}

.typing-model {
  font-family: var(--font-title);
  font-size: 8px;
  letter-spacing: 1px;
}

.typing-indicator .typing-dots span {
  animation: typingBounce 1.2s ease-in-out infinite;
  display: inline-block;
}
.typing-indicator .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ── Input Area ───────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--input-bg);
  border-top: 2px solid var(--border);
  gap: 8px;
  transition: background 0.8s, border-color 0.8s;
}

.prompt-symbol {
  font-size: 20px;
  color: var(--text);
  animation: cursorBlink 1s steps(2) infinite;
  transition: color 0.8s;
}

@keyframes cursorBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 20px;
  caret-color: var(--text);
  transition: color 0.8s;
}

.terminal-input::placeholder {
  color: var(--text-dim);
  transition: color 0.8s;
}

.send-btn {
  background: transparent;
  border: 1px solid var(--text-dim);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 20px;
  padding: 2px 10px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}

.send-btn:hover {
  background: var(--text);
  color: var(--screen-bg);
}

/* ── Reboot Overlay ───────────────────────────────────────── */
.reboot-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.reboot-overlay.active {
  display: flex;
  animation: rebootFlash 4s ease forwards;
}

@keyframes rebootFlash {
  0% { opacity: 0; background: #000; }
  5% { opacity: 1; background: #fff; }
  10% { background: #000; }
  15% { background: #111; }
  20% { background: #000; }
  40% { background: #0a0a0a; }
  100% { opacity: 0; background: #fdf6e3; }
}

.reboot-text {
  text-align: center;
  color: #33ff33;
  font-family: var(--font-main);
  font-size: 24px;
  animation: rebootTextAppear 4s ease forwards;
}

@keyframes rebootTextAppear {
  0%, 10% { opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

.reboot-bar {
  width: 300px;
  height: 16px;
  background: #222;
  border: 1px solid #33ff33;
  margin: 16px auto;
  overflow: hidden;
}

.reboot-progress {
  height: 100%;
  background: #33ff33;
  width: 0%;
  animation: rebootProgress 3.5s linear 0.5s forwards;
}

@keyframes rebootProgress {
  to { width: 100%; }
}

.reboot-sub {
  font-size: 16px;
  color: #ffbd2e;
  margin-top: 8px;
}

/* ── Confetti Canvas ──────────────────────────────────────── */
#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}

/* ── Party decorations ────────────────────────────────────── */
.phase-party .prompt-symbol {
  animation: partyBlink 1s steps(2) infinite;
}

@keyframes partyBlink {
  0%, 49% { opacity: 1; color: #d4a0ff; }
  50%, 100% { opacity: 0; }
}

.phase-party .titlebar {
  background: linear-gradient(90deg, #d4a0ff, #ff80ab, #ffab40, #69f0ae);
  background-size: 300% 100%;
  animation: partyGradient 3s ease infinite;
}

@keyframes partyGradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.phase-party .titlebar-text {
  color: #fff;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* Birthday emoji decoration */
.phase-party .titlebar-text::after {
  content: ' 🎂🎉';
}

/* ── Responsive ───────────────────────────────────────────── */

/* Tablet breakpoint */
@media (max-width: 768px) {
  .monitor {
    width: 98vw;
    max-width: 98vw;
  }

  .screen {
    min-height: 50vh;
    max-height: 70vh;
  }

  .chat-message {
    font-size: 18px;
  }
}

/* Mobile breakpoint (iPhone, Android phones) */
@media (max-width: 600px) {
  body {
    align-items: flex-start;
    padding: 0;
    /* Fix for iOS Safari 100vh issue */
    min-height: 100vh;
    min-height: -webkit-fill-available;
    min-height: 100dvh;
  }

  .monitor {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: -webkit-fill-available;
    height: 100dvh;
  }

  .monitor-frame {
    border-radius: 0;
    border: none;
    height: 100%;
    display: flex;
    flex-direction: column;
    /* Safe area for iPhone notch and home indicator */
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .monitor-stand,
  .monitor-base {
    display: none;
  }

  .screen {
    flex: 1;
    min-height: 0;
    max-height: none;
  }

  .titlebar {
    font-size: 7px;
    padding: 8px 12px;
    gap: 8px;
    flex-shrink: 0;
  }

  .titlebar-buttons {
    gap: 5px;
  }

  .titlebar-buttons span {
    width: 10px;
    height: 10px;
  }

  .titlebar-text {
    font-size: 6px;
  }

  .titlebar-status {
    font-size: 7px;
  }

  .chat-area {
    padding: 12px;
  }

  .chat-message {
    font-size: 16px;
    padding: 10px 0;
    line-height: 1.5;
  }

  .chat-message .msg-label {
    font-size: 8px;
  }

  .terminal-input {
    font-size: 16px;
    /* Prevent iOS zoom on focus */
  }

  .input-area {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    gap: 10px;
    flex-shrink: 0;
  }

  .prompt-symbol {
    font-size: 18px;
  }

  .send-btn {
    font-size: 18px;
    padding: 6px 14px;
    /* Better touch target */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .verification-bar {
    font-size: 7px;
    gap: 8px;
    padding: 6px 12px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .boot-sequence {
    padding: 16px;
    font-size: 15px;
    line-height: 1.8;
  }

  .typing-indicator {
    padding: 4px 12px 6px;
    font-size: 14px;
  }

  .typing-model {
    font-size: 7px;
  }

  /* Reboot overlay mobile adjustments */
  .reboot-text {
    font-size: 18px;
    padding: 0 20px;
  }

  .reboot-bar {
    width: 80vw;
    max-width: 280px;
    height: 12px;
  }

  .reboot-sub {
    font-size: 13px;
  }
}

/* Small phones (iPhone SE, older models) */
@media (max-width: 375px) {
  .titlebar {
    font-size: 6px;
    padding: 6px 10px;
  }

  .titlebar-text {
    font-size: 5px;
  }

  .chat-message {
    font-size: 15px;
  }

  .chat-message .msg-label {
    font-size: 7px;
  }

  .verification-bar {
    font-size: 6px;
    gap: 6px;
  }

  .boot-sequence {
    font-size: 14px;
  }
}

/* Landscape mode on phones */
@media (max-height: 500px) and (orientation: landscape) {
  .screen {
    min-height: 200px;
    max-height: 60vh;
  }

  .boot-sequence {
    padding: 10px;
    font-size: 14px;
    line-height: 1.5;
  }

  .titlebar {
    padding: 4px 10px;
  }

  .verification-bar {
    padding: 4px 10px;
  }

  .input-area {
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}

/* General short screens */
@media (max-height: 700px) {
  .screen {
    min-height: 300px;
  }
}

/* Prevent zoom on iOS when focusing inputs */
@supports (-webkit-touch-callout: none) {
  .terminal-input {
    font-size: 16px;
  }
}
