@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Variable.ttf") format("truetype");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Sans";
  src: url("fonts/IBMPlexSans-Variable.ttf") format("truetype");
  font-weight: 100 700;
  font-stretch: 75% 100%;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "PT Sans";
  src: url("fonts/PTSans-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Press Start 2P";
  src: url("fonts/PressStart2P-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #e4ded2;
  --paper-2: #f6f2ea;
  --ink: #1b1712;
  --muted: #655e53;
  --line: #cfc6b6;
  --accent: #b6401a;
  --accent-ink: #fff7f2;
  --accent-text: #a3381a;
  --accent-hover: #9a3412;
  --accent-soft: #fff7f2;
  --surface: rgba(246, 242, 234, 0.72);
  --hover: #fffdf8;
  --line-hover: #9a8d78;
  --line-dashed: #b3a794;
  --pressed-hover: #322b24;
  --pressed-muted: #d9d0c2;
  --table-head: #ebe4d8;
  --glow: rgba(182, 64, 26, 0.08);
  --shadow: rgba(27, 23, 18, 0.16);
  --logo-bg: #1b1712;
  --logo-tile: #ffffff;
  --stage: #12110e;
  --ok: #245c38;
  color-scheme: light;
}

/* Dark follows the system unless the visitor picked light, or picked dark.
   The two blocks hold the same values. The preview's checkerboard is not
   themed: it turns light or dark by the glyph colour. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161411;
    --paper-2: #221f1a;
    --ink: #efe9df;
    --muted: #a69e90;
    --line: #3b362f;
    --accent: #e0673d;
    --accent-ink: #1d0f08;
    --accent-text: #e0673d;
    --accent-hover: #ec7c55;
    --accent-soft: #3a2118;
    --surface: rgba(34, 31, 26, 0.72);
    --hover: #2c2822;
    --line-hover: #6b6255;
    --line-dashed: #554d42;
    --pressed-hover: #d8d0c3;
    --pressed-muted: #5c5448;
    --table-head: #2a2620;
    --glow: rgba(224, 103, 61, 0.1);
    --shadow: rgba(0, 0, 0, 0.45);
    --logo-bg: #efe9df;
    --logo-tile: #161411;
    --ok: #7cc79a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #161411;
  --paper-2: #221f1a;
  --ink: #efe9df;
  --muted: #a69e90;
  --line: #3b362f;
  --accent: #e0673d;
  --accent-ink: #1d0f08;
  --accent-text: #e0673d;
  --accent-hover: #ec7c55;
  --accent-soft: #3a2118;
  --surface: rgba(34, 31, 26, 0.72);
  --hover: #2c2822;
  --line-hover: #6b6255;
  --line-dashed: #554d42;
  --pressed-hover: #d8d0c3;
  --pressed-muted: #5c5448;
  --table-head: #2a2620;
  --glow: rgba(224, 103, 61, 0.1);
  --shadow: rgba(0, 0, 0, 0.45);
  --logo-bg: #efe9df;
  --logo-tile: #161411;
  --ok: #7cc79a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 400px at 10% -10%, var(--glow), transparent 50%),
    var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

button, input, textarea, select { font: inherit; color: inherit; }

.top, .layout, .foot {
  width: min(1180px, calc(100% - 32px));
  margin-left: auto;
  margin-right: auto;
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 22px 0 16px;
}

.header-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-left: auto; }
.header-controls .seg { padding: 5px 10px; font-size: 13px; }

.logo .logo-bg, .logo .logo-letters { fill: var(--logo-bg); }
.logo .logo-tile { fill: var(--logo-tile); }

.brand {
  margin: 0;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-link:hover span { color: var(--muted); }

.logo {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
}

.logo text {
  user-select: none;
  -webkit-user-select: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
  padding-bottom: 16px;
}

.output {
  position: sticky;
  top: 12px;
  align-self: start;
}

.output:has(.preview-wrap.has-warn) {
  top: 68px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

fieldset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 0;
  padding: 8px 12px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  min-inline-size: 0;
}

fieldset > :not(button) {
  align-self: stretch;
}

.box-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  cursor: pointer;
  user-select: none;
}

.box-label {
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.2;
}

.fold {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.fold svg {
  display: block;
  width: 14px;
  height: 14px;
  transition: transform 0.12s ease;
}

.fold:hover {
  border-color: var(--ink);
  background: var(--hover);
  color: var(--ink);
}

fieldset.is-collapsed {
  padding-bottom: 8px;
}

fieldset.is-collapsed .box-head { margin-bottom: 0; }

fieldset.is-collapsed .fold svg { transform: rotate(-90deg); }

fieldset.is-collapsed > :not(.box-head) { display: none; }

.presets, .chips, .dl-row, .slice-row, .color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.presets button, .chips button, .ghost, .primary, .secondary, .fold, .fmt,
.font-btn, .dropzone, textarea, input, select, .warn-mark {
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.presets button, .chips button, .ghost, .primary, .secondary {
  border: 1px solid var(--line);
  background: var(--paper-2);
  cursor: pointer;
}

.presets button:hover:not(:disabled),
.chips button:hover:not(:disabled),
.ghost:hover:not(:disabled),
.secondary:hover:not(:disabled) {
  border-color: var(--ink);
  background: var(--hover);
}

.presets button[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--pressed-hover);
  border-color: var(--pressed-hover);
  color: var(--paper-2);
}

.presets button {
  flex: 1 1 100px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  text-align: left;
}

.presets button span {
  color: var(--muted);
  font-size: 12px;
}

.presets button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper-2);
}

.presets button[aria-pressed="true"] span { color: var(--pressed-muted); }

.fonts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.font-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  text-align: center;
  cursor: pointer;
}

.font-btn input { position: absolute; opacity: 0; pointer-events: none; }

.font-btn:hover {
  border-color: var(--ink);
  background: var(--hover);
}

.font-btn:has(input:checked) {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper-2);
}

.font-btn:has(input:checked):hover {
  background: var(--pressed-hover);
  border-color: var(--pressed-hover);
}

.font-btn:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.font-name {
  font-size: 16px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.15;
}

.face-inter { font-family: "Inter", sans-serif; }
.face-mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 14px; }
.face-plex { font-family: "IBM Plex Sans", sans-serif; font-stretch: 100%; }
.face-pt { font-family: "PT Sans", sans-serif; }
.face-press { font-family: "Press Start 2P", monospace; font-size: 12px; line-height: 1.35; }
.font-btn.font-wide { grid-column: 1 / -1; }

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-top: 8px;
  min-height: 64px;
  padding: 12px;
  border: 1px dashed var(--line-dashed);
  background: transparent;
  color: var(--ink);
  text-align: center;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.is-over {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.font-picker:has(#font-upload:checked) .dropzone {
  border-style: solid;
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper-2);
}

.font-picker:has(#font-upload:checked) .dropzone:hover,
.font-picker:has(#font-upload:checked) .dropzone.is-over {
  background: var(--pressed-hover);
  border-color: var(--accent);
}

.dropzone:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.drop-title {
  max-width: 100%;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-hint { color: var(--muted); font-size: 12px; }

.font-picker:has(#font-upload:checked) .drop-hint { color: var(--pressed-muted); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ghost, .primary, .secondary {
  padding: 8px 12px;
}

.ghost { background: transparent; }

.primary {
  flex: 1;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.secondary { flex: 1; background: var(--paper-2); }

button:disabled, .primary:disabled, .secondary:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea, input[type="number"], select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper-2);
  padding: 8px;
}

textarea:hover, input[type="number"]:hover, select:hover,
textarea:focus, input[type="number"]:focus, select:focus {
  border-color: var(--line-hover);
  background: var(--hover);
}

.check:hover { color: var(--ink); }

textarea {
  resize: vertical;
  min-height: 58px;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.span-2 { grid-column: 1 / -1; }

.chips { margin-top: 8px; }

label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.scale-row input[type="range"] { width: 100%; accent-color: var(--accent); }

.scale-row output { color: var(--ink); font-variant-numeric: tabular-nums; }

.color-row label { align-items: center; grid-auto-flow: column; }
.check { grid-auto-flow: column; justify-content: start; align-items: center; color: var(--ink); }

.color-row { margin-top: 10px; }

/* The stats line and the cell-lines toggle share a row under the preview. */
.preview-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 16px;
}

.check.grid-toggle { margin-top: 8px; color: var(--muted); }

.format {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  margin: 10px 0 2px;
}

/* Two labels stacked in one cell, so the button keeps the width of the
   longer one and its neighbours do not move when it switches. */
.swap { display: inline-grid; justify-items: center; }
.swap > span { grid-area: 1 / 1; }
.swap .swap-done { opacity: 0; }
.swap.is-done .swap-idle { opacity: 0; }
.swap.is-done .swap-done { opacity: 1; }
.swap.is-done, .swap.is-done:hover:not(:disabled) { border-color: var(--ok); color: var(--ok); }

.align-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 10px;
}

.align-label { font-size: 13px; color: var(--muted); }
.align-row .seg { padding: 6px 10px; font-size: 13px; }

.fmt-color {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 6px;
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
}

.fmt-color input[type="color"] {
  width: 36px;
  height: 32px;
}

.fmt {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  cursor: pointer;
}

.fmt svg { display: block; width: 18px; height: 18px; }

.fmt:hover {
  border-color: var(--ink);
  background: var(--hover);
}

.fmt[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper-2);
}

.fmt[aria-pressed="true"]:hover {
  background: var(--pressed-hover);
  border-color: var(--pressed-hover);
}

.effect { display: grid; gap: 6px; }
.effect + .effect { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.effect-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}
.effect-row > label:first-child { grid-auto-flow: column; align-items: center; }
.effect:not(:has(.check input:checked)) .effect-row { opacity: 0.4; }

input[type="color"] {
  width: 42px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}

input[type="color"]:hover { border-color: var(--ink); }

.color-row:has(#transparent:checked) #bg-color { opacity: 0.4; }

.hint, .stats, .hover-readout, .status, .foot p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hint.warn { color: var(--accent-text); }

.field-error { margin: 8px 0 0; color: var(--accent-text); font-size: 13px; }

input[type="number"][aria-invalid="true"],
input[type="number"][aria-invalid="true"]:hover,
input[type="number"][aria-invalid="true"]:focus {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.font-picker:has(#font-upload[aria-invalid="true"]) .dropzone {
  border-style: solid;
  border-color: var(--accent);
}

.preview-wrap {
  position: relative;
}

.warn-mark,
.warn-tip { display: none; }

.warn-mark {
  position: absolute;
  z-index: 4;
  left: -22px;
  top: 0;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--accent-hover);
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: "Palatino Linotype", Palatino, serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  place-items: center;
}

.preview-wrap.has-warn .warn-mark { display: grid; }

.warn-mark:hover, .warn-mark:focus-visible {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
}

.warn-tip {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  margin: 0;
  padding: 8px 10px;
  background: var(--ink);
  color: var(--paper-2);
  font-size: 13px;
  line-height: 1.35;
}

.preview-wrap.has-warn .warn-mark:hover + .warn-tip,
.preview-wrap.has-warn .warn-mark:focus-visible + .warn-tip {
  display: block;
}

.stage {
  position: relative;
  width: 100%;
  background-color: #24221c;
  border: 1px solid #2a261f;
  box-shadow: 0 18px 40px var(--shadow);
}

.stage.matte-dark {
  background-color: #2a2823;
  background-image:
    linear-gradient(45deg, #3a3832 25%, transparent 25%),
    linear-gradient(-45deg, #3a3832 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a3832 75%),
    linear-gradient(-45deg, transparent 75%, #3a3832 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.stage.matte-light {
  background-color: #efeae1;
  background-image:
    linear-gradient(45deg, #d7d0c4 25%, transparent 25%),
    linear-gradient(-45deg, #d7d0c4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d7d0c4 75%),
    linear-gradient(-45deg, transparent 75%, #d7d0c4 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#atlas { z-index: 1; }
#atlas.pixelated { image-rendering: pixelated; }
#overlay { z-index: 2; }

.stage-msg {
  position: relative;
  z-index: 3;
  margin: 0;
  padding: 28px 16px;
  text-align: center;
  color: #f4f0e7;
}

.stage.matte-light .stage-msg { color: #1b1712; }

.stats, .hover-readout {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.hover-readout { min-height: 1.4em; color: var(--muted); }

.uv-block { margin-top: 14px; }

.uv-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.uv-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.segmented { display: flex; }

.seg {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.seg + .seg { margin-left: -1px; }
.seg:hover { position: relative; border-color: var(--ink); background: var(--hover); }
.seg[aria-pressed="true"] { position: relative; border-color: var(--ink); background: var(--ink); color: var(--paper-2); }

.uv-summary {
  margin: 8px 0 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.uv-head h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
}

.table-wrap {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--paper-2);
}

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }

th, td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th { position: sticky; top: 0; background: var(--table-head); font-weight: 600; }

td.char-cell { font-size: 16px; }

.downloads { margin-top: 10px; }

/* A label that does not fit moves its button to the next line instead of wrapping. */
.dl-row button { white-space: nowrap; }

.slice-row label { flex: 0 0 110px; }
.slice-row #save-zip { flex: 1 1 180px; align-self: end; }

.status { min-height: 0; }
.status.bad { color: var(--accent-text); }
.status.ok { color: var(--ok); }

.foot {
  padding: 4px 0 28px;
  border-top: 1px solid var(--line);
}

.foot a { color: var(--ink); text-underline-offset: 2px; }
.foot a:hover { color: var(--accent-text); }

/* 404.html */
.not-found {
  width: min(1180px, calc(100% - 32px));
  margin: 12vh auto 0;
}

.not-found h1 {
  margin: 0 0 16px;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  font-size: 64px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}

.not-found p { margin: 8px 0 0; font-size: 16px; }
.not-found a { color: var(--accent-text); text-underline-offset: 2px; }
.not-found a:hover { color: var(--accent-hover); }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .output,
  .output:has(.preview-wrap.has-warn) {
    order: -1;
    position: static;
    top: auto;
  }
  .brand { font-size: 26px; }
  .top { padding-top: 16px; }
  .warn-mark { left: 8px; top: 8px; }
}
