/* PIXELBOY Studio - same flat, hairline-ruled, pixel-font look as PIXELBOY Web,
   laid out like an image editor: tool strip, options bar, viewport, panels, status bar. */
@font-face {
  font-family: 'Press Start 2P';
  font-display: swap;
  src: url(fonts/press-start-2p.woff2) format('woff2');
}
:root {
  --bg: #0e0e0e; --bg-2: #141414; --fg: #c9c9c9; --dim: #6e6e6e; --line: #232323; --line-2: #333; --live: #c8532f;
  --font: 'Press Start 2P', ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; }
body {
  display: flex; flex-direction: column; background: var(--bg); color: var(--fg);
  font: 8px/1.6 var(--font); overflow: hidden; touch-action: manipulation;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; border-radius: 0; }
button, select {
  background: none; border: 1px solid var(--line-2); padding: 6px 8px; cursor: pointer; min-height: 24px;
}
button:hover, select:hover { border-color: var(--dim); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 1px solid var(--live); outline-offset: 1px; }
button.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
button[hidden] { display: none; }
select { background: var(--bg); max-width: 100%; }
a { color: var(--dim); text-decoration: none; padding: 6px 8px; }
a:hover { color: var(--fg); }
.dim { color: var(--dim); }
.spacer { flex: 1; }

/* ------------------------------------------------------------- top bar */
.topbar, .status { display: flex; align-items: center; gap: 12px; padding: 4px 12px; flex-wrap: wrap; }
.topbar { border-bottom: 1px solid var(--line); min-height: 38px; }
.status { border-top: 1px solid var(--line); gap: 10px; padding: 4px 8px; min-height: 34px; }
h1 { margin: 0; display: flex; align-items: center; gap: 8px; font-weight: 400; }
h1 img { display: block; image-rendering: pixelated; }
h1 .sub { color: var(--live); }
.segmented { display: flex; }
.segmented button + button { border-left: 0; }
label.inline { display: flex; align-items: center; gap: 6px; color: var(--dim); }
.optrow { border-bottom: 1px solid var(--line); padding: 4px 12px; min-height: 36px; display: flex; align-items: center; }
.optbar { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; flex-wrap: wrap; }
.optbar .hint { color: var(--dim); }
.optbar input[type=range] { width: 160px; }
.zoomctl { display: flex; }
.zoomctl button { min-width: 28px; padding: 4px 6px; }
.zoomctl button + button { border-left: 0; }
#z-pct { min-width: 52px; }

/* ----------------------------------------------------------- workspace */
.workspace { flex: 1; min-height: 0; display: flex; }
.tools { width: 40px; flex: none; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; padding: 6px 4px; }
.tools button[hidden] { display: none; }
.tools button { padding: 4px 0 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 36px; }
.tools svg { width: 16px; height: 16px; fill: currentColor; shape-rendering: crispEdges; }
.tools b { font-weight: 400; font-size: 8px; opacity: .6; }

.viewport {
  flex: 1; min-width: 0; position: relative; overflow: hidden; cursor: grab; touch-action: none;
  background: repeating-conic-gradient(#141414 0 25%, #101010 0 50%) 0 0 / 16px 16px;
}
.viewport.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#view { display: block; image-rendering: pixelated; }
.drop { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--dim); pointer-events: none; line-height: 2; }
.viewport.has-image .drop { display: none; }
.viewport.dragging { outline: 2px dashed var(--live); outline-offset: -8px; }
.stage-bar { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; }
.stage-bar button { background: rgba(14,14,14,.85); }
.toast {
  position: absolute; top: 8px; left: 8px; right: 8px; background: rgba(14,14,14,.92); border: 1px solid var(--live);
  padding: 6px 8px; color: var(--fg); pointer-events: none;
}

/* Reframing: the picture moves under a fixed window (GB mode and Dither mode) */
.reframe { position: absolute; inset: 0; cursor: grab; touch-action: none; background: #060606; }
.reframe[hidden] { display: none; }
.reframe.panning { cursor: grabbing; }
#rf-img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.rf-win { position: absolute; box-shadow: 0 0 0 9999px rgba(6,6,6,.72); outline: 1px solid #fff; pointer-events: none; }
#rf-out { position: absolute; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.rf-grid { position: absolute; inset: 0; display: none;
  background:
    linear-gradient(to right, transparent 33.1%, rgba(255,255,255,.45) 33.3% 33.6%, transparent 33.8% 66.2%, rgba(255,255,255,.45) 66.4% 66.7%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.1%, rgba(255,255,255,.45) 33.3% 33.6%, transparent 33.8% 66.2%, rgba(255,255,255,.45) 66.4% 66.7%, transparent 66.9%); }
.rf-win.guide .rf-grid { display: block; }

/* -------------------------------------------------------------- panels */
.panel { width: 300px; flex: none; border-left: 1px solid var(--line); overflow-y: auto; padding-bottom: 12px; }
.sec { border-bottom: 1px solid var(--line); }
.sec-h {
  display: flex; width: 100%; justify-content: space-between; border: 0; padding: 9px 12px; color: var(--dim);
  letter-spacing: 1px; min-height: 0; text-align: left;
}
.sec-h:hover { color: var(--fg); }
.sec-h::after { content: '-'; }
.sec.collapsed .sec-h::after { content: '+'; }
.sec.collapsed .sec-b { display: none; }
.sec-b { padding: 0 12px 10px; }
.row { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 8px; min-height: 22px; }
.row.wide { grid-template-columns: 96px 1fr; }
.row > .v { text-align: right; color: var(--dim); }
.row[hidden] { display: none; }
.row.btnrow { display: block; margin: 4px 0; }
.row.btnrow button { width: 100%; text-align: left; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.row .segmented { grid-column: 2 / 4; }
.row .segmented button { flex: 1; padding: 6px 2px; }
.row select { grid-column: 2 / 4; }
.row.tog button { grid-column: 2 / 4; }
.row.dims { grid-template-columns: 1fr 1fr 28px; gap: 6px; margin: 4px 0; }
.row.dims label { display: flex; align-items: center; gap: 6px; color: var(--dim); }
.row.dims input[type=number] {
  width: 100%; min-width: 0; background: var(--bg); color: var(--fg); border: 1px solid var(--line-2); padding: 5px 4px; min-height: 24px;
  -moz-appearance: textfield; appearance: textfield;
}
.row.dims input[type=number]::-webkit-inner-spin-button { display: none; }
.row.dims button { padding: 4px 0; text-align: center; justify-content: center; }
.chips { display: flex; height: 8px; flex: 1; max-width: 140px; }
.chips i { flex: 1; outline: 1px solid var(--line-2); outline-offset: -1px; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 16px; background: none; margin: 0; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 8px; height: 14px; margin-top: -6px; background: var(--fg); border: 0; }
input[type=range]::-moz-range-thumb { width: 8px; height: 14px; background: var(--fg); border: 0; border-radius: 0; }

/* -------------------------------------------------------------- dialog */
dialog {
  background: var(--bg); color: var(--fg); border: 1px solid var(--line-2); padding: 0; width: min(560px, 94vw);
  max-height: 86dvh; flex-direction: column;
}
dialog[open] { display: flex; }
dialog::backdrop { background: rgba(0,0,0,.7); }
.dlg-head, .dlg-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px; flex-wrap: wrap; }
.dlg-head { border-bottom: 1px solid var(--line); }
.dlg-foot { border-top: 1px solid var(--line); justify-content: flex-start; }
.grid { overflow-y: auto; padding: 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; min-height: 120px; }
.sw { border: 1px solid var(--line-2); padding: 6px; text-align: left; display: block; }
.sw.on { border-color: var(--live); }
.sw .chips { max-width: none; height: 14px; margin-bottom: 6px; }
.sw .nm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { grid-column: 1 / -1; color: var(--dim); padding: 12px; }

/* --------------------------------------------------------------- phone */
@media (max-width: 760px) {
  body { overflow: auto; }
  body > * { flex-shrink: 0; }
  .topbar { gap: 8px; }
  .workspace { flex-direction: column; flex: none; }
  .tools { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); padding: 4px 8px; }
  .tools button { flex-direction: row; gap: 6px; padding: 4px 12px; }
  .viewport { height: 54dvh; flex: none; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .row { grid-template-columns: 88px 1fr 40px; }
  button, select { min-height: 36px; }
  .status { position: sticky; bottom: 0; background: var(--bg); }
}

/* ------------------------------------------------- sessions, editor, split */
.sessbar { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sessbar .ghost { border-color: transparent; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sessbar .ghost:hover { border-color: var(--line-2); }

.cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card { border: 1px solid var(--line-2); padding: 6px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; min-width: 0; }
.card:hover { border-color: var(--dim); }
.card.on { border-color: var(--live); }
.card img { width: 100%; height: 96px; object-fit: contain; image-rendering: pixelated; background: #000; display: block; }
.card .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .dim { font-size: 8px; }
.cardbar { display: flex; flex-wrap: wrap; gap: 4px; }
.cardbar button { padding: 3px 5px; min-height: 0; }

.edlist { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.edrow { display: flex; align-items: center; gap: 6px; }
.edrow input[type=color] { width: 36px; height: 26px; padding: 0; border: 1px solid var(--line-2); background: none; cursor: pointer; }
.edrow input[type=text], #ed-name {
  background: var(--bg); color: var(--fg); border: 1px solid var(--line-2); padding: 5px 6px; min-height: 26px; min-width: 0;
}
.edrow input[type=text] { width: 80px; }
.edrow button { padding: 3px 7px; min-height: 26px; }
#ed-name { flex: 1; }

.row.palrow { display: flex; gap: 6px; align-items: stretch; }
.row.palrow #pal-btn { flex: 1; width: auto; }
.row.palrow .ed-btn { width: auto; flex: none; }
.row.looksbar { display: flex; gap: 6px; margin: 4px 0 2px; }
.row.looksbar button { flex: 1; padding: 5px 4px; }

.split { position: absolute; top: 0; bottom: 0; width: 0; z-index: 3; }
.split::before { content: ''; position: absolute; top: 0; bottom: 0; left: calc(-1px / var(--z, 1)); width: calc(2px / var(--z, 1)); background: #fff; box-shadow: 0 0 0 calc(1px / var(--z, 1)) #000; }
.split i {
  position: absolute; top: 50%; left: calc(-14px / var(--z, 1)); width: calc(28px / var(--z, 1)); height: calc(28px / var(--z, 1));
  margin-top: calc(-14px / var(--z, 1)); background: #fff; border: calc(2px / var(--z, 1)) solid #000; cursor: ew-resize; touch-action: none;
}
.split[hidden] { display: none; }
/* the selection box of the pasted photo: an outline, square handles on the corners, a round one on a stem to turn it */
.ovbox { position: absolute; z-index: 4; pointer-events: none; box-sizing: border-box;
  outline: calc(1px / var(--z, 1)) solid #fff; box-shadow: 0 0 0 calc(2px / var(--z, 1)) rgba(0, 0, 0, .55); }
.ovbox[hidden] { display: none; }
.ovbox b { position: absolute; pointer-events: auto; touch-action: none; box-sizing: border-box; }
.ovc { width: calc(11px / var(--z, 1)); height: calc(11px / var(--z, 1)); margin: calc(-5.5px / var(--z, 1)) 0 0 calc(-5.5px / var(--z, 1));
  background: #fff; border: calc(1.5px / var(--z, 1)) solid #111; cursor: pointer; }
.ovc:hover { background: var(--live); }
.ovc.ovc-nw { left: 0; top: 0; } .ovc.ovc-ne { left: 100%; top: 0; } .ovc.ovc-sw { left: 0; top: 100%; } .ovc.ovc-se { left: 100%; top: 100%; }
.ovstem { position: absolute; left: 50%; top: calc(-24px / var(--z, 1)); width: calc(1px / var(--z, 1)); height: calc(24px / var(--z, 1));
  margin-left: calc(-.5px / var(--z, 1)); background: #fff; box-shadow: 0 0 0 calc(1px / var(--z, 1)) rgba(0, 0, 0, .55); pointer-events: none; }
.ovr { left: 50%; top: calc(-24px / var(--z, 1)); width: calc(18px / var(--z, 1)); height: calc(18px / var(--z, 1));
  margin: calc(-18px / var(--z, 1)) 0 0 calc(-9px / var(--z, 1)); border-radius: 50%; background: #fff center / 70% no-repeat; border: calc(1.5px / var(--z, 1)) solid #111; cursor: grab;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23111' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 8a5 5 0 1 1-1.6-3.7'/%3E%3Cpath d='M13 2.5v3h-3'/%3E%3C/svg%3E"); }
.ovr:hover { background-color: var(--live); }
.ovr:active { cursor: grabbing; }

.row.readout { display: block; color: var(--dim); margin-top: 2px; }
.row.readout:empty { display: none; }

/* long parameter names (RetroArch shaders): the name on its own line, the control under it */
.row.stack { grid-template-columns: 1fr 44px; gap: 2px 8px; margin: 3px 0 5px; }
.row.stack > span:first-child { grid-column: 1 / 3; color: var(--dim); white-space: normal; line-height: 1.35; }
.row.stack > button { grid-column: 1 / 3; }

.help-body { padding: 12px 14px; max-height: 70dvh; overflow-y: auto; }
.help-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.help-body dt { color: var(--live); white-space: nowrap; }
.help-body dd { margin: 0; color: var(--fg); line-height: 1.5; }
.wipe-body { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.wipe-body label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
#wipe-sure { color: var(--live); margin: 4px 0 0; }
#wipe-go.armed { border-color: var(--live); color: var(--live); }

/* the bottom bar: zoom and status on the left, undo, save and a MORE menu on the right */
.status .grp { display: flex; align-items: center; gap: 6px; }
.morewrap { position: relative; }
.more { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 20; min-width: 210px; display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: var(--bg); border: 1px solid var(--line-2); box-shadow: 0 6px 24px rgba(0, 0, 0, .6); }
.more[hidden] { display: none; }
.more button, .more a { display: block; width: 100%; text-align: left; padding: 7px 8px; border: 1px solid transparent; color: var(--fg); text-decoration: none; background: none; }
.more button:hover, .more a:hover { border-color: var(--line-2); background: rgba(255, 255, 255, .05); }
.more hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.more .dim { padding: 6px 8px 2px; font-size: 8px; }
