:root {
  color-scheme: dark;
  --bg: #14120f;
  --panel: #221e18;
  --line: #3c342a;
  --text: #f4ecdf;
  --muted: #b4a58e;
  --gold: #e0b15a;
  --green: #8fbf78;
  --blue: #8eb4d4;
  --red: #d48b7a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Segoe UI", sans-serif;
}

h1, h2, p { margin: 0; }

h1 { font-size: 20px; font-weight: 650; }

h2 {
  margin: 22px 0 8px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.bar, .controls, .flags, .note, .progress, #board {
  padding-left: 20px;
  padding-right: 20px;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
  padding-top: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.title-block { min-width: 220px; }

#status { margin-top: 4px; color: var(--muted); }

.connect, .controls, .flags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }

input, select, button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #16130f;
  color: var(--text);
  padding: 0 8px;
  font: inherit;
}

button { cursor: pointer; background: #2c261e; }

button[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
}

button:disabled { opacity: 0.45; cursor: default; }

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
}

.controls { padding-top: 14px; }

.grow { flex: 1; min-width: 220px; }

.grow input, #host, #slot { width: 100%; }

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

.search-row input { flex: 1; min-width: 0; width: auto; }

.search-row select { width: 124px; }

#host { min-width: 160px; }
#port { width: 90px; }
#slot { min-width: 140px; }

.flags, .note, .progress { padding-top: 10px; color: var(--muted); }

.progress table {
  border-collapse: collapse;
}

.progress th, .progress td {
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.progress th:first-child,
.progress td:first-child { width: 140px; }

.progress th:nth-child(2),
.progress td:nth-child(2),
.progress th:nth-child(3),
.progress td:nth-child(3) {
  width: 88px;
  padding-right: 16px;
  text-align: right;
}

.progress th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.progress th:last-child,
.progress-action {
  width: auto;
  padding-left: 12px;
  border-bottom: 0;
  text-align: left;
  white-space: nowrap;
}

.progress-action button { height: 28px; white-space: nowrap; }

.flags span {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
}

#board { padding-bottom: 40px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 8px;
}

.tile {
  position: relative;
  min-height: 104px;
  padding: 10px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #1c1914;
}

.tile.unlocked { border-color: var(--gold); }

.tile.locked .kind,
.tile.locked .name,
.tile.locked .detail { opacity: 0.45; }

.tile.locked .icon { filter: grayscale(1) brightness(0.72); }

.tile.unreachable { box-shadow: inset 0 0 0 1px #a85a4e; }

.logic {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-top: 12px solid #a85a4e;
  border-right: 12px solid transparent;
}

.gate {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-bottom: 12px solid var(--blue);
  border-right: 12px solid transparent;
}

h2.unreachable { color: #d48b7a; }

.tile-body {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.icon {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  object-fit: contain;
  image-rendering: auto;
}

.fallback {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

body.compact .grid {
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 4px;
}

body.compact .tile {
  min-height: 56px;
  height: 56px;
  padding: 4px;
}

body.compact .tile-copy,
body.compact .kind,
body.compact .name,
body.compact .detail { display: none; }

body.compact .icon,
body.compact .fallback {
  width: 48px;
  height: 48px;
  flex-basis: 48px;
}

body.compact .mark {
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  font-size: 10px;
  line-height: 14px;
}

.kind {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.kind.gear { color: var(--gold); }
.kind.building { color: #c4a27a; }
.kind.resource, .kind.gather { color: var(--green); }
.kind.boss { color: var(--gold); }
.kind.stats { color: var(--red); }
.kind.research { color: var(--blue); }

.name { font-weight: 650; }

.detail {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.pity {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #2a241c;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 12px;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.pity.unknown {
  border-color: var(--line);
  color: var(--muted);
}

body.compact .pity {
  right: 2px;
  bottom: 2px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  font-size: 10px;
  line-height: 12px;
}

.mark {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  color: #1a140c;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  font-weight: 700;
}

.empty { color: var(--muted); padding-top: 16px; }

dialog {
  width: min(440px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  padding: 16px 18px 14px;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

dialog h2 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 16px;
}

dialog p { margin: 0 0 10px; }

.info-links { display: flex; gap: 14px; }

.info-links a { color: var(--gold); }

dialog form { display: flex; justify-content: flex-end; margin-top: 4px; }
