/* Brick Box: an isometric pixel brick builder. */

:root {
  --bg: #262a36;
  --bg-2: #2f3442;
  --panel: #353b4b;
  --ink: #eef0f4;
  --dim: #aab2c4;
  --edge: #12141b;
  --red: #c4281c;
  --yellow: #f5cd2f;
  --blue: #1e5aa8;
  --green: #287f46;
  --pixel: 'Silkscreen', 'Courier New', monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--pixel);
  /* A playroom rug */
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.04), transparent 60%),
    repeating-linear-gradient(45deg, transparent 0 6px, rgba(0, 0, 0, 0.08) 6px 7px),
    repeating-linear-gradient(-45deg, transparent 0 6px, rgba(0, 0, 0, 0.08) 6px 7px),
    var(--bg);
}

button,
.quit {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

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

.skip-link {
  position: absolute;
  top: 8px;
  left: 16px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--yellow);
  color: #1a1a1a;
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: none;
}

.noscript {
  margin: 16px;
  padding: 12px;
  background: var(--panel);
}

/* --- Toolbar ------------------------------------------------------------------ */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 12px 16px 8px;
}
.brand {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.04em;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--red), 5px 5px 0 var(--edge);
  text-transform: uppercase;
}
.tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

/* Chunky pixel buttons with a stepped shadow */
.tools button,
.tools .quit,
.modes button,
.wide,
.share-actions button,
dialog .close,
.banner button {
  display: inline-block;
  padding: 6px 10px 5px;
  border: 0;
  background: var(--bg-2);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
  text-decoration: none;
  box-shadow:
    inset -2px -2px 0 rgba(0, 0, 0, 0.35),
    inset 2px 2px 0 rgba(255, 255, 255, 0.12),
    0 0 0 2px var(--edge),
    3px 3px 0 2px var(--edge);
}
.tools button:active,
.tools .quit:active,
.modes button:active,
.wide:active {
  transform: translate(2px, 2px);
  box-shadow:
    inset 2px 2px 0 rgba(0, 0, 0, 0.35),
    0 0 0 2px var(--edge),
    1px 1px 0 2px var(--edge);
}
.tools button[aria-pressed='true'],
.modes button[aria-pressed='true'] {
  background: var(--blue);
}
#tool-erase[aria-pressed='true'] {
  background: var(--red);
}
#btn-view-l,
#btn-view-r {
  font-family: system-ui, sans-serif;
  font-size: 16px;
  padding: 3px 9px 4px;
}
.tools .quit {
  background: #6b2b26;
}
.tools button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.banner {
  width: fit-content;
  max-width: min(92vw, 640px);
  margin: 6px auto 0;
  padding: 8px 14px;
  background: var(--yellow);
  color: #1a1a1a;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--edge), 4px 4px 0 2px var(--edge);
}
.banner button {
  margin: 6px 4px 0;
  background: #fff;
  color: #1a1a1a;
}

/* --- Layout ------------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
  padding: 8px 16px;
}
.stage-wrap {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 300px;
  overflow: hidden;
}
#stage {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}
#stage:focus-visible {
  outline-offset: 4px;
}
body.erasing #stage {
  cursor: not-allowed;
}

.panel {
  padding: 12px;
  background: var(--panel);
  box-shadow: 0 0 0 2px var(--edge), 5px 5px 0 2px var(--edge);
}
.modes {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.modes button {
  flex: 1;
}
.cat {
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--dim);
  text-transform: uppercase;
}
.cat:first-child {
  margin-top: 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.part {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 2px;
  border: 0;
  background: var(--bg-2);
  box-shadow: 0 0 0 2px var(--edge);
}
.part canvas {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
}
.part[aria-pressed='true'] {
  background: #4a5470;
  box-shadow: 0 0 0 2px var(--yellow);
}
.part .count {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 11px;
  text-shadow: 1px 1px 0 var(--edge);
}
.part:disabled {
  opacity: 0.3;
}
.colors {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
}
.swatch {
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  box-shadow:
    inset -2px -2px 0 rgba(0, 0, 0, 0.3),
    0 0 0 2px var(--edge);
}
.swatch.trans {
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.35) 0 3px, transparent 3px 6px) !important;
}
.swatch[aria-pressed='true'] {
  box-shadow:
    inset -2px -2px 0 rgba(0, 0, 0, 0.3),
    0 0 0 3px var(--yellow);
}
.box-label {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.5;
}
.box-label b {
  color: var(--yellow);
  font-weight: 400;
}
.wide {
  width: 100%;
  margin-top: 12px;
  background: var(--green);
}
.keys {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--dim);
}
.keys summary {
  cursor: pointer;
  color: var(--ink);
}
.keys ul {
  margin: 4px 0;
  padding-left: 16px;
}
kbd {
  padding: 0 3px;
  background: var(--bg-2);
  font-family: inherit;
  color: var(--ink);
}

.status {
  margin: 4px 0 18px;
  padding: 0 16px;
  font-size: 13px;
  text-align: center;
  color: var(--dim);
  min-height: 1.4em;
}

/* --- Share dialog ------------------------------------------------------------- */

dialog {
  max-width: min(92vw, 440px);
  padding: 20px;
  border: 0;
  background: var(--panel);
  color: var(--ink);
  font-family: var(--pixel);
  box-shadow: 0 0 0 2px var(--edge), 6px 6px 0 2px var(--edge);
}
dialog::backdrop {
  background: rgba(10, 12, 18, 0.6);
}
dialog h2 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 400;
  color: var(--yellow);
}
dialog p {
  font-size: 13px;
  line-height: 1.5;
}
.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.share-actions button {
  background: var(--blue);
}
dialog .close {
  margin-top: 8px;
}
.share-note {
  min-height: 1.5em;
  word-break: break-all;
}

/* --- Small screens ------------------------------------------------------------ */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .panel {
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
  }
  .grid {
    grid-template-columns: repeat(6, 1fr);
  }
  .colors {
    grid-template-columns: repeat(10, 1fr);
  }
}
@media (max-width: 480px) {
  .brand {
    font-size: 20px;
  }
  .tools button,
  .tools .quit {
    font-size: 12px;
    padding: 5px 7px 4px;
  }
  .grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ?card: just the baseplate, filling the frame (scripts/share-card.html) */
body.card {
  background: var(--bg);
}
body.card .toolbar,
body.card .panel,
body.card .status,
body.card .banner {
  display: none;
}
body.card #stage {
  position: fixed;
  left: 0;
  top: -15vw;
  width: 100vw;
  height: auto;
}
