:root {
  color-scheme: light;
  font-family: "Segoe UI", sans-serif;
  color: #292820;
  background: #f6f2ea;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --surface: #fffdf9;
  --line: #e5dfd4;
  --muted: #716d64;
  --accent: #6b7752;
  --accent-dark: #4d5937;
  --accent-soft: #eef0e8;
  --focus: #b8c39c;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.info-icon:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin-top: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Page shell */

.app-shell {
  width: min(1180px, calc(100% - 40px));
  min-height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  padding: 18px 0 40px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 14px;
}

.app-title {
  margin-bottom: 5px;
  font-family: Georgia, serif;
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1;
}

.app-title svg {
  display: block;
  width: auto;
  height: 26px;
  overflow: visible;
}

.app-title--stitched {
  font-size: 0;
}

/* Footer with the version, filled in by the deploy workflow; empty when run locally. */
.app-version {
  margin-top: auto;
  padding-top: 32px;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

.app-version:empty {
  display: none;
}

.intro {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.save-status {
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.8rem;
  cursor: help;
}

/* Tabs */

.mode-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.mode-tab {
  margin-bottom: -1px;
  padding: 8px 20px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.mode-tab:hover {
  color: var(--accent-dark);
}

.mode-tab[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--accent-dark);
}

/* Workspace */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 264px;
  gap: 16px;
  align-items: start;
}

.workspace > .controls-column {
  order: 2;
}

.controls-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.controls-panel,
.pattern-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 6px 22px rgb(61 54 39 / 5%);
}

.controls-panel {
  padding: 6px 16px;
}

.pattern-panel {
  min-width: 0;
  padding: 12px;
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section[hidden] {
  display: none;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-heading:last-child {
  margin-bottom: 0;
}

.section-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.info-icon {
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 0.65rem;
  font-style: italic;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  cursor: help;
}

.info-icon:hover,
.info-icon:focus-visible {
  color: var(--accent-dark);
}

/* Buttons */

.icon-button {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--accent);
}

.icon-button[hidden] {
  display: none;
}

.icon-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.icon-button--filled {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: white;
}

.icon-button--filled:hover:not(:disabled) {
  background: var(--accent-dark);
}

.icon-button--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button--ghost:hover:not(:disabled) {
  border-color: var(--line);
  background: white;
  color: var(--accent-dark);
}

.icon-button--danger:hover:not(:disabled) {
  border-color: #c62828;
  color: #c62828;
}

.icon-button--text {
  width: auto;
  min-width: 34px;
  padding: 0 7px;
}

.primary-button,
.secondary-button {
  min-height: 38px;
  border-radius: 8px;
  font-weight: 600;
}

.primary-button {
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  background: white;
  color: inherit;
}

.secondary-button:hover {
  border-color: var(--accent);
}

/* Library */

.library-select {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: inherit;
}

.item-title-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 8px;
}

.pattern-name-input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  padding: 4px 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-family: Georgia, serif;
  font-size: 1.25rem;
  text-overflow: ellipsis;
}

.pattern-name-input:read-only {
  cursor: default;
}

.pattern-name-input:not(:read-only) {
  padding-left: 8px;
  border-color: var(--line);
  background: white;
}

.item-section .pattern-name-input {
  width: 100%;
  font-size: 1.25rem;
}

.item-actions {
  display: flex;
  gap: 2px;
  margin: 4px 0 0 -6px;
}

.library-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.library-actions .icon-button--filled {
  margin-right: 4px;
}

.stock-swatches {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.stock-swatch {
  width: 16px;
  height: 16px;
  border: 1px solid rgb(0 0 0 / 16%);
  border-radius: 50%;
}

.stock-count {
  margin-left: 4px;
  font-weight: 600;
}

#import-library-input,
#import-element-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#import-library-input:focus-visible + .icon-button,
#import-element-input:focus-visible + .icon-button {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Size, symmetry, working mode */

.size-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.size-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.size-input {
  width: 58px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: inherit;
}

.symmetry-current {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--accent-dark);
  font-size: 0.9rem;
  font-weight: 600;
}

.symmetry-icon {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.symmetry-icon svg,
.symmetry-choice svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.symmetry-icon .axis-fill,
.symmetry-choice .axis-fill {
  fill: currentColor;
  fill-opacity: 0.22;
  stroke: none;
}

.symmetry-icon .frame,
.symmetry-choice .frame {
  stroke-width: 1.2;
  opacity: 0.45;
}

.element-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  max-width: 240px;
  height: 34px;
  padding: 2px 10px 2px 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: inherit;
  cursor: pointer;
}

.element-picker:hover {
  border-color: var(--accent);
}

.element-picker canvas {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 5px;
}

.element-picker-name {
  overflow: hidden;
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Library browser and tags */

.item-tags-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.item-tags-row:not(:has(.tag-chip, .tag-input:not([hidden]))) {
  display: none;
}

.tag-list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 4px 0 9px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 600;
}

.tag-chip-label,
.tag-chip-remove {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
  cursor: pointer;
}

.tag-chip-label {
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-chip-label:hover {
  text-decoration: underline;
}

.tag-chip-remove {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}

.tag-chip-remove:hover {
  background: rgb(198 40 40 / 14%);
  color: #c62828;
}

.tag-chip--filter {
  padding: 0 9px;
  background: white;
  color: inherit;
  cursor: pointer;
}

.tag-chip--filter:hover {
  border-color: var(--accent);
}

.tag-chip--filter[aria-pressed="true"] {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: white;
}

.tag-count {
  margin-left: 5px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
}

.tag-chip--filter[aria-pressed="true"] .tag-count {
  color: rgb(255 255 255 / 80%);
}

.tag-chip--manage .tag-count {
  margin: 0 2px 0 4px;
}

.tag-empty {
  color: var(--muted);
  font-size: 0.8rem;
}

.tag-input {
  height: 28px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: inherit;
  font-size: 0.82rem;
}

.item-tags-row .tag-input {
  width: 110px;
}

.tag-input--inline {
  width: 9em;
  height: 22px;
  margin-left: -5px;
}

.library-dialog {
  width: min(1120px, calc(100% - 24px));
  height: min(88vh, 940px);
  max-height: calc(100% - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  box-shadow: 0 16px 48px rgb(41 40 32 / 20%);
}

.library-dialog[open] {
  display: flex;
}

.library-dialog::backdrop {
  background: rgb(41 40 32 / 45%);
}

.library-dialog-form {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 16px 18px;
}

.library-dialog-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.library-dialog-header h2 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 1.3rem;
  font-weight: 500;
  white-space: nowrap;
}

.library-dialog-header .color-search {
  flex: 1 1 200px;
}

.library-dialog-header .segmented[hidden] {
  display: none;
}

.library-filter-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.library-filter-row .tag-list {
  flex: 1;
  max-height: 5.6rem;
  overflow: auto;
}

.library-status-row {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.library-select-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.link-button[hidden] {
  display: none;
}

.library-grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 2px;
}

.gallery-empty {
  grid-column: 1 / -1;
  padding: 36px 0;
  color: var(--muted);
  text-align: center;
}

.gallery-sentinel {
  grid-column: 1 / -1;
  height: 1px;
}

.gallery-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  content-visibility: auto;
  contain-intrinsic-size: auto 210px;
}

.gallery-card:hover {
  border-color: var(--accent);
}

.gallery-card.is-current {
  border-color: var(--accent-dark);
  box-shadow: 0 0 0 1px var(--accent-dark);
}

.gallery-card.is-selected {
  background: var(--accent-soft);
}

.gallery-open {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.gallery-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #faf7f0;
}

.gallery-name {
  overflow: hidden;
  font-size: 0.85rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-meta {
  color: var(--muted);
  font-size: 0.72rem;
}

.gallery-check {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 18px;
  height: 18px;
  margin: 0;
  opacity: 0;
  accent-color: var(--accent-dark);
  cursor: pointer;
}

.gallery-card:hover .gallery-check,
.gallery-check:focus-visible,
.gallery-check:checked,
.library-grid.has-selection .gallery-check {
  opacity: 1;
}

.gallery-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.gallery-tags:empty {
  display: none;
}

.gallery-tag-adder {
  display: contents;
}

.gallery-tag-add {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-color: var(--line);
  opacity: 0;
}

.gallery-card:hover .gallery-tag-add,
.gallery-tag-add:focus-visible,
.gallery-card.is-tagging .gallery-tag-add {
  opacity: 1;
}

.gallery-card .tag-input {
  width: 100%;
}

.gallery-card .tag-input[hidden] {
  display: none;
}

.gallery-tag {
  position: relative;
  max-width: 100%;
  overflow: hidden;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.68rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-tag-remove {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 16px;
  padding: 0;
  border: 0;
  background: var(--accent-soft);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
}

.gallery-tag:hover .gallery-tag-remove,
.gallery-tag-remove:focus-visible {
  opacity: 1;
}

.gallery-tag-remove:hover {
  background: #f3d6d6;
  color: #c62828;
}

.library-bulk {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.library-bulk[hidden] {
  display: none;
}

.library-bulk-divider {
  align-self: stretch;
  width: 1px;
  margin: 4px 6px;
  background: var(--line);
}

.library-bulk-icon {
  flex: none;
  width: 18px;
  height: 18px;
  margin-right: -2px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.library-bulk .tag-input {
  width: 200px;
  height: 34px;
}

/* Print */

.print-root {
  display: none;
}

.print-page {
  position: relative;
  overflow: hidden;
  color: #111;
  font-family: "Segoe UI", Arial, sans-serif;
  break-after: page;
  page-break-after: always;
}

.print-page:last-child {
  break-after: auto;
  page-break-after: auto;
}

.print-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6mm;
  height: 9mm;
  font-size: 3.6mm;
}

.print-header span {
  color: #444;
  font-size: 3.2mm;
}

.print-chart,
.print-overview-chart {
  display: block;
}

.print-chart text,
.print-overview-chart text {
  font-family: "Segoe UI Symbol", "DejaVu Sans", "Arial Unicode MS", "Segoe UI", sans-serif;
}

.print-overview-info {
  height: 30mm;
}

.print-overview-info h1,
.print-legend-title {
  margin: 0 0 2mm;
  font-size: 6.5mm;
  font-weight: 600;
}

.print-overview-info p {
  margin: 0 0 1.5mm;
  font-size: 3.6mm;
}

.print-legend {
  display: grid;
  gap: 0 8mm;
  margin-top: 4mm;
}

.print-legend-row {
  display: flex;
  align-items: center;
  gap: 3mm;
  height: 8mm;
  border-bottom: 0.2mm solid #ddd;
  font-size: 3.5mm;
}

.print-legend-row svg {
  flex: none;
}

.print-legend-code {
  flex: none;
  min-width: 17mm;
  font-weight: 600;
}

.print-legend-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-legend-count {
  flex: none;
  color: #444;
}

@media print {
  body.is-printing {
    min-height: 0;
    background: white;
  }

  body.is-printing .app-shell {
    display: none;
  }

  body.is-printing .print-root {
    display: block;
  }
}

/* Colour dialog */

.color-dialog {
  width: min(900px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  box-shadow: 0 16px 48px rgb(41 40 32 / 20%);
}

.color-dialog::backdrop {
  background: rgb(41 40 32 / 45%);
}

.color-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.color-dialog-header h2 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 1.3rem;
  font-weight: 500;
}

.color-dialog .help-text {
  margin: 4px 0 12px;
}

.color-dialog-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.color-search {
  flex: 1 1 200px;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: inherit;
}

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.segmented button {
  height: 34px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: white;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
  height: min(52vh, 460px);
  overflow: auto;
  padding: 2px;
  align-content: start;
}

.color-grid-empty {
  grid-column: 1 / -1;
  padding: 24px 0;
  color: var(--muted);
  text-align: center;
}

.color-tile {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: inherit;
  text-align: left;
}

.color-tile:hover {
  border-color: var(--accent);
}

.color-tile[aria-pressed="true"] {
  border-color: var(--accent-dark);
  background: var(--accent-soft);
}

.color-tile[aria-disabled="true"] {
  border-style: dashed;
  cursor: not-allowed;
}

.color-tile-swatch {
  width: 28px;
  height: 28px;
  border: 1px solid rgb(0 0 0 / 16%);
  border-radius: 6px;
}

.color-tile-text {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

.color-tile-code {
  font-size: 0.85rem;
  font-weight: 700;
}

.color-tile-name {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-tile--owned::after {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.color-dialog-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 12px;
}

.color-dialog-count {
  color: var(--muted);
  font-size: 0.82rem;
}

.color-credit {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.72rem;
}

.color-credit a {
  color: inherit;
}

.color-dialog-footer .primary-button {
  min-width: 90px;
}

/* Dialogs */

.new-element-dialog {
  width: min(500px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  box-shadow: 0 16px 48px rgb(41 40 32 / 20%);
}

.new-element-dialog::backdrop {
  background: rgb(41 40 32 / 45%);
}

.new-element-form h2 {
  margin-bottom: 6px;
  font-family: Georgia, serif;
  font-size: 1.3rem;
  font-weight: 500;
}

.help-text {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.dimension-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.dimension-fields label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.dimension-fields input {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: inherit;
}

.creation-symmetry {
  margin: 0;
  padding: 8px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.creation-symmetry legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 600;
}

.symmetry-choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.symmetry-choice {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  padding: 8px 4px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.symmetry-choice:hover {
  border-color: var(--accent);
}

.symmetry-choice[aria-checked="true"] {
  border-color: var(--accent-dark);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.symmetry-choice-description {
  min-height: 3.2em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

#new-element-help {
  margin: 10px 0 0;
}

#new-element-help:empty {
  display: none;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

/* Toolbar */

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 10px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9f7f1;
}

.painting-tools,
.toolbar-side,
.tool-group,
.subtools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.painting-tools {
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.toolbar-side {
  gap: 10px;
  margin-left: auto;
}

.painting-tools[hidden],
.tool-group[hidden],
.subtools[hidden],
.palette[hidden],
.line-selection-status[hidden] {
  display: none;
}

/* Main tools are green; the subtools of the chosen tool sit right after it. */
.tool-main {
  border-color: #b8c39c;
  background: #dde4cf;
  color: var(--accent-dark);
}

.tool-main:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: #cfd8bd;
}

.tool-main[aria-pressed="true"] {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: white;
}

.subtools {
  margin-right: 10px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}

.palette-group {
  flex-wrap: wrap;
  gap: 4px;
}

.tool-divider {
  align-self: stretch;
  width: 1px;
  margin: 4px 2px;
  background: var(--line);
}

.selection-size {
  min-width: 70px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.zoom-level {
  min-width: 46px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
}

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

.color-choice {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
}

.color-choice:hover {
  border-color: var(--line);
}

.color-choice[aria-pressed="true"] {
  border-color: var(--accent-dark);
}

.color-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid rgb(0 0 0 / 14%);
  border-radius: 50%;
}

/* Grid */

.grid-scroll-area {
  max-height: min(72vh, 760px);
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #fbfaf6;
  background-image:
    linear-gradient(45deg, #f1eee6 25%, transparent 25%),
    linear-gradient(-45deg, #f1eee6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1eee6 75%),
    linear-gradient(-45deg, transparent 75%, #f1eee6 75%);
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-size: 10px 10px;
}

.grid-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 16px;
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.placement-help {
  margin-left: auto;
}

.symmetry-legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: help;
}

.symmetry-legend[hidden] {
  display: none;
}

.symmetry-legend-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid #8a927d;
  border-radius: 3px;
  background: #dfe5d6;
}

.pattern-grid {
  display: grid;
  width: max-content;
  gap: 1px;
  padding: 1px;
  background: #d5d0c5;
}

.composition-canvas {
  display: block;
  background: #fffdf9;
  cursor: crosshair;
  image-rendering: pixelated;
}

.composition-stage {
  position: relative;
  width: max-content;
  height: max-content;
}

.composition-stage[hidden],
.pattern-grid[hidden] {
  display: none;
}

.placement-preview {
  position: absolute;
  z-index: 1;
  border: 3px solid;
  box-shadow: 0 0 0 2px white;
  pointer-events: none;
}

.placement-preview--valid {
  border-color: #16803c;
  background: rgb(22 128 60 / 18%);
}

.placement-preview--invalid {
  border-color: #c62828;
  background: rgb(198 40 40 / 22%);
}

.stitch-cell {
  position: relative;
  width: var(--stitch-size, 20px);
  height: var(--stitch-size, 20px);
  padding: 0;
  border: 0;
  background: #fffdf9;
}

.stitch-cell--major-column {
  border-right: 2px solid #847d70;
}

.stitch-cell--major-row {
  border-bottom: 2px solid #847d70;
}

.stitch-cell--symmetry-boundary-column {
  border-right: 3px solid var(--accent-dark);
}

.stitch-cell--symmetry-boundary-row {
  border-bottom: 3px solid var(--accent-dark);
}

.pattern-grid--compact .stitch-cell--major-column,
.pattern-grid--compact .stitch-cell--symmetry-boundary-column {
  border-right-width: 1px;
}

.pattern-grid--compact .stitch-cell--major-row,
.pattern-grid--compact .stitch-cell--symmetry-boundary-row {
  border-bottom-width: 1px;
}

.stitch-cell--reflected::after {
  position: absolute;
  inset: 1px;
  background: rgb(107 119 82 / 24%);
  content: "";
  pointer-events: none;
}

.stitch-cell--reflected:disabled {
  cursor: default;
  opacity: 1;
}

.stitch-cell--line-row::before,
.stitch-cell--line-column::before {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgb(77 89 55 / 24%);
  content: "";
  pointer-events: none;
}

.stitch-cell--line-row.stitch-cell--line-column::before {
  background: rgb(77 89 55 / 45%);
}

.line-selection-status {
  color: var(--accent-dark);
  font-weight: 600;
}

.stitch-cell:hover {
  box-shadow: inset 0 0 0 2px var(--accent);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 560px);
    padding-top: 16px;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace > .controls-column {
    order: 0;
  }
}
