:root {
  color-scheme: dark;
  --paper: #1d2028;
  --panel: #282d36;
  --tint: #323744;
  --hover: #373e4a;
  --ink: #f0f1ec;
  --dim: #b7bdc8;
  --line: #464c58;
  --control-border: #77808f;
  --accent: #f1c275;
  --accent-hover: #ffd293;
  --on-accent: #251e14;
  --selection: #443a2c;
  --focus: #9ed6ff;
  --trace: #8ad7e6;
  --header: #11151d;
  --on-header: #f4f4ee;
  --mark: #ffce80;
  --board: #10151e;
  --tile-r: #f0927c;
  --tile-g: #8cd2a1;
  --tile-b: #81b9fe;
  --tile-ink: #121e2b;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  font:
    16px/1.5 "Inter",
    system-ui,
    sans-serif;
  color: var(--ink);
  background: var(--paper);
}
:root[data-theme="blueprint"] {
  color-scheme: light;
  --paper: #f3f6fa;
  --panel: #ffffff;
  --tint: #e8eef7;
  --hover: #e1eafb;
  --ink: #142942;
  --dim: #4b6077;
  --line: #c6d2e0;
  --control-border: #778aa1;
  --accent: #2456ad;
  --accent-hover: #174491;
  --on-accent: #ffffff;
  --selection: #d9e7ff;
  --focus: #1757af;
  --trace: #a9540f;
  --header: #182e4b;
  --on-header: #f3f7ff;
  --mark: #b4d6ff;
  --board: #1c3048;
  --tile-r: #ee9e91;
  --tile-g: #91c8ac;
  --tile-b: #80b7f0;
}
:root[data-theme="blueprint"] .tile.empty {
  background: radial-gradient(circle, #426080 0.8px, transparent 1px);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
a {
  color: var(--accent);
  text-underline-offset: 0.22em;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button,
select,
input {
  min-height: 42px;
  border: 1px solid var(--control-border);
  background: var(--panel);
  border-radius: 5px;
  padding: 0.42rem 0.75rem;
}
button,
select {
  cursor: pointer;
}
button:hover:not(:disabled),
a.puzzle-row:hover {
  background: var(--hover);
}
button:disabled {
  cursor: default;
  opacity: 0.55;
}
button.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: 650;
}
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
button[aria-pressed="true"] {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--selection);
}
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.skip {
  position: fixed;
  top: -10rem;
  left: 1rem;
  z-index: 5;
  background: var(--panel);
  padding: 0.5rem;
}
.skip:focus {
  top: 0.5rem;
}
.topbar {
  min-height: 70px;
  background: var(--header);
  color: var(--on-header);
  display: flex;
  align-items: center;
  gap: clamp(1rem, 5vw, 4rem);
  padding: 0.8rem max(1rem, calc((100% - 1120px) / 2));
}
.topbar a {
  color: inherit;
  text-decoration: none;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 1.55rem;
  letter-spacing: -0.055em;
}
.brand:before {
  content: "";
  width: 1.05em;
  height: 1.05em;
  background: var(--mark);
  clip-path: polygon(6% 7%, 94% 50%, 6% 93%, 26% 50%);
}
.topbar nav {
  display: flex;
  align-items: center;
  gap: clamp(0.8rem, 3vw, 2rem);
  flex: 1;
  flex-wrap: wrap;
}
.topbar nav a {
  font-size: 0.94rem;
  padding: 0.43rem 0;
  border-bottom: 2px solid transparent;
}
.topbar nav a[aria-current="page"] {
  color: var(--mark);
  border-color: currentColor;
}
.topbar nav a:last-child {
  margin-left: auto;
}
main {
  max-width: 1152px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 3rem) 1rem 5rem;
}
h1,
h2,
p {
  margin: 0 0 0.8rem;
}
h1,
h2 {
  letter-spacing: -0.045em;
  line-height: 1.15;
}
h1 {
  font-size: clamp(2.1rem, 5vw, 3.25rem);
  font-weight: 700;
}
h2 {
  font-size: 1.5rem;
}
.page-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.25rem;
}
.page-head h1 {
  margin-bottom: 0.35rem;
}
.meta,
small {
  color: var(--dim);
  font-size: 0.89rem;
}
.filters,
.controls,
.palette,
.vote {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}
.filters {
  margin: 1.1rem 0 1.5rem;
}
.filters input {
  flex: 1;
  min-width: 12rem;
}
.puzzle-list {
  border-top: 2px solid var(--ink);
}
.puzzle-row {
  display: grid;
  grid-template-columns: 64px minmax(8rem, 1fr) repeat(3, minmax(3rem, 5rem));
  align-items: center;
  gap: 1.25rem;
  padding: 0.72rem 0.7rem;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
}
.puzzle-row:has(.stat:nth-child(6)) {
  grid-template-columns: 64px minmax(8rem, 1fr) repeat(4, minmax(3rem, 5rem));
}
.mini-board {
  width: 64px;
  height: 48px;
  border-radius: 2px;
  image-rendering: pixelated;
}
.puzzle-name {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}
.puzzle-name strong {
  overflow-wrap: anywhere;
  font-size: 1.08rem;
}
.stat {
  display: grid;
  font-family: var(--mono);
  font-size: 0.92rem;
}
.stat small {
  font: 0.8rem system-ui;
}
.controls {
  margin: 0.9rem 0;
}
.controls a {
  padding: 0.35rem 0;
}
.notice {
  border-left: 3px solid var(--accent);
  padding: 0.55rem 0.85rem;
  background: var(--tint);
  margin: 0.8rem 0;
}
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.03fr) minmax(0, 1fr);
  gap: clamp(1rem, 3vw, 2rem);
  align-items: start;
  margin: 1.2rem 0 2rem;
}
.board-panel,
.program-panel {
  min-width: 0;
}
.board {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 2px;
  padding: clamp(6px, 1vw, 12px);
  border-radius: 5px;
  background: var(--board);
}
.tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  font: 700 clamp(0.58rem, 1.4vw, 1.05rem)/1 var(--mono);
  color: var(--tile-ink);
}
.tile.r {
  background: var(--tile-r);
}
.tile.g {
  background: var(--tile-g);
}
.tile.b {
  background: var(--tile-b);
}
.program-panel {
  padding: 1.1rem;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 5px;
}
.program-panel > h2 {
  display: inline-block;
  margin-right: 0.8rem;
}
.functions {
  display: grid;
  gap: 0.45rem;
  margin: 0.8rem 0 1rem;
}
.function-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.22rem;
}
.function-row > b {
  width: 1.8rem;
  font: 600 0.9rem var(--mono);
}
.slot {
  min-height: 34px;
  min-width: 30px;
  padding: 0.2rem 0.15rem;
  font: 600 0.84rem var(--mono);
  background: var(--tint);
}
.slot.executing {
  box-shadow: 0 0 0 3px var(--trace);
}
.palette {
  margin: 0.75rem 0;
}
.palette button {
  min-height: 36px;
  font-size: 0.88rem;
}
.vote {
  font-family: var(--mono);
}
.vote button {
  min-width: 42px;
}
.auth-form {
  display: grid;
  gap: 1rem;
  max-width: 26rem;
}
.auth-form label {
  display: grid;
  gap: 0.25rem;
}
.table-wrap {
  overflow-x: auto;
  margin: 0.8rem 0;
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.5rem;
}
th {
  font-size: 0.86rem;
  background: var(--tint);
}
.cloud {
  display: flex;
  list-style: none;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 0.75rem 0;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
}
.cloud a {
  display: inline-block;
  padding: 0.3rem 0;
  font: 400 1.05rem var(--mono);
}
.cloud strong {
  font-weight: 800;
}
@media (max-width: 740px) {
  .workbench {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 0.2rem 1rem;
  }
  .topbar nav {
    gap: 0.8rem;
  }
  .page-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .puzzle-row,
  .puzzle-row:has(.stat:nth-child(6)) {
    grid-template-columns: 48px minmax(0, 1fr) 3rem;
    gap: 0.65rem;
  }
  .mini-board {
    width: 48px;
    height: 36px;
  }
  .puzzle-row .stat {
    display: none;
  }
  .puzzle-row .stat:nth-child(4) {
    display: grid;
  }
  .filters input {
    min-width: 8rem;
  }
  .tile {
    font-size: 0.8rem;
  }
  .program-panel {
    padding: 0.8rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}

#theme {
  background: var(--header);
  color: var(--on-header);
  font-size: 0.9rem;
  border-color: #8290a3;
  color-scheme: dark;
}
.topbar :focus-visible {
  outline-color: var(--mark);
}
@media (max-width: 740px) {
  #theme { margin-left: auto; }
  .topbar nav {
    order: 1;
    flex: 1 0 100%;
    min-width: 0;
    gap: .8rem;
  }
  .topbar nav a:last-child {
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
footer {
  max-width: 1152px;
  margin: 0 auto;
  padding: 0.5rem 1rem 1.4rem;
  font-size: 0.87rem;
}
