/* 8bit Critters — character creator.
   Tokens and type lifted from the Shape Kit v2 sheet (design-system-sheet.html).
   Radii: none. Shadows: none. Every surface is square — that is the sheet's idiom. */

:root {
  --paper: #E6E9EA;   /* page */
  --card:  #F6F7F7;   /* inverted text on ink */
  --plate: #FBFCFC;   /* surfaces */
  --sel:   #EDF0FE;   /* selected surface */
  --ink:   #12171A;
  --ink2:  #59646B;
  --rule:  #C3C9CC;
  --spot:  #1B3BD0;

  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Archivo", Helvetica, Arial, sans-serif;
  --serif: "Newsreader", Georgia, serif;

  --pad: clamp(14px, 3vw, 34px);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  /* Kills the 300ms tap delay and the gray flash on iOS. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

img {
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

button { font: inherit; color: inherit; background: none; border: 0; }

:focus-visible { outline: 2px solid var(--spot); outline-offset: 2px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--rule); }

.page {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  padding: 0 var(--pad) 60px;
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
}

/* ---- masthead ---- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 26px 0 14px;
  border-bottom: 2px solid var(--ink);
}

.eyebrow {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--spot);
}

.title {
  margin: 0;
  font-family: var(--sans);
  font-variation-settings: 'wdth' 118;
  font-weight: 800;
  text-transform: uppercase;
  font-size: clamp(1.9rem, 5vw, 3.1rem);
  line-height: .92;
  letter-spacing: -.015em;
}

/* ---- two columns ---- */

.layout {
  display: flex;
  gap: clamp(16px, 2.4vw, 30px);
  align-items: flex-start;
  flex-wrap: wrap;
  padding-top: 22px;
}

.plate-col {
  flex: 1 1 340px;
  min-width: 300px;
  position: sticky;
  top: 14px;
}

.rail { flex: 1 1 420px; min-width: 300px; }

/* The one thing the page needs styled without JavaScript. It lives here rather than in a
   style attribute so the Content-Security-Policy never has to allow 'unsafe-inline'. */
.noscript {
  font-family: var(--mono);
  font-size: 12px;
  padding: 0 var(--pad) 40px;
}

/* ---- the plate ---- */

/* A fixed stage. The preview draws the whole 59x74 generator grid rather than a crop,
   so the frame is one size for every character and the figure holds its place instead of
   jumping and rescaling between picks. Zoom scales the art inside the box; it never
   resizes the box, and once the art outgrows the stage the frame clips it. */
.plate {
  position: relative;
  background: var(--plate);
  border: 1px solid var(--rule);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 400px;
  overflow: hidden;
}

.plate img { flex: none; }

.specrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink2);
}

.zoom { display: flex; gap: 6px; }

.zoom-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: var(--plate);
  border: 1px solid var(--rule);
  cursor: pointer;
  font-family: var(--mono);
}
.zoom-btn:hover { border-color: var(--ink); }
.zoom-btn[disabled] { opacity: .4; cursor: default; }
.zoom-btn[disabled]:hover { border-color: var(--rule); }

.zoom-label { display: grid; place-items: center; min-width: 34px; }

.actions { display: flex; gap: 10px; padding-top: 14px; }

.btn {
  flex: 1;
  /* also a flex row of its own, so a button with an icon centers as one unit */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 14px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.btn-solid { background: var(--ink); color: var(--card); border: 1px solid var(--ink); }
.btn-solid:hover { background: var(--spot); border-color: var(--spot); }

.btn-ghost { background: transparent; border: 1px solid var(--ink); }
.btn-ghost:hover { border-color: var(--spot); color: var(--spot); }

/* ---- rail sections ---- */

.section-head {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--spot);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
}
.section-head--spaced { margin-top: 28px; }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.preset {
  background: var(--plate);
  border: 1px solid var(--rule);
  padding: 8px 4px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.preset:hover { border-color: var(--spot); }

.preset .box {
  height: var(--preset-box, 62px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}

.preset .name {
  font-family: var(--sans);
  font-variation-settings: 'wdth' 106;
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.palette-row { display: flex; gap: 8px; flex-wrap: wrap; }

.swatch {
  background: var(--plate);
  border: 1px solid var(--rule);
  padding: 5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.swatch:hover { border-color: var(--spot); }
.swatch[aria-pressed="true"] { background: var(--sel); border-color: var(--spot); }

.swatch .name {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink2);
}

/* ---- collapsible groups ---- */

.group-btn {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 30px 0 0;
  padding: 0 0 9px;
  background: transparent;
  border-bottom: 2px solid var(--ink);
  cursor: pointer;
  text-align: left;
}
.group-btn:hover { border-color: var(--spot); }

.group-btn .left { display: flex; align-items: baseline; gap: 10px; }
.group-btn .mark { font-family: var(--mono); font-size: 11px; color: var(--spot); }

.group-btn .group-title {
  font-family: var(--sans);
  font-variation-settings: 'wdth' 112;
  font-weight: 800;
  font-size: 19px;
  text-transform: uppercase;
  letter-spacing: -.01em;
}

.group-btn .note,
.family h3 .note {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink2);
}

.group-body[hidden] { display: none; }

.family h3 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
  font-weight: 400;
}

.family h3 .fam-title {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--spot);
}

.opt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--cell, 100px), 1fr));
  gap: 8px;
}

/* ---- part modifier slider (whisker length) ----
   Sits under a part family's cards and only appears when the option it modifies is
   the selected one. Square like every other surface in the sheet. */
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 9px;
  padding: 9px 12px;
  background: var(--plate);
  border: 1px solid var(--rule);
}

.slider-row[hidden] { display: none; }

.slider-row .slider-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink2);
  white-space: nowrap;
}

.slider-row input[type="range"] {
  flex: 1;
  min-width: 80px;
  accent-color: var(--spot);
  cursor: pointer;
  margin: 0;
}

.slider-row .slider-val {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .06em;
  min-width: 26px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* The download button carries an icon, so it becomes a flex row. The icon keeps its
   own size while the label swaps for the "Building" / "Downloaded" flash. */
.btn-ico {
  flex: 0 0 auto;
  margin-right: 7px;
  vertical-align: -1px;
}

.btn:disabled {
  opacity: .55;
  cursor: default;
}

.opt {
  background: var(--plate);
  border: 1px solid var(--rule);
  padding: 7px 4px 5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.opt:hover { border-color: var(--spot); }
.opt[aria-pressed="true"] { background: var(--sel); border-color: var(--spot); }

.opt .box {
  /* Each family is only as tall as its own tallest crop, so a nub-eared family
     carries none of the whitespace a tall-eared one needs. Set from JS. */
  height: var(--box, 40px);
  display: flex;
  align-items: var(--align, center);
  justify-content: center;
  overflow: hidden;
}

.opt .label {
  font-family: var(--sans);
  font-variation-settings: 'wdth' 106;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  text-align: center;
  line-height: 1.2;
}

/* ---- colophon ---- */

.colophon {
  margin-top: 44px;
  padding-top: 14px;
  border-top: 2px solid var(--ink);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink2);
}

/* ---- mobile: one column, plate pinned to the top ----
   Desktop makes the left column sticky so the sprite stays visible while you pick.
   Stacked, that intent only survives if the plate pins to the top of the viewport —
   otherwise the first scroll hides the thing every card is a diff against. */

@media (max-width: 759px) {
  .layout { display: block; padding-top: 16px; }

  .plate-col {
    position: sticky;
    top: 0;
    z-index: 20;
    /* full-bleed, so rail content scrolls under paper and not under a gap */
    margin: 0 calc(-1 * var(--pad));
    padding: 10px var(--pad) 12px;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
  }

  /* Still a fixed stage, only a shorter one — a phone cannot spare 400px above the
     rail. The floor is the 222px the minimum zoom needs, so even a small screen opens
     with the whole critter inside the frame rather than clipped. */
  .plate { height: clamp(232px, 36vh, 400px); }

  .specrow { padding-top: 8px; font-size: 10.5px; }
  .actions { padding-top: 10px; }

  /* touch targets */
  .btn { padding: 13px 12px; min-height: 44px; }
  .zoom-btn { width: 32px; height: 32px; }

  .rail { margin-top: 20px; }

  .opt { padding: 9px 4px 7px; }
  .preset { padding: 10px 4px 8px; }

  .group-btn { margin-top: 26px; padding-bottom: 11px; }
  .colophon { margin-top: 34px; }
}

@media (max-width: 380px) {
  .opt-grid { grid-template-columns: repeat(auto-fill, minmax(var(--cell-sm, 88px), 1fr)); }
}

/* Hover styling is a lie on touch screens — it sticks after a tap. */
@media (hover: none) {
  .preset:hover, .swatch:hover, .opt:hover { border-color: var(--rule); }
  .swatch[aria-pressed="true"]:hover, .opt[aria-pressed="true"]:hover { border-color: var(--spot); }
  .btn-solid:hover { background: var(--ink); border-color: var(--ink); }
  .btn-ghost:hover { border-color: var(--ink); color: var(--ink); }
  .zoom-btn:hover { border-color: var(--rule); }
  .group-btn:hover { border-color: var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
