:root {
  --bg: #050505;
  --fg: #e0e0e0;
  --primary: #00ff41; /* Matrix Green */
  --secondary: #008f11;
  --accent: #d600ff; /* Cyberpunk Purple */
  --grid: rgba(0, 255, 65, 0.05);
  --border: #333;
  --font-mono: "Courier New", Courier, monospace;
  --scanline: rgba(0, 0, 0, 0.5);
  --glass: rgba(10, 10, 10, 0.8);
}

/* --- Base Setup & CRT Effect --- */
* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  overflow-x: hidden;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  text-shadow: 0 0 2px rgba(224, 224, 224, 0.3);
  /* CRT Scanline Background */
  background-image: 
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), 
    linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
  background-size: 100% 2px, 6px 100%;
}

/* Optional: CRT Curvature Vignette */
body::before {
  content: " ";
  display: block;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: radial-gradient(circle, rgba(0,0,0,0) 60%, rgba(0,0,0,0.6) 100%);
  pointer-events: none;
  z-index: 999;
}

/* --- Typography & ASCII Details --- */
h1, h2, h3 {
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 1rem;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 0.5rem;
}

h1 { 
  color: var(--primary); 
  text-shadow: 0 0 8px var(--secondary);
}

a { color: var(--primary); text-decoration: none; transition: all 0.3s; }
a:hover { color: #fff; text-shadow: 0 0 5px #fff; }

/* --- Layout --- */
header {
  padding: 2rem;
  text-align: center;
  border-bottom: 1px double var(--border);
  position: relative;
  z-index: 10;
  background: rgba(5,5,5,0.9);
}

main {
  max-width: 1200px; /* Wider for gallery */
  margin: 2rem auto;
  padding: 0 1rem;
  position: relative;
  z-index: 1;
}

/* --- Navigation (ASCII Tabs) --- */
nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.5rem;
}

nav a {
  padding: 10px 20px;
  border: 1px solid var(--secondary);
  position: relative;
  overflow: hidden;
  background: rgba(0, 255, 65, 0.05);
}

nav a::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: var(--primary);
  transition: transform 0.4s cubic-bezier(0.2, 1, 0.3, 1);
  z-index: -1;
  transform: skewX(-20deg);
}

nav a:hover::before, nav a.active::before {
  left: 0;
  transform: skewX(0deg);
}

nav a:hover, nav a.active {
  color: #000;
  box-shadow: 0 0 15px var(--secondary);
}

nav a.right { margin-left: auto; border-color: var(--accent); color: var(--accent); }
nav a.right:hover { background: var(--accent); color: #000; box-shadow: 0 0 15px var(--accent); }

/* --- Forms & Inputs --- */
label {
  display: block;
  margin: 1rem 0 0.5rem;
  color: #888;
  font-size: 0.8rem;
}

input, textarea, select {
  width: 100%;
  background: #000;
  border: 1px solid #333;
  color: var(--primary);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 1rem;
  transition: all 0.3s;
  border-radius: 0; /* Brutalist */
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(0, 255, 65, 0.2);
  background: #0a0a0a;
}

/* Custom File Input Styling */
input[type="file"] {
  padding: 1rem;
  border: 1px dashed var(--secondary);
  cursor: pointer;
}

/* --- Buttons --- */
button, .btn {
  display: inline-block;
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 8px 16px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  position: relative;
  transition: all 0.3s;
  overflow: hidden;
  font-weight: bold;
  font-size: 0.8rem;
  text-align: center;
  margin-top: 1rem;
}

button:hover, .btn:hover {
  background: var(--primary);
  color: #000;
  box-shadow: 0 0 15px var(--secondary);
  text-decoration: none;
}

button:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Working button state */
.btn-working {
  background: var(--secondary) !important;
  color: #000 !important;
  border-color: var(--primary) !important;
  box-shadow: 0 0 20px var(--primary) !important;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 20px var(--primary);
  }
  50% {
    box-shadow: 0 0 30px var(--primary);
  }
}

/* Button spinner */
.btn-spinner {
  display: inline-block;
  animation: blink 0.8s infinite;
  margin-left: 4px;
}

/* Abort button */
.btn-abort {
  display: inline-block;
  margin-right: 10px;
  margin-top: 0 !important;
  padding: 4px 12px;
  font-size: 0.7rem;
  background: rgba(214, 0, 255, 0.1);
  color: var(--accent);
  border: 1px solid var(--accent);
  cursor: pointer;
  transition: all 0.3s;
}

.btn-abort:hover {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 10px var(--accent);
}

.btn-danger {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger:hover {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 15px var(--accent);
}

/* Primary Button Style */
.btn-primary {
  background: var(--primary);
  color: #000;
  border-color: var(--primary);
  font-weight: bold;
}

.btn-primary:hover {
  background: var(--secondary);
  border-color: var(--secondary);
  color: #000;
  box-shadow: 0 0 15px var(--primary);
}

/* Ghost Button Style */
.btn-ghost {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--fg);
  color: #000;
  border-color: var(--fg);
  box-shadow: 0 0 15px rgba(224, 224, 224, 0.3);
}

/* --- Dropzone --- */
.dropzone {
  border: 2px dashed #444;
  padding: 2rem;
  text-align: center;
  margin-top: 1rem;
  transition: all 0.3s;
  color: #666;
}

.dropzone.focus {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(0, 255, 65, 0.05);
  transform: scale(1.02);
}

/* --- Chat Box --- */
.chat-box {
  height: 500px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.5);
  padding: 1rem;
  overflow-y: auto;
  /* Scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: var(--primary) #111;
}

.chat-msg {
  margin: 1rem 0;
  padding: 1rem;
  border-left: 3px solid;
  animation: fadeIn 0.3s ease;
}

.chat-msg.user {
  border-color: var(--accent);
  background: rgba(214, 0, 255, 0.05);
  text-align: right;
  margin-left: 20%;
}

.chat-msg.bot {
  border-color: var(--primary);
  background: rgba(0, 255, 65, 0.05);
  margin-right: 20%;
}

/* --- Gallery Grid --- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  margin-top: 2rem;
}

.card {
  border: 1px solid #333;
  background: #050505;
  transition: all 0.3s ease;
  position: relative;
  display: flex;
  flex-direction: column;
}

.card:hover {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.1);
  z-index: 2;
}

.card img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  display: block;
  transition: all 0.3s;
}

.caption {
  padding: 12px;
  color: #aaa;
  font-size: 0.8rem;
  border-bottom: 1px dashed #222;
  background: rgba(255,255,255,0.02);
  flex-grow: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  transition: max-height 0.3s;
  max-height: 4.5em; /* 3 lines approx */
}

.card:hover .caption {
  color: #fff;
}

.actions {
  padding: 10px;
  display: flex;
  gap: 10px;
  background: #080808;
}

.actions .btn {
  flex: 1;
  font-size: 0.75rem;
  padding: 8px 4px;
  margin-top: 0; /* override generic button margin */
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* Cursor effect */
.typing-cursor::after {
  content: '█';
  animation: blink 1s infinite;
  color: var(--primary);
  margin-left: 2px;
}

/* Glitch Text (Simple version) */
.glitch {
  position: relative;
}

.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--bg);
}

.glitch::before {
  left: 2px;
  text-shadow: -1px 0 red;
  clip: rect(24px, 550px, 90px, 0);
  animation: glitch-anim-1 2.5s infinite linear alternate-reverse;
}

.glitch::after {
  left: -2px;
  text-shadow: -1px 0 blue;
  clip: rect(85px, 550px, 140px, 0);
  animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

@keyframes glitch-anim-1 {
  0% { clip: rect(20px, 9999px, 80px, 0); }
  20% { clip: rect(60px, 9999px, 10px, 0); }
  40% { clip: rect(90px, 9999px, 100px, 0); }
  60% { clip: rect(10px, 9999px, 40px, 0); }
  80% { clip: rect(50px, 9999px, 120px, 0); }
  100% { clip: rect(30px, 9999px, 70px, 0); }
}

@keyframes glitch-anim-2 {
  0% { clip: rect(120px, 9999px, 10px, 0); }
  20% { clip: rect(10px, 9999px, 100px, 0); }
  40% { clip: rect(60px, 9999px, 40px, 0); }
  60% { clip: rect(80px, 9999px, 120px, 0); }
  80% { clip: rect(30px, 9999px, 140px, 0); }
  100% { clip: rect(70px, 9999px, 90px, 0); }
}

/* Lightbox */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.95);
  backdrop-filter: blur(5px);
  display: none;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  cursor: zoom-out;
}

.lightbox.open {
  display: flex;
}

.lightbox img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  border: 2px solid var(--primary);
  box-shadow: 0 0 50px rgba(0,255,65,0.2);
  cursor: default;
}

.lb-caption {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80%;
  padding: 1rem 2rem;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid var(--primary);
  color: var(--primary);
  text-align: center;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.lb-close {
  position: absolute;
  top: 2rem;
  right: 2rem;
  width: 50px;
  height: 50px;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid var(--primary);
  color: var(--primary);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.3s;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-close:hover {
  background: var(--primary);
  color: #000;
  transform: rotate(90deg);
}

/* Result Grid for Generated Images */
.result {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Status message wrapper */
.status-message {
  display: inline-block;
  white-space: nowrap;
}

.result img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border: 1px solid #333;
  cursor: zoom-in;
  transition: all 0.3s;
}

.result img:hover {
  border-color: var(--primary);
  box-shadow: 0 0 15px rgba(0, 255, 65, 0.2);
  transform: scale(1.02);
}

/* Preview for Pasted/Uploaded Images */
.preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  margin-bottom: 20px;
}

.preview .thumb {
  position: relative;
  width: 100px;
  height: 100px;
  border: 1px solid #333;
  overflow: hidden;
}

.preview .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.preview .remove:hover {
  background: var(--accent);
  color: #000;
  transform: scale(1.1);
}

/* Chat Images */
.chat-msg img {
  max-width: 200px;
  max-height: 200px;
  object-fit: contain;
  border: 1px solid #333;
  margin-top: 8px;
  cursor: zoom-in;
  transition: all 0.3s;
}

.chat-msg img:hover {
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(0, 255, 65, 0.2);
}

/* Utility Classes */
.hidden { display: none; }
.active { display: block; }
.tab { display: none; animation: fadeIn 0.5s; }
.tab.active { display: block; }

.muted { color: #666; font-size: 0.85rem; }
.no-wrap { white-space: nowrap; }

/* --- Resolution & Aspect Ratio Selector --- */
.config-section {
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px dashed var(--border);
  background: rgba(0, 255, 65, 0.02);
}

.config-section-title {
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.res-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 1rem;
}

.res-btn {
  flex: 1;
  padding: 10px 0;
  text-align: center;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s;
}

.res-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.res-btn.active {
  border-color: var(--primary);
  background: rgba(0, 255, 65, 0.15);
  color: var(--primary);
  box-shadow: 0 0 10px rgba(0, 255, 65, 0.2);
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.ratio-card {
  border: 1px solid var(--border);
  background: transparent;
  height: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  padding: 8px;
}

.ratio-card:hover {
  border-color: var(--primary);
}

.ratio-card.active {
  border-color: var(--primary);
  background: rgba(0, 255, 65, 0.15);
  box-shadow: 0 0 10px rgba(0, 255, 65, 0.2);
}

.icon-box {
  border: 2px solid var(--fg);
  margin-bottom: 6px;
  box-sizing: content-box;
  transition: border-color 0.3s;
}

.ratio-card:hover .icon-box,
.ratio-card.active .icon-box {
  border-color: var(--primary);
}

.ratio-text {
  font-size: 0.7rem;
  color: var(--fg);
  transition: color 0.3s;
}

.ratio-card:hover .ratio-text,
.ratio-card.active .ratio-text {
  color: var(--primary);
}

/* Aspect ratio icon sizes */
.icon-auto { width: 14px; height: 14px; border-style: dashed; }
.icon-1-1 { width: 14px; height: 14px; }
.icon-21-9 { width: 21px; height: 9px; }
.icon-16-9 { width: 18px; height: 10px; }
.icon-4-3 { width: 16px; height: 12px; }
.icon-3-2 { width: 18px; height: 12px; }
.icon-5-4 { width: 15px; height: 12px; }
.icon-9-16 { width: 10px; height: 18px; }
.icon-3-4 { width: 12px; height: 16px; }
.icon-2-3 { width: 12px; height: 18px; }
.icon-4-5 { width: 12px; height: 15px; }

@media (max-width: 600px) {
  .ratio-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Template Preview */
.template-preview {
    border: 1px dashed var(--primary);
    background: rgba(0, 255, 65, 0.02);
    color: var(--primary);
}
.template-desc {
    background: transparent;
    border-left: 3px solid var(--primary);
    color: var(--fg);
}

/* Loading Shimmer override for dark theme */
.optimized-img[data-loading="true"] {
  background: repeating-linear-gradient(
    45deg,
    #111,
    #111 10px,
    #222 10px,
    #222 20px
  );
  animation: scrollBackground 20s linear infinite;
}
@keyframes scrollBackground {
  from { background-position: 0 0; }
  to { background-position: 100% 0; }
}
