:root {
  --bg: #d6d6d6;
  --panel: #f2f2f2;
  --panel2: #ffffff;
  --text: #111;
  --muted: #555;
  --line: #8b8b8b;
  --line2: #c5c5c5;
  --header: #20242b;
  --headerText: #fff;
  --blue: #245cc7;
  --blue2: #1746a2;
  --danger: #b00020;
  --boardBg: #ffffff;
  --boardOuter: #d8d8d8;
  --boardSurface: #ffffff;
  --boardHeader: #f7f7f7;
  --boardBorder: #111111;
  --grid100: rgba(0,0,0,.08);
  --grid10: rgba(0,0,0,.055);
  --grid1: rgba(0,0,0,.10);
  --minimapOuter: #e9e9e9;
  --minimapClaim: #d0d0d0;
  --minimapBorder: #555555;
  --minimapViewport: #245cc7;
}

body.dark {
  --bg: #181b20;
  --panel: #22262d;
  --panel2: #1b1f25;
  --text: #eceff4;
  --muted: #b7bec8;
  --line: #505967;
  --line2: #39414d;
  --header: #101319;
  --headerText: #f5f7fa;
  --blue: #3d78e7;
  --blue2: #2d62c5;
  --danger: #c53b57;
  --boardBg: #101319;
  --boardOuter: #0f1318;
  --boardSurface: #11161d;
  --boardHeader: #1a1f26;
  --boardBorder: #8b94a4;
  --grid100: rgba(255,255,255,.18);
  --grid10: rgba(255,255,255,.11);
  --grid1: rgba(255,255,255,.18);
  --minimapOuter: #20252d;
  --minimapClaim: #5b6573;
  --minimapBorder: #77808d;
  --minimapViewport: #6ea0ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 12px;
  background: var(--header);
  color: var(--headerText);
  border-bottom: 2px solid #111;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: #fff;
  color: #111;
  border: 1px solid #111;
  font-weight: 700;
  font-size: 11px;
}
.brand h1 { margin: 0; font-size: 18px; line-height: 1; white-space: nowrap; }
.brand p { margin: 2px 0 0; color: #c7cbd3; font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.layout {
  height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
}
.sidebar {
  overflow: auto;
  padding: 8px;
  background: color-mix(in srgb, var(--bg) 88%, #bcbcbc 12%);
  border-right: 1px solid var(--line);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  margin-bottom: 8px;
  padding: 10px;
}
.panel h2 { margin: 0 0 8px; font-size: 15px; }
.note { color: var(--muted); font-size: 12px; line-height: 1.35; margin: 6px 0; }

.boxline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line2);
  background: var(--panel2);
  padding: 7px;
  margin: 7px 0;
}
.bundleGrid, .modeGrid {
  display: grid;
  gap: 5px;
  margin: 7px 0;
}
.bundleGrid { grid-template-columns: 1fr 1fr 1fr; }
.modeGrid.three { grid-template-columns: 1fr 1fr 1fr; }
.bundleGrid .button, .modeGrid .button { padding: 6px 4px; line-height: 1.15; }
.bundleGrid span { font-size: 11px; color: var(--muted); }
.button.primary span { color: #fff; }

.fields { display: grid; gap: 7px; margin: 7px 0; }
.fields.two { grid-template-columns: 1fr 1fr; align-items: end; }
.fields.customCredits { grid-template-columns: 1fr 110px; align-items: end; }
label { display: grid; gap: 4px; color: var(--text); font-size: 12px; }
input, textarea, select {
  width: 100%;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  padding: 6px;
  outline: none;
}
input[type="color"] { height: 38px; padding: 2px; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.checkline { display: flex; align-items: flex-start; gap: 8px; margin: 4px 0; }
.checkline input { width: auto; margin-top: 2px; }

.button {
  border: 1px solid var(--line);
  padding: 7px 9px;
  color: var(--text);
  background: var(--panel2);
}
.button:hover { filter: brightness(1.04); }
.button.primary {
  border-color: #113d90;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}
.button.primary:hover { background: var(--blue2); }
.button.danger {
  border-color: #7a0014;
  color: #fff;
  background: var(--danger);
}
.full { width: 100%; margin-top: 6px; }

.boardShell { min-width: 0; overflow: hidden; background: var(--boardOuter); position: relative; }
.boardHeader {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px;
  background: var(--boardHeader);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--text);
}
#coordReadout { white-space: nowrap; }
#boardCanvas {
  width: 100%;
  height: calc(100vh - 48px - 30px);
  display: block;
  background: var(--boardBg);
  cursor: crosshair;
}
body.panMode #boardCanvas { cursor: grab; }
body.panMode #boardCanvas:active { cursor: grabbing; }

.overlay {
  position: absolute;
  z-index: 5;
}
.topRight { top: 38px; right: 12px; }
.bottomRight { right: 12px; bottom: 12px; }
#minimapCanvas {
  width: 160px;
  height: 160px;
  border: 1px solid var(--line);
  background: var(--panel2);
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.controlsBar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.floatingBtn {
  min-width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.floatingBtn:hover { filter: brightness(1.05); }
.floatingToggle { min-width: 60px; }

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}
.modal::backdrop { background: rgba(0,0,0,.45); }
.modalCard {
  position: relative;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 34px);
  overflow: auto;
  padding: 16px;
  background: var(--panel2);
  border: 2px solid #222;
  box-shadow: 6px 6px 0 rgba(0,0,0,.3);
  display: grid;
  gap: 10px;
}
.rulesCard { width: min(760px, calc(100vw - 24px)); }
.rulesCard li { margin: 7px 0; }
.close {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}
.modalActions { display: flex; gap: 8px; flex-wrap: wrap; }
.knownAccounts { border-top: 1px solid var(--line2); padding-top: 10px; display: grid; gap: 6px; }
.accountRow { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid var(--line2); padding: 6px; }
.accountRow span { font-size: 12px; color: var(--text); }

@media (max-width: 850px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .layout { height: auto; min-height: calc(100vh - 48px); grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  #boardCanvas { height: 64vh; }
  .topRight { top: 38px; right: 8px; }
  #minimapCanvas { width: 120px; height: 120px; }
}

textarea { min-height: 120px; resize: vertical; }
