:root {
  --bg: #14161b;
  --panel: #1c2027;
  --panel-2: #232833;
  --line: #333a47;
  --text: #e6e9ef;
  --muted: #98a1b2;
  --accent: #f0b429;
  --bad: #ff8f8f;
  --wood: #8fd18b;
  --iron: #9cc2e8;
  --workers: #d7bd8a;
  --soldiers: #e59a9a;
  --efficiency: #c2a8e0;

  --col-left: 215px;
  --col-board: 662px;
  --col-right: 250px;
  --col-gap: 16px;
}

.tiled {
  background-image:
    var(--terrain-img, none),
    url("https://www.factions-online.com/map/base_objects.png");
  background-size: 1700% 3187.5%, 850% 1806.25%;
  background-position: var(--terrain-pos, 0 0), 0.4166667% 0.1831502%;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 {
  font-size: 17px;
  margin: 0;
  letter-spacing: 0.3px;
}

h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin: 0 0 8px;
}

.wrap {
  width: calc(var(--col-left) + var(--col-board) + var(--col-right) + 2 * var(--col-gap));
  max-width: 100%;
  margin: 0 auto;
}

/* ---------- top bar ---------- */

.topbar {
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar .wrap {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.field input {
  width: 58px;
  padding: 5px 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
}

.count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
  padding: 4px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.count.at-cap {
  color: var(--accent);
  border-color: var(--accent);
}

.status {
  font-size: 12px;
  color: var(--accent);
  min-height: 1em;
  flex: 1 1 12ch;
}

.status.error {
  color: var(--bad);
}

.totals {
  display: flex;
  gap: 16px;
  margin-left: auto;
}

.total {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.total-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.total-value {
  font-variant-numeric: tabular-nums;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.1;
}

.total-main {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.total-global {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.total-sub .total-global {
  margin-right: 3px;
}

.total-sub {
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* ---------- the right-hand column ---------- */

.side-column {
  display: grid;
  gap: var(--col-gap);
  align-content: start;
  min-width: 0;
}

.stat-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  margin: 0;
  align-items: baseline;
}

.stat-list dt {
  font-size: 11px;
  color: var(--muted);
}

.stat-list dd {
  margin: 0;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

button {
  padding: 6px 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

button:hover {
  border-color: #4b566b;
}

.settings-open {
  flex: none;
  background: transparent;
  color: var(--muted);
}

.settings-open:hover {
  color: var(--text);
}

/* ---------- layout ---------- */

main.wrap {
  display: grid;
  grid-template-columns: var(--col-left) var(--col-board) var(--col-right);
  gap: var(--col-gap);
  padding: 16px 0 28px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

/* ---------- sidebar views and help ---------- */

.view-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
}

.view-tab {
  flex: 1;
  padding: 6px 0;
  text-align: center;
}

.view-tab[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--panel-2);
}

.help {
  flex: none;
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  line-height: 20px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  cursor: help;
  user-select: none;
}

.help:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--panel-2);
}

h3>.help {
  margin-left: 4px;
  vertical-align: middle;
}

/* ---------- palette ---------- */

.palette-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px;
  margin-bottom: 12px;
}

.tier-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 9px;
}

.tier-tab {
  flex: 1;
  padding: 5px 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

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

#building-palette {
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.swatch {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 7px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  text-align: left;
  width: 100%;
}

.swatch:hover {
  background: var(--panel-2);
}

.swatch[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--panel-2);
}

.swatch-chip {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.45);
  flex: none;
  display: grid;
  place-items: center;
  background-color: var(--panel-2);
  overflow: hidden;
}

.swatch-chip img {
  width: 18px;
  height: 18px;
  image-rendering: pixelated;
}

.swatch-name {
  flex: 1;
}

.swatch-key {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.swatch-count {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.swatch.at-limit {
  opacity: 0.5;
}

.swatch.at-limit .swatch-count {
  color: var(--accent);
}

.hint {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0;
}

.rotate-hint {
  margin-top: 8px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--text);
}

kbd {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  font: inherit;
  font-size: 0.92em;
}

.build-level {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.build-level input {
  width: 62px;
  padding: 5px 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
}

.build-level input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

#build-level-note {
  margin-top: 4px;
}

/* ---------- the solver ---------- */

.goal-list {
  list-style: decimal inside;
  margin: 8px 0;
  padding: 0;
  font-size: 12px;
}

.goal {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 2px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-2);
}

.goal+.goal {
  margin-top: 3px;
}

.goal:first-child .goal-name {
  color: var(--accent);
}

.goal-name {
  flex: 1;
  min-width: 0;
}

.goal-move {
  padding: 1px 5px;
  font-size: 10px;
  line-height: 1.4;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.goal-move:hover:enabled {
  border-color: var(--line);
  color: var(--text);
}

.goal-move:disabled {
  opacity: 0.25;
  cursor: default;
}

.goal-mode {
  margin: 0 0 8px;
  font-size: 11.5px;
}

.goal-weight {
  width: 44px;
  padding: 2px 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.goal-add {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.goal-add select {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.goal-reading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.goal-reading select {
  min-width: 0;
  flex: 1;
  padding: 5px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.goal-add select:disabled,
#add-goal:disabled {
  opacity: 0.5;
  cursor: default;
}

#add-goal {
  flex: none;
}

#solve {
  width: 100%;
  margin-bottom: 6px;
}

#solve[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.solve-result {
  margin-top: 8px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  line-height: 1.5;
}

.terrain-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

#terrain-toggle {
  width: 100%;
}

#terrain-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

#terrain-editor {
  margin-top: 12px;
}

/* ---------- board bar ---------- */

.board-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.board-bar button:disabled {
  opacity: 0.4;
  cursor: default;
}

.board-bar button:disabled:hover {
  border-color: var(--line);
}

.history-step {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 5ch;
}

#share-open {
  margin-left: auto;
}

/* ---------- the export box ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-card {
  position: relative;
  width: 560px;
  max-width: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
}

.modal-close {
  margin-left: auto;
  padding: 2px 8px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 13px;
}

.modal-close:hover {
  color: var(--text);
}

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  width: 100%;
  aspect-ratio: 1;
  padding: 2px;
  background: var(--line);
  border-radius: 6px;
  touch-action: none;
}

.tile {
  position: relative;
  padding: 0;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  overflow: hidden;
}

.tile.grabbable {
  cursor: grab;
}

.tile.terrain-mode {
  cursor: crosshair;
}

.tile.no-build {
  cursor: not-allowed;
}

.tile.no-build::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg,
      rgba(0, 0, 0, 0.16) 0 3px,
      rgba(0, 0, 0, 0) 3px 7px);
}

.tile:hover {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
}

.tile.selected {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.tile.drag-source .frame {
  opacity: 0.22;
}

.tile.drop-ok {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.tile.drop-bad {
  box-shadow: inset 0 0 0 3px var(--bad);
}

.tile img {
  position: absolute;
  image-rendering: pixelated;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55));
}

.tile .frame {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-position: center;
  background-size: 75% 75%;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  pointer-events: none;
}

.tile .frame .art {
  position: static;
  width: 55%;
  height: 55%;
  object-fit: contain;
}

.tile img.ghost,
.tile .frame.ghost {
  opacity: 0.5;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.tile img.ghost-bad,
.tile .frame.ghost-bad {
  opacity: 0.3;
  filter: grayscale(1);
}

.tile .frame.ghost .art.ghost,
.tile .frame.ghost-bad .art.ghost-bad {
  opacity: 1;
}

.tile.spanning {
  overflow: visible;
  z-index: 2;
}

.tile .frame.span-h {
  transform: translateX(calc(50% + 1px));
}

.tile .frame.span-v {
  transform: translateY(calc(50% + 1px));
}

.tile .frame .seal {
  top: 12.5%;
  right: 12.5%;
  width: 22%;
  height: 22%;
  filter: drop-shadow(0 0 2px #000) drop-shadow(0 0 2px #000);
}

.tile .level {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
  pointer-events: none;
}

.tile .yield {
  position: absolute;
  left: 2px;
  top: 1px;
  font-size: 9px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
  pointer-events: none;
  line-height: 1.1;
  text-align: left;
}

.tile .yield .cap {
  opacity: 0.75;
  font-weight: 600;
}

/* ---------- inspector ---------- */

.inspector dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: 3px 10px;
  margin: 0 0 12px;
  font-size: 12.5px;
}

.inspector dt {
  color: var(--muted);
}

.inspector dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inspector h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin: 14px 0 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.level-editor {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.level-editor input {
  width: 62px;
  padding: 5px 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
}

.level-editor button {
  width: 28px;
  padding: 6px 0;
}

.seal-picker {
  margin-bottom: 10px;
}

.seal-buttons {
  display: flex;
  gap: 6px;
  margin: 5px 0 6px;
}

.seal-swatch {
  width: 32px;
  height: 32px;
  padding: 3px;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
}

.seal-swatch img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

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

.seal-swatch:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.seal-picker.no-seal>.hint:first-child {
  opacity: 0.5;
}

/* ---------- game modifiers ---------- */

details.panel {
  grid-column: 1 / -1;
}

details.panel summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

details.panel summary::-webkit-details-marker {
  display: none;
}

details.panel summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 11px;
}

details.panel[open] summary::before {
  content: "▾";
}

details.panel summary h2 {
  margin: 0;
}

.modifiers-set {
  color: var(--accent);
}

.modifiers-body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 20px 26px;
  margin-top: 12px;
  align-items: start;
}

.modifier-group {
  min-width: 0;
}

/* The wide table stands beside both narrow groups rather than under one. */
.modifier-group-wide {
  grid-row: span 2;
}

/* Nine columns is more than a narrow window has room for; the table scrolls
   inside its own group rather than pushing the page sideways. */
.modifier-scroll {
  overflow-x: auto;
}

.modifier-group h3 {
  margin: 0 0 3px;
  font-size: 12px;
  font-weight: 600;
}

.modifier-group .hint {
  margin-bottom: 8px;
  max-width: 46ch;
}

.modifier-scalars {
  display: grid;
  gap: 5px;
}

.modifier-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.modifier-field em {
  font-style: normal;
  font-size: 10px;
  opacity: 0.7;
}

.modifier-field>span:first-child {
  flex: 1;
}

.modifier-unit {
  opacity: 0.6;
}

.modifier-table {
  border-collapse: collapse;
  font-size: 11px;
  color: var(--muted);
}

.modifier-table th {
  font-weight: 600;
  text-align: center;
  padding: 0 4px 4px;
  white-space: nowrap;
}

.modifier-table td {
  padding: 2px 4px 2px 0;
}

.modifier-row-name {
  text-align: right;
  padding-right: 8px;
  white-space: nowrap;
}

.modifier-input {
  width: 62px;
  padding: 4px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.modifier-input.modifier-on {
  border-color: var(--accent);
  color: var(--accent);
}

/* Eight of them across, so they give up what the standalone boxes can spare. */
.modifier-table .modifier-input {
  width: 54px;
}

/* Sized to end where the boxes above it do, so the column keeps one edge. */
.modifier-select {
  width: 94px;
  padding: 4px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.modifier-select.modifier-on {
  border-color: var(--accent);
  color: var(--accent);
}

/* It answers for every group, so it sits under all of them rather than in the
   column the last one happened to leave room in. */
.modifiers-foot {
  grid-column: 1 / -1;
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.inspector-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
}

.empty {
  color: var(--muted);
  font-size: 12.5px;
  margin: 0;
}

.wood-value {
  color: var(--wood);
}

.iron-value {
  color: var(--iron);
}

.workers-value {
  color: var(--workers);
}

.soldiers-value {
  color: var(--soldiers);
}

.efficiency-value {
  color: var(--efficiency);
}

/* ---------- settings ---------- */

.setting+.setting {
  margin-top: 14px;
}

.setting-name {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.choice {
  display: flex;
  gap: 4px;
}

.choice button {
  flex: 1;
  padding: 7px 0;
  text-align: center;
}

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

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

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

#compute-note,
#effort-note {
  margin-top: 8px;
}

.effort-fields {
  display: grid;
  grid-template-columns: auto 90px 1fr;
  align-items: center;
  gap: 6px 10px;
  margin-top: 10px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.effort-fields label {
  display: contents;
  font-size: 12px;
  color: var(--muted);
}

.effort-fields input {
  width: 100%;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.effort-fields .hint {
  font-size: 11px;
}

.effort-fields input:disabled {
  opacity: 0.75;
  cursor: default;
}

/* ---------- export and import ---------- */

#share-text {
  width: 100%;
  padding: 7px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: 11px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  resize: vertical;
  overflow-wrap: anywhere;
}

#share-text:focus {
  outline: none;
  border-color: var(--accent);
}

.share-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.share-actions .checkbox {
  margin-left: 6px;
}

#share-note {
  margin-top: 8px;
}

@media (max-width: 1180px) {
  .wrap {
    width: 100%;
  }

  main.wrap {
    grid-template-columns: var(--col-left) minmax(0, 1fr) var(--col-right);
    padding: 16px 16px 28px;
  }
}

@media (max-width: 860px) {
  main.wrap {
    grid-template-columns: 1fr;
  }

  .board {
    max-width: var(--col-board);
    margin: 0 auto;
  }
}