/* StreamPaint
 *
 * The page background must stay transparent by default: in view mode this page
 * is an OBS Browser Source composited over live video, and any opaque pixel we
 * paint here lands on the broadcast. Only the editor shell opts into a
 * background, and it does so on #app rather than on body.
 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: transparent;
  color: #e8e8ea;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ editor */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #14141a;
}

#bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #1c1c24;
  border-bottom: 1px solid #2c2c38;
  flex: 0 0 auto;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #9aa0ff;
}

.spacer { flex: 1 1 auto; }

.field { display: flex; align-items: center; gap: 6px; }
.field > span { color: #9a9aa8; }

.muted { color: #8a8a98; }

.status { font-variant-numeric: tabular-nums; }
.status.ok { color: #4ec97b; }
.status.warn { color: #e8b04a; }
.status.bad { color: #e8635a; }

.painters { display: flex; gap: 6px; align-items: center; }
.painters .chip {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  color: #14141a;
  font-weight: 600;
  white-space: nowrap;
}

input[type="text"], input[type="color"] {
  background: #101016;
  color: #e8e8ea;
  border: 1px solid #33334a;
  border-radius: 5px;
  padding: 4px 7px;
  font: inherit;
}
input[type="text"]:focus, button:focus-visible {
  outline: 2px solid #6b6bff;
  outline-offset: 1px;
}
input[type="color"] { padding: 2px; width: 100%; height: 30px; cursor: pointer; }

button {
  background: #2a2a38;
  color: #e8e8ea;
  border: 1px solid #3a3a50;
  border-radius: 5px;
  padding: 5px 10px;
  font: inherit;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #34344a; }
button:disabled { opacity: 0.45; cursor: default; }

kbd {
  font: 11px ui-monospace, monospace;
  color: #9a9aa8;
  border: 1px solid #3a3a50;
  border-radius: 3px;
  padding: 0 3px;
}

#body { display: flex; flex: 1 1 auto; min-height: 0; }

#palette {
  width: 168px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px;
  background: #1c1c24;
  border-right: 1px solid #2c2c38;
  overflow-y: auto;
}

.group { display: flex; flex-direction: column; gap: 6px; }
.group.grow { flex: 1 1 auto; }
.group.check { flex-direction: row; align-items: center; gap: 7px; cursor: pointer; }
.grouplabel {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7a7a90;
}

#tools { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 2px;
  font-size: 10px;
  line-height: 1;
}
.tool .glyph { font-size: 17px; line-height: 1; }
.tool.active {
  background: #3d3d8f;
  border-color: #6b6bff;
  color: #fff;
}

.sizes { display: flex; gap: 5px; }
.sizes button {
  flex: 1 1 0;
  display: grid;
  place-items: center;
  height: 30px;
  padding: 0;
}
.sizes .dot { background: currentColor; border-radius: 50%; }
.sizes button.active { background: #3d3d8f; border-color: #6b6bff; }

.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.swatch {
  aspect-ratio: 1;
  border: 1px solid #00000066;
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
}
.swatch.active { outline: 2px solid #fff; outline-offset: 1px; }

input[type="range"] { width: 100%; accent-color: #6b6bff; }

/* -------------------------------------------------------------- the stage */

#stagewrap, #viewport {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

/* View mode: no padding, transparent, fills the source exactly. */
#viewport { padding: 0; height: 100%; width: 100%; }

#stage, #viewstage {
  position: relative;
  /* Sized in pixels by JS so the 16:9 aspect ratio is exact and the
     screen-to-canvas mapping stays a single well-defined scale factor. */
}

/* The editor shows paint over a white backdrop so light colours are visible;
   in the overlay there is no backdrop at all. */
#stage { background: #fff; box-shadow: 0 0 0 1px #2c2c38, 0 8px 32px #0008; }

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#underlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  opacity: 0;
  pointer-events: none;
  user-select: none;
}

.layer.committed { z-index: 2; }
.layer.scratch { z-index: 3; }
#cursors { position: absolute; inset: 0; z-index: 4; pointer-events: none; }

#stage .layer.scratch { touch-action: none; }

.cursor {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.4s;
  will-change: left, top;
}
.cursor-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 3px #0009;
  flex: 0 0 auto;
}
.cursor-label {
  font-size: 10px;
  font-weight: 600;
  color: #14141a;
  padding: 0 5px;
  border-radius: 999px;
  white-space: nowrap;
  transform: translateY(9px);
  box-shadow: 0 1px 3px #0006;
}
.cursor-label:empty { display: none; }

/* ------------------------------------------------------------------- gate */

#gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #14141a;
  z-index: 10;
  padding: 20px;
  overflow-y: auto;
}
#gate .card {
  width: min(560px, 100%);
  background: #1c1c24;
  border: 1px solid #2c2c38;
  border-radius: 10px;
  padding: 22px;
}
#gate h1 { margin: 0 0 4px; font-size: 19px; color: #9aa0ff; }
#gate p { color: #9a9aa8; margin: 0 0 16px; }
#setup { display: flex; flex-direction: column; gap: 12px; }
#setup label { display: flex; flex-direction: column; gap: 4px; }
#setup label > span { font-size: 12px; color: #9a9aa8; }
#setup small { color: #6a6a80; }
.links {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid #2c2c38;
  padding-top: 14px;
}
.linkrow { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; align-items: center; }
.linkrow > span { font-size: 12px; color: #9a9aa8; }
.linkrow input { font: 11px ui-monospace, monospace; }
.hint { font-size: 12px; line-height: 1.5; margin: 0; }
