:root {
  --bg: #0c0a0f;
  --panel: #15111b;
  --line: #2a2233;
  --pink: #ff3d9a;
  --cyan: #3df2ff;
  --lime: #c6ff3d;
  --text: #f6eefb;
  --dim: #8d7fa0;
  --ink: #12060c;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg) radial-gradient(var(--line) 1px, transparent 1px) 0 0 / 12px 12px;
  color: var(--text);
  font: 13px/1.2 'Silkscreen', Consolas, monospace;
  text-transform: lowercase;
  overflow: hidden;
}

/* ---------- header ---------- */

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 2px solid var(--pink);
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 2px 0 var(--pink), -2px 0 var(--cyan);
}

nav { display: flex; flex-wrap: wrap; gap: 10px; }

button {
  font: inherit;
  text-transform: inherit;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--pink);
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--pink);
  touch-action: manipulation;
}
button:hover { background: #21182b; }
button:active, button.held { transform: translate(3px, 3px); box-shadow: none; }
button:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
button:disabled { opacity: .35; cursor: default; box-shadow: none; transform: none; }
button.primary, button.on { background: var(--pink); color: var(--ink); }
button.alt { border-color: var(--lime); box-shadow: 3px 3px 0 var(--lime); }
button.alt:active { box-shadow: none; }
body.cropping #crop { background: var(--lime); border-color: var(--lime); color: var(--ink); box-shadow: 3px 3px 0 var(--lime); }

/* ---------- layout ---------- */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
}

#stage {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px;
}

.frame { position: relative; min-height: 0; }
.frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}
#orig { visibility: hidden; }
#stage.peek #orig { visibility: visible; }
#stage.peek #out { visibility: hidden; }
#cropc { object-fit: fill; cursor: crosshair; touch-action: none; }
body:not(.has-img) #out, body:not(.has-img) #orig { display: none; }

#drop {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 3px dashed var(--pink);
  box-shadow: none;
  color: var(--dim);
  font-size: 15px;
}
#drop b { font-size: 72px; line-height: 1; color: var(--pink); }
#drop:hover { background: #ff3d9a12; }
#drop:active { transform: none; }
body.has-img #drop { display: none; }
body.dragging #drop { display: flex; border-color: var(--lime); background: #0c0a0fd9; }
body.dragging #drop b { color: var(--lime); }

/* little blinking square while a slow fry is cooking */
#stage::after {
  content: '';
  position: absolute;
  top: 24px;
  right: 24px;
  width: 12px;
  height: 12px;
  background: var(--lime);
  opacity: 0;
  pointer-events: none;
}
#stage[data-busy]::after { animation: blink .5s .25s infinite; }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

#toast {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 12px;
  background: var(--ink);
  border: 2px solid var(--lime);
  color: var(--lime);
}

/* ---------- filter strip ---------- */

#filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-color: var(--pink) transparent;
  scrollbar-width: thin;
}
body:not(.has-img) #filters, body.cropping #filters { display: none; }
.filt {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 4px;
  background: transparent;
  border: 2px solid transparent;
  box-shadow: none;
  color: var(--dim);
  font-size: 10px;
}
.filt:hover { background: transparent; color: var(--text); }
.filt:active { transform: none; }
.filt.on { border-color: var(--pink); color: var(--text); background: transparent; }
.filt canvas {
  width: 84px;
  height: 84px;
  object-fit: cover;
  background: var(--panel);
  display: block;
}

#cropbar { display: none; flex-wrap: wrap; gap: 8px; align-items: center; }
body.cropping #cropbar { display: flex; }
#cropbar .gap { flex: 1; }

/* ---------- controls ---------- */

aside {
  overflow-y: auto;
  padding: 14px 16px 24px;
  background: var(--panel);
  border-left: 2px solid var(--line);
  scrollbar-color: var(--pink) var(--panel);
}

#tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-bottom: 14px; }
#lookform { display: flex; gap: 8px; padding-bottom: 14px; }
#lookform[hidden] { display: none; }
#lookform input {
  flex: 1;
  min-width: 0;
  font: inherit;
  text-transform: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--lime);
  padding: 6px 8px;
}
#lookform input:focus { outline: none; border-color: var(--pink); }
.filt.mine span { color: var(--lime); }
.filt .x {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  line-height: 18px;
  text-align: center;
  background: var(--ink);
  border: 2px solid var(--pink);
  color: var(--pink);
  font-style: normal;
  font-size: 11px;
}
.filt { position: relative; }

.sec { border-top: 2px solid var(--line); }
.sec-h { display: flex; align-items: center; gap: 8px; }
.sec-t {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 0;
  background: none;
  border: 0;
  box-shadow: none;
  text-align: left;
}
.sec-t:hover, .sec-t:active { background: none; transform: none; }
.sec-t::before { content: '+'; color: var(--pink); font-weight: 700; width: 12px; }
.sec.open .sec-t::before { content: '-'; }
.sec-t .n { flex: 1; color: var(--lime); font-weight: 700; }
.sec-t output { color: var(--pink); }
.sec-r { padding: 4px 8px; font-size: 11px; box-shadow: none; border-color: var(--line); color: var(--dim); }
.sec-r:hover { border-color: var(--pink); color: var(--text); }
.sec-b { display: none; padding-bottom: 10px; }
.sec.open .sec-b { display: block; }

.sl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 6px 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.sl output { color: var(--lime); min-width: 3ch; text-align: right; cursor: text; }
.sl output:hover { text-decoration: underline; }
.sl .num {
  width: 6ch;
  font: inherit;
  color: var(--lime);
  background: var(--bg);
  border: 2px solid var(--lime);
  padding: 0 4px;
  text-align: right;
  -moz-appearance: textfield;
}
.sl .num::-webkit-inner-spin-button, .sl .num::-webkit-outer-spin-button { -webkit-appearance: none; }
.sl input[type=range] { grid-column: 1 / -1; }
.sl.off { opacity: .35; }
.sl.colors { align-items: center; cursor: default; }
.sw { display: flex; gap: 6px; }
.sw input[type=color] {
  width: 44px;
  height: 26px;
  padding: 0;
  border: 2px solid var(--pink);
  background: none;
  cursor: pointer;
}
.sw input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.sw input[type=color]::-webkit-color-swatch { border: 0; }

.tgs { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0; }
.tg { padding: 6px 10px; box-shadow: none; border-color: var(--line); color: var(--dim); }
.tg:hover { border-color: var(--pink); color: var(--text); }
.tg.on { background: var(--pink); border-color: var(--pink); color: var(--ink); }

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --a: 0%;
  --b: 0%;
}
input[type=range]:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

input[type=range]::-webkit-slider-runnable-track {
  box-sizing: border-box;
  height: 10px;
  border: 2px solid var(--pink);
  background: linear-gradient(to right, var(--bg) var(--a), var(--pink) var(--a), var(--pink) var(--b), var(--bg) var(--b));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 14px;
  height: 22px;
  margin-top: -8px;
  background: var(--text);
  border: 2px solid var(--ink);
  border-radius: 0;
  box-shadow: 2px 2px 0 var(--pink);
}

input[type=range]::-moz-range-track {
  box-sizing: border-box;
  height: 10px;
  border: 2px solid var(--pink);
  background: linear-gradient(to right, var(--bg) var(--a), var(--pink) var(--a), var(--pink) var(--b), var(--bg) var(--b));
}
input[type=range]::-moz-range-thumb {
  box-sizing: border-box;
  width: 14px;
  height: 22px;
  background: var(--text);
  border: 2px solid var(--ink);
  border-radius: 0;
  box-shadow: 2px 2px 0 var(--pink);
}

/* ---------- camera ---------- */

#camui {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  background: #0c0a0fe6;
}
#camui[hidden] { display: none; }
#camui video { max-width: 100%; max-height: 75vh; border: 2px solid var(--pink); background: #000; }
#camui div { display: flex; gap: 10px; }

/* ---------- phone ---------- */

@media (max-width: 820px) {
  body { overflow: auto; height: auto; }
  header { padding: 10px 12px; }
  h1 { font-size: 17px; }
  nav { gap: 8px; }
  button { padding: 7px 9px; }
  main { display: block; }
  #stage {
    position: sticky;
    top: 0;
    z-index: 1;
    height: 52vh;
    padding: 10px;
    gap: 8px;
    background: var(--bg);
    border-bottom: 2px solid var(--line);
  }
  .filt canvas { width: 64px; height: 64px; }
  aside { border-left: 0; overflow: visible; }
}
