:root {
  /* Tweet (the meme itself) keeps light-mode X colors */
  --tweet-bg: #ffffff;
  --tweet-text: rgb(15, 20, 25);

  /* Terminal palette */
  --bg: #000000;
  --bg-deep: #050505;
  --green: #00ff41;
  --green-dim: #008f1f;
  --green-faint: #003c0e;
  --magenta: #ff00ff;
  --cyan: #00ffff;
  --amber: #ffb000;
  --text: #c8ffd0;
  --secondary: #5a8a5e;
  --term-border: #00ff41;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'VT323', 'Share Tech Mono', ui-monospace, "Courier New", monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px 14px 60px;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  position: relative;
}

/* CRT scanlines */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 255, 65, 0.035) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: screen;
}
.scanlines::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -20%;
  height: 18%;
  background: linear-gradient(to bottom, transparent, rgba(0, 255, 65, 0.04), transparent);
  animation: rollscan 7s linear infinite;
  pointer-events: none;
}
@keyframes rollscan {
  0%   { transform: translateY(0); }
  100% { transform: translateY(800%); }
}

/* CRT corner vignette */
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8999;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.8) 100%);
}

.terminal {
  width: 100%;
  max-width: 760px;
  border: 1px solid var(--green-dim);
  background: var(--bg-deep);
  box-shadow:
    0 0 0 1px rgba(0, 255, 65, 0.08),
    0 0 28px rgba(0, 255, 65, 0.08),
    inset 0 0 60px rgba(0, 255, 65, 0.02);
  padding: 0 0 22px;
  position: relative;
  z-index: 1;
}

/* Faux terminal title bar */
.term-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(0, 255, 65, 0.08), rgba(0, 255, 65, 0.02));
  border-bottom: 1px solid var(--green-dim);
  font-size: 17px;
}
.term-bar .dot {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px currentColor;
}
.term-bar .dot-r { background: #ff5f56; color: #ff5f56; }
.term-bar .dot-y { background: #ffbd2e; color: #ffbd2e; }
.term-bar .dot-g { background: #27c93f; color: #27c93f; }
.term-bar .term-title {
  flex: 1;
  text-align: center;
  color: var(--green-dim);
  letter-spacing: 0.06em;
}
.term-bar .term-ver {
  color: var(--magenta);
  font-size: 15px;
}

/* Glitchy title */
.page-head {
  padding: 22px 22px 8px;
}
.page-title {
  font-family: 'VT323', monospace;
  font-size: clamp(30px, 7vw, 62px);
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1;
  display: inline;
}
.page-head .glitch {
  color: var(--green);
  text-shadow:
    0 0 6px rgba(0, 255, 65, 0.6),
    0 0 18px rgba(0, 255, 65, 0.25);
  position: relative;
  display: inline-block;
  white-space: nowrap;
}
.page-head .domain {
  color: var(--green-dim);
  font-size: 0.5em;
  letter-spacing: 0.04em;
  text-shadow: 0 0 4px rgba(0, 143, 31, 0.5);
  vertical-align: baseline;
  white-space: nowrap;
}
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  pointer-events: none;
  text-shadow: none;
}
.glitch::before {
  color: var(--magenta);
  transform: translate(-2px, 0);
  animation: glitch-x 3.2s infinite steps(1);
  clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
  opacity: 0.85;
}
.glitch::after {
  color: var(--cyan);
  transform: translate(2px, 0);
  animation: glitch-y 4.1s infinite steps(1);
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
  opacity: 0.7;
}
@keyframes glitch-x {
  0%, 92%, 100% { transform: translate(-2px, 0); }
  93% { transform: translate(-5px, -1px); }
  95% { transform: translate(1px, 2px); }
  97% { transform: translate(-3px, 1px); }
}
@keyframes glitch-y {
  0%, 88%, 100% { transform: translate(2px, 0); }
  89% { transform: translate(4px, 1px); }
  91% { transform: translate(-2px, -2px); }
  94% { transform: translate(3px, 0); }
}

.boot {
  color: var(--green-dim);
  font-size: 19px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.boot .prompt { color: var(--green); }
.boot .dots::after {
  content: '';
  animation: dots 1.4s steps(4) infinite;
}
@keyframes dots {
  0%, 100% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
.boot .bar {
  display: inline-block;
  width: 140px;
  height: 10px;
  border: 1px solid var(--green-dim);
  position: relative;
  margin: 0 4px;
}
.boot .bar-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: load 2.4s ease-out 1 forwards;
  transform-origin: left center;
  transform: scaleX(0);
}
@keyframes load { to { transform: scaleX(1); } }
.boot .pct { color: var(--green); }

/* Frame around meme */
.frame {
  margin: 16px 22px 22px;
  border: 1px dashed var(--green-dim);
  padding: 16px;
  position: relative;
  background:
    linear-gradient(rgba(0, 255, 65, 0.015), rgba(0, 255, 65, 0.015));
}
.frame-label {
  position: absolute;
  top: -10px;
  left: 14px;
  background: var(--bg-deep);
  color: var(--magenta);
  padding: 0 8px;
  font-size: 16px;
  letter-spacing: 0.12em;
}

/* The meme itself (image + overlay) */
.tweet-meme {
  position: relative;
  width: 100%;
  max-width: 700px;
  aspect-ratio: 1000 / 425;
  margin: 0 auto;
  background: var(--tweet-bg);
  border-radius: 6px;
  overflow: hidden;
  container-type: inline-size;
}

.tweet-meme img.bg {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.mask {
  position: absolute;
  top: 42.3%;
  bottom: 15.2%;
  left: 8.2%;
  right: 5%;
  background: var(--tweet-bg);
  color: var(--tweet-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Ubuntu, sans-serif;
  font-size: 3cqw;
  line-height: 1.32;
  letter-spacing: -0.005em;
  padding: 0.4cqw 0 0;
  display: flex;
  flex-direction: column;
  gap: 1.2cqw;
  overflow: visible;
}

/* X-style character counter, baked into the meme */
.char-counter {
  position: absolute;
  bottom: -1cqw;
  right: 0;
  width: 3.2cqw;
  height: 3.2cqw;
  display: flex;
  align-items: center;
  justify-content: center;
}
.counter-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.counter-ring .track {
  fill: none;
  stroke: #ccd6dd;
  stroke-width: 2.6;
}
.counter-ring .progress {
  fill: none;
  stroke: #1d9bf0;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: 87.96;
  stroke-dashoffset: 87.96;
  transition: stroke-dashoffset 180ms ease, stroke 180ms ease;
}
.char-counter.over .counter-ring .progress {
  stroke-dasharray: 87.96;
  stroke-dashoffset: 0;
}
.count-text {
  position: relative;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.2cqw;
  font-weight: 700;
  color: #536471;
  line-height: 1;
}
.char-counter.over .count-text {
  color: #f4212e;
}

.bomb {
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  cursor: text;
  border-radius: 4px;
  padding: 1px 3px;
  margin: -1px -3px;
  transition: background 120ms ease, box-shadow 120ms ease;
}
body:not(.exporting) .bomb:hover { background: rgba(29, 155, 240, 0.06); }
body:not(.exporting) .bomb:focus {
  background: rgba(29, 155, 240, 0.10);
  box-shadow: 0 0 0 1px rgba(29, 155, 240, 0.35);
}
.bomb:empty::before {
  content: attr(data-placeholder);
  color: #999;
  font-style: italic;
}

/* Generator */
.generator {
  display: flex;
  gap: 10px;
  margin: 0 22px 14px;
  align-items: stretch;
  flex-wrap: wrap;
}
.prompt-line {
  flex: 1;
  min-width: 240px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--green-dim);
  background: rgba(0, 255, 65, 0.025);
  padding: 0 10px;
  font-size: 22px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.prompt-line:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 14px rgba(0, 255, 65, 0.25), inset 0 0 12px rgba(0, 255, 65, 0.05);
}
.prompt-line .prompt { color: var(--green); }
.prompt-line .prompt-label { color: var(--green-dim); }
.prompt-line .prompt-bracket { color: var(--green-dim); }
.prompt-line input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 22px;
  background: transparent;
  border: 0;
  color: var(--green);
  outline: none;
  padding: 10px 4px;
  caret-color: var(--green);
}
.prompt-line input::placeholder {
  color: var(--secondary);
  font-style: italic;
}

.generator button {
  font: inherit;
  font-size: 22px;
  padding: 10px 22px;
  border: 1px solid var(--green);
  background: transparent;
  color: var(--green);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease, box-shadow 120ms ease;
  letter-spacing: 0.04em;
  text-shadow: 0 0 4px rgba(0, 255, 65, 0.4);
}
.generator button:hover:not(:disabled) {
  background: var(--green);
  color: #000;
  box-shadow: 0 0 18px rgba(0, 255, 65, 0.5);
  text-shadow: none;
}
.generator button:disabled { opacity: 0.6; cursor: progress; }
.gen-spin {
  display: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(0, 255, 65, 0.25);
  border-top-color: var(--green);
  animation: spin 720ms linear infinite;
}
.generator button.loading .gen-label { display: none; }
.generator button.loading .gen-spin { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin: 0 22px 18px;
}
.controls button {
  font: inherit;
  font-size: 22px;
  padding: 8px 18px;
  border: 1px solid var(--green-dim);
  background: transparent;
  color: var(--green);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.controls button:hover {
  background: var(--green);
  color: #000;
  border-color: var(--green);
  box-shadow: 0 0 14px rgba(0, 255, 65, 0.4);
}
.controls button.primary {
  border-color: var(--green);
  background: rgba(0, 255, 65, 0.06);
}
.controls button.ghost {
  color: var(--green-dim);
  border-color: var(--green-faint);
}
.controls button.ghost:hover {
  color: #000;
  background: var(--green-dim);
  border-color: var(--green-dim);
  box-shadow: 0 0 12px rgba(0, 143, 31, 0.4);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #000;
  color: var(--green);
  border: 1px solid var(--green);
  padding: 10px 18px;
  font-size: 19px;
  letter-spacing: 0.04em;
  transition: transform 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 0 22px rgba(0, 255, 65, 0.35);
  z-index: 10000;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Footer */
.page-foot {
  margin: 14px 22px 0;
  color: var(--secondary);
  font-size: 18px;
  letter-spacing: 0.04em;
}
.page-foot .prompt { color: var(--green); }
.page-foot .cursor {
  display: inline-block;
  color: var(--green);
  animation: blink 1.1s steps(2) infinite;
  margin-left: 4px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Export cleanup */
body.exporting .mask { caret-color: transparent; }
body.exporting .bomb,
body.exporting .tweet-meme {
  background: var(--tweet-bg) !important;
  box-shadow: none !important;
}

/* Small-screen tweaks */
@media (max-width: 540px) {
  .page-head { padding: 16px 16px 6px; }
  .frame { margin: 12px 14px 18px; padding: 12px; }
  .generator, .controls, .page-foot { margin-left: 14px; margin-right: 14px; }
  .prompt-line, .prompt-line input,
  .generator button,
  .controls button { font-size: 19px; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .glitch::before, .glitch::after { animation: none; }
  .scanlines::after { animation: none; }
  .boot .bar-fill { animation: none; transform: scaleX(1); }
  .page-foot .cursor { animation: none; }
}
