:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  background: #052c60;
  --tile-size: 120px;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  touch-action: none;
}

#paving {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

#paving.is-dragging, #paving.is-dragging .tile { cursor: grabbing; }

.tile {
  position: absolute;
  width: var(--tile-size);
  height: var(--tile-size);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #052c60;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tile-image {
  display: block;
  position: absolute;
  inset: 0;
  /* Crop the thin frame already present in the source image. */
  background: url("img/tile.png") center / 100.54% 100.54% no-repeat;
  pointer-events: none;
  transition: transform 200ms ease-in-out;
}

.tile:focus-visible { outline: 3px solid #fff; outline-offset: -4px; z-index: 1; }

.controls {
  position: fixed;
  z-index: 2;
  top: 12px;
  left: 12px;
  width: min(280px, calc(100vw - 24px));
  padding: 12px;
  border-radius: 10px;
  background: rgb(255 250 230 / 94%);
  box-shadow: 0 2px 12px rgb(0 0 0 / 15%);
  color: #052c60;
  font-size: 13px;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}

.zoom { display: flex; align-items: center; gap: 12px; }
#controls-toggle { display: block; margin: 0; min-width: 34px; font-size: 18px; flex: 0 0 auto; }
.menu-heading { display: flex; align-items: center; justify-content: space-between; gap: 5px; margin-bottom: 10px; }
.menu-heading h1 { flex: 1; min-width: 0; font-size: 14px; margin: 0; font-weight: 650; text-align: center; }
.learn-more { display: inline-block; font-size: 11px; }
.controls a { color: inherit; text-underline-offset: 2px; }
.source-links { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 12px; font-size: 11px; }
.controls.is-collapsed h1, .controls.is-collapsed .languages { display: none; }
.controls.is-collapsed .menu-heading { margin-bottom: 0; }
.languages { display: flex; flex-shrink: 0; gap: 2px; }
.controls .languages button { flex: 0 0 auto; padding: 5px; min-height: 28px; border: 0; border-radius: 4px; background: transparent; color: #052c60; font: 11px system-ui, sans-serif; cursor: pointer; }
.languages button[aria-pressed="true"] { background: #052c60; color: white; }
.controls.is-collapsed { width: auto; padding: 6px; }
.controls.is-collapsed #controls-toggle { margin: 0; }
.controls .patterns button, #apply-pattern, #export-image { position: relative; padding-right: 27px; }
#export-image { width: 100%; margin-top: 6px; }
#export-status { display: block; margin-top: 6px; line-height: 1.4; }
#export-status:empty { display: none; }
.controls button.is-loading { opacity: 1; cursor: progress; }
.is-loading::after {
  content: '';
  position: absolute;
  right: 8px;
  top: calc(50% - 6px);
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 650ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.zoom input { flex: 1; min-width: 0; margin: 0; accent-color: #052c60; cursor: pointer; }
.patterns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.patterns button[data-pattern="random"] { grid-column: 1 / -1; }
.patterns button { min-width: 0; }
.controls button {
  flex: 1 0 auto;
  min-height: 34px;
  padding: 6px 9px;
  border: 0;
  border-radius: 5px;
  font: inherit;
  color: inherit;
  background: rgb(5 44 96 / 9%);
  cursor: pointer;
  touch-action: manipulation;
}
.controls button:hover { background: rgb(5 44 96 / 18%); }
.patterns button[aria-pressed="true"] { background: #052c60; color: #fff9e5; }
.controls button:focus-visible, input:focus-visible { outline: 2px solid #052c60; outline-offset: 2px; }

[hidden] { display: none !important; }
.panel-actions { display: flex; gap: 6px; margin-top: 6px; }
.panel-actions button[aria-expanded="true"] { background: #052c60; color: #fff9e5; }
#editor { display: grid; gap: 8px; margin-top: 14px; }
.sequence-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#info-toggle { flex: 0 0 auto; min-height: 0; padding: 4px 0 4px 8px; background: transparent; border-radius: 0; font-size: 12px; }
#info-toggle::after { content: ' ⌄'; }
#info-toggle[aria-expanded="true"]::after { content: ' ⌃'; }
#info-toggle:hover { text-decoration: underline; }
#apply-pattern.is-pending { font-weight: 700; }
#sequence {
  width: 100%;
  min-width: 0;
  padding: 8px;
  border: 1px solid rgb(5 44 96 / 25%);
  border-radius: 5px;
  font: 16px ui-monospace, monospace;
  color: inherit;
  background: #fffdf5;
}
.shift-label { display: flex; justify-content: space-between; margin-top: 4px; }
#shift { width: 100%; margin: 0; accent-color: #052c60; }
#pattern-name { font: bold 14px ui-monospace, monospace; overflow-wrap: anywhere; }
#preview { display: grid; grid-template-columns: repeat(12, 1fr); overflow: hidden; }
.preview-tile { position: relative; aspect-ratio: 1; overflow: hidden; background: #052c60; }
#editor small { line-height: 1.4; }
#editor-status:empty { display: none; }
.controls button:disabled { opacity: 0.45; cursor: default; }
#info { line-height: 1.5; }
#info p:last-child { margin-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  .tile-image { transition: none; }
  .is-loading::after { animation: none; }
}
