:root {
  --app-gap: 16px;
  --controls-width: 430px;
  --controls-height: 620px;
  --stage-size: 620px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
}

.arts-app {
  height: 100%;
  overflow: hidden;
}

label,
.control-field {
  display: grid;
  min-width: 0;
  gap: 3px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
}

.control-field > label {
  display: block;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
}

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: 100dvh;
  padding: 16px;
  grid-template-rows: minmax(0, 1fr);
}

.workbench {
  display: grid;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  grid-template-areas: "title controls preview download";
  grid-template-columns: auto var(--controls-width) var(--stage-size) auto;
  align-items: start;
  justify-content: center;
  gap: var(--app-gap);
}

.lane-title {
  position: relative;
  display: flex;
  width: max-content;
  align-self: start;
  align-items: center;
  grid-area: title;
}

.lane-title h1 {
  margin: 0;
  padding: 0.34rem 0.56rem;
  border: 1px solid var(--starsector-title-edge);
  color: var(--text);
  font-size: 1.42rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
}

.lane-title h1:active {
  transform: translateY(1px);
}

.home-link {
  position: absolute;
  top: calc(100% + 6px);
  left: 3px;
  color: var(--muted);
  font-size: 10px;
  text-underline-offset: 3px;
  white-space: nowrap;
}

.home-link:hover,
.home-link:focus-visible {
  color: var(--hot);
}

.lane-download {
  display: flex;
  width: 104px;
  height: var(--stage-size);
  flex-direction: column;
  align-self: start;
  align-items: stretch;
  grid-area: download;
}

.action-stack {
  display: grid;
  gap: 6px;
}

.action-stack button {
  width: 100%;
  min-width: 104px;
  padding: 4px 6px;
  font-size: 11px;
}

.controls {
  width: var(--controls-width);
  height: var(--controls-height);
  min-height: 0;
  padding: 9px;
  overflow: auto;
  grid-area: controls;
}

.control-stack {
  display: grid;
  gap: 8px;
}

.control-group {
  display: grid;
  padding: 8px;
  border: 1px solid var(--edge);
  background: rgb(4 12 18 / 82%);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 42%) inset;
  gap: 7px;
}

.control-group h2,
.control-group h3,
.control-group summary {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.control-group summary {
  cursor: pointer;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.control-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.range-readout {
  display: flex;
  align-items: center;
  gap: 7px;
}

.range-readout output {
  min-width: 5ch;
  color: var(--muted);
  text-align: right;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.action-row > * {
  flex: 1 1 auto;
}

.stage-column {
  display: grid;
  width: var(--stage-size);
  min-width: 0;
  min-height: 0;
  grid-area: preview;
  grid-template-rows: var(--stage-size) auto;
  gap: 8px;
}

.stage {
  position: relative;
  display: grid;
  width: var(--stage-size);
  height: var(--stage-size);
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  place-items: center;
}

.stage canvas,
.stage img,
.stage svg {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.stage canvas {
  width: auto;
  height: auto;
  image-rendering: pixelated;
}

.error {
  position: absolute;
  z-index: 4;
  top: 10px;
  right: 10px;
  left: 10px;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid #a34f40;
  color: #ffd0c8;
  background: #32130e;
  font-size: 12px;
}

.status-strip {
  display: grid;
  padding: 0;
  font-size: 11px;
  gap: 4px;
}

.status-strip-silent {
  position: absolute;
  width: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.progress-track {
  height: 8px;
  border: 1px solid var(--edge);
  background: var(--page);
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--hot);
}

.status-line {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  gap: 12px;
}

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

.palette-row {
  display: grid;
  grid-template-columns: 2.4em minmax(0, 1fr);
  align-items: center;
  gap: 5px;
}

.palette-row span {
  color: var(--muted);
  font-size: 11px;
}

dialog {
  max-width: min(420px, calc(100vw - 28px));
  padding: 14px;
  border: 1px solid var(--edge-strong);
  border-radius: 0;
  color: var(--text);
  background: var(--raised);
  box-shadow: var(--starsector-inset), var(--starsector-glow);
}

dialog::backdrop {
  background: rgb(2 5 8 / 82%);
}

dialog p {
  margin: 0 0 14px;
}

.arts-index {
  min-height: 100dvh;
  overflow: auto;
}

.collection-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.collection-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
}

.collection-header h1 {
  margin: 0;
  padding: 0.4rem 0.62rem;
  border: 1px solid var(--starsector-title-edge);
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.collection-home {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-underline-offset: 3px;
}

.collection-home:hover,
.collection-home:focus-visible {
  color: var(--hot);
}

.craft-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.craft-link {
  display: grid;
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  grid-template-rows: auto 1fr;
}

.craft-link:hover,
.craft-link:focus-visible {
  border-color: var(--hot);
  outline: 1px solid var(--hot);
  outline-offset: 2px;
}

.craft-link img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-bottom: 1px solid var(--edge);
  object-fit: cover;
}

.craft-copy {
  display: grid;
  padding: 12px 14px 14px;
  align-content: start;
  gap: 5px;
}

.craft-copy h2,
.craft-copy p {
  margin: 0;
}

.craft-copy h2 {
  color: var(--hot);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.craft-copy p {
  color: var(--muted);
  font-family: var(--starsector-font-mono);
  font-size: 0.78rem;
  line-height: 1.35;
}

html.layout-stacked .workbench {
  grid-template-areas:
    "title download"
    "controls controls"
    "preview preview";
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, var(--controls-height)) auto;
  align-content: start;
  align-items: start;
  justify-items: stretch;
  gap: 8px;
}

html.layout-stacked .lane-title {
  justify-self: start;
}

html.layout-stacked .lane-title h1 {
  padding: 4px 7px;
  font-size: clamp(15px, 3.9vw, 18px);
}

html.layout-stacked .home-link {
  display: none;
}

html.layout-stacked .lane-download {
  width: auto;
  height: auto;
  align-self: start;
  justify-self: stretch;
}

html.layout-stacked .action-stack {
  grid-template-columns: repeat(var(--action-count), minmax(0, 1fr));
  gap: 4px;
}

html.layout-stacked .action-stack button {
  min-width: 0;
  padding: 4px 3px;
  overflow: hidden;
  font-size: clamp(8px, 2.45vw, 10px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.layout-stacked .controls,
html.layout-stacked .stage-column {
  justify-self: center;
}

.hyperkiki-app {
  --action-count: 5;
}

.tongues-app {
  --action-count: 3;
}

@media (max-width: 700px) {
  .collection-shell {
    padding: 16px 12px 28px;
  }

  .collection-header {
    align-items: start;
    flex-direction: column;
    gap: 9px;
  }

  .craft-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}
