/* =====================================================
   PIXEL CHEM LAB — style.css
   Pixel-art retro OS window manager aesthetic
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323:wght@400&display=swap');

/* ── CSS VARIABLES ─────────────────────────────────── */
:root {
  --px: 4px;
  --bg:      #06060f;
  --desktop: #0b0b1e;
  --panel:   #10102a;
  --panel2:  #0d0d22;
  --border:  #2a2a55;
  --border2: #3a3a7a;
  --accent:  #00ffcc;
  --accent2: #ff6aff;
  --accent3: #ffcc00;
  --danger:  #ff3333;
  --text:    #c8c8f0;
  --dim:     #4a4a7a;
  --green:   #44ff88;
  --orange:  #ff8844;
  --blue:    #4488ff;
  --win-title-h: 28px;
  --win-resize:  8px;
  --taskbar-h:   40px;
  --font-pixel:  'Press Start 2P', monospace;
  --font-mono:   'VT323', monospace;
  /* Dynamic scale factor injected by JS */
  --scale: 1;
}

/* ── RESET ─────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  image-rendering: pixelated;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(14px, 1.6vw, 20px);
  cursor: default;
  user-select: none;
}

/* ── SCANLINE OVERLAY ──────────────────────────────── */
body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent, transparent 2px,
    rgba(0,0,0,0.07) 2px, rgba(0,0,0,0.07) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ── DESKTOP ───────────────────────────────────────── */
#desktop {
  position: fixed; inset: 0;
  bottom: var(--taskbar-h);
  background:
    radial-gradient(ellipse at 20% 20%, rgba(0,80,60,0.18) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(80,0,120,0.18) 0%, transparent 60%),
    var(--desktop);
  overflow: hidden;
}

/* Pixel grid background */
#desktop::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(40,40,80,0.25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(40,40,80,0.25) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}

/* ── TASKBAR ───────────────────────────────────────── */
#taskbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--taskbar-h);
  background: #08081a;
  border-top: 3px solid var(--border2);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  z-index: 8000;
  box-shadow: 0 -4px 0 #000;
}

#taskbar-logo {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--accent);
  text-shadow: 1px 1px 0 #003322, 2px 2px 0 rgba(0,255,204,0.3);
  padding: 0 10px 0 4px;
  border-right: 3px solid var(--border);
  margin-right: 4px;
  white-space: nowrap;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.tb-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 2px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-pixel);
  font-size: 6px;
  cursor: pointer;
  height: 28px;
  white-space: nowrap;
  transition: none;
  letter-spacing: 0.5px;
}
.tb-btn:hover           { border-color: var(--accent); background: rgba(0,255,204,0.06); }
.tb-btn.minimized       { opacity: 0.5; border-style: dashed; }
.tb-btn.active          { border-color: var(--accent); background: rgba(0,255,204,0.1); color: var(--accent); }
.tb-btn .tb-icon        { font-size: 14px; }

#tb-clock {
  margin-left: auto;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--accent3);
  text-shadow: 1px 1px 0 #443300;
  padding-left: 10px;
  border-left: 3px solid var(--border);
  flex-shrink: 0;
}

/* ── WINDOW BASE ───────────────────────────────────── */
.win {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  min-height: 140px;
  background: var(--panel);
  border: 3px solid var(--border2);
  box-shadow: 6px 6px 0 #000, 3px 3px 0 rgba(0,0,0,0.6);
  overflow: hidden;
  transition: box-shadow 0.05s;
  will-change: transform;
}

.win.focused {
  border-color: var(--accent);
  box-shadow: 8px 8px 0 #000, 0 0 0 1px rgba(0,255,204,0.2), 4px 4px 0 rgba(0,0,0,0.6);
  z-index: 100 !important;
}

.win.minimized {
  display: none;
}

/* Title bar */
.win-titlebar {
  height: var(--win-title-h);
  display: flex;
  align-items: center;
  padding: 0 6px;
  background: #080820;
  border-bottom: 3px solid var(--border2);
  cursor: grab;
  flex-shrink: 0;
  gap: 6px;
  user-select: none;
}

.win-titlebar:active { cursor: grabbing; }

.win.focused .win-titlebar {
  background: #0d0d2a;
  border-bottom-color: var(--accent);
}

.win-icon { font-size: 14px; flex-shrink: 0; }

.win-title {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.5px;
}

.win.focused .win-title { color: var(--accent); }

/* Window controls */
.win-controls {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.win-btn {
  width: 16px; height: 16px;
  border: 2px solid;
  background: var(--panel2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-family: var(--font-pixel);
  line-height: 1;
  transition: none;
}

.win-btn:active { transform: translate(1px,1px); }
.win-btn.minimize { border-color: var(--accent3); color: var(--accent3); }
.win-btn.maximize { border-color: var(--green);   color: var(--green); }
.win-btn.close    { border-color: var(--danger);  color: var(--danger); }
.win-btn.minimize:hover { background: rgba(255,204,0,0.15); }
.win-btn.maximize:hover { background: rgba(68,255,136,0.15); }
.win-btn.close:hover    { background: rgba(255,51,51,0.15); }

/* Window body */
.win-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Resize handles */
.resize-handle {
  position: absolute;
  z-index: 10;
}
.resize-handle.se { bottom: 0; right: 0; width: 14px; height: 14px; cursor: se-resize; }
.resize-handle.sw { bottom: 0; left:  0; width: 14px; height: 14px; cursor: sw-resize; }
.resize-handle.ne { top:    0; right: 0; width: 14px; height: 14px; cursor: ne-resize; }
.resize-handle.nw { top:    0; left:  0; width: 14px; height: 14px; cursor: nw-resize; }
.resize-handle.n  { top:  0;   left: 14px; right: 14px; height: 6px; cursor: n-resize; }
.resize-handle.s  { bottom: 0; left: 14px; right: 14px; height: 6px; cursor: s-resize; }
.resize-handle.e  { top: 14px; right: 0;  bottom: 14px; width: 6px; cursor: e-resize; }
.resize-handle.w  { top: 14px; left:  0;  bottom: 14px; width: 6px; cursor: w-resize; }

/* Corner pixel decoration */
.resize-handle.se::after {
  content: '';
  position: absolute; bottom: 2px; right: 2px;
  width: 8px; height: 8px;
  background:
    linear-gradient(135deg, transparent 50%, var(--border2) 50%),
    repeating-linear-gradient(135deg, var(--border2) 0, var(--border2) 2px, transparent 2px, transparent 4px);
}

/* ── PANEL TITLE BAR ───────────────────────────────── */
.panel-hdr {
  font-family: var(--font-pixel);
  font-size: 6.5px;
  color: var(--accent3);
  padding: 7px 10px;
  border-bottom: 3px solid var(--border);
  background: var(--panel2);
  text-shadow: 1px 1px 0 #554400;
  letter-spacing: 1px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}

/* ── SCROLLBAR ─────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #080818; }
::-webkit-scrollbar-thumb { background: var(--border2); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── CHEMICAL LIBRARY WINDOW ───────────────────────── */
#chem-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chem-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  cursor: pointer;
  border: 2px solid transparent;
}
.chem-item:hover  { border-color: var(--accent); background: rgba(0,255,204,0.05); }
.chem-item.active { border-color: var(--accent2); background: rgba(255,106,255,0.08); }

.chem-emoji { font-size: 18px; flex-shrink: 0; width: 26px; text-align: center; }
.chem-info  { flex: 1; min-width: 0; }
.chem-name  { font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chem-fml   { font-size: 12px; color: var(--dim); }

.chem-badge {
  font-family: var(--font-pixel);
  font-size: 5px;
  padding: 2px 5px;
  border: 2px solid;
  flex-shrink: 0;
  white-space: nowrap;
}
.badge-acid   { border-color: var(--danger); color: var(--danger); }
.badge-solid  { border-color: var(--orange); color: var(--orange); }
.badge-liquid { border-color: var(--blue);   color: var(--blue); }
.badge-gas    { border-color: var(--green);  color: var(--green); }

/* ── BEAKER / REACTION WINDOW ──────────────────────── */
#beaker-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  gap: 12px;
  min-height: 0;
  flex-wrap: wrap;
}

.canvas-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.canvas-lbl {
  font-family: var(--font-pixel);
  font-size: 5.5px;
  color: var(--dim);
  white-space: nowrap;
}

canvas {
  image-rendering: pixelated;
  display: block;
}

#beaker-canvas  { border: 3px solid #4455aa; }
#molecule-canvas { border: 3px solid var(--border); background: #030310; }

/* Mixer strip */
#mixer-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-top: 3px solid var(--border);
  background: var(--panel2);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.mixer-lbl {
  font-family: var(--font-pixel);
  font-size: 5.5px;
  color: var(--dim);
  flex-shrink: 0;
  line-height: 1.6;
}

.mix-slot {
  width: 78px;
  height: 52px;
  border: 2px dashed var(--border2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  font-size: 11px;
  color: var(--dim);
  padding: 3px;
  flex-shrink: 0;
}
.mix-slot:hover { border-color: var(--accent); background: rgba(0,255,204,0.04); }
.mix-slot.filled { border-style: solid; border-color: var(--accent); background: rgba(0,255,204,0.06); }

.slot-emoji { font-size: 16px; }
.slot-txt   { font-size: 12px; color: var(--accent); line-height: 1.2; text-align: center; }
.slot-rm {
  position: absolute; top: 1px; right: 3px;
  color: var(--danger); font-size: 13px; cursor: pointer; line-height: 1;
}

.px-btn {
  font-family: var(--font-pixel);
  font-size: 7px;
  border: none;
  padding: 10px 13px;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  flex-shrink: 0;
  transition: none;
}
.px-btn:active { transform: translate(2px,2px); box-shadow: none !important; }

#react-btn {
  background: var(--accent);
  color: #001a12;
  box-shadow: 4px 4px 0 #004433;
}
#react-btn:hover { transform: translate(-1px,-1px); box-shadow: 5px 5px 0 #004433; }

#clear-btn {
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
  box-shadow: 3px 3px 0 #330000;
}
#clear-btn:hover { background: rgba(255,51,51,0.08); }

/* ── LOG WINDOW ────────────────────────────────────── */
#reaction-log {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  font-size: 15px;
  line-height: 1.7;
}
.log-line { padding: 3px 2px; border-bottom: 1px solid rgba(30,30,70,0.8); }
.log-line.info     { color: var(--dim); }
.log-line.ok       { color: var(--accent); }
.log-line.warn     { color: var(--accent3); }
.log-line.danger   { color: var(--danger); }
.log-line.product  { color: var(--green); }
.log-line.sep      { color: #2a2a55; }

.log-cursor { animation: blink 0.8s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Status badges row */
#status-row {
  display: flex;
  gap: 8px;
  padding: 5px 8px;
  border-top: 2px solid var(--border);
  background: #080818;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.stat-chip {
  font-family: var(--font-pixel);
  font-size: 5.5px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: 2px solid var(--border2);
  white-space: nowrap;
}
.stat-chip span { color: var(--accent); }

/* ── GRAPH WINDOW ──────────────────────────────────── */
#graph-inner {
  flex: 1;
  display: flex;
  gap: 8px;
  padding: 8px;
  min-height: 0;
  overflow: hidden;
}

#graph-canvas  { flex: 1; min-width: 0; border: 2px solid var(--border); background: #030310; }
#energy-canvas { flex-shrink: 0; border: 2px solid var(--border); background: #030310; }

/* ── TOOLTIP ───────────────────────────────────────── */
#tooltip {
  position: fixed;
  background: var(--panel2);
  border: 3px solid var(--accent);
  padding: 8px 12px;
  font-size: 14px;
  pointer-events: none;
  z-index: 9000;
  max-width: 230px;
  display: none;
  line-height: 1.8;
  box-shadow: 4px 4px 0 #000;
}
.tip-title {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--accent);
  margin-bottom: 5px;
  word-break: break-word;
}

/* ── PIXEL ANIMATIONS ──────────────────────────────── */
@keyframes px-shake {
  0%,100% { transform: translate(var(--wx,40px), var(--wy,80px)); }
  25%      { transform: translate(calc(var(--wx,40px) - 4px), var(--wy,80px)); }
  75%      { transform: translate(calc(var(--wx,40px) + 4px), var(--wy,80px)); }
}
.shake { animation: px-shake 0.3s steps(2) 3; }

/* ── RESPONSIVE SCALING ────────────────────────────── */
/* Windows scale their content via CSS scale() applied by JS.
   Base layout is designed at 1280×800. */
.win-body canvas,
.win-body #chem-list,
.win-body #reaction-log {
  /* content will flow and resize naturally inside flex containers */
}

/* Make sure canvases never overflow their containers */
#beaker-wrap canvas {
  max-height: 100%;
  max-width: 100%;
}

/* ── MISC UTILITIES ────────────────────────────────── */
.flex-row { display: flex; flex-direction: row; }
.flex-col { display: flex; flex-direction: column; }
.gap4     { gap: 4px; }
.gap8     { gap: 8px; }
.flex1    { flex: 1; }

/* Pixel art border style */
.px-inset {
  box-shadow: inset 2px 2px 0 rgba(0,0,0,0.4), inset -2px -2px 0 rgba(255,255,255,0.03);
}

/* Blinking pixel indicator */
.blink-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--accent);
  animation: blink 1s step-end infinite;
  vertical-align: middle;
  margin-right: 4px;
}

/* ── DANGER LEVEL COLORS ───────────────────────────── */
.dl1 { color: var(--green); }
.dl2 { color: #aaff44; }
.dl3 { color: var(--accent3); }
.dl4 { color: var(--orange); }
.dl5 { color: var(--danger); }
