:root {
  --beige: #d8cdb4;
  --beige-dark: #b9ad91;
  --chassis: #2a2620;
  --bg: #12100c;
  --amber: #ffb000;
  --teletext-yellow: #ffff00;
  --red: #cc2b2b;
  --green: #35d07f;
  --cyan: #35d0d0;
  --ink: #efe9d8;
  --panel: #211d17;
  --border: #4a3f2e;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, #1e1a12 0%, #0a0906 70%),
    var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  min-height: 100vh;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

header { text-align: center; margin-bottom: 14px; }
header h1 {
  font-weight: 800;
  font-size: clamp(20px, 5vw, 30px);
  letter-spacing: -0.5px;
  margin: 0;
  color: var(--amber);
  text-shadow: 0 0 18px rgba(255,176,0,0.35);
}
header h1 .thin { font-weight: 300; color: var(--beige); }
header .sub {
  font-weight: 300;
  font-size: 12px;
  color: var(--beige-dark);
  margin: 6px 0 0;
  letter-spacing: 0.5px;
}

/* CRT monitor */
.crt-wrap { display: flex; justify-content: center; margin-bottom: 18px; }
.crt {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 640 / 512;
  background: #000;
  border-radius: 18px;
  padding: 18px;
  border: 6px solid var(--beige-dark);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.9),
    0 0 0 3px #6b5f45,
    0 20px 50px rgba(0,0,0,0.7);
  overflow: hidden;
  transition: box-shadow .2s;
}
.crt.drag { box-shadow: 0 0 0 4px var(--green), 0 0 40px var(--green); }
.crt canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  border-radius: 8px;
  background: #000;
}
.crt.curved canvas { transform: scale(1.01); }

.scanlines {
  pointer-events: none;
  position: absolute; inset: 18px;
  border-radius: 8px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.28) 3px,
    rgba(0,0,0,0.28) 4px
  );
}
.vignette {
  pointer-events: none;
  position: absolute; inset: 18px;
  border-radius: 8px;
  box-shadow: inset 0 0 90px rgba(0,0,0,0.85);
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.5) 100%);
}

/* Controls */
#controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.panel.speed { flex-direction: row; }
.panel.speed label { font-size: 12px; color: var(--beige-dark); }
.panel.speed input[type=range] { flex: 1; min-width: 120px; accent-color: var(--amber); }
.panel.speed #speedVal { color: var(--amber); font-weight: 500; font-size: 12px; }

.btn {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 13px;
  color: var(--ink);
  background: linear-gradient(180deg, #3a3327, #262019);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  transition: transform .06s, background .15s, box-shadow .15s;
  box-shadow: 0 2px 0 #14110c;
}
.btn:hover { background: linear-gradient(180deg, #443c2d, #2c261d); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.small { font-size: 12px; padding: 7px 10px; }
.btn.upload { position: relative; }
.btn.danger {
  background: linear-gradient(180deg, #d84040, #8c1f1f);
  border-color: #a02525;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 2px 0 #4a0e0e;
}
.btn.danger:hover { background: linear-gradient(180deg, #e85252, #a02525); }
.btn.flash { filter: brightness(1.8); }

.counter {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 800;
  color: var(--amber);
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  letter-spacing: 3px;
  margin-left: auto;
}

/* Debug */
#debug {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 20px;
}
#debug summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--beige-dark);
  font-weight: 500;
  padding: 4px 0;
}
.debug-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 8px; }
@media (min-width: 560px) { .debug-grid { grid-template-columns: 1fr 1fr; } }
#debug pre {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--green);
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  overflow-x: auto;
  white-space: pre;
}
.hex-tools label { font-size: 12px; color: var(--beige-dark); display: block; margin-bottom: 6px; }
.hex-tools input {
  font-family: var(--mono);
  background: #000;
  border: 1px solid var(--border);
  color: var(--amber);
  border-radius: 5px;
  padding: 5px 8px;
  width: 110px;
}
#hexView { color: var(--cyan); }

footer {
  text-align: center;
  font-size: 11px;
  color: var(--beige-dark);
  border-top: 1px dashed var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
footer a { color: var(--amber); text-decoration: none; font-weight: 500; }
footer a:hover { text-decoration: underline; }

@media (max-width: 480px) {
  .btn { flex: 1 1 auto; text-align: center; }
  .counter { margin-left: 0; }
}