:root {
  color-scheme: dark;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: #111315;
  color: #eef1f4;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #111315;
}

#sim-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: #08090a;
  cursor: grab;
}

#sim-canvas.dragging {
  cursor: grabbing;
}

.panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: min(430px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 14px;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 8px;
  background: rgb(18 21 24 / 92%);
  box-shadow: 0 16px 48px rgb(0 0 0 / 38%);
}

.panel-header {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
}

.title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.small-header-button {
  width: auto;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.panel.collapsed {
  width: min(430px, calc(100vw - 32px));
  overflow: hidden;
}

.panel.collapsed .panel-header {
  margin-bottom: 0;
}

.panel.collapsed .panel-body {
  display: none;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
}

#status-line {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: #aab2bd;
  font-size: 13px;
  line-height: 1.25;
}

.control-section {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid rgb(255 255 255 / 10%);
}

label {
  display: grid;
  gap: 6px;
  color: #d9dee5;
  font-size: 13px;
  font-weight: 650;
}

.label-row {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.info-icon {
  position: relative;
  display: inline-grid;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 999px;
  color: #9fc9ff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  cursor: help;
}

.global-tooltip {
  position: fixed;
  z-index: 9999;
  width: min(270px, calc(100vw - 64px));
  padding: 8px 10px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 999px;
  background: #edf6ff;
  box-shadow: 0 10px 30px rgb(0 0 0 / 34%);
  color: #16202a;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, calc(-100% + 4px));
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

.global-tooltip.visible {
  opacity: 1;
  transform: translate(-50%, -100%);
}

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

select,
input,
button {
  width: 100%;
}

select,
input[type="number"],
input[type="text"],
button {
  height: 36px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 6px;
  background: #20262c;
  color: #f4f7fb;
  font: inherit;
}

button {
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: #2b333b;
}

select:disabled,
input:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:disabled:hover {
  background: #20262c;
}

input[type="range"] {
  accent-color: #55a7ff;
}

input[type="number"],
input[type="text"] {
  padding: 0 10px;
  font: inherit;
}

input[type="color"] {
  height: 34px;
  padding: 2px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 6px;
  background: #20262c;
}

.inline-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.inline-control input {
  width: 16px;
  height: 16px;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  padding: 12px 0;
  border-top: 1px solid rgb(255 255 255 / 10%);
}

.two-column-row,
.piece-add-row,
.anchor-row,
.radius-row,
.inline-setting-row,
.split-setting-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.inline-setting-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.inline-setting-row > select,
.inline-setting-row > input {
  width: min(190px, 42vw);
}

.compact-setting-row {
  grid-template-columns: auto minmax(140px, 190px);
  justify-content: start;
}

.compact-setting-row > select {
  width: 180px;
}

.inline-setting-row > .inline-control {
  padding-left: 10px;
  border-left: 1px solid rgb(255 255 255 / 12%);
}

.split-setting-row {
  grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1fr);
  align-items: stretch;
}

.setting-pair {
  align-content: end;
}

.row-divider {
  width: 1px;
  min-height: 52px;
  background: rgb(255 255 255 / 12%);
}

.checkbox-pair .inline-control {
  min-height: 36px;
}

.radius-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.visual-progress {
  align-self: end;
  min-height: 36px;
  padding-left: 12px;
  border-left: 1px solid rgb(255 255 255 / 12%);
  white-space: nowrap;
}

.is-disabled {
  opacity: 0.45;
}

.separated-row > * + * {
  padding-left: 12px;
  border-left: 1px solid rgb(255 255 255 / 12%);
}

.invalid-input {
  border-color: #ff6b6b !important;
  color: #ffb4b4 !important;
  background: #321d22 !important;
}

.offset-input-wrap {
  position: relative;
  display: block;
}

.offset-input-wrap input {
  position: relative;
  z-index: 1;
}

.offset-input-wrap.invalid-offset input.invalid-input {
  color: transparent !important;
  caret-color: #f4f7fb;
}

.offset-input-highlight {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  align-items: center;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  overflow: hidden;
  color: #f4f7fb;
  font: inherit;
  line-height: 36px;
  pointer-events: none;
  white-space: pre;
}

.offset-input-wrap.invalid-offset .offset-input-highlight {
  display: flex;
}

.offset-input-highlight .invalid-char {
  color: #ff6b6b;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

.offset-input-highlight .valid-char {
  color: #f4f7fb;
}

#prime-color-controls {
  display: grid;
  gap: 6px;
}

#prime-divisor-label {
  margin-bottom: 0;
}

#continuous-offset-group.is-disabled {
  opacity: 0.45;
}

.piece-add-row label {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.anchor-row label {
  grid-template-columns: auto 56px;
  justify-content: start;
  align-items: center;
}

.piece-add-row label {
  min-width: 0;
}

.anchor-row input[type="color"] {
  justify-self: start;
  width: 56px;
}

.piece-add-row button {
  grid-column: 1 / -1;
}

.piece-add-row {
  margin-bottom: 8px;
}

.army-list {
  display: grid;
  gap: 6px;
}

.army-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 42px 42px 42px;
  gap: 6px;
  align-items: center;
  min-height: 36px;
  cursor: grab;
}

.army-empty-row {
  min-height: 36px;
  border: 1px dashed rgb(255 255 255 / 14%);
  border-radius: 6px;
}

.army-row:active {
  cursor: grabbing;
}

.army-row span {
  min-width: 0;
  overflow: hidden;
  color: #eef1f4;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.army-row .army-swatch {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 999px;
}

.army-row button {
  height: 34px;
  padding: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 1;
}

.log-section {
  gap: 6px;
}

#placement-log {
  max-height: 180px;
  margin: 0;
  overflow: auto;
  padding: 8px;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 6px;
  background: #090b0d;
  color: #cbd5df;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
  white-space: pre-wrap;
}

@media (max-width: 520px) {
  .panel {
    top: 8px;
    left: 8px;
    width: calc(100vw - 16px);
    max-height: min(58vh, calc(100vh - 16px));
  }

  .split-setting-row {
    grid-template-columns: 1fr;
  }

  .row-divider {
    width: 100%;
    min-height: 1px;
    height: 1px;
  }
}
