* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.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;
}

body {
  background: #0a0a14;
  color: #e0e0e0;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.6;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#terminal {
  flex: 1;
  height: 0;
  width: 100%;
  background: #1a1a2e;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  border-top: 1px solid #2d2d44;
  position: relative;
}

#terminal::-webkit-scrollbar {
  width: 5px;
}

#terminal::-webkit-scrollbar-track {
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 2px,
    #1e1e34 2px,
    #1e1e34 4px
  );
  border-left: 1px solid #2d2d44;
}

#terminal::-webkit-scrollbar-thumb {
  background: #4a4a6a;
  border-radius: 0;
  min-height: 30px;
}

#terminal::-webkit-scrollbar-thumb:hover {
  background: #5a5a7a;
}

/* Firefox */
#terminal {
  scrollbar-width: thin;
  scrollbar-color: #4a4a6a #1e1e34;
}

/* Title bar */
.title-bar {
  background: linear-gradient(180deg, #2d2d44 0%, #25253a 100%);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #3d3d55;
  position: sticky;
  top: 0;
  z-index: 10;
  user-select: none;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot.red { background: #ef4444; }
.dot.yellow { background: #eab308; }
.dot.green { background: #22c55e; }

.title-text {
  color: #777;
  font-size: 12px;
  margin-left: 8px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

#terminal-body {
  padding: 20px;
  min-height: calc(100% - 40px);
}

/* Content */
.title-line {
  color: #777;
  font-size: 12px;
  margin-bottom: 8px;
}

.title-line .prompt-symbol {
  color: #eab308;
}

.separator {
  height: 1px;
  background: linear-gradient(90deg, transparent, #3d3d55, transparent);
  margin: 12px 0;
}

.prompt-line {
  margin: 4px 0;
  word-break: break-all;
}

.prompt-symbol {
  color: #22d3ee;
  font-weight: 700;
}

.prompt-text {
  color: #e0e0e0;
}

.cursor {
  color: #4ade80;
  animation: blink 1s step-end infinite;
}

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

.line {
  margin: 4px 0;
  word-break: break-word;
  white-space: pre-wrap;
}

.line-response {
  color: #e0e0e0;
}

.line-thinking {
  color: #888;
  font-style: italic;
}

.line-outcome {
  font-weight: 700;
  margin: 8px 0;
}

.code-block {
  background: #2d2d44;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 8px 0;
  border-left: 3px solid #4ade80;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #e0e0e0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}

.code-block::-webkit-scrollbar {
  height: 4px;
}

.code-block::-webkit-scrollbar-track {
  background: transparent;
}

.code-block::-webkit-scrollbar-thumb {
  background: #4a4a6a;
  border-radius: 0;
}

.muted {
  color: #555;
}

.skill-suggestions span {
  transition: border-color 0.15s;
}

/* ── Fade + Slide In ── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 5px rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.6); }
}

@keyframes flashGreen {
  0% { background-color: rgba(74, 222, 128, 0.15); }
  100% { background-color: transparent; }
}

.line-outcome.critical {
  animation: fadeSlideIn 0.3s ease-out, shake 0.5s ease-in-out, pulseGlow 2s ease-in-out infinite;
}

.line-outcome.success {
  animation: fadeSlideIn 0.3s ease-out, flashGreen 0.8s ease-out;
}

.line, .code-block, .separator, .toolcall, .progress-bar, .thinking-block {
  animation: fadeSlideIn 0.25s ease-out both;
}

/* ── Thinking Block (Collapsible) ── */
.thinking-block {
  margin: 8px 0;
  border-left: 2px solid #3d3d55;
  border-radius: 0 6px 6px 0;
  background: rgba(45, 45, 68, 0.3);
  overflow: hidden;
  transition: border-color 0.3s;
}

.thinking-block.done {
  border-left-color: #4ade80;
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  cursor: pointer;
  user-select: none;
  color: #888;
  font-size: 13px;
  transition: background 0.15s;
}

.thinking-header:hover {
  background: rgba(45, 45, 68, 0.5);
}

.toggle-icon {
  color: #4a4a6a;
  font-size: 10px;
  width: 12px;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.thinking-spinner {
  color: #22d3ee;
  width: 14px;
  display: inline-block;
  text-align: center;
  flex-shrink: 0;
}

.thinking-block.done .thinking-spinner {
  color: #4ade80;
}

.thinking-title {
  color: #888;
  flex: 1;
  font-style: italic;
}

.thinking-block.done .thinking-title {
  font-style: normal;
  color: #888;
}

.thinking-summary {
  color: #555;
  font-size: 11px;
  margin-left: auto;
}

.thinking-body {
  padding: 0 12px 6px 24px;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.2s ease;
  max-height: 500px;
  opacity: 1;
  overflow: hidden;
}

.thinking-block.collapsed .thinking-body {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* ── Tool Call Trees ── */
.toolcall {
  margin: 2px 0;
  color: #888;
  font-size: 13px;
}

.toolcall .tc-branch {
  color: #4a4a6a;
}

.toolcall .tc-label {
  color: #aaa;
}

.toolcall .tc-result {
  color: #4ade80;
}

.toolcall .tc-error {
  color: #ef4444;
}

/* ── Progress Bar ── */
.progress-bar {
  margin: 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.progress-chars {
  color: #4ade80;
  font-size: 12px;
  letter-spacing: 0;
  font-variant-east-asian: full-width;
}

.progress-label {
  color: #888;
  font-size: 11px;
  min-width: 32px;
}

/* ── Syntax Highlighting ── */
.hl-keyword { color: #c792ea; }
.hl-string { color: #c3e88d; }
.hl-number { color: #f78c6c; }
.hl-comment { color: #546e7a; font-style: italic; }
.hl-function { color: #82aaff; }
.hl-type { color: #ffcb6b; }
.hl-operator { color: #89ddff; }
.hl-builtin { color: #f07178; }
.hl-variable { color: #eeffff; }
.hl-prop { color: #b2ccd6; }
.hl-tag { color: #f07178; }
.hl-attr { color: #c792ea; }
.hl-punctuation { color: #89ddff; }

/* Footer */
#footer {
  width: 100%;
  padding: 6px 16px;
  background: #1a1a2e;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  border-top: 1px solid #2d2d44;
  transition: border-color 0.3s;
}

.kofi-link {
  color: #aaa;
  text-decoration: none;
  margin-left: 8px;
  transition: color 0.2s;
  cursor: pointer;
}
.kofi-link:hover {
  color: #ff5e5b;
}

.status-bar {
  color: #888;
  transition: color 0.3s;
}

.status-bar.thinking {
  color: #22d3ee;
}
.status-bar.crisis {
  color: #ef4444;
}
.status-bar.streaming {
  color: #4ade80;
}
.status-bar.error {
  color: #ef4444;
}
.status-bar.idle {
  color: #555;
}

.status-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

.footer-center {
  display: flex;
  align-items: center;
  gap: 4px;
}
.footer-sep {
  width: 1px;
  height: 12px;
  background: #3d3d55;
  margin: 0 4px;
}
.share-link {
  color: #aaa;
  cursor: pointer;
  transition: color 0.2s;
  animation: shareAppear 0.4s ease-out;
  animation-fill-mode: backwards;
}
.share-link:hover {
  color: #22d3ee;
}
.share-link.active {
  animation: sharePulse 5s ease-in-out 0.4s infinite;
}

@keyframes shareAppear {
  0% { opacity: 0; transform: scale(0.7); }
  60% { transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes sharePulse {
  0%, 100% { text-shadow: 0 0 3px rgba(34, 211, 238, 0); }
  50% { text-shadow: 0 0 12px rgba(34, 211, 238, 0.7), 0 0 24px rgba(34, 211, 238, 0.3); }
}

.hint-bar {
  color: #3d3d55;
  font-size: 12px;
  flex: 1;
  text-align: center;
  transition: color 0.5s;
  cursor: default;
}

.hint-bar.visible {
  color: #22d3ee;
}

.status-mode {
  color: #22d3ee;
  font-weight: 500;
}

.status-sep {
  color: #3d3d55;
}

/* Responsive */
/* ── Crisis Events ── */
@keyframes pulseRed {
  0%, 100% { box-shadow: 0 0 5px rgba(239, 68, 68, 0.2); border-color: #ef4444; }
  50% { box-shadow: 0 0 25px rgba(239, 68, 68, 0.5); border-color: #ff6b6b; }
}

@keyframes crisisShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.crisis-banner {
  margin: 12px 0;
  border: 2px solid #ef4444;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.08);
  padding: 16px;
  animation: pulseRed 1.5s ease-in-out infinite, fadeSlideIn 0.3s ease-out;
}

.crisis-banner.danger {
  animation: pulseRed 0.5s ease-in-out infinite, crisisShake 0.2s ease-in-out infinite, fadeSlideIn 0.3s ease-out;
}

.crisis-title {
  color: #ef4444;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
}

.crisis-detail {
  color: #aaa;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 4px;
}

.crisis-hint {
  color: #f59e0b;
  font-size: 12px;
  margin-top: 8px;
}

.crisis-countdown {
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.crisis-countdown-icon {
  color: #ef4444;
  font-weight: 700;
  min-width: 24px;
}

.crisis-countdown-bar {
  flex: 1;
  height: 6px;
  background: #2d2d44;
  border-radius: 3px;
  overflow: hidden;
}

.crisis-countdown-fill {
  height: 100%;
  background: #ef4444;
  border-radius: 3px;
  transition: width 0.5s linear, background 0.3s;
}

.crisis-countdown-fill.warning {
  background: #f59e0b;
}

.crisis-countdown-fill.danger {
  background: #ef4444;
  animation: crisisShake 0.3s ease-in-out infinite;
}

.crisis-time-label {
  color: #888;
  font-size: 12px;
  min-width: 28px;
  text-align: right;
}

.crisis-prompt {
  margin: 8px 0 4px 0;
  word-break: break-all;
}

.crisis-prompt-symbol {
  color: #ef4444;
  font-weight: 700;
}

.crisis-warning {
  color: #f59e0b;
  font-size: 13px;
  margin: 4px 0;
}

.crisis-success {
  color: #4ade80;
  font-size: 13px;
  margin: 4px 0;
}

@media (max-width: 640px) {
  #terminal {
    font-size: 13px;
  }

  #terminal-body {
    padding: 12px;
  }

  .code-block {
    padding: 10px 12px;
    font-size: 12px;
  }

  .title-bar {
    padding: 6px 12px;
  }
}

/* ── Share Overlay ── */
.share-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Share Panel ── */
.share-panel {
  background: #1a1a2e;
  border: 1px solid #3d3d55;
  border-radius: 12px;
  width: 660px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.2s ease-out;
}

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

.share-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #2d2d44;
  color: #e0e0e0;
  font-weight: 600;
  font-size: 15px;
}

.share-close {
  color: #666;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s;
}
.share-close:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.share-body {
  padding: 18px;
}

/* Image */
.share-image-section {
  text-align: center;
  margin-bottom: 16px;
}

.share-canvas {
  width: 100%;
  max-width: 560px;
  border-radius: 8px;
  border: 1px solid #2d2d44;
  display: block;
  margin: 0 auto;
}

.share-download {
  display: inline-block;
  margin-top: 8px;
  color: #22d3ee;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.15s;
}
.share-download:hover {
  color: #4ade80;
  text-decoration: underline;
}

/* Text */
.share-text-section textarea {
  width: 100%;
  background: #2d2d44;
  border: 1px solid #3d3d55;
  border-radius: 6px;
  color: #e0e0e0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 10px;
  resize: vertical;
  min-height: 70px;
  outline: none;
  box-sizing: border-box;
}
.share-text-section textarea:focus {
  border-color: #22d3ee;
}

/* Actions */
.share-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.share-action {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #3d3d55;
  border-radius: 6px;
  background: #2d2d44;
  color: #e0e0e0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  user-select: none;
}
.share-action:hover {
  background: #3d3d55;
}
.share-action.twitter {
  border-color: #1da1f2;
  color: #1da1f2;
}
.share-action.twitter:hover {
  background: rgba(29, 161, 242, 0.1);
}
.share-action.hn {
  border-color: #ff6600;
  color: #ff6600;
}
.share-action.hn:hover {
  background: rgba(255, 102, 0, 0.1);
}
.share-action.copy {
  border-color: #4ade80;
  color: #4ade80;
}
.share-action.copy:hover {
  background: rgba(74, 222, 128, 0.1);
}

.share-action.copied {
  border-color: #4ade80;
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
}

/* ── Ko-fi Overlay ── */
.kofi-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.kofi-panel {
  background: #1a1a2e;
  border: 1px solid #3d3d55;
  border-radius: 12px;
  width: 440px;
  max-width: 95vw;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.2s ease-out;
}

.kofi-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #2d2d44;
  color: #e0e0e0;
  font-weight: 600;
  font-size: 15px;
}

.kofi-close {
  color: #666;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s;
}
.kofi-close:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.kofi-panel-body {
  padding: 0;
  line-height: 0;
}
.kofi-panel-body iframe {
  display: block;
}

@media (max-width: 480px) {
  .share-actions {
    flex-direction: column;
  }
  .share-body {
    padding: 12px;
  }
  .share-panel {
    max-width: 98vw;
    max-height: 95vh;
  }
}
