/*
 * style.css -- strictly two tones: #000 and #fff. Anything that needs to read
 * as "grey" uses a dashed border instead of a grey value. The single
 * exception lives on the canvas, not here: the onion skin ghost is drawn grey.
 */

:root {
  --fg: #fff;
  --bg: #000;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 12px/1.4 ui-monospace, "DejaVu Sans Mono", "Liberation Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
  overflow: hidden;
}

h1, h2, h3 {
  margin: 0;
  font-size: 12px;
  font-weight: normal;
  text-transform: uppercase;
}

p { margin: 0 0 6px; }

.dim {
  border: 1px dashed var(--fg);
  padding: 1px 4px;
  font-size: 10px;
  letter-spacing: 0.1em;
}

.hidden { display: none !important; }
.hidden-input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

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

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

#app > * { min-width: 0; }

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--fg);
  flex-wrap: wrap;
}

#topbar h1 {
  font-size: 13px;
  letter-spacing: 0.14em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#save-indicator {
  border: 1px dashed var(--fg);
  padding: 3px 6px;
  min-width: 74px;
  text-align: center;
}

#workspace {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 274px;
  min-height: 0;
}

/* without this the oversized canvas would stretch the whole page instead of
   scrolling inside its own container */
#workspace > * { min-width: 0; }

.panel {
  border-right: 1px solid var(--fg);
  overflow-y: auto;
  padding: 8px;
}

#sidebar {
  border-right: none;
  border-left: 1px solid var(--fg);
}

.group { margin-bottom: 14px; }

.group > h2 {
  border-bottom: 1px solid var(--fg);
  padding-bottom: 3px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.group > h3 {
  margin: 8px 0 4px;
}

.hint {
  border-left: 1px dashed var(--fg);
  padding-left: 5px;
  font-size: 11px;
  line-height: 1.5;
}

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

button {
  font: inherit;
  letter-spacing: inherit;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--fg);
  padding: 4px 7px;
  cursor: pointer;
  text-transform: uppercase;
  white-space: nowrap;
}

button:hover { background: var(--fg); color: var(--bg); }
button:active { outline: 1px solid var(--fg); outline-offset: 1px; }

button.on {
  background: var(--fg);
  color: var(--bg);
}

button.on:hover {
  outline: 1px solid var(--fg);
  outline-offset: -3px;
}

button:disabled,
button:disabled:hover {
  background: var(--bg);
  color: var(--fg);
  border-style: dashed;
  cursor: not-allowed;
}

button:disabled span.key { border-style: dashed; }

.row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.row.wrap { flex-wrap: wrap; }
.row > button { flex: 1 1 auto; }
.half { flex: 1 1 0; }
.third { flex: 1 1 0; }

.tool-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tool {
  text-align: left;
  display: flex;
  align-items: center;
  gap: 7px;
}

span.key {
  border: 1px solid currentColor;
  padding: 0 3px;
  font-size: 10px;
}

#brush-row button { padding: 4px 0; }

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  align-items: stretch;
}

.pad button { padding: 3px 0; }

.wrap-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px dashed var(--fg);
  font-size: 10px;
  cursor: pointer;
  user-select: none;
}

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 9px;
  height: 9px;
  margin: 0;
  border: 1px solid var(--fg);
  background: var(--bg);
}

input[type="checkbox"]:checked { background: var(--fg); }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.field label { text-transform: uppercase; }

input[type="number"],
textarea {
  font: inherit;
  letter-spacing: inherit;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--fg);
  padding: 3px 4px;
}

input[type="number"] { width: 74px; }
input:focus, textarea:focus, button:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 1px;
}

.readout { border: 1px dashed var(--fg); padding: 2px 6px; }

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

#stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
}

#canvas-wrap {
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 12px;
  min-height: 0;
}

/* outline, not border: it must not shift the canvas box used for hit testing */
#board {
  outline: 1px solid var(--fg);
  image-rendering: pixelated;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

#statusbar {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  border-top: 1px solid var(--fg);
  padding: 4px 10px;
}

#statusbar b { font-weight: normal; }

/* ---- preview ---------------------------------------------------------- */

.preview-box {
  border: 1px solid var(--fg);
  padding: 4px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  overflow: auto;
}

#preview { image-rendering: pixelated; display: block; }

/* ---- timeline --------------------------------------------------------- */

/* grid so the scrolling strip below becomes a min-width:0 item and stops
   pushing its intrinsic width onto the page */
#timeline {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  border-top: 1px solid var(--fg);
  padding: 4px 8px 8px;
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

#frame-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  min-height: 96px;
}

.frame-cell {
  border: 1px solid var(--fg);
  padding: 2px;
  cursor: pointer;
  flex: 0 0 auto;
  background: var(--bg);
}

.frame-cell canvas {
  display: block;
  width: 128px;
  height: 64px;
  image-rendering: pixelated;
}

.frame-cell .label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  padding: 1px 2px 0;
}

.frame-cell.on {
  outline: 1px solid var(--fg);
  outline-offset: 1px;
}

.frame-cell.on .label {
  background: var(--fg);
  color: var(--bg);
}

/* ---- modal ------------------------------------------------------------ */

#modal {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}

/*
 * Wide enough for a full C array row without wrapping. Those rows are 16
 * bytes = 97 characters, and the box loses 48px to its border, the body
 * padding, the textarea border and padding, and the vertical scrollbar.
 * Sized in ch so it holds up whatever monospace font the browser picks.
 */
.modal-box {
  border: 1px solid var(--fg);
  width: min(calc(100ch + 48px), 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--fg);
  padding: 6px 8px;
}

.modal-head h2 { letter-spacing: 0.14em; }

.modal-body {
  padding: 10px;
  overflow: auto;
}

.modal-panel { display: none; }
.modal-panel.on { display: block; }

.modal-panel h3 {
  margin: 12px 0 5px;
  border-bottom: 1px solid var(--fg);
  padding-bottom: 3px;
}

.modal-panel > h3:first-child { margin-top: 0; }

.modal-body textarea {
  width: 100%;
  height: 220px;
  resize: vertical;
  margin: 6px 0;
  /* the ch based width of .modal-box assumes no extra tracking */
  letter-spacing: normal;
  white-space: pre-wrap;
  word-break: break-all;
}

/* C arrays have meaningful line breaks: never reflow them, scroll instead */
.modal-body textarea.nowrap {
  white-space: pre;
  word-break: normal;
  overflow-x: auto;
}

table.keys { border-collapse: collapse; width: 100%; }
table.keys td {
  border: 1px solid var(--fg);
  padding: 2px 5px;
  vertical-align: top;
}
table.keys td:first-child { white-space: nowrap; width: 1%; }

/* ---- narrow screens --------------------------------------------------- */

@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100%; }
  #workspace { grid-template-columns: minmax(0, 1fr); }
  .panel { border: none; border-bottom: 1px solid var(--fg); overflow: visible; }
  #sidebar { border-left: none; border-bottom: none; border-top: 1px solid var(--fg); }
  #canvas-wrap { padding: 6px; justify-items: start; }
  #stage { order: -1; }
  #canvas-wrap { min-height: 220px; }
  .tool-list { display: grid; grid-template-columns: 1fr 1fr; }
  .preview-box { justify-items: start; }
}
