:root {
  color-scheme: light;
  --ink: #000;
  --paper: #f6f6f2;
  --line: #000;
}

* { box-sizing: border-box; }

html, body {
  touch-action: manipulation;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

main {
  width: 100%;
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.topbar, .controls { display: flex; align-items: center; gap: 4px; padding: 5px; }
.topbar {
  order: 0;
  justify-content: flex-start;
  border-bottom: 1px solid var(--line);
}
.controls {
  order: 2;
  display: grid;
  grid-template-columns: auto auto;
  justify-content: space-between;
  border-top: 1px solid var(--line);
}
.size-controls { display: flex; align-items: center; gap: 3px; }
.rule { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.settings-row {
  grid-column: 1 / -1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}
.rule strong { font-weight: 700; }
h1 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.rule { display: flex; align-items: center; gap: 4px; }
input, button { border: 1px solid var(--line); border-radius: 0; background: var(--paper); color: var(--ink); font: inherit; height: 24px; white-space: nowrap; }
input { width: 52px; padding: 2px 4px; text-align: center; }
button, .button { cursor: pointer; padding: 2px 7px; }
.button { border: 1px solid var(--line); background: var(--paper); color: var(--ink); font: inherit; height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.step-control, .size-control { width: 2.5em; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.palette-picker { font-weight: 700; white-space: nowrap; }
.palette-menu {
  position: absolute;
  z-index: 2;
  bottom: 29px;
  right: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 3px;
  width: min(310px, calc(100vw - 10px));
  padding: 4px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.palette-menu[hidden] { display: none; }
.palette-option {
  display: grid;
  grid-template-columns: 18px 18px 1fr;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 28px;
  padding: 3px;
  text-align: left;
}
.swatch { display: block; width: 16px; height: 16px; border: 1px solid var(--line); }
.palette-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label, .rule, .button { white-space: nowrap; }
button:hover, button:focus-visible, .button:hover, .button:focus-visible { background: var(--ink); color: var(--paper); outline: none; }
button.active, .button.active { background: var(--ink); color: var(--paper); }
.controls { justify-content: space-between; flex-wrap: wrap; }
.control-group { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; position: relative; }
.label { margin-right: 2px; font-weight: 700; }
.switch { min-width: 150px; margin-right: 0; white-space: nowrap; }
#automata {
  order: 1;
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  image-rendering: pixelated;
  background: #fff;
}
@media (max-width: 600px) {
  .controls { align-items: flex-start; }
  .control-group { width: 100%; }
}
