* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #050807;
  color: #fff;
  font: 13px sans-serif;
}

body {
  overflow-x: hidden;
}

.page {
  min-height: 100vh;
  padding: 12px;
}

.topbar,
.constructor {
  padding: 8px;
  background: rgba(20, 20, 20, 0.88);
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

.backLink {
  display: inline-block;
  margin-bottom: 6px;
  color: #aaa;
  text-decoration: none;
}

.backLink:hover {
  color: #fff;
}

.headingRow,
.constructorHeader,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.headingRow {
  justify-content: space-between;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  font-weight: 600;
}

h2 {
  font-size: 15px;
  font-weight: 600;
}

.headingRow p,
.constructorHeader p,
.matrixHint {
  margin-top: 3px;
  color: #888;
  font-size: 11px;
}

.fpsReadout {
  color: #00ff66;
  font-variant-numeric: tabular-nums;
}

.performanceReadout {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  text-align: right;
}

.fpsWarning {
  color: #ffd166;
  font-size: 11px;
}

.compatibilityNote {
  color: #888;
  font-size: 11px;
}

.toolbar {
  align-items: end;
  margin-top: 8px;
}

.field {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #fff;
  white-space: nowrap;
}

.sliderField {
  flex-direction: column;
  align-items: flex-start;
}

input,
select,
button {
  min-height: 30px;
  padding: 5px 8px;
  background: #222;
  color: #eee;
  border: 1px solid #444;
  border-radius: 4px;
  font: inherit;
}

button,
select,
input[type="range"] {
  cursor: pointer;
}

button:hover,
select:hover,
input:hover {
  background: #333;
}

input[type="range"] {
  width: 130px;
  min-height: auto;
  accent-color: #00ff66;
}

output {
  color: #aaa;
  font-variant-numeric: tabular-nums;
}

.totalParticles {
  color: #888;
  font-size: 11px;
}

.canvasShell {
  height: min(64vh, 680px);
  min-height: 300px;
  margin: 8px 0;
  overflow: hidden;
  border: 1px solid #1f2b25;
  border-radius: 6px;
  background: #050807;
}

#simulation {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.constructorHeader {
  justify-content: space-between;
  align-items: end;
}

.presetControls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.matrix {
  display: grid;
  gap: 3px;
  width: min(100%, 570px);
  margin-top: 10px;
  overflow-x: auto;
}

.matrixCorner,
.matrixLabel,
.matrixCell {
  min-width: 58px;
  min-height: 42px;
}

.matrixCorner,
.matrixLabel {
  display: grid;
  place-items: center;
  color: #aaa;
  font-size: 11px;
}

.matrixLabel {
  border-left: 3px solid var(--species-color);
}

.matrixCell {
  width: 100%;
  padding: 4px;
  border: 1px solid #333;
  border-radius: 3px;
  color: #fff;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.matrixCell:focus {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.matrixHint {
  margin-top: 8px;
}

.shareControls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  color: #aaa;
}

.shareControls input {
  min-width: min(520px, 100%);
  flex: 1 1 280px;
  font-family: monospace;
}

.shareControls output {
  color: #00ff66;
  font-size: 11px;
}

@media (max-width: 760px) {
  .toolbar,
  .constructorHeader,
  .presetControls {
    align-items: stretch;
  }

  .field,
  .sliderField,
  .presetControls button,
  .presetControls select {
    flex: 1 1 auto;
  }

  .sliderField input[type="range"] {
    width: 100%;
  }

  .canvasShell {
    height: 52vh;
  }
}
