:root {
  --bg: #090c12;
  --panel: #111622;
  --panel-2: #171e2e;
  --border: #242d42;
  --text: #e9eef7;
  --muted: #8a95ad;
  --accent: #4aa8ff;
  --green: #3dd68c;
  --yellow: #f7c948;
  --red: #f26d6d;
  --purple: #d07dff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(17, 22, 34, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.offline { background: var(--red); }
.dot.auth { background: var(--yellow); }

.badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.badge.dry { background: #18304d; color: var(--accent); }
.badge.live { background: #451c24; color: var(--red); }

.pill {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 14px;
  padding: 14px;
  max-width: 1480px;
  margin: 0 auto;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }
}

.side-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.card-head h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

summary.card-head {
  list-style: none;
  margin-bottom: 0;
  cursor: pointer;
}
summary.card-head::-webkit-details-marker { display: none; }
details[open] summary.card-head { margin-bottom: 12px; }

.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--panel-2);
  color: var(--text);
}

.seg-full {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
}

.seg-two {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  width: 100%;
}

.seg-four {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
}

.seg-xs .seg-btn {
  padding: 3px 7px;
  font-size: 11px;
}

.slider-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

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

.slider-head .accent {
  color: var(--text);
  font-size: 13px;
}

.range {
  width: 100%;
  accent-color: var(--accent);
  height: 26px;
  cursor: pointer;
}

.end-after-box {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sec-inline {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sec-inline input {
  width: 68px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  text-align: right;
}

.frame-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05070b;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

#frameImg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(9, 12, 18, 0.88);
  text-align: center;
  padding: 16px;
}

.action-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 560px) {
  .action-bar {
    grid-template-columns: repeat(2, 1fr);
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:active { transform: scale(0.98); }
.btn.ghost { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.btn.primary { background: #1e4b85; border-color: #3678cb; color: #fff; }
.btn.warn { background: #3b2d14; border-color: #7d5b1e; color: var(--yellow); }
.btn.danger { background: #5a1f28; border-color: #b43c4d; color: #fff; }
.btn.danger-outline { background: transparent; border-color: #7c313d; color: var(--red); }
.btn.full { width: 100%; margin-top: 8px; }

.thought {
  background: #0d1524;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 10px;
}

.loot-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.loot-chip {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.loot-chip.gold b { color: var(--yellow); }
.loot-chip.elixir b { color: var(--purple); }
.loot-chip.de b { color: #b7c3d9; }
.loot-chip.sum b { color: var(--green); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 700; margin-top: 2px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

.toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.timeline {
  max-height: 320px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.t-row {
  padding: 7px 6px;
  border-bottom: 1px solid #1d2436;
}
.t-row .st { color: var(--green); font-weight: 700; }
.t-row .act { color: var(--yellow); display: block; margin-top: 2px; word-break: break-word; }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: #1b283f;
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 13px;
  max-width: 92vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.modal {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  width: min(460px, 94vw);
  padding: 0;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.72); }
.modal-body { padding: 16px; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.bldg-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.bldg-toolbar .btn.primary {
  flex: 1;
}

.bldg-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bldg-mini-actions {
  display: flex;
  gap: 6px;
}

.btn.xs {
  min-height: 26px;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 6px;
}

.bldg-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 310px;
  overflow-y: auto;
}

.bldg-empty {
  padding: 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.bldg-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.bldg-card.status-completed { opacity: 0.55; }
.bldg-card.status-skipped { border-color: #7d5b1e; }

.bldg-thumb {
  width: 184px;
  max-width: 56%;
  height: auto;
  border-radius: 6px;
  border: 1px solid #2b354d;
  flex: none;
  display: block;
}

.bldg-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.bldg-cost {
  font-size: 12px;
  font-weight: 700;
}
.bldg-cost.gold { color: var(--yellow); }
.bldg-cost.elixir { color: var(--purple); }
.bldg-cost.dark_elixir { color: #b7c3d9; }

.bldg-tag {
  display: inline-block;
  width: fit-content;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.bldg-tag.pending { color: var(--accent); background: #13253d; }
.bldg-tag.completed { color: var(--green); background: #113022; }
.bldg-tag.skipped { color: var(--yellow); background: #382a10; }

.bldg-controls {
  display: flex;
  gap: 4px;
  flex: none;
}

.icon-btn {
  min-width: 30px;
  min-height: 30px;
  padding: 0 6px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn.add { background: #19422f; border-color: #2c7a56; color: var(--green); }
.icon-btn.del { background: #3b1920; border-color: #7c313d; color: var(--red); }
.icon-btn:active { transform: scale(0.95); }
